00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef ORO_SIGNAL_BASE_HPP
00040 #define ORO_SIGNAL_BASE_HPP
00041
00042 #include <boost/intrusive_ptr.hpp>
00043 #include <boost/function.hpp>
00044
00045 #include "../rtt-config.h"
00046
00047 #if defined(OROBLD_OS_NO_ASM)
00048 #define ORO_SIGNAL_USE_RT_LIST
00049 #else
00050 #define ORO_SIGNAL_USE_LIST_LOCK_FREE
00051 #endif
00052
00053 #include "../os/Atomic.hpp"
00054 #ifdef ORO_SIGNAL_USE_LIST_LOCK_FREE
00055 #include "ListLockFree.hpp"
00056 #include <boost/shared_ptr.hpp>
00057 #else
00058 #ifdef ORO_SIGNAL_USE_RT_LIST
00059 #include "../os/Mutex.hpp"
00060 #include "../os/rt_list.hpp"
00061 #else
00062 #include "../os/Mutex.hpp"
00063 #include <list>
00064 #endif
00065 #endif
00066
00067 namespace RTT
00068 {
00069 namespace internal {
00070
00071 class SignalBase;
00072
00080 class RTT_API ConnectionBase
00081 {
00082 protected:
00083 RTT_API friend void intrusive_ptr_add_ref(ConnectionBase*);
00084 RTT_API friend void intrusive_ptr_release(ConnectionBase*);
00085 bool mconnected;
00086 SignalBase* m_sig;
00087
00092 os::AtomicInt refcount;
00093
00097 void ref();
00101 void deref();
00102
00103 protected:
00104 virtual ~ConnectionBase();
00105 public:
00106 ConnectionBase(SignalBase* sig);
00107
00108 typedef boost::intrusive_ptr<ConnectionBase> shared_ptr;
00109
00110 inline bool connected() { return mconnected && m_sig; }
00111 bool connect();
00112 bool disconnect();
00113 void destroy();
00114 private:
00115 ConnectionBase(const ConnectionBase& );
00116 const ConnectionBase& operator=( const ConnectionBase& );
00117 };
00118
00119 RTT_API void intrusive_ptr_add_ref( ConnectionBase* p );
00120 RTT_API void intrusive_ptr_release( ConnectionBase* p );
00121
00128 class RTT_API SignalBase
00129 {
00130 public:
00131 typedef ConnectionBase::shared_ptr connection_t;
00132 #ifdef ORO_SIGNAL_USE_LIST_LOCK_FREE
00133 typedef ListLockFree<connection_t> connections_list;
00134 #else
00135 #ifdef ORO_SIGNAL_USE_RT_LIST
00136 typedef RTT::os::rt_list< connection_t > connections_list;
00137 #else
00138 typedef std::list< connection_t > connections_list;
00139 #endif
00140 typedef connections_list::iterator iterator;
00141 typedef connections_list::iterator const_iterator;
00142 #endif
00143 protected:
00144 friend class ConnectionBase;
00145
00146 void conn_setup( connection_t conn );
00147
00148 void conn_connect( connection_t conn );
00149
00150 void conn_disconnect( connection_t conn );
00151
00152 void conn_destroy( connection_t conn );
00153 protected:
00154 connections_list mconnections;
00155 #ifdef ORO_SIGNAL_USE_LIST_LOCK_FREE
00156
00157 #else
00158
00161 void cleanup();
00162
00163 RTT::os::MutexRecursive m;
00164 iterator itend;
00165 #ifdef ORO_SIGNAL_USE_RT_LIST
00166 int disconcount;
00167 #else
00168 int concount;
00169 #endif
00170 #endif
00171 bool emitting;
00172 SignalBase();
00173 public:
00180 virtual ~SignalBase();
00181
00186 void disconnect();
00187
00193 void destroy();
00194
00204 void reserve(size_t conns);
00208 virtual int arity() const = 0;
00209 private:
00210 SignalBase(const SignalBase& );
00211 const SignalBase& operator=( const SignalBase& );
00212
00213 };
00214 }
00215
00216 }
00217 #endif