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 #ifndef PortBase_h
00060 #define PortBase_h
00061
00062 #include <rtm/RTC.h>
00063
00064 #include <string>
00065 #include <vector>
00066 #include <ace/Guard_T.h>
00067 #include <ace/Recursive_Thread_Mutex.h>
00068 #include <rtm/idl/RTCSkel.h>
00069 #include <rtm/CORBA_SeqUtil.h>
00070 #include <rtm/NVUtil.h>
00071
00072 #include <iostream>
00073 namespace RTC
00074 {
00075
00076
00124 class PortBase
00125 : public virtual POA_RTC::Port,
00126 public virtual PortableServer::RefCountServantBase
00127 {
00128 public:
00152 PortBase(const char* name = "");
00153
00154
00166 virtual ~PortBase();
00167
00168
00210 virtual PortProfile* get_port_profile();
00211
00212
00252 virtual ConnectorProfileList* get_connector_profiles();
00253
00254
00276 virtual ConnectorProfile* get_connector_profile(const char* connector_id);
00277
00278
00314 virtual ReturnCode_t connect(ConnectorProfile& connector_profile);
00315
00316
00340 virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile);
00341
00342
00366 virtual ReturnCode_t disconnect(const char* connector_id);
00367
00368
00392 virtual ReturnCode_t notify_disconnect(const char* connector_id);
00393
00394
00414 virtual ReturnCode_t disconnect_all();
00415
00416
00417
00418
00419
00439 void setName(const char* name);
00440
00441
00459 const PortProfile& getProfile() const;
00460
00461
00483 void setPortRef(Port_ptr port_ref);
00484
00485
00507 Port_ptr getPortRef();
00508
00509
00529 void setOwner(RTObject_ptr owner);
00530
00531
00532
00533
00534
00535 protected:
00600 virtual ReturnCode_t
00601 publishInterfaces(ConnectorProfile& connector_profile) = 0;
00602
00603
00628 virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
00629
00630
00655 virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
00656
00657
00719 virtual ReturnCode_t
00720 subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00721
00722
00759 virtual void
00760 unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00761
00762
00763
00764
00765
00783 bool isEmptyId(const ConnectorProfile& connector_profile) const;
00784
00785
00805 const std::string getUUID() const;
00806
00807
00827 void setUUID(ConnectorProfile& connector_profile) const;
00828
00829
00851 bool isExistingConnId(const char* id);
00852
00853
00881 ConnectorProfile findConnProfile(const char* id);
00882
00883
00910 CORBA::Long findConnProfileIndex(const char* id);
00911
00912
00940 void updateConnectorProfile(const ConnectorProfile& connector_profile);
00941
00942
00965 bool eraseConnectorProfile(const char* id);
00966
00967
01014 bool appendInterface(const char* name, const char* type_name,
01015 PortInterfacePolarity pol);
01016
01017
01043 bool deleteInterface(const char* name, PortInterfacePolarity pol);
01044
01045
01065 template <class ValueType>
01066 void addProperty(const char* key, ValueType value)
01067 {
01068 CORBA_SeqUtil::push_back(m_profile.properties,
01069 NVUtil::newNV(key, value));
01070 }
01071
01072
01073 protected:
01081 PortProfile m_profile;
01082 RTC::Port_var m_objref;
01083 mutable ACE_Recursive_Thread_Mutex m_profile_mutex;
01084 typedef ACE_Guard<ACE_Recursive_Thread_Mutex> Guard;
01085
01086
01087
01088
01096 struct if_name
01097 {
01098 if_name(const char* name) : m_name(name) {};
01099 bool operator()(const PortInterfaceProfile& prof)
01100 {
01101 return m_name == std::string(prof.instance_name);
01102 }
01103 std::string m_name;
01104 };
01105
01106
01114 struct find_conn_id
01115 {
01116 find_conn_id(const char* id) : m_id(id) {};
01117 bool operator()(const ConnectorProfile& cprof)
01118 {
01119 return m_id == std::string(cprof.connector_id);
01120 }
01121 std::string m_id;
01122 };
01123
01124
01132 struct find_port_ref
01133 {
01134 find_port_ref(Port_ptr port_ref) : m_port(port_ref) {};
01135 bool operator()(Port_ptr port_ref)
01136 {
01137 return m_port->_is_equivalent(port_ref);
01138 }
01139 Port_ptr m_port;
01140 };
01141
01142
01150 struct connect_func
01151 {
01152 Port_var port_ref;
01153 ConnectorProfile connector_profile;
01154 ReturnCode_t return_code;
01155
01156 connect_func() {};
01157 connect_func(Port_ptr p, ConnectorProfile& prof)
01158 : port_ref(p), connector_profile(prof) {};
01159 void operator()(Port_ptr p)
01160 {
01161 if (!port_ref->_is_equivalent(p))
01162 {
01163 ReturnCode_t retval;
01164 retval = p->notify_connect(connector_profile);
01165 if (retval != RTC::RTC_OK)
01166 {
01167 return_code = retval;
01168 }
01169 }
01170 }
01171 };
01172
01173
01181 struct disconnect_func
01182 {
01183 Port_var port_ref;
01184 ConnectorProfile connector_profile;
01185 ReturnCode_t return_code;
01186
01187 disconnect_func() : return_code(RTC::RTC_OK) {};
01188 disconnect_func(Port_ptr p, ConnectorProfile& prof)
01189 : port_ref(p), connector_profile(prof), return_code(RTC::RTC_OK) {};
01190 void operator()(Port_ptr p)
01191 {
01192 if (!port_ref->_is_equivalent(p))
01193 {
01194 ReturnCode_t retval;
01195 retval = p->disconnect(connector_profile.connector_id);
01196 if (retval != RTC::RTC_OK)
01197 {
01198 return_code = retval;
01199 }
01200 }
01201 }
01202 };
01203
01204
01212 struct disconnect_all_func
01213 {
01214 ReturnCode_t return_code;
01215 PortBase* port;
01216
01217 disconnect_all_func() {};
01218 disconnect_all_func(PortBase* p)
01219 : return_code(RTC::RTC_OK), port(p) {};
01220 void operator()(ConnectorProfile& p)
01221 {
01222 ReturnCode_t retval;
01223 retval = port->disconnect(p.connector_id);
01224 if (retval != RTC::RTC_OK)
01225 {
01226 return_code = retval;
01227 }
01228 }
01229 };
01230
01231
01239 struct find_interface
01240 {
01241 find_interface(const char* name, PortInterfacePolarity pol)
01242 : m_name(name), m_pol(pol)
01243 {}
01244
01245 bool operator()(const PortInterfaceProfile& prof)
01246 {
01247 std::string name(CORBA::string_dup(prof.instance_name));
01248 return ((m_name == name) && (m_pol == prof.polarity));
01249 }
01250 std::string m_name;
01251 PortInterfacePolarity m_pol;
01252 };
01253
01254 friend class disconnect_all_func;
01255
01256 };
01257 };
01258 #endif // PortBase_h