00001
00020 #ifndef RTC_PORTBASE_H
00021 #define RTC_PORTBASE_H
00022
00023 #include <rtm/RTC.h>
00024
00025 #include <string>
00026 #include <vector>
00027 #include <coil/Guard.h>
00028 #include <coil/Mutex.h>
00029 #include <rtm/idl/RTCSkel.h>
00030 #include <rtm/CORBA_SeqUtil.h>
00031 #include <rtm/NVUtil.h>
00032 #include <rtm/SystemLogger.h>
00033
00034 #include <iostream>
00035
00036 #ifdef WIN32
00037 #pragma warning( disable : 4290 )
00038 #endif
00039
00040 namespace RTC
00041 {
00042 class ConnectionCallback;
00043
00134 class PortBase
00135 : public virtual POA_RTC::PortService,
00136 public virtual PortableServer::RefCountServantBase
00137 {
00138 public:
00162 PortBase(const char* name = "");
00163
00181 virtual ~PortBase(void);
00182
00234 virtual PortProfile* get_port_profile()
00235 throw (CORBA::SystemException);
00236
00262 const PortProfile& getPortProfile() const;
00263
00316 virtual ConnectorProfileList* get_connector_profiles()
00317 throw (CORBA::SystemException);
00318
00358 virtual ConnectorProfile* get_connector_profile(const char* connector_id)
00359 throw (CORBA::SystemException);
00360
00518 virtual ReturnCode_t connect(ConnectorProfile& connector_profile)
00519 throw (CORBA::SystemException);
00520
00636 virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile)
00637 throw (CORBA::SystemException);
00638
00704 virtual ReturnCode_t disconnect(const char* connector_id)
00705 throw (CORBA::SystemException);
00706
00795 virtual ReturnCode_t notify_disconnect(const char* connector_id)
00796 throw (CORBA::SystemException);
00797
00817 virtual ReturnCode_t disconnect_all()
00818 throw (CORBA::SystemException);
00819
00820
00821
00822
00839 virtual void activateInterfaces() = 0;
00840
00857 virtual void deactivateInterfaces() = 0;
00858
00878 void setName(const char* name);
00879
00897 const char* getName() const;
00898
00916 const PortProfile& getProfile() const;
00917
00939 void setPortRef(PortService_ptr port_ref);
00940
00962 PortService_ptr getPortRef();
00963
00983 void setOwner(RTObject_ptr owner);
00984
00985
00986
00987
01032 void setOnPublishInterfaces(ConnectionCallback* on_publish);
01033
01078 void setOnSubscribeInterfaces(ConnectionCallback* on_subscribe);
01079
01131 void setOnConnected(ConnectionCallback* on_connected);
01132
01178 void setOnUnsubscribeInterfaces(ConnectionCallback* on_subscribe);
01179
01223 void setOnDisconnected(ConnectionCallback* on_disconnected);
01224
01249 void setOnConnectionLost(ConnectionCallback* on_connection_lost);
01250
01251
01252
01253
01254 protected:
01321 virtual ReturnCode_t
01322 publishInterfaces(ConnectorProfile& connector_profile) = 0;
01323
01350 virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
01351
01378 virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
01379
01443 virtual ReturnCode_t
01444 subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
01445
01483 virtual void
01484 unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
01485
01501 virtual void setConnectionLimit(int limit_value);
01502
01523 virtual ReturnCode_t _publishInterfaces(void);
01524
01525
01526
01553 bool isEmptyId(const ConnectorProfile& connector_profile) const;
01554
01574 const std::string getUUID() const;
01575
01595 void setUUID(ConnectorProfile& connector_profile) const;
01596
01622 bool isExistingConnId(const char* id);
01623
01653 ConnectorProfile findConnProfile(const char* id);
01654
01683 CORBA::Long findConnProfileIndex(const char* id);
01684
01712 void updateConnectorProfile(const ConnectorProfile& connector_profile);
01713
01743 bool eraseConnectorProfile(const char* id);
01744
01794 bool appendInterface(const char* name, const char* type_name,
01795 PortInterfacePolarity pol);
01796
01826 bool deleteInterface(const char* name, PortInterfacePolarity pol);
01827
01851 template <class ValueType>
01852 void addProperty(const char* key, ValueType value)
01853 {
01854 CORBA_SeqUtil::push_back(m_profile.properties,
01855 NVUtil::newNV(key, value));
01856 }
01857
01879 void appendProperty(const char* key, const char* value)
01880 {
01881 NVUtil::appendStringValue(m_profile.properties, key, value);
01882 }
01883
01884 protected:
01896 void updateConnectors();
01914 bool checkPorts(::RTC::PortServiceList& ports);
01915
01923 mutable Logger rtclog;
01931 PortProfile m_profile;
01932
01940 RTC::PortService_var m_objref;
01948 mutable coil::Mutex m_profile_mutex;
01949 typedef coil::Guard<coil::Mutex> Guard;
01950
01958 std::string m_ownerInstanceName;
01959
01967 int m_connectionLimit;
01968
01983 ConnectionCallback* m_onPublishInterfaces;
01997 ConnectionCallback* m_onSubscribeInterfaces;
02012 ConnectionCallback* m_onConnected;
02026 ConnectionCallback* m_onUnsubscribeInterfaces;
02040 ConnectionCallback* m_onDisconnected;
02041
02056 ConnectionCallback* m_onConnectionLost;
02057
02058
02059
02060
02061
02069 struct find_conn_id
02070 {
02071 find_conn_id(const char* id) : m_id(id) {};
02072 bool operator()(const ConnectorProfile& cprof)
02073 {
02074 return m_id == std::string(cprof.connector_id);
02075 }
02076 std::string m_id;
02077 };
02078
02086 struct find_port_ref
02087 {
02088 find_port_ref(PortService_ptr port_ref) : m_port(port_ref) {};
02089 bool operator()(PortService_ptr port_ref)
02090 {
02091 return m_port->_is_equivalent(port_ref);
02092 }
02093 PortService_ptr m_port;
02094 };
02095
02103 struct find_interface
02104 {
02105 find_interface(const char* name, PortInterfacePolarity pol)
02106 : m_name(name), m_pol(pol)
02107 {}
02108
02109 bool operator()(const PortInterfaceProfile& prof)
02110 {
02111 CORBA::String_var name(CORBA::string_dup(prof.instance_name));
02112 return ((m_name == (const char *)name) && (m_pol == prof.polarity));
02113 }
02114 std::string m_name;
02115 PortInterfacePolarity m_pol;
02116 };
02117 };
02118 };
02119
02120 #ifdef WIN32
02121 #pragma warning( default : 4290 )
02122 #endif
02123
02124 #endif // RTC_PORTBASE_H