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

OutPortCorbaConsumer.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00020 /*
00021  * $Log: OutPortCorbaConsumer.h,v $
00022  * Revision 1.2  2007/01/06 17:57:27  n-ando
00023  * Interface subscription/unsubscription functions (subscribeInterface()
00024  * and unsubscribeInterface()) are added.
00025  *
00026  * Revision 1.1  2006/12/02 18:47:29  n-ando
00027  * OutPortCorbaConsumer class was moved from OutPortConsumer.h
00028  *
00029  */
00030 
00031 #ifndef OutPortCorbaConsumer_h
00032 #define OutPortCorbaConsumer_h
00033  
00034 #include <rtm/idl/DataPortSkel.h>
00035 #include <rtm/BufferBase.h>
00036 #include <rtm/CorbaConsumer.h>
00037 #include <rtm/OutPortConsumer.h>
00038 
00039 namespace RTC
00040 {
00050   template <class DataType>
00051   class OutPortCorbaConsumer
00052     : public OutPortConsumer,
00053       public CorbaConsumer<RTC::OutPortAny>
00054   {
00055   public:
00063     OutPortCorbaConsumer(BufferBase<DataType>& buffer)
00064       : m_buffer(buffer)
00065     {}
00066     
00074     virtual ~OutPortCorbaConsumer(){} 
00075     
00076     bool get(DataType& data)
00077     {
00078       DataType* d;
00079       try
00080         {
00081           if ((*(_ptr()->get())) >>= d)
00082             {
00083               data = (*d);
00084               return true;
00085             }
00086         }
00087       catch (...)
00088         {
00089           return false;
00090         }
00091       return false;
00092     }
00093 
00094 
00095     virtual void pull()
00096     {
00097       DataType data;
00098       if (get(data))
00099         {
00100           m_buffer.write(data);
00101         }
00102     }
00103     
00104 
00105     virtual bool subscribeInterface(const SDOPackage::NVList& properties)
00106     {
00107       CORBA::Long index;
00108       index = NVUtil::find_index(properties,
00109                                  "dataport.corba_any.outport_ref");
00110       if (index < 0) return false;
00111 
00112       CORBA::Object_ptr obj;
00113       if (properties[index].value >>= CORBA::Any::to_object(obj))
00114         {
00115           setObject(obj);
00116           return true;
00117         }
00118       return false;
00119     }
00120 
00121 
00122     virtual void unsubscribeInterface(const SDOPackage::NVList& properties)
00123     {
00124       CORBA::Long index;
00125       index = NVUtil::find_index(properties,
00126                                  "dataport.corba_any.outport_ref");
00127       if (index < 0) return;
00128 
00129       CORBA::Object_ptr obj;
00130       if (properties[index].value >>= CORBA::Any::to_object(obj))
00131         {
00132           if (getObject()->_is_equivalent(obj))
00133             releaseObject();
00134         }
00135     }
00136 
00137   private:
00138     RTC::OutPortAny_var m_outport;
00139     BufferBase<DataType>& m_buffer;
00140   };
00141 };     // namespace RTC
00142 #endif // OutPortCorbaConsumer_h
00143 

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