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

PortBase.h

説明を見る。
00001 
00002 // -*- C++ -*-
00020 /*
00021  * $Log: PortBase.h,v $
00022  * Revision 1.10.2.1  2007/07/20 16:01:45  n-ando
00023  * Useless friend class declaration was deleted.
00024  *
00025  * Revision 1.10  2007/04/26 15:31:34  n-ando
00026  * The header include order was modified to define _REENTRANT before
00027  * including ace/config-lite.h in Linux systems.
00028  * In ace 5.4.7 or later, _REENTRANT flag should be defined explicitly.
00029  *
00030  * Revision 1.9  2007/04/13 15:53:03  n-ando
00031  * RTC::OK was changed to RTC::RTC_OK.
00032  *
00033  * Revision 1.8  2007/02/04 17:00:59  n-ando
00034  * Object reference variable was added.
00035  *
00036  * Revision 1.7  2007/01/04 00:43:35  n-ando
00037  * Now, notify_connect() and notify_disconnect() behavior can be customized
00038  * publishInterfaces(), subscribeInterfaces() and unsubscribeInterfaces().
00039  *
00040  * Revision 1.6  2006/12/02 18:50:22  n-ando
00041  * A trivial fix.
00042  *
00043  * Revision 1.5  2006/11/27 09:57:09  n-ando
00044  * addProvider() function was added for registration of provider.
00045  * addConsumer() function was added for registration of consumer.
00046  *
00047  * Revision 1.4  2006/11/06 01:46:47  n-ando
00048  * #include <assert.h> was added.
00049  *
00050  * Revision 1.3  2006/11/06 01:16:39  n-ando
00051  * Now PortBase doesn't depend on PortProfileHelper.
00052  * Class refference manual has been updated.
00053  *
00054  * Revision 1.2  2006/10/17 19:06:45  n-ando
00055  * connect(), disconnect() and disconnect_all() was implemented.
00056  *
00057  * Revision 1.1  2006/10/17 10:22:24  n-ando
00058  * The first commitment.
00059  *
00060  */
00061 
00062 #ifndef PortBase_h
00063 #define PortBase_h
00064 
00065 #include <rtm/RTC.h>
00066 
00067 #include <string>
00068 #include <vector>
00069 #include <ace/Guard_T.h>
00070 #include <ace/Recursive_Thread_Mutex.h>
00071 #include <rtm/idl/RTCSkel.h>
00072 #include <rtm/CORBA_SeqUtil.h>
00073 #include <rtm/NVUtil.h>
00074 
00075 #include <iostream>
00076 namespace RTC
00077 {
00078   //  class ConsumerBase;
00079 
00127   class PortBase
00128     : public virtual POA_RTC::Port,
00129       public virtual PortableServer::RefCountServantBase
00130   {
00131   public:
00155     PortBase(const char* name = "");
00156 
00157 
00169     virtual ~PortBase();
00170 
00171 
00213     virtual PortProfile* get_port_profile();
00214 
00215 
00255     virtual ConnectorProfileList* get_connector_profiles();
00256 
00257 
00279     virtual ConnectorProfile* get_connector_profile(const char* connector_id);
00280 
00281 
00317     virtual ReturnCode_t connect(ConnectorProfile& connector_profile);
00318 
00319 
00343     virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile);
00344 
00345 
00369     virtual ReturnCode_t disconnect(const char* connector_id);
00370 
00371 
00395     virtual ReturnCode_t notify_disconnect(const char* connector_id);
00396 
00397 
00417     virtual ReturnCode_t disconnect_all();
00418 
00419 
00420     //============================================================
00421     // Local operations
00422     //============================================================
00442     void setName(const char* name);
00443 
00444 
00462     const PortProfile& getProfile() const;
00463     
00464 
00486     void setPortRef(Port_ptr port_ref);
00487 
00488 
00510     Port_ptr getPortRef();
00511 
00512 
00532     void setOwner(RTObject_ptr owner);
00533 
00534 
00535     //============================================================
00536     // protected operations
00537     //============================================================
00538   protected:
00603     virtual ReturnCode_t
00604     publishInterfaces(ConnectorProfile& connector_profile) = 0;
00605     
00606 
00631     virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
00632 
00633 
00658     virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
00659 
00660 
00722     virtual ReturnCode_t
00723     subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00724     
00725     
00762     virtual void
00763     unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
00764 
00765 
00766     //============================================================
00767     // protected utility functions
00768     //============================================================
00786     bool isEmptyId(const ConnectorProfile& connector_profile) const;
00787 
00788 
00808     const std::string getUUID() const;
00809 
00810 
00830     void setUUID(ConnectorProfile& connector_profile) const;
00831 
00832 
00854     bool isExistingConnId(const char* id);
00855 
00856 
00884     ConnectorProfile findConnProfile(const char* id);
00885     
00886 
00913     CORBA::Long findConnProfileIndex(const char* id);
00914 
00915 
00943     void updateConnectorProfile(const ConnectorProfile& connector_profile);
00944 
00945 
00968     bool eraseConnectorProfile(const char* id);
00969 
00970 
01017     bool appendInterface(const char* name, const char* type_name,
01018                          PortInterfacePolarity pol);
01019 
01020 
01046     bool deleteInterface(const char* name, PortInterfacePolarity pol);
01047     
01048 
01068     template <class ValueType>
01069     void addProperty(const char* key, ValueType value)
01070     {
01071       CORBA_SeqUtil::push_back(m_profile.properties,
01072                                NVUtil::newNV(key, value));
01073     }
01074 
01075 
01076   protected:
01084     PortProfile m_profile;
01085     RTC::Port_var m_objref;
01086     mutable ACE_Recursive_Thread_Mutex m_profile_mutex;
01087     typedef ACE_Guard<ACE_Recursive_Thread_Mutex> Guard;
01088     
01089     //============================================================
01090     // Functor
01091     //============================================================
01099     struct if_name
01100     {
01101       if_name(const char* name) : m_name(name) {};
01102       bool operator()(const PortInterfaceProfile& prof)
01103       {
01104         return m_name == std::string(prof.instance_name);
01105       }
01106       std::string m_name;
01107     };
01108     
01109     
01117     struct find_conn_id
01118     {
01119       find_conn_id(const char* id) : m_id(id) {};
01120       bool operator()(const ConnectorProfile& cprof)
01121       {
01122         return m_id == std::string(cprof.connector_id);
01123       }
01124       std::string m_id;
01125     };
01126 
01127 
01135     struct find_port_ref
01136     {
01137       find_port_ref(Port_ptr port_ref) : m_port(port_ref) {};
01138       bool operator()(Port_ptr port_ref)
01139       {
01140         return m_port->_is_equivalent(port_ref);
01141       }
01142       Port_ptr m_port;
01143     };
01144         
01145     
01153     struct connect_func
01154     {
01155       Port_var port_ref;
01156       ConnectorProfile connector_profile;
01157       ReturnCode_t return_code;
01158       
01159       connect_func() {};
01160       connect_func(Port_ptr p, ConnectorProfile& prof)
01161         : port_ref(p), connector_profile(prof) {};
01162       void operator()(Port_ptr p)
01163       {
01164         if (!port_ref->_is_equivalent(p))
01165           {
01166             ReturnCode_t retval;
01167             retval = p->notify_connect(connector_profile);
01168             if (retval != RTC::RTC_OK)
01169               {
01170                 return_code = retval;
01171               }
01172           }
01173       }
01174     };
01175     
01176     
01184     struct disconnect_func
01185     {
01186       Port_var port_ref;
01187       ConnectorProfile connector_profile;
01188       ReturnCode_t return_code;
01189       
01190       disconnect_func() : return_code(RTC::RTC_OK) {};
01191       disconnect_func(Port_ptr p, ConnectorProfile& prof)
01192         : port_ref(p), connector_profile(prof), return_code(RTC::RTC_OK) {};
01193       void operator()(Port_ptr p)
01194       {
01195         if (!port_ref->_is_equivalent(p))
01196           {
01197             ReturnCode_t retval;
01198             retval = p->disconnect(connector_profile.connector_id);
01199             if (retval != RTC::RTC_OK)
01200               {
01201                 return_code = retval;
01202               }
01203           }
01204       }
01205     };
01206     
01207     
01215     struct disconnect_all_func
01216     {
01217       ReturnCode_t return_code;
01218       PortBase* port;
01219       
01220       disconnect_all_func() {};
01221       disconnect_all_func(PortBase* p) 
01222         : return_code(RTC::RTC_OK), port(p) {};
01223       void operator()(ConnectorProfile& p)
01224       {
01225         ReturnCode_t retval;
01226         retval = port->disconnect(p.connector_id);
01227         if (retval != RTC::RTC_OK)
01228           {
01229             return_code = retval;
01230           }
01231       }
01232     };
01233     
01234 
01242     struct find_interface
01243     {
01244       find_interface(const char* name, PortInterfacePolarity pol)
01245         : m_name(name), m_pol(pol)
01246       {}
01247 
01248       bool operator()(const PortInterfaceProfile& prof)
01249       {
01250         std::string name(CORBA::string_dup(prof.instance_name));
01251         return ((m_name == name) && (m_pol == prof.polarity));
01252       }
01253       std::string m_name;
01254       PortInterfacePolarity m_pol;
01255     };
01256   };
01257 };
01258 #endif // PortBase_h

OpenRTMに対してMon Jul 23 17:08:04 2007に生成されました。  doxygen 1.4.1