DataOutPort.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00020 /*
00021  * $Log: DataOutPort.h,v $
00022  * Revision 1.7  2007/04/13 15:45:08  n-ando
00023  * RTC::OK was changed to RTC::RTC_OK.
00024  *
00025  * Revision 1.6  2007/01/21 09:45:31  n-ando
00026  * To advertise interface profile, publishInterfaceProfile() is called now.
00027  *
00028  * Revision 1.5  2007/01/14 22:57:54  n-ando
00029  * A bug fix about template argument for buffer-type in constructor.
00030  *
00031  * Revision 1.4  2007/01/12 14:30:01  n-ando
00032  * A trivial bug fix.
00033  *
00034  * Revision 1.3  2007/01/06 17:44:11  n-ando
00035  * The behavior on notify_connect() and notify_disconnect() are now
00036  * implemented in protected functions(ex. publisherInterfaces()).
00037  *
00038  * Revision 1.2  2006/12/02 18:29:15  n-ando
00039  * Now OutPortCorbaProvider and InPortCorbaConsumer are used.
00040  *
00041  * Revision 1.1  2006/11/27 09:44:37  n-ando
00042  * The first commitment.
00043  *
00044  *
00045  */
00046 
00047 #ifndef DataOutPort_h
00048 #define DataOutPort_h
00049 
00050 
00051 #include <rtm/PortBase.h>
00052 #include <rtm/BufferBase.h>
00053 #include <rtm/OutPortCorbaProvider.h>
00054 #include <rtm/InPortCorbaConsumer.h>
00055 #include <rtm/OutPort.h>
00056 #include <rtm/NVUtil.h>
00057 #include <rtm/PublisherFactory.h>
00058 
00059 namespace RTC
00060 {
00070   class DataOutPort
00071     : public PortBase
00072   {
00073   public:
00081     template <class DataType, template <class DataType> class Buffer>
00082     DataOutPort(const char* name, OutPort<DataType, Buffer>& outport)
00083       : PortBase(name), m_outport(outport)
00084     {
00085       // PortProfile::properties ¤òÀßÄê
00086       addProperty("port.port_type", "DataOutPort");
00087       
00088       m_providers.push_back(new OutPortCorbaProvider<DataType>(outport));
00089       m_providers.back()->publishInterfaceProfile(m_profile.properties);
00090       m_consumers.push_back(new InPortCorbaConsumer<DataType>(outport));
00091     }
00092 
00093 
00101     virtual ~DataOutPort();
00102 
00103     
00160   protected:
00205     virtual ReturnCode_t
00206     publishInterfaces(ConnectorProfile& connector_profile);
00207     
00208 
00245     virtual ReturnCode_t
00246     subscribeInterfaces(const ConnectorProfile& connector_profile);
00247     
00248 
00279     virtual void
00280     unsubscribeInterfaces(const ConnectorProfile& connector_profile);
00281 
00282 
00283     
00284     struct publish
00285     {
00286       publish(SDOPackage::NVList& prop) : m_prop(prop) {}
00287       void operator()(OutPortProvider* provider)
00288       {
00289         provider->publishInterface(m_prop);
00290       }
00291       SDOPackage::NVList& m_prop;
00292     };
00293 
00294     struct unsubscribe
00295     {
00296       unsubscribe(const SDOPackage::NVList& prop) : m_prop(prop) {}
00297       void operator()(InPortConsumer* consumer)
00298       {
00299         consumer->unsubscribeInterface(m_prop);
00300       }
00301       const SDOPackage::NVList& m_prop;
00302     };
00303 
00304   private:
00305     std::vector<OutPortProvider*> m_providers;
00306     std::vector<InPortConsumer*> m_consumers;
00307     OutPortBase& m_outport;
00308 
00309     PublisherFactory m_pf;
00310 
00311     struct subscribe
00312     {
00313       subscribe(const ConnectorProfile& prof)
00314         : m_prof(&prof), _consumer(NULL) 
00315       {
00316       }
00317 
00318       subscribe(const subscribe& subs)
00319         : m_prof(subs.m_prof),
00320           _consumer(subs._consumer)
00321       {
00322       }
00323 
00324       subscribe& operator=(const subscribe& subs)
00325       {
00326         if (this == &subs) return *this;
00327         m_prof = subs.m_prof;
00328         _consumer = subs._consumer;
00329         return *this;
00330       }
00331 
00332       void operator()(InPortConsumer* cons)
00333       {
00334         if (cons->subscribeInterface(m_prof->properties))
00335           {
00336             _consumer = cons;
00337           }
00338       }
00339       const ConnectorProfile* m_prof;
00340       InPortConsumer* _consumer;
00341     };
00342 
00343 
00344   };
00345 }; // namespace RTC
00346 
00347 #endif // DataOutPort_h

Generated on Tue Sep 25 00:47:15 2007 for OpenRTM by  doxygen 1.4.6