00001
00020 #ifndef OutPortCorbaConsumer_h
00021 #define OutPortCorbaConsumer_h
00022
00023 #include <rtm/idl/DataPortSkel.h>
00024 #include <rtm/BufferBase.h>
00025 #include <rtm/CorbaConsumer.h>
00026 #include <rtm/OutPortConsumer.h>
00027
00028 namespace RTC
00029 {
00056 template <class DataType>
00057 class OutPortCorbaConsumer
00058 : public OutPortConsumer,
00059 public CorbaConsumer<RTC::OutPortAny>
00060 {
00061 public:
00079 OutPortCorbaConsumer(BufferBase<DataType>& buffer)
00080 : m_buffer(buffer)
00081 {}
00082
00096 virtual ~OutPortCorbaConsumer(){}
00097
00119 bool get(DataType& data)
00120 {
00121 const DataType* d;
00122 try
00123 {
00124 CORBA::Any_var a_var(_ptr()->get());
00125 if (*((const CORBA::Any*)(a_var.operator->())) >>= d)
00126 {
00127 data = (*d);
00128 return true;
00129 }
00130 }
00131 catch (...)
00132 {
00133 return false;
00134 }
00135 return false;
00136 }
00137
00153 virtual void pull()
00154 {
00155 DataType data;
00156 if (get(data))
00157 {
00158 m_buffer.write(data);
00159 }
00160 }
00161
00184 virtual bool subscribeInterface(const SDOPackage::NVList& properties)
00185 {
00186 CORBA::Long index;
00187 index = NVUtil::find_index(properties,
00188 "dataport.corba_any.outport_ref");
00189 if (index < 0) return false;
00190
00191 CORBA::Object_ptr obj;
00192 if (properties[index].value >>= CORBA::Any::to_object(obj))
00193 {
00194 setObject(obj);
00195 return true;
00196 }
00197 return false;
00198 }
00199
00217 virtual void unsubscribeInterface(const SDOPackage::NVList& properties)
00218 {
00219 CORBA::Long index;
00220 index = NVUtil::find_index(properties,
00221 "dataport.corba_any.outport_ref");
00222 if (index < 0) return;
00223
00224 CORBA::Object_ptr obj;
00225 if (properties[index].value >>= CORBA::Any::to_object(obj))
00226 {
00227 if (getObject()->_is_equivalent(obj))
00228 releaseObject();
00229 }
00230 }
00231
00232 private:
00233 RTC::OutPortAny_var m_outport;
00234 BufferBase<DataType>& m_buffer;
00235 };
00236 };
00237 #endif // OutPortCorbaConsumer_h