メインページ | ネームスペース一覧 | クラス階層 | 構成 | Directories | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ

PortBase.h

説明を見る。
00001 
00002 // -*- C++ -*-
00020 /*
00021  * $Log: PortBase.h,v $
00022  * Revision 1.10.2.3  2007/09/20 11:26:08  n-ando
00023  * A function getPortProfile() was added to get PortProfile locally.
00024  *
00025  * Revision 1.10.2.2  2007/09/19 07:42:01  n-ando
00026  * A trivial bug fix.
00027  *
00028  * Revision 1.10.2.1  2007/07/20 16:01:45  n-ando
00029  * Useless friend class declaration was deleted.
00030  *
00031  * Revision 1.10  2007/04/26 15:31:34  n-ando
00032  * The header include order was modified to define _REENTRANT before
00033  * including ace/config-lite.h in Linux systems.
00034  * In ace 5.4.7 or later, _REENTRANT flag should be defined explicitly.
00035  *
00036  * Revision 1.9  2007/04/13 15:53:03  n-ando
00037  * RTC::OK was changed to RTC::RTC_OK.
00038  *
00039  * Revision 1.8  2007/02/04 17:00:59  n-ando
00040  * Object reference variable was added.
00041  *
00042  * Revision 1.7  2007/01/04 00:43:35  n-ando
00043  * Now, notify_connect() and notify_disconnect() behavior can be customized
00044  * publishInterfaces(), subscribeInterfaces() and unsubscribeInterfaces().
00045  *
00046  * Revision 1.6  2006/12/02 18:50:22  n-ando
00047  * A trivial fix.
00048  *
00049  * Revision 1.5  2006/11/27 09:57:09  n-ando
00050  * addProvider() function was added for registration of provider.
00051  * addConsumer() function was added for registration of consumer.
00052  *
00053  * Revision 1.4  2006/11/06 01:46:47  n-ando
00054  * #include <assert.h> was added.
00055  *
00056  * Revision 1.3  2006/11/06 01:16:39  n-ando
00057  * Now PortBase doesn't depend on PortProfileHelper.
00058  * Class refference manual has been updated.
00059  *
00060  * Revision 1.2  2006/10/17 19:06:45  n-ando
00061  * connect(), disconnect() and disconnect_all() was implemented.
00062  *
00063  * Revision 1.1  2006/10/17 10:22:24  n-ando
00064  * The first commitment.
00065  *
00066  */
00067 
00068 #ifndef PortBase_h
00069 #define PortBase_h
00070 
00071 #include <rtm/RTC.h>
00072 
00073 #include <string>
00074 #include <vector>
00075 #include <ace/Guard_T.h>
00076 #include <ace/Recursive_Thread_Mutex.h>
00077 #include <rtm/idl/RTCSkel.h>
00078 #include <rtm/CORBA_SeqUtil.h>
00079 #include <rtm/NVUtil.h>
00080 
00081 #include <iostream>
00082 namespace RTC
00083 {
00084   //  class ConsumerBase;
00085 
00133   class PortBase
00134     : public virtual POA_RTC::Port,
00135       public virtual PortableServer::RefCountServantBase
00136   {
00137   public:
00161     PortBase(const char* name = "");
00162 
00163 
00175     virtual ~PortBase();
00176 
00177 
00219     virtual PortProfile* get_port_profile();
00220 
00221     const PortProfile& getPortProfile() const;
00222 
00262     virtual ConnectorProfileList* get_connector_profiles();
00263 
00264 
00286     virtual ConnectorProfile* get_connector_profile(const char* connector_id);
00287 
00288 
00324     virtual ReturnCode_t connect(ConnectorProfile& connector_profile);
00325 
00326 
00350     virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile);
00351 
00352 
00376     virtual ReturnCode_t disconnect(const char* connector_id);
00377 
00378 
00402     virtual ReturnCode_t notify_disconnect(const char* connector_id);
00403 
00404 
00424     virtual ReturnCode_t disconnect_all();
00425 
00426 
00427     //============================================================
00428     // Local operations
00429     //============================================================
00449     void setName(const char* name);
00450 
00451 
00469     const PortProfile& getProfile() const;
00470     
00471 
00493     void setPortRef(Port_ptr port_ref);
00494 
00495 
00517     Port_ptr getPortRef();
00518 
00519 
00539     void setOwner(RTObject_ptr owner);
00540 
00541 
00542     //============================================================
00543     // protected operations
00544     //============================================================
00545   protected:
00610     virtual ReturnCode_t
00611     publishInterfaces(ConnectorProfile& connector_profile) = 0;
00612     
00613 
00638     virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
00639 
00640 
00665     virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
00666 
00667 
00729     virtual ReturnCode_t
00730     subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00731     
00732     
00769     virtual void
00770     unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00771 
00772 
00773     //============================================================
00774     // protected utility functions
00775     //============================================================
00793     bool isEmptyId(const ConnectorProfile& connector_profile) const;
00794 
00795 
00815     const std::string getUUID() const;
00816 
00817 
00837     void setUUID(ConnectorProfile& connector_profile) const;
00838 
00839 
00861     bool isExistingConnId(const char* id);
00862 
00863 
00891     ConnectorProfile findConnProfile(const char* id);
00892     
00893 
00920     CORBA::Long findConnProfileIndex(const char* id);
00921 
00922 
00950     void updateConnectorProfile(const ConnectorProfile& connector_profile);
00951 
00952 
00975     bool eraseConnectorProfile(const char* id);
00976 
00977 
01024     bool appendInterface(const char* name, const char* type_name,
01025                          PortInterfacePolarity pol);
01026 
01027 
01053     bool deleteInterface(const char* name, PortInterfacePolarity pol);
01054     
01055 
01075     template <class ValueType>
01076     void addProperty(const char* key, ValueType value)
01077     {
01078       CORBA_SeqUtil::push_back(m_profile.properties,
01079                                NVUtil::newNV(key, value));
01080     }
01081 
01082 
01083   protected:
01091     PortProfile m_profile;
01092     RTC::Port_var m_objref;
01093     mutable ACE_Recursive_Thread_Mutex m_profile_mutex;
01094     typedef ACE_Guard<ACE_Recursive_Thread_Mutex> Guard;
01095     
01096     //============================================================
01097     // Functor
01098     //============================================================
01106     struct if_name
01107     {
01108       if_name(const char* name) : m_name(name) {};
01109       bool operator()(const PortInterfaceProfile& prof)
01110       {
01111         return m_name == std::string(prof.instance_name);
01112       }
01113       std::string m_name;
01114     };
01115     
01116     
01124     struct find_conn_id
01125     {
01126       find_conn_id(const char* id) : m_id(id) {};
01127       bool operator()(const ConnectorProfile& cprof)
01128       {
01129         return m_id == std::string(cprof.connector_id);
01130       }
01131       std::string m_id;
01132     };
01133 
01134 
01142     struct find_port_ref
01143     {
01144       find_port_ref(Port_ptr port_ref) : m_port(port_ref) {};
01145       bool operator()(Port_ptr port_ref)
01146       {
01147         return m_port->_is_equivalent(port_ref);
01148       }
01149       Port_ptr m_port;
01150     };
01151         
01152     
01160     struct connect_func
01161     {
01162       Port_var port_ref;
01163       ConnectorProfile connector_profile;
01164       ReturnCode_t return_code;
01165       
01166       connect_func() {};
01167       connect_func(Port_ptr p, ConnectorProfile& prof)
01168         : port_ref(p), connector_profile(prof), return_code(RTC::RTC_OK) {};
01169       void operator()(Port_ptr p)
01170       {
01171         if (!port_ref->_is_equivalent(p))
01172           {
01173             ReturnCode_t retval;
01174             retval = p->notify_connect(connector_profile);
01175             if (retval != RTC::RTC_OK)
01176               {
01177                 return_code = retval;
01178               }
01179           }
01180       }
01181     };
01182     
01183     
01191     struct disconnect_func
01192     {
01193       Port_var port_ref;
01194       ConnectorProfile connector_profile;
01195       ReturnCode_t return_code;
01196       
01197       disconnect_func() : return_code(RTC::RTC_OK) {};
01198       disconnect_func(Port_ptr p, ConnectorProfile& prof)
01199         : port_ref(p), connector_profile(prof), return_code(RTC::RTC_OK) {};
01200       void operator()(Port_ptr p)
01201       {
01202         if (!port_ref->_is_equivalent(p))
01203           {
01204             ReturnCode_t retval;
01205             retval = p->disconnect(connector_profile.connector_id);
01206             if (retval != RTC::RTC_OK)
01207               {
01208                 return_code = retval;
01209               }
01210           }
01211       }
01212     };
01213     
01214     
01222     struct disconnect_all_func
01223     {
01224       ReturnCode_t return_code;
01225       PortBase* port;
01226       
01227       disconnect_all_func() {};
01228       disconnect_all_func(PortBase* p) 
01229         : return_code(RTC::RTC_OK), port(p) {};
01230       void operator()(ConnectorProfile& p)
01231       {
01232         ReturnCode_t retval;
01233         retval = port->disconnect(p.connector_id);
01234         if (retval != RTC::RTC_OK)
01235           {
01236             return_code = retval;
01237           }
01238       }
01239     };
01240     
01241 
01249     struct find_interface
01250     {
01251       find_interface(const char* name, PortInterfacePolarity pol)
01252         : m_name(name), m_pol(pol)
01253       {}
01254 
01255       bool operator()(const PortInterfaceProfile& prof)
01256       {
01257         std::string name(CORBA::string_dup(prof.instance_name));
01258         return ((m_name == name) && (m_pol == prof.polarity));
01259       }
01260       std::string m_name;
01261       PortInterfacePolarity m_pol;
01262     };
01263   };
01264 };
01265 #endif // PortBase_h

OpenRTMに対してFri Oct 5 05:14:57 2007に生成されました。  doxygen 1.4.1