InPortCorbaCdrConsumer.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 #include <rtm/NVUtil.h>
22 
23 namespace RTC
24 {
34  : rtclog("InPortCorbaCdrConsumer")
35  {
36  }
37 
46  {
47  RTC_PARANOID(("~InPortCorbaCdrConsumer()"));
48  }
49 
58  {
60  }
61 
70  put(const cdrMemoryStream& data)
71  {
72  RTC_PARANOID(("put()"));
73 
74 #ifndef ORB_IS_RTORB
75  ::OpenRTM::CdrData tmp(data.bufSize(), data.bufSize(),
76  static_cast<CORBA::Octet*>(data.bufPtr()), 0);
77 #else // ORB_IS_RTORB
78  OpenRTM_CdrData *cdrdata_tmp = new OpenRTM_CdrData();
79  cdrdata_tmp->_buffer =
80  (CORBA_octet *)RtORB_alloc(data.bufSize(), "InPortCorbaCdrComsumer::put");
81  memcpy(cdrdata_tmp->_buffer, data.bufPtr(), data.bufSize());
82  cdrdata_tmp->_length = cdrdata_tmp->_maximum= data.bufSize();
83  ::OpenRTM::CdrData tmp(cdrdata_tmp);
84 #endif // ORB_IS_RTORB
85  try
86  {
87  // return code conversion
88  // (IDL)OpenRTM::DataPort::ReturnCode_t -> DataPortStatus
89  return convertReturnCode(_ptr()->put(tmp));
90  }
91  catch (...)
92  {
93  return CONNECTION_LOST;
94  }
95  return UNKNOWN_ERROR;
96  }
97 
107  {
108  return;
109  }
110 
120  {
121  RTC_TRACE(("subscribeInterface()"));
122  RTC_DEBUG_STR((NVUtil::toString(properties)));
123 
124  // getting InPort's ref from IOR string
125  if (subscribeFromIor(properties)) { return true; }
126 
127  // getting InPort's ref from Object reference
128  if (subscribeFromRef(properties)) { return true; }
129 
130  return false;;
131  }
132 
142  {
143  RTC_TRACE(("unsubscribeInterface()"));
144  RTC_DEBUG_STR((NVUtil::toString(properties)));
145 
146  if (unsubscribeFromIor(properties)) { return; }
147  unsubscribeFromRef(properties);
148  }
149 
150  //----------------------------------------------------------------------
151  // private functions
152 
162  {
163  RTC_TRACE(("subscribeFromIor()"));
164 
165  CORBA::Long index;
166  index = NVUtil::find_index(properties,
167  "dataport.corba_cdr.inport_ior");
168  if (index < 0)
169  {
170  RTC_ERROR(("inport_ior not found"));
171  return false;
172  }
173 
174  const char* ior(0);
175  if (!(properties[index].value >>= ior))
176  {
177  RTC_ERROR(("inport_ior has no string"));
178  return false;
179  }
180 
181  CORBA::ORB_ptr orb = RTC::Manager::instance().getORB();
182  CORBA::Object_var obj = orb->string_to_object(ior);
183 
184  if (CORBA::is_nil(obj))
185  {
186  RTC_ERROR(("invalid IOR string has been passed"));
187  return false;
188  }
189 
190  if (!setObject(obj.in()))
191  {
192  RTC_WARN(("Setting object to consumer failed."));
193  return false;
194  }
195  return true;
196  }
197 
207  {
208  RTC_TRACE(("subscribeFromRef()"));
209  CORBA::Long index;
210  index = NVUtil::find_index(properties,
211  "dataport.corba_cdr.inport_ref");
212  if (index < 0)
213  {
214  RTC_ERROR(("inport_ref not found"));
215  return false;
216  }
217 
218  CORBA::Object_var obj;
219  if (!(properties[index].value >>= CORBA::Any::to_object(obj.out())))
220  {
221  RTC_ERROR(("prop[inport_ref] is not objref"));
222  return true;
223  }
224 
225  if (CORBA::is_nil(obj))
226  {
227  RTC_ERROR(("prop[inport_ref] is not objref"));
228  return false;
229  }
230 
231  if (!setObject(obj.in()))
232  {
233  RTC_ERROR(("Setting object to consumer failed."));
234  return false;
235  }
236  return true;
237  }
238 
248  {
249  RTC_TRACE(("unsubscribeFromIor()"));
250  CORBA::Long index;
251  index = NVUtil::find_index(properties,
252  "dataport.corba_cdr.inport_ior");
253  if (index < 0)
254  {
255  RTC_ERROR(("inport_ior not found"));
256  return false;
257  }
258 
259  const char* ior;
260  if (!(properties[index].value >>= ior))
261  {
262  RTC_ERROR(("prop[inport_ior] is not string"));
263  return false;
264  }
265 
266  CORBA::ORB_ptr orb = RTC::Manager::instance().getORB();
267  CORBA::Object_var var = orb->string_to_object(ior);
268  if (!(_ptr()->_is_equivalent(var)))
269  {
270  RTC_ERROR(("connector property inconsistency"));
271  return false;
272  }
273 
274  releaseObject();
275  return true;
276  }
277 
287  {
288  RTC_TRACE(("unsubscribeFromRef()"));
289  CORBA::Long index;
290  index = NVUtil::find_index(properties,
291  "dataport.corba_cdr.inport_ref");
292  if (index < 0) { return false; }
293 
294  CORBA::Object_var obj;
295  if (!(properties[index].value >>= CORBA::Any::to_object(obj.out())))
296  {
297  return false;
298  }
299 
300  if (!(_ptr()->_is_equivalent(obj.in()))) { return false; }
301 
302  releaseObject();
303  return true;
304  }
305 
315  {
316  switch (ret)
317  {
318  case OpenRTM::PORT_OK:
320  break;
321  case OpenRTM::PORT_ERROR:
323  break;
324  case OpenRTM::BUFFER_FULL:
326  break;
327  case OpenRTM::BUFFER_TIMEOUT:
329  break;
330  case OpenRTM::UNKNOWN_ERROR:
332  break;
333  default:
335  break;
336  }
338  }
339 
340 }; // namespace RTC
341 
342 extern "C"
343 {
352  {
354  factory.addFactory("corba_cdr",
359  }
360 };
virtual bool subscribeInterface(const SDOPackage::NVList &properties)
Subscribe to the data sending notification.
InPortConsumer abstract class.
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
virtual void releaseObject()
Clear CORBA object setting.
InPortCorbaCdrConsumer class.
RT-Component.
AbstractClass * Creator()
Creator template.
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
ReturnCode addFactory(const Identifier &id, Creator creator, Destructor destructor)
Add factory.
virtual void unsubscribeInterface(const SDOPackage::NVList &properties)
Unsubscribe the data send notification.
virtual ReturnCode put(const cdrMemoryStream &data)
Send data to the destination port.
void InPortCorbaCdrConsumerInit(void)
Module initialization.
CORBA::ORB_ptr getORB()
Get the pointer to ORB.
Definition: Manager.cpp:832
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
GlobalFactory template class.
#define RTC_WARN(fmt)
Warning log output macro.
Definition: SystemLogger.h:444
bool unsubscribeFromRef(const SDOPackage::NVList &properties)
ubsubscribing (Object reference version)
#define RTC_DEBUG_STR(str)
Definition: SystemLogger.h:489
#define RTC_PARANOID(fmt)
Paranoid level log output macro.
Definition: SystemLogger.h:555
const CORBA::Long find_index(const SDOPackage::NVList &nv, const char *name)
Return the index of element specified by name from NVList.
Definition: NVUtil.cpp:227
virtual bool setObject(CORBA::Object_ptr obj)
Set Object.
std::string toString(const SDOPackage::NVList &nv, const char *name)
Get NVList of specifid name as string.
Definition: NVUtil.cpp:282
#define RTC_TRACE(fmt)
list index
Definition: rtimages.py:10
NameValue and NVList utility functions.
typename::OpenRTM::InPortCdr::_ptr_type _ptr()
Get Object reference narrowed as ObjectType.
bool unsubscribeFromIor(const SDOPackage::NVList &properties)
ubsubscribing (IOR version)
::RTC::BufferStatus::Enum ReturnCode
prop
Organization::get_organization_property ();.
bool subscribeFromIor(const SDOPackage::NVList &properties)
Getting object reference fromn IOR string.
void Destructor(AbstractClass *&obj)
Destructor template.
Class represents a set of properties.
Definition: Properties.h:101
InPortCorbaCdrConsumer class.
bool subscribeFromRef(const SDOPackage::NVList &properties)
Getting object reference fromn Any directry.
virtual ~InPortCorbaCdrConsumer(void)
Destructor.
InPortConsumer::ReturnCode convertReturnCode(OpenRTM::PortStatus ret)
Return codes conversion.
DATAPORTSTATUS_ENUM InPortCorbaCdrConsumer(void)
Constructor.
virtual void init(coil::Properties &prop)
Initializing configuration.
virtual void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:52