connection_handler.h
Go to the documentation of this file.00001 #ifndef _SIGX_CONNECTION_HANDLER_HPP_
00002 #define _SIGX_CONNECTION_HANDLER_HPP_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <tr1/memory>
00024 #include <map>
00025 #include <sigc++/signal.h>
00026 #include <glib.h>
00027 #include <glibmm/thread.h>
00028 #include <glibmm/main.h>
00029 #include <sigxconfig.h>
00030 #include <sigx/fwddecl.h>
00031 #include <sigx/noninstantiatable.h>
00032 #include <sigx/signal_traits.h>
00033 #include <sigx/signal_source_base.h>
00034 #include <sigx/connection_wrapper.h>
00035
00036
00037 namespace sigx
00038 {
00039
00044 class SIGX_API connection_handler: noninstantiatable
00045 {
00046 public:
00054 static void destroy(const sigc_connection_ptr* handle);
00055
00060 static void store(
00061 const std::tr1::shared_ptr<sigc_connection_ptr>& _A_refconn,
00062 const sigc::connection& c);
00063
00064
00065 protected:
00074 struct connections_container_wrapper
00075 {
00080 typedef std::map<const sigc_connection_ptr* const , std::tr1::shared_ptr<sigc_connection_ptr> > container_type;
00081
00082 container_type m_connections;
00083 ~connections_container_wrapper();
00084 };
00085
00086 static Glib::StaticPrivate<connections_container_wrapper> thread_specific_connections;
00087 };
00088
00089
00090 template<typename T_signal, internal::signal_group I_oneof>
00091 class typed_connection_handler;
00092
00093 template<typename T_signal>
00094 class typed_connection_handler<T_signal, internal::SIGGROUP_SIGC>: noninstantiatable
00095 {
00096 public:
00097 typedef T_signal signal_type;
00098 typedef typename signal_type::slot_type slot_type;
00099
00104 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)
00105 {
00106
00107 g_return_if_fail(psigsource.get());
00108
00109
00110 typedef signal_type (*fp_sig_getter)(signal_source_ptr);
00111 const fp_sig_getter getsig =
00112 reinterpret_cast<fp_sig_getter>(psigsource->getter());
00113
00114
00115 const sigc::connection& c = getsig(psigsource.get()).connect(_A_slot);
00116
00117 connection_handler::store(_A_refconnptr, c);
00118 }
00119 };
00120
00123 template<typename T_signal>
00124 class typed_connection_handler<T_signal, internal::SIGGROUP_GLIB_PROXY>: noninstantiatable
00125 {
00126 public:
00127 typedef T_signal signal_type;
00128 typedef typename signal_type::SlotType slot_type;
00129 typedef typename signal_type::VoidSlotType void_slot_type;
00130
00133 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)
00134 {
00135
00136 g_return_if_fail(psigsource.get());
00137
00138
00139 typedef signal_type (*fp_sig_getter)(signal_source_ptr);
00140 const fp_sig_getter getsig =
00141 reinterpret_cast<fp_sig_getter>(psigsource->getter());
00142
00143
00144 const sigc::connection& c = getsig(psigsource.get()).connect(_A_slot, after);
00145
00146 connection_handler::store(_A_refconnptr, c);
00147 }
00148
00151 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)
00152 {
00153
00154 g_return_if_fail(psigsource.get());
00155
00156
00157 typedef signal_type (*fp_sig_getter)(signal_source_ptr);
00158 const fp_sig_getter getsig =
00159 reinterpret_cast<fp_sig_getter>(psigsource->getter());
00160
00161
00162 const sigc::connection& c = getsig(psigsource.get()).connect_notify(_A_slot, after);
00163
00164 connection_handler::store(_A_refconnptr, c);
00165 }
00166 };
00167
00170 template<>
00171 class SIGX_API typed_connection_handler<Glib::SignalIdle, internal::SIGGROUP_IRRELEVANT>: noninstantiatable
00172 {
00173 public:
00174 typedef Glib::SignalIdle signal_type;
00175 typedef sigc::slot<bool> slot_type;
00176
00179 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);
00180 };
00181
00182
00185 template<>
00186 class SIGX_API typed_connection_handler<Glib::SignalTimeout, internal::SIGGROUP_IRRELEVANT>: noninstantiatable
00187 {
00188 public:
00189 typedef Glib::SignalTimeout signal_type;
00190 typedef sigc::slot<bool> slot_type;
00191
00194 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);
00195 };
00196
00197
00200 template<>
00201 class SIGX_API typed_connection_handler<Glib::SignalIO, internal::SIGGROUP_IRRELEVANT>: noninstantiatable
00202 {
00203 public:
00204 typedef Glib::SignalIO signal_type;
00205 typedef sigc::slot<bool, Glib::IOCondition> slot_type;
00206
00209 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);
00210 };
00211
00212
00215 template<>
00216 class SIGX_API typed_connection_handler<Glib::SignalChildWatch, internal::SIGGROUP_IRRELEVANT>: noninstantiatable
00217 {
00218 public:
00219 typedef Glib::SignalChildWatch signal_type;
00220 typedef sigc::slot<void, GPid, int> slot_type;
00221
00224 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);
00225 };
00226
00227
00228 }
00229
00230
00231 #endif // end file guard