Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

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/OutPortTcpSockProvider.h>
00055 #include <rtm/InPortCorbaConsumer.h>
00056 #include <rtm/InPortTcpSockConsumer.h>
00057 #include <rtm/OutPort.h>
00058 #include <rtm/NVUtil.h>
00059 #include <rtm/PublisherFactory.h>
00060 #include <rtm/Properties.h>
00061 
00062 namespace RTC
00063 {
00073   class DataOutPort
00074     : public PortBase
00075   {
00076   public:
00084     template <class DataType, template <class DataType> class Buffer>
00085     DataOutPort(const char* name, OutPort<DataType, Buffer>& outport,
00086                 Properties& prop)
00087       : PortBase(name), m_outport(outport)
00088     {
00089       // PortProfile::properties ¤òÀßÄê
00090       addProperty("port.port_type", "DataOutPort");
00091       
00092       m_providers.push_back(new OutPortCorbaProvider<DataType>(outport));
00093       m_providers.back()->publishInterfaceProfile(m_profile.properties);
00094 
00095       m_providers.push_back(new OutPortTcpSockProvider<DataType>(outport));
00096       m_providers.back()->publishInterfaceProfile(m_profile.properties);
00097 
00098       m_consumers.push_back(new InPortCorbaConsumer<DataType>(outport));
00099       m_consumers.push_back(new InPortTcpSockConsumer<DataType>(outport, prop));
00100 
00101     }
00102 
00103 
00111     virtual ~DataOutPort();
00112 
00113     
00170   protected:
00215     virtual ReturnCode_t
00216     publishInterfaces(ConnectorProfile& connector_profile);
00217     
00218 
00255     virtual ReturnCode_t
00256     subscribeInterfaces(const ConnectorProfile& connector_profile);
00257     
00258 
00289     virtual void
00290     unsubscribeInterfaces(const ConnectorProfile& connector_profile);
00291 
00292 
00293     
00294     struct publish
00295     {
00296       publish(SDOPackage::NVList& prop) : m_prop(prop) {}
00297       void operator()(OutPortProvider* provider)
00298       {
00299         provider->publishInterface(m_prop);
00300       }
00301       SDOPackage::NVList& m_prop;
00302     };
00303 
00304     struct unsubscribe
00305     {
00306       unsubscribe(const SDOPackage::NVList& prop) : m_prop(prop) {}
00307       void operator()(InPortConsumer* consumer)
00308       {
00309         consumer->unsubscribeInterface(m_prop);
00310       }
00311       const SDOPackage::NVList& m_prop;
00312     };
00313 
00314   private:
00315     std::vector<OutPortProvider*> m_providers;
00316     std::vector<InPortConsumer*> m_consumers;
00317     OutPortBase& m_outport;
00318 
00319     PublisherFactory m_pf;
00320 
00321     struct subscribe
00322     {
00323       subscribe(const ConnectorProfile& prof)
00324         : m_prof(&prof), _consumer(NULL) 
00325       {
00326       }
00327 
00328       subscribe(const subscribe& subs)
00329         : m_prof(subs.m_prof),
00330           _consumer(subs._consumer)
00331       {
00332       }
00333 
00334       subscribe& operator=(const subscribe& subs)
00335       {
00336         if (this == &subs) return *this;
00337         m_prof = subs.m_prof;
00338         _consumer = subs._consumer;
00339         return *this;
00340       }
00341 
00342       void operator()(InPortConsumer* cons)
00343       {
00344         if (cons->subscribeInterface(m_prof->properties))
00345           {
00346             _consumer = cons;
00347           }
00348       }
00349       const ConnectorProfile* m_prof;
00350       InPortConsumer* _consumer;
00351     };
00352 
00353 
00354   };
00355 }; // namespace RTC
00356 
00357 #endif // DataOutPort_h

Generated on Fri Oct 5 05:15:59 2007 for OpenRTM by  doxygen 1.4.1