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

InPortCorbaConsumer.h

説明を見る。
00001 // -*- C++ -*-
00020 /*
00021  * $Log: InPortCorbaConsumer.h,v $
00022  * Revision 1.3.4.2  2007/09/19 07:47:28  n-ando
00023  * A trivial fix.
00024  *
00025  * Revision 1.3.4.1  2007/08/20 06:31:10  n-ando
00026  * push() function was modified to detect buffer read error.
00027  *
00028  * Revision 1.3  2007/01/09 09:56:38  n-ando
00029  * Kanji-code has changed.
00030  *
00031  * Revision 1.2  2007/01/06 17:50:57  n-ando
00032  * Interface subscription/unsubscription functions (subscribeInterface()
00033  * and unsubscribeInterface()) are added.
00034  * The clone() function to clone the instance is added.
00035  *
00036  * Revision 1.1  2006/12/02 18:39:57  n-ando
00037  * InPortCorbaConsumer class was moved from InPortConsumer.h
00038  *
00039  */
00040 
00041 #ifndef InPortCorbaConsumer_h
00042 #define InPortCorbaConsumer_h
00043 
00044 #include <rtm/idl/DataPortSkel.h>
00045 #include <rtm/BufferBase.h>
00046 #include <rtm/CorbaConsumer.h>
00047 #include <rtm/InPortConsumer.h>
00048 #include <iostream>
00049  
00050 namespace RTC
00051 {
00052   template <class DataType>
00053   class InPortCorbaConsumer
00054     : public InPortConsumer,
00055       public CorbaConsumer<RTC::InPortAny>
00056   {
00057   public:
00058     InPortCorbaConsumer(BufferBase<DataType>& buffer)
00059       : m_buffer(buffer)
00060     {
00061     }
00062 
00063 
00064     InPortCorbaConsumer(const InPortCorbaConsumer<DataType>& consumer)
00065       : CorbaConsumer<RTC::InPortAny>(consumer), m_buffer(consumer.m_buffer)
00066     {
00067     }
00068 
00069     InPortCorbaConsumer&
00070     operator=(const InPortCorbaConsumer<DataType>& consumer)
00071     {
00072       if (this == &consumer) return *this;
00073       m_buffer = consumer.m_buffer;
00074     }
00075 
00076 
00077     virtual ~InPortCorbaConsumer()
00078     {}
00079 
00080     void put(DataType& data)
00081     {
00082       CORBA::Any tmp;
00083       tmp <<= data;
00084       _ptr()->put(tmp);
00085     }
00086 
00087     void push()
00088     {
00089       DataType data;
00090       CORBA::Any tmp;
00091       m_buffer.read(data);
00092       tmp <<= data;
00093 
00094       // 本当はエラー処理をすべき
00095       if (CORBA::is_nil(_ptr())) return;
00096       try
00097         {
00098           _ptr()->put(tmp);
00099         }
00100       catch(...)
00101         {
00102           //hoge オブジェクトが無効になったらdisconnectすべき
00103           return;
00104         }
00105     }
00106 
00107     virtual InPortCorbaConsumer* clone() const
00108     {
00109       return new InPortCorbaConsumer<DataType>(*this);
00110     }
00111 
00112     virtual bool subscribeInterface(const SDOPackage::NVList& properties)
00113     {
00114       if (!NVUtil::isStringValue(properties,
00115                                  "dataport.dataflow_type",
00116                                  "Push"))
00117         {
00118           return false;
00119         }
00120       
00121       CORBA::Long index;
00122       index = NVUtil::find_index(properties,
00123                                  "dataport.corba_any.inport_ref");
00124       if (index < 0)
00125         {
00126           return false;
00127         }
00128       
00129       CORBA::Object_ptr obj;
00130       if (properties[index].value >>= CORBA::Any::to_object(obj))
00131         {
00132           if (!CORBA::is_nil(obj))
00133             {
00134               setObject(obj);
00135               return true;
00136             }
00137         }
00138       return false;;
00139     }
00140 
00141 
00142     virtual void unsubscribeInterface(const SDOPackage::NVList& properties)
00143     {
00144       ;
00145     }
00146 
00147 
00148   private:
00149     BufferBase<DataType>& m_buffer;
00150   };
00151 };     // namespace RTC
00152 #endif // InPortCorbaConsumer_h
00153 

OpenRTMに対してFri Oct 5 05:14:57 2007に生成されました。  doxygen 1.4.1