00001
00019
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 #ifndef PortBase_h
00048 #define PortBase_h
00049
00050 #include <string>
00051 #include <vector>
00052 #include <ace/Guard_T.h>
00053 #include <ace/Recursive_Thread_Mutex.h>
00054 #include <rtm/idl/RTCSkel.h>
00055 #include <rtm/CORBA_SeqUtil.h>
00056 #include <rtm/NVUtil.h>
00057
00058 #include <iostream>
00059 namespace RTC
00060 {
00061
00062
00110 class PortBase
00111 : public virtual POA_RTC::Port,
00112 public virtual PortableServer::RefCountServantBase
00113 {
00114 public:
00138 PortBase(const char* name = "");
00139
00140
00152 virtual ~PortBase();
00153
00154
00196 virtual PortProfile* get_port_profile();
00197
00198
00238 virtual ConnectorProfileList* get_connector_profiles();
00239
00240
00262 virtual ConnectorProfile* get_connector_profile(const char* connector_id);
00263
00264
00300 virtual ReturnCode_t connect(ConnectorProfile& connector_profile);
00301
00302
00326 virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile);
00327
00328
00352 virtual ReturnCode_t disconnect(const char* connector_id);
00353
00354
00378 virtual ReturnCode_t notify_disconnect(const char* connector_id);
00379
00380
00400 virtual ReturnCode_t disconnect_all();
00401
00402
00403
00404
00405
00425 void setName(const char* name);
00426
00427
00445 const PortProfile& getProfile() const;
00446
00447
00469 void setPortRef(Port_ptr port_ref);
00470
00471
00493 Port_ptr getPortRef();
00494
00495
00515 void setOwner(RTObject_ptr owner);
00516
00517
00518
00519
00520
00521 protected:
00586 virtual ReturnCode_t
00587 publishInterfaces(ConnectorProfile& connector_profile) = 0;
00588
00589
00614 virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
00615
00616
00641 virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
00642
00643
00705 virtual ReturnCode_t
00706 subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00707
00708
00745 virtual void
00746 unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00747
00748
00749
00750
00751
00769 bool isEmptyId(const ConnectorProfile& connector_profile) const;
00770
00771
00791 const std::string getUUID() const;
00792
00793
00813 void setUUID(ConnectorProfile& connector_profile) const;
00814
00815
00837 bool isExistingConnId(const char* id);
00838
00839
00867 ConnectorProfile findConnProfile(const char* id);
00868
00869
00896 CORBA::Long findConnProfileIndex(const char* id);
00897
00898
00926 void updateConnectorProfile(const ConnectorProfile& connector_profile);
00927
00928
00951 bool eraseConnectorProfile(const char* id);
00952
00953
01000 bool appendInterface(const char* name, const char* type_name,
01001 PortInterfacePolarity pol);
01002
01003
01029 bool deleteInterface(const char* name, PortInterfacePolarity pol);
01030
01031
01051 template <class ValueType>
01052 void addProperty(const char* key, ValueType value)
01053 {
01054 CORBA_SeqUtil::push_back(m_profile.properties,
01055 NVUtil::newNV(key, value));
01056 }
01057
01058
01059 protected:
01067 PortProfile m_profile;
01068
01069 mutable ACE_Recursive_Thread_Mutex m_profile_mutex;
01070 typedef ACE_Guard<ACE_Recursive_Thread_Mutex> Guard;
01071
01072
01073
01074
01082 struct if_name
01083 {
01084 if_name(const char* name) : m_name(name) {};
01085 bool operator()(const PortInterfaceProfile& prof)
01086 {
01087 return m_name == std::string(prof.instance_name);
01088 }
01089 std::string m_name;
01090 };
01091
01092
01100 struct find_conn_id
01101 {
01102 find_conn_id(const char* id) : m_id(id) {};
01103 bool operator()(const ConnectorProfile& cprof)
01104 {
01105 return m_id == std::string(cprof.connector_id);
01106 }
01107 std::string m_id;
01108 };
01109
01110
01118 struct find_port_ref
01119 {
01120 find_port_ref(Port_ptr port_ref) : m_port(port_ref) {};
01121 bool operator()(Port_ptr port_ref)
01122 {
01123 return m_port->_is_equivalent(port_ref);
01124 }
01125 Port_ptr m_port;
01126 };
01127
01128
01136 struct connect_func
01137 {
01138 Port_var port_ref;
01139 ConnectorProfile connector_profile;
01140 ReturnCode_t return_code;
01141
01142 connect_func() {};
01143 connect_func(Port_ptr p, ConnectorProfile& prof)
01144 : port_ref(p), connector_profile(prof) {};
01145 void operator()(Port_ptr p)
01146 {
01147 if (!port_ref->_is_equivalent(p))
01148 {
01149 ReturnCode_t retval;
01150 retval = p->notify_connect(connector_profile);
01151 if (retval != RTC::OK)
01152 {
01153 return_code = retval;
01154 }
01155 }
01156 }
01157 };
01158
01159
01167 struct disconnect_func
01168 {
01169 Port_var port_ref;
01170 ConnectorProfile connector_profile;
01171 ReturnCode_t return_code;
01172
01173 disconnect_func() : return_code(RTC::OK) {};
01174 disconnect_func(Port_ptr p, ConnectorProfile& prof)
01175 : port_ref(p), connector_profile(prof), return_code(RTC::OK) {};
01176 void operator()(Port_ptr p)
01177 {
01178 if (!port_ref->_is_equivalent(p))
01179 {
01180 ReturnCode_t retval;
01181 retval = p->disconnect(connector_profile.connector_id);
01182 if (retval != RTC::OK)
01183 {
01184 return_code = retval;
01185 }
01186 }
01187 }
01188 };
01189
01190
01198 struct disconnect_all_func
01199 {
01200 ReturnCode_t return_code;
01201 PortBase* port;
01202
01203 disconnect_all_func() {};
01204 disconnect_all_func(PortBase* p)
01205 : return_code(RTC::OK), port(p) {};
01206 void operator()(ConnectorProfile& p)
01207 {
01208 ReturnCode_t retval;
01209 retval = port->disconnect(p.connector_id);
01210 if (retval != RTC::OK)
01211 {
01212 return_code = retval;
01213 }
01214 }
01215 };
01216
01217
01225 struct find_interface
01226 {
01227 find_interface(const char* name, PortInterfacePolarity pol)
01228 : m_name(name), m_pol(pol)
01229 {}
01230
01231 bool operator()(const PortInterfaceProfile& prof)
01232 {
01233 std::string name(CORBA::string_dup(prof.instance_name));
01234 return ((m_name == name) && (m_pol == prof.polarity));
01235 }
01236 std::string m_name;
01237 PortInterfacePolarity m_pol;
01238 };
01239
01240 friend class disconnect_all_func;
01241
01242 };
01243 };
01244 #endif // PortBase_h