00001
00002
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #ifndef PortBase_h
00069 #define PortBase_h
00070
00071 #include <rtm/RTC.h>
00072
00073 #include <string>
00074 #include <vector>
00075 #include <ace/Guard_T.h>
00076 #include <ace/Recursive_Thread_Mutex.h>
00077 #include <rtm/idl/RTCSkel.h>
00078 #include <rtm/CORBA_SeqUtil.h>
00079 #include <rtm/NVUtil.h>
00080
00081 #include <iostream>
00082 namespace RTC
00083 {
00084
00085
00133 class PortBase
00134 : public virtual POA_RTC::Port,
00135 public virtual PortableServer::RefCountServantBase
00136 {
00137 public:
00161 PortBase(const char* name = "");
00162
00163
00175 virtual ~PortBase();
00176
00177
00219 virtual PortProfile* get_port_profile();
00220
00221 const PortProfile& getPortProfile() const;
00222
00262 virtual ConnectorProfileList* get_connector_profiles();
00263
00264
00286 virtual ConnectorProfile* get_connector_profile(const char* connector_id);
00287
00288
00324 virtual ReturnCode_t connect(ConnectorProfile& connector_profile);
00325
00326
00350 virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile);
00351
00352
00376 virtual ReturnCode_t disconnect(const char* connector_id);
00377
00378
00402 virtual ReturnCode_t notify_disconnect(const char* connector_id);
00403
00404
00424 virtual ReturnCode_t disconnect_all();
00425
00426
00427
00428
00429
00449 void setName(const char* name);
00450
00451
00469 const PortProfile& getProfile() const;
00470
00471
00493 void setPortRef(Port_ptr port_ref);
00494
00495
00517 Port_ptr getPortRef();
00518
00519
00539 void setOwner(RTObject_ptr owner);
00540
00541
00542
00543
00544
00545 protected:
00610 virtual ReturnCode_t
00611 publishInterfaces(ConnectorProfile& connector_profile) = 0;
00612
00613
00638 virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
00639
00640
00665 virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
00666
00667
00729 virtual ReturnCode_t
00730 subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00731
00732
00769 virtual void
00770 unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00771
00772
00773
00774
00775
00793 bool isEmptyId(const ConnectorProfile& connector_profile) const;
00794
00795
00815 const std::string getUUID() const;
00816
00817
00837 void setUUID(ConnectorProfile& connector_profile) const;
00838
00839
00861 bool isExistingConnId(const char* id);
00862
00863
00891 ConnectorProfile findConnProfile(const char* id);
00892
00893
00920 CORBA::Long findConnProfileIndex(const char* id);
00921
00922
00950 void updateConnectorProfile(const ConnectorProfile& connector_profile);
00951
00952
00975 bool eraseConnectorProfile(const char* id);
00976
00977
01024 bool appendInterface(const char* name, const char* type_name,
01025 PortInterfacePolarity pol);
01026
01027
01053 bool deleteInterface(const char* name, PortInterfacePolarity pol);
01054
01055
01075 template <class ValueType>
01076 void addProperty(const char* key, ValueType value)
01077 {
01078 CORBA_SeqUtil::push_back(m_profile.properties,
01079 NVUtil::newNV(key, value));
01080 }
01081
01082
01083 protected:
01091 PortProfile m_profile;
01092 RTC::Port_var m_objref;
01093 mutable ACE_Recursive_Thread_Mutex m_profile_mutex;
01094 typedef ACE_Guard<ACE_Recursive_Thread_Mutex> Guard;
01095
01096
01097
01098
01106 struct if_name
01107 {
01108 if_name(const char* name) : m_name(name) {};
01109 bool operator()(const PortInterfaceProfile& prof)
01110 {
01111 return m_name == std::string(prof.instance_name);
01112 }
01113 std::string m_name;
01114 };
01115
01116
01124 struct find_conn_id
01125 {
01126 find_conn_id(const char* id) : m_id(id) {};
01127 bool operator()(const ConnectorProfile& cprof)
01128 {
01129 return m_id == std::string(cprof.connector_id);
01130 }
01131 std::string m_id;
01132 };
01133
01134
01142 struct find_port_ref
01143 {
01144 find_port_ref(Port_ptr port_ref) : m_port(port_ref) {};
01145 bool operator()(Port_ptr port_ref)
01146 {
01147 return m_port->_is_equivalent(port_ref);
01148 }
01149 Port_ptr m_port;
01150 };
01151
01152
01160 struct connect_func
01161 {
01162 Port_var port_ref;
01163 ConnectorProfile connector_profile;
01164 ReturnCode_t return_code;
01165
01166 connect_func() {};
01167 connect_func(Port_ptr p, ConnectorProfile& prof)
01168 : port_ref(p), connector_profile(prof), return_code(RTC::RTC_OK) {};
01169 void operator()(Port_ptr p)
01170 {
01171 if (!port_ref->_is_equivalent(p))
01172 {
01173 ReturnCode_t retval;
01174 retval = p->notify_connect(connector_profile);
01175 if (retval != RTC::RTC_OK)
01176 {
01177 return_code = retval;
01178 }
01179 }
01180 }
01181 };
01182
01183
01191 struct disconnect_func
01192 {
01193 Port_var port_ref;
01194 ConnectorProfile connector_profile;
01195 ReturnCode_t return_code;
01196
01197 disconnect_func() : return_code(RTC::RTC_OK) {};
01198 disconnect_func(Port_ptr p, ConnectorProfile& prof)
01199 : port_ref(p), connector_profile(prof), return_code(RTC::RTC_OK) {};
01200 void operator()(Port_ptr p)
01201 {
01202 if (!port_ref->_is_equivalent(p))
01203 {
01204 ReturnCode_t retval;
01205 retval = p->disconnect(connector_profile.connector_id);
01206 if (retval != RTC::RTC_OK)
01207 {
01208 return_code = retval;
01209 }
01210 }
01211 }
01212 };
01213
01214
01222 struct disconnect_all_func
01223 {
01224 ReturnCode_t return_code;
01225 PortBase* port;
01226
01227 disconnect_all_func() {};
01228 disconnect_all_func(PortBase* p)
01229 : return_code(RTC::RTC_OK), port(p) {};
01230 void operator()(ConnectorProfile& p)
01231 {
01232 ReturnCode_t retval;
01233 retval = port->disconnect(p.connector_id);
01234 if (retval != RTC::RTC_OK)
01235 {
01236 return_code = retval;
01237 }
01238 }
01239 };
01240
01241
01249 struct find_interface
01250 {
01251 find_interface(const char* name, PortInterfacePolarity pol)
01252 : m_name(name), m_pol(pol)
01253 {}
01254
01255 bool operator()(const PortInterfaceProfile& prof)
01256 {
01257 std::string name(CORBA::string_dup(prof.instance_name));
01258 return ((m_name == name) && (m_pol == prof.polarity));
01259 }
01260 std::string m_name;
01261 PortInterfacePolarity m_pol;
01262 };
01263 };
01264 };
01265 #endif // PortBase_h