sigx++ 2.0.1
|
00001 #ifndef _SIGX_CONNECTION_HPP_ 00002 #define _SIGX_CONNECTION_HPP_ 00003 00004 /* 00005 * Copyright 2006 Klaus Triendl 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Library General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Library General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Library General Public 00018 * License along with this library; if not, write to the Free 00019 * Software Foundation, 51 Franklin Street, Fifth Floor, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include <tr1/memory> // std::tr1::shared_ptr 00024 #include <sigxconfig.h> 00025 #include <sigx/fwddecl.h> 00026 #include <sigx/shared_dispatchable.h> 00027 00028 00029 namespace sigx 00030 { 00031 00035 class SIGX_API connection_wrapper 00036 { 00037 private: 00038 // volatile because the value should be always read from the variable itself; 00039 // this is necessary because the sigc::connection* is "late bound", i.e. 00040 // it is set by the server thread after an asynchronous "connect" message. 00041 // When the next tunnel functor is created (let's say with disconnect()) 00042 // then m_sigc_conn is dereferenced (*m_sigc_conn) and the actual pointer 00043 // value (the sigc::connection*) is treated volatile at the other side of 00044 // the tunnel (at the server thread's side). 00045 // It is const because the connection_wrapper object doesn't modify the pointer. 00046 typedef std::tr1::shared_ptr<const volatile sigc_connection_ptr> shared_sigc_conn_ptr; 00047 00048 00049 public: 00052 connection_wrapper(); 00056 connection_wrapper(const shared_dispatchable& _A_disp, const shared_sigc_conn_ptr& _A_conn); 00059 connection_wrapper(const connection_wrapper& other) throw(); 00060 00064 ~connection_wrapper() throw(); 00065 00068 connection_wrapper& operator =(const connection_wrapper& other); 00069 00070 public: 00074 bool empty() const; 00075 00079 bool connected() const; 00080 00084 bool blocked() const; 00085 00089 bool block(bool should_block = true); 00090 00094 bool unblock(); 00095 00099 void disconnect(); 00100 00105 operator bool(); 00106 00107 protected: 00108 void destroy_self(); 00109 00110 00111 private: 00113 shared_sigc_conn_ptr m_sigc_conn; 00116 shared_dispatchable m_shared_disp; 00119 volatile int* m_sigcconn_refcount; 00120 }; 00121 00122 00123 } // namespace sigx 00124 00125 00126 #endif // end file guard