CorbaPort.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef CorbaPort_h
00021 #define CorbaPort_h
00022 
00023 #include <rtm/PortBase.h>
00024 #include <rtm/CorbaConsumer.h>
00025 #include <rtm/NVUtil.h>
00026 
00041 namespace RTC
00042 {
00135   class CorbaPort
00136     : public PortBase
00137   {
00138   public:
00153     CorbaPort(const char* name);
00154     
00166     virtual ~CorbaPort(void);
00167     
00202     bool registerProvider(const char* instance_name, const char* type_name,
00203                           PortableServer::RefCountServantBase& provider);
00204     
00245     bool registerConsumer(const char* instance_name, const char* type_name,
00246                           CorbaConsumerBase& consumer);
00247     
00248   protected:
00336     virtual ReturnCode_t
00337     publishInterfaces(ConnectorProfile& connector_profile);
00338     
00419     virtual ReturnCode_t
00420     subscribeInterfaces(const ConnectorProfile& connector_profile);
00421     
00443     virtual void
00444     unsubscribeInterfaces(const ConnectorProfile& connector_profile);
00445 
00446     //============================================================
00447     // Local operations
00448     //============================================================
00465     virtual void activateInterfaces();
00466 
00483     virtual void deactivateInterfaces();
00484 
00485   private:
00493     NVList m_providers;
00494     std::vector<PortableServer::RefCountServantBase*> m_servants;
00495     
00503     struct Consumer
00504     {
00505       Consumer(const char* _instance_name, const char* _type_name,
00506                CorbaConsumerBase& _cons)
00507         : name(std::string("port.")
00508                + _type_name
00509                + std::string(".")
00510                + _instance_name),
00511           consumer(_cons)
00512       {}
00513       Consumer(const Consumer& cons)
00514         : name(cons.name), consumer(cons.consumer)
00515       {        
00516       }
00517       Consumer operator=(const Consumer& _cons)
00518       {
00519         Consumer cons(_cons);
00520         return cons;
00521       }
00522       std::string name;
00523       CorbaConsumerBase& consumer;
00524     };
00525     std::vector<Consumer> m_consumers;
00526     
00527     // functors
00535     struct unsubscribe
00536     {
00537       unsubscribe(std::vector<Consumer>& cons)
00538         : m_cons(cons), m_len(cons.size())
00539       {
00540       }
00541       
00542       void operator()(const SDOPackage::NameValue& nv)
00543       {
00544         for (CORBA::ULong i = 0; i < m_len; ++i)
00545           {
00546             std::string name(nv.name);
00547             if (m_cons[i].name == name)
00548               {
00549                 m_cons[i].consumer.releaseObject();
00550               }
00551           }
00552       }
00553       std::vector<Consumer> m_cons;
00554       CORBA::ULong m_len;
00555     };
00556   };
00557 };
00558 #endif // CorbaPort_h

Generated on Sun May 24 14:08:45 2009 for OpenRTM by  doxygen 1.5.3