PortBase.h

説明を見る。
00001 // -*- C++ -*-
00020 #ifndef PortBase_h
00021 #define PortBase_h
00022 
00023 #include <rtm/RTC.h>
00024 
00025 #include <string>
00026 #include <vector>
00027 #include <ace/Guard_T.h>
00028 #include <ace/Recursive_Thread_Mutex.h>
00029 #include <rtm/idl/RTCSkel.h>
00030 #include <rtm/CORBA_SeqUtil.h>
00031 #include <rtm/NVUtil.h>
00032 
00033 #include <iostream>
00034 namespace RTC
00035 {
00126   class PortBase
00127     : public virtual POA_RTC::Port,
00128       public virtual PortableServer::RefCountServantBase
00129   {
00130   public:
00154     PortBase(const char* name = "");
00155     
00171     virtual ~PortBase();
00172     
00214     virtual PortProfile* get_port_profile()
00215       throw (CORBA::SystemException);
00216     
00236     const PortProfile& getPortProfile() const;
00237     
00277     virtual ConnectorProfileList* get_connector_profiles()
00278       throw (CORBA::SystemException);
00279     
00307     virtual ConnectorProfile* get_connector_profile(const char* connector_id)
00308       throw (CORBA::SystemException);
00309     
00443     virtual ReturnCode_t connect(ConnectorProfile& connector_profile)
00444       throw (CORBA::SystemException);
00445     
00482     virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile)
00483       throw (CORBA::SystemException);
00484     
00517     virtual ReturnCode_t disconnect(const char* connector_id)
00518       throw (CORBA::SystemException);
00519     
00559     virtual ReturnCode_t notify_disconnect(const char* connector_id)
00560       throw (CORBA::SystemException);
00561     
00581     virtual ReturnCode_t disconnect_all()
00582       throw (CORBA::SystemException);
00583     
00584     //============================================================
00585     // Local operations
00586     //============================================================
00606     void setName(const char* name);
00607     
00625     const PortProfile& getProfile() const;
00626     
00648     void setPortRef(Port_ptr port_ref);
00649     
00671     Port_ptr getPortRef();
00672     
00692     void setOwner(RTObject_ptr owner);
00693     
00694     //============================================================
00695     // protected operations
00696     //============================================================
00697   protected:
00764     virtual ReturnCode_t
00765     publishInterfaces(ConnectorProfile& connector_profile) = 0;
00766     
00793     virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
00794     
00821     virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
00822     
00886     virtual ReturnCode_t
00887     subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00888     
00926     virtual void
00927     unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00928     
00929     //============================================================
00930     // protected utility functions
00931     //============================================================
00958     bool isEmptyId(const ConnectorProfile& connector_profile) const;
00959     
00979     const std::string getUUID() const;
00980     
01000     void setUUID(ConnectorProfile& connector_profile) const;
01001     
01027     bool isExistingConnId(const char* id);
01028     
01058     ConnectorProfile findConnProfile(const char* id);
01059     
01088     CORBA::Long findConnProfileIndex(const char* id);
01089     
01117     void updateConnectorProfile(const ConnectorProfile& connector_profile);
01118     
01148     bool eraseConnectorProfile(const char* id);
01149     
01199     bool appendInterface(const char* name, const char* type_name,
01200                          PortInterfacePolarity pol);
01201     
01231     bool deleteInterface(const char* name, PortInterfacePolarity pol);
01232     
01256     template <class ValueType>
01257     void addProperty(const char* key, ValueType value)
01258     {
01259       CORBA_SeqUtil::push_back(m_profile.properties,
01260                                NVUtil::newNV(key, value));
01261     }
01262     
01263   protected:
01271     PortProfile m_profile;
01272     
01280     RTC::Port_var m_objref;
01281     mutable ACE_Recursive_Thread_Mutex m_profile_mutex;
01282     typedef ACE_Guard<ACE_Recursive_Thread_Mutex> Guard;
01283     
01284     //============================================================
01285     // Functor
01286     //============================================================
01294     struct if_name
01295     {
01296       if_name(const char* name) : m_name(name) {};
01297       bool operator()(const PortInterfaceProfile& prof)
01298       {
01299         return m_name == std::string(prof.instance_name);
01300       }
01301       std::string m_name;
01302     };
01303     
01311     struct find_conn_id
01312     {
01313       find_conn_id(const char* id) : m_id(id) {};
01314       bool operator()(const ConnectorProfile& cprof)
01315       {
01316         return m_id == std::string(cprof.connector_id);
01317       }
01318       std::string m_id;
01319     };
01320     
01328     struct find_port_ref
01329     {
01330       find_port_ref(Port_ptr port_ref) : m_port(port_ref) {};
01331       bool operator()(Port_ptr port_ref)
01332       {
01333         return m_port->_is_equivalent(port_ref);
01334       }
01335       Port_ptr m_port;
01336     };
01337     
01345     struct connect_func
01346     {
01347       Port_var port_ref;
01348       ConnectorProfile connector_profile;
01349       ReturnCode_t return_code;
01350       
01351       connect_func() {};
01352       connect_func(Port_ptr p, ConnectorProfile& prof)
01353         : port_ref(p), connector_profile(prof), return_code(RTC::RTC_OK) {};
01354       void operator()(Port_ptr p)
01355       {
01356         if (!port_ref->_is_equivalent(p))
01357           {
01358             ReturnCode_t retval;
01359             retval = p->notify_connect(connector_profile);
01360             if (retval != RTC::RTC_OK)
01361               {
01362                 return_code = retval;
01363               }
01364           }
01365       }
01366     };
01367     
01375     struct disconnect_func
01376     {
01377       Port_var port_ref;
01378       ConnectorProfile connector_profile;
01379       ReturnCode_t return_code;
01380       
01381       disconnect_func() : return_code(RTC::RTC_OK) {};
01382       disconnect_func(Port_ptr p, ConnectorProfile& prof)
01383         : port_ref(p), connector_profile(prof), return_code(RTC::RTC_OK) {};
01384       void operator()(Port_ptr p)
01385       {
01386         if (!port_ref->_is_equivalent(p))
01387           {
01388             ReturnCode_t retval;
01389             retval = p->disconnect(connector_profile.connector_id);
01390             if (retval != RTC::RTC_OK)
01391               {
01392                 return_code = retval;
01393               }
01394           }
01395       }
01396     };
01397     
01405     struct disconnect_all_func
01406     {
01407       ReturnCode_t return_code;
01408       PortBase* port;
01409       
01410       disconnect_all_func() {};
01411       disconnect_all_func(PortBase* p) 
01412         : return_code(RTC::RTC_OK), port(p) {};
01413       void operator()(ConnectorProfile& p)
01414       {
01415         ReturnCode_t retval;
01416         retval = port->disconnect(p.connector_id);
01417         if (retval != RTC::RTC_OK)
01418           {
01419             return_code = retval;
01420           }
01421       }
01422     };
01423     
01431     struct find_interface
01432     {
01433       find_interface(const char* name, PortInterfacePolarity pol)
01434         : m_name(name), m_pol(pol)
01435       {}
01436       
01437       bool operator()(const PortInterfaceProfile& prof)
01438       {
01439         std::string name(CORBA::string_dup(prof.instance_name));
01440         return ((m_name == name) && (m_pol == prof.polarity));
01441       }
01442       std::string m_name;
01443       PortInterfacePolarity m_pol;
01444     };
01445   };
01446 };
01447 #endif // PortBase_h

OpenRTMに対してThu May 29 15:03:26 2008に生成されました。  doxygen 1.5.3