PortBase.h
Go to the documentation of this file.
00001 // -*- C++ -*-
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 #include <rtm/PortConnectListener.h>
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:
00164     PortBase(const char* name = "");
00165     
00183     virtual ~PortBase(void);
00184     
00236     virtual PortProfile* get_port_profile()
00237       throw (CORBA::SystemException);
00238     
00264     const PortProfile& getPortProfile() const;
00265     
00318     virtual ConnectorProfileList* get_connector_profiles()
00319       throw (CORBA::SystemException);
00320     
00360     virtual ConnectorProfile* get_connector_profile(const char* connector_id)
00361       throw (CORBA::SystemException);
00362     
00520     virtual ReturnCode_t connect(ConnectorProfile& connector_profile)
00521       throw (CORBA::SystemException);
00522     
00638     virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile)
00639       throw (CORBA::SystemException);
00640     
00706     virtual ReturnCode_t disconnect(const char* connector_id)
00707       throw (CORBA::SystemException);
00708     
00797     virtual ReturnCode_t notify_disconnect(const char* connector_id)
00798       throw (CORBA::SystemException);
00799     
00819     virtual ReturnCode_t disconnect_all()
00820       throw (CORBA::SystemException);
00821     
00822     //============================================================
00823     // Local operations
00824     //============================================================
00841     virtual void activateInterfaces() = 0;
00842 
00859     virtual void deactivateInterfaces() = 0;
00860 
00880     void setName(const char* name);
00881 
00899    const char* getName() const;
00900 
00918     const PortProfile& getProfile() const;
00919     
00941     void setPortRef(PortService_ptr port_ref);
00942     
00964     PortService_ptr getPortRef();
00965     
00985     void setOwner(RTObject_ptr owner);
00986 
00987     //============================================================
00988     // callbacks
00989     //============================================================
01034     void setOnPublishInterfaces(ConnectionCallback* on_publish);
01035 
01080     void setOnSubscribeInterfaces(ConnectionCallback* on_subscribe);
01081 
01133     void setOnConnected(ConnectionCallback* on_connected);
01134 
01180     void setOnUnsubscribeInterfaces(ConnectionCallback* on_subscribe);
01181 
01225     void setOnDisconnected(ConnectionCallback* on_disconnected);
01226 
01251     void setOnConnectionLost(ConnectionCallback* on_connection_lost);
01252 
01273     void setPortConnectListenerHolder(PortConnectListeners* portconnListeners);
01274 
01275     //============================================================
01276     // protected operations
01277     //============================================================
01278   protected:
01345     virtual ReturnCode_t
01346     publishInterfaces(ConnectorProfile& connector_profile) = 0;
01347     
01374     virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
01375     
01402     virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
01403     
01467     virtual ReturnCode_t
01468     subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
01469     
01507     virtual void
01508     unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
01509 
01525     virtual void setConnectionLimit(int limit_value);
01526     
01547     virtual ReturnCode_t _publishInterfaces(void);
01548     //============================================================
01549     // protected utility functions
01550     //============================================================
01577     bool isEmptyId(const ConnectorProfile& connector_profile) const;
01578     
01598     const std::string getUUID() const;
01599     
01619     void setUUID(ConnectorProfile& connector_profile) const;
01620     
01646     bool isExistingConnId(const char* id);
01647     
01677     ConnectorProfile findConnProfile(const char* id);
01678     
01707     CORBA::Long findConnProfileIndex(const char* id);
01708     
01736     void updateConnectorProfile(const ConnectorProfile& connector_profile);
01737     
01767     bool eraseConnectorProfile(const char* id);
01768     
01818     bool appendInterface(const char* name, const char* type_name,
01819                          PortInterfacePolarity pol);
01820     
01850     bool deleteInterface(const char* name, PortInterfacePolarity pol);
01851     
01875     template <class ValueType>
01876     void addProperty(const char* key, ValueType value)
01877     {
01878       CORBA_SeqUtil::push_back(m_profile.properties,
01879                                NVUtil::newNV(key, value));
01880     }
01881 
01907     void appendProperty(const char* key, const char* value)
01908     {
01909       NVUtil::appendStringValue(m_profile.properties, key, value);
01910     }
01911     
01912   protected:
01930     void updateConnectors();
01931 
01949 #ifndef ORB_IS_RTORB
01950     bool checkPorts(::RTC::PortServiceList& ports);
01951 #else // ORB_IS_RTORB
01952     bool checkPorts(RTC_PortServiceList& ports);
01953 #endif // ORB_IS_RTORB
01954 
01955 
01956     inline void onNotifyConnect(const char* portname,
01957                                 RTC::ConnectorProfile& profile)
01958     {
01959       if (m_portconnListeners != NULL)
01960         {
01961           m_portconnListeners->
01962             portconnect_[ON_NOTIFY_CONNECT].notify(portname, profile);
01963         }
01964     }
01965 
01966     inline void onNotifyDisconnect(const char* portname,
01967                                    RTC::ConnectorProfile& profile)
01968     {
01969       if (m_portconnListeners != NULL)
01970         {
01971           m_portconnListeners->
01972             portconnect_[ON_NOTIFY_DISCONNECT].notify(portname, profile);
01973         }
01974     }
01975     inline void onUnsubscribeInterfaces(const char* portname,
01976                                         RTC::ConnectorProfile& profile)
01977     {
01978       if (m_portconnListeners != NULL)
01979         {
01980           m_portconnListeners->
01981             portconnect_[ON_UNSUBSCRIBE_INTERFACES].notify(portname, profile);
01982         }
01983     }
01984 
01985     inline void onPublishInterfaces(const char* portname,
01986                                     RTC::ConnectorProfile& profile,
01987                                     ReturnCode_t ret)
01988     {
01989       if (m_portconnListeners != NULL)
01990         {
01991           m_portconnListeners->
01992             portconnret_[ON_PUBLISH_INTERFACES].notify(portname,
01993                                                        profile, ret);
01994         }
01995     }
01996 
01997     inline void onConnectNextport(const char* portname,
01998                                   RTC::ConnectorProfile& profile,
01999                                   ReturnCode_t ret)
02000     {
02001       if (m_portconnListeners != NULL)
02002         {
02003           m_portconnListeners->
02004             portconnret_[ON_CONNECT_NEXTPORT].notify(portname,
02005                                                      profile, ret);
02006         }
02007     }
02008 
02009     inline void onSubscribeInterfaces(const char* portname,
02010                                       RTC::ConnectorProfile& profile,
02011                                       ReturnCode_t ret)
02012     {
02013       if (m_portconnListeners != NULL)
02014         {
02015           m_portconnListeners->
02016             portconnret_[ON_SUBSCRIBE_INTERFACES].notify(portname,
02017                                                          profile, ret);
02018         }
02019     }
02020 
02021     inline void onConnected(const char* portname,
02022                             RTC::ConnectorProfile& profile,
02023                             ReturnCode_t ret)
02024     {
02025       if (m_portconnListeners != NULL)
02026         {
02027           m_portconnListeners->
02028             portconnret_[ON_CONNECTED].notify(portname, profile, ret);
02029         }
02030     }
02031 
02032     inline void onDisconnectNextport(const char* portname,
02033                                  RTC::ConnectorProfile& profile,
02034                                  ReturnCode_t ret)
02035     {
02036       if (m_portconnListeners != NULL)
02037         {
02038           m_portconnListeners->
02039             portconnret_[ON_DISCONNECT_NEXT].notify(portname, profile, ret);
02040         }
02041     }
02042 
02043     inline void onDisconnected(const char* portname,
02044                                RTC::ConnectorProfile& profile,
02045                                ReturnCode_t ret)
02046     {
02047       if (m_portconnListeners != NULL)
02048         {
02049           m_portconnListeners->
02050             portconnret_[ON_DISCONNECTED].notify(portname, profile, ret);
02051         }
02052     }
02053 
02054   protected:
02062     mutable Logger rtclog;
02070     PortProfile m_profile;
02071     
02079     RTC::PortService_var m_objref;
02087     mutable coil::Mutex m_profile_mutex;
02088     mutable coil::Mutex m_connectorsMutex;
02089     typedef coil::Guard<coil::Mutex> Guard;
02090 
02098     std::string m_ownerInstanceName;
02099 
02107     int m_connectionLimit;
02108     
02123     ConnectionCallback* m_onPublishInterfaces;
02137     ConnectionCallback* m_onSubscribeInterfaces;
02152     ConnectionCallback* m_onConnected;
02166     ConnectionCallback* m_onUnsubscribeInterfaces;
02180     ConnectionCallback* m_onDisconnected;
02181 
02196     ConnectionCallback* m_onConnectionLost;
02197 
02211     PortConnectListeners* m_portconnListeners;
02212 
02213     //============================================================
02214     // Functor
02215     //============================================================
02223     struct find_conn_id
02224     {
02225       find_conn_id(const char* id) : m_id(id) {};
02226       bool operator()(const ConnectorProfile& cprof)
02227       {
02228         return m_id == std::string(cprof.connector_id);
02229       }
02230       std::string m_id;
02231     };  // struct find_conn_id
02232     
02240     struct find_port_ref
02241     {
02242       find_port_ref(PortService_ptr port_ref) : m_port(port_ref) {};
02243       bool operator()(PortService_ptr port_ref)
02244       {
02245         return m_port->_is_equivalent(port_ref);
02246       }
02247       PortService_ptr m_port;
02248     };  // struct find_port_ref
02249     
02257     struct find_interface
02258     {
02259       find_interface(const char* name, PortInterfacePolarity pol)
02260         : m_name(name), m_pol(pol)
02261       {}
02262       
02263       bool operator()(const PortInterfaceProfile& prof)
02264       {
02265         CORBA::String_var name(CORBA::string_dup(prof.instance_name));
02266         return ((m_name == (const char *)name) && (m_pol == prof.polarity));
02267       }
02268       std::string m_name;
02269       PortInterfacePolarity m_pol;
02270     };  // struct find_interface
02271   };  // class PortBase
02272 };  // namespace RTC
02273 
02274 #ifdef WIN32
02275 #pragma warning( default : 4290 )
02276 #endif
02277 
02278 #endif // RTC_PORTBASE_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:06