sigx++  2.0.1
connection_handler.h
Go to the documentation of this file.
1 #ifndef _SIGX_CONNECTION_HANDLER_HPP_
2 #define _SIGX_CONNECTION_HANDLER_HPP_
3 
4 /*
5  * Copyright 2005 Klaus Triendl
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the Free
19  * Software Foundation, 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #include <tr1/memory> // std::tr1::shared_ptr
24 #include <map>
25 #include <sigc++/signal.h>
26 #include <glib.h> // message macros
27 #include <glibmm/thread.h> // Glib::StaticPrivate
28 #include <glibmm/main.h>
29 #include <sigxconfig.h>
30 #include <sigx/fwddecl.h>
31 #include <sigx/noninstantiatable.h>
32 #include <sigx/signal_traits.h>
35 
36 
37 namespace sigx
38 {
39 
45 {
46 public:
54  static void destroy(const sigc_connection_ptr* handle);
55 
60  static void store(
61  const std::tr1::shared_ptr<sigc_connection_ptr>& _A_refconn,
62  const sigc::connection& c);
63 
64 
65 protected:
75  {
80  typedef std::map<const sigc_connection_ptr* const /*handle*/, std::tr1::shared_ptr<sigc_connection_ptr> > container_type;
81 
82  container_type m_connections;
84  };
85 
86  static Glib::StaticPrivate<connections_container_wrapper> thread_specific_connections;
87 };
88 
89 
90 template<typename T_signal, internal::signal_group I_oneof>
92 
93 template<typename T_signal>
95 {
96 public:
97  typedef T_signal signal_type;
98  typedef typename signal_type::slot_type slot_type;
99 
104  static void connect(const std::tr1::shared_ptr<sigc_connection_ptr>& _A_refconnptr, const std::tr1::shared_ptr<signal_source_base>& psigsource, const slot_type& _A_slot)
105  {
106  // must have a valid signal source
107  g_return_if_fail(psigsource.get());
108 
109  // get the signal from the signal source ...
110  typedef signal_type (*fp_sig_getter)(signal_source_ptr);
111  const fp_sig_getter getsig =
112  reinterpret_cast<fp_sig_getter>(psigsource->getter());
113 
114  // ... and connect the slot
115  const sigc::connection& c = getsig(psigsource.get()).connect(_A_slot);
116  // ... store the resulting connection in the container of the thread's connections
117  connection_handler::store(_A_refconnptr, c);
118  }
119 };
120 
123 template<typename T_signal>
125 {
126 public:
127  typedef T_signal signal_type;
128  typedef typename signal_type::SlotType slot_type;
129  typedef typename signal_type::VoidSlotType void_slot_type;
130 
133  static void connect(const std::tr1::shared_ptr<sigc_connection_ptr>& _A_refconnptr, const std::tr1::shared_ptr<signal_source_base>& psigsource, const slot_type& _A_slot, bool after)
134  {
135  // must have a valid signal source
136  g_return_if_fail(psigsource.get());
137 
138  // get the signal from the signal source ...
139  typedef signal_type (*fp_sig_getter)(signal_source_ptr);
140  const fp_sig_getter getsig =
141  reinterpret_cast<fp_sig_getter>(psigsource->getter());
142 
143  // ... and connect the slot
144  const sigc::connection& c = getsig(psigsource.get()).connect(_A_slot, after);
145  // ... store the resulting connection in the container of the thread's connections
146  connection_handler::store(_A_refconnptr, c);
147  }
148 
151  static void connect_notify(const std::tr1::shared_ptr<sigc_connection_ptr>& _A_refconnptr, const std::tr1::shared_ptr<signal_source_base>& psigsource, const void_slot_type& _A_slot, bool after)
152  {
153  // must have a valid signal source
154  g_return_if_fail(psigsource.get());
155 
156  // get the signal from the signal source ...
157  typedef signal_type (*fp_sig_getter)(signal_source_ptr);
158  const fp_sig_getter getsig =
159  reinterpret_cast<fp_sig_getter>(psigsource->getter());
160 
161  // ... and connect the slot
162  const sigc::connection& c = getsig(psigsource.get()).connect_notify(_A_slot, after);
163  // ... store the resulting connection in the container of the thread's connections
164  connection_handler::store(_A_refconnptr, c);
165  }
166 };
167 
170 template<>
172 {
173 public:
174  typedef Glib::SignalIdle signal_type;
175  typedef sigc::slot<bool> slot_type;
176 
179  static void connect(const std::tr1::shared_ptr<sigc_connection_ptr>& _A_refconnptr, const std::tr1::shared_ptr<signal_source_base>& psigsource, const slot_type& _A_slot, int priority);
180 };
181 
182 
185 template<>
187 {
188 public:
189  typedef Glib::SignalTimeout signal_type;
190  typedef sigc::slot<bool> slot_type;
191 
194  static void connect(const std::tr1::shared_ptr<sigc_connection_ptr>& _A_refconnptr, const std::tr1::shared_ptr<signal_source_base>& psigsource, const slot_type& _A_slot, unsigned int interval, int priority);
195 };
196 
197 
200 template<>
202 {
203 public:
204  typedef Glib::SignalIO signal_type;
205  typedef sigc::slot<bool, Glib::IOCondition> slot_type;
206 
209  static void connect(const std::tr1::shared_ptr<sigc_connection_ptr>& _A_refconnptr, const std::tr1::shared_ptr<signal_source_base>& psigsource, const slot_type& _A_slot, int fd, Glib::IOCondition condition, int priority);
210 };
211 
212 
215 template<>
217 {
218 public:
219  typedef Glib::SignalChildWatch signal_type;
220  typedef sigc::slot<void, GPid, int> slot_type;
221 
224  static void connect(const std::tr1::shared_ptr<sigc_connection_ptr>& _A_refconnptr, const std::tr1::shared_ptr<signal_source_base>& psigsource, const slot_type& _A_slot, GPid pid, int priority);
225 };
226 
227 
228 } // namespace sigx
229 
230 
231 #endif // end file guard
sigc::slot< bool > slot_type
Definition: connection_handler.h:190
static Glib::StaticPrivate< connections_container_wrapper > thread_specific_connections
Definition: connection_handler.h:86
container_type m_connections
Definition: connection_handler.h:82
sigc::slot< bool > slot_type
Definition: connection_handler.h:175
Definition: fwddecl.h:34
Glib::SignalChildWatch signal_type
Definition: connection_handler.h:219
Glib::SignalTimeout signal_type
Definition: connection_handler.h:189
sigc::connection * sigc_connection_ptr
Definition: fwddecl.h:72
static void connect(const std::tr1::shared_ptr< sigc_connection_ptr > &_A_refconnptr, const std::tr1::shared_ptr< signal_source_base > &psigsource, const slot_type &_A_slot)
Definition: connection_handler.h:104
static void store(const std::tr1::shared_ptr< sigc_connection_ptr > &_A_refconn, const sigc::connection &c)
Stores a sigc::connection in the context of the server thread.
Definition: connection_handler.cpp:40
Stores connections of any client thread to a server thread's signal and destroys them along with the ...
Definition: connection_handler.h:44
T_signal signal_type
Definition: connection_handler.h:97
sigc::slot< bool, Glib::IOCondition > slot_type
Definition: connection_handler.h:205
Definition: signal_traits.h:98
Definition: signal_traits.h:100
static void connect_notify(const std::tr1::shared_ptr< sigc_connection_ptr > &_A_refconnptr, const std::tr1::shared_ptr< signal_source_base > &psigsource, const void_slot_type &_A_slot, bool after)
Definition: connection_handler.h:151
std::map< const sigc_connection_ptr *const , std::tr1::shared_ptr< sigc_connection_ptr > > container_type
a map of connections living in the context of the owner thread.
Definition: connection_handler.h:80
signal_type::VoidSlotType void_slot_type
Definition: connection_handler.h:129
Glib::SignalIO signal_type
Definition: connection_handler.h:204
signal_type::slot_type slot_type
Definition: connection_handler.h:98
Glib::SignalIdle signal_type
Definition: connection_handler.h:174
Definition: auto_dispatchable.h:27
Definition: connection_handler.h:91
Definition: signal_traits.h:99
signal_source_base * signal_source_ptr
Definition: fwddecl.h:71
signal_type::SlotType slot_type
Definition: connection_handler.h:128
static void connect(const std::tr1::shared_ptr< sigc_connection_ptr > &_A_refconnptr, const std::tr1::shared_ptr< signal_source_base > &psigsource, const slot_type &_A_slot, bool after)
Definition: connection_handler.h:133
A Private constructor ensures derived classes cannot be created.
Definition: noninstantiatable.h:33
sigc::slot< void, GPid, int > slot_type
Definition: connection_handler.h:220