OutPortCorbaCdrConsumer.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
5 
19 
20 import sys
21 from omniORB import any
22 import OpenRTM_aist
23 import OpenRTM
24 
25 
52  """
53  """
54 
55 
72  def __init__(self):
73  OpenRTM_aist.CorbaConsumer.__init__(self)
74  self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("OutPortCorbaCdrConsumer")
75  self._buffer = None
76  self._profile = None
77  self._listeners = None
78  return
79 
80 
93  def __del__(self, CorbaConsumer=OpenRTM_aist.CorbaConsumer):
94  self._rtcout.RTC_PARANOID("~OutPortCorbaCdrConsumer()")
95  CorbaConsumer.__del__(self)
96  pass
97 
98 
99 
127  def init(self, prop):
128  self._rtcout.RTC_TRACE("init()")
129  return
130 
131 
132 
158  def setBuffer(self, buffer):
159  self._rtcout.RTC_TRACE("setBuffer()")
160  self._buffer = buffer
161  return
162 
163 
164  # void OutPortCorbaCdrConsumer::setListener(ConnectorInfo& info,
165  # ConnectorListeners* listeners)
166  def setListener(self, info, listeners):
167  self._rtcout.RTC_TRACE("setListener()")
168  self._listeners = listeners
169  self._profile = info
170  return
171 
172 
173 
195  def get(self, data):
196  self._rtcout.RTC_PARANOID("get()")
197 
198  try:
199  outportcdr = self.getObject()._narrow(OpenRTM.OutPortCdr)
200  ret,cdr_data = outportcdr.get()
201 
202  if ret == OpenRTM.PORT_OK:
203  self._rtcout.RTC_DEBUG("get() successful")
204  data[0] = cdr_data
205  self.onReceived(data[0])
206  self.onBufferWrite(data[0])
207 
208  if self._buffer.full():
209  self._rtcout.RTC_INFO("InPort buffer is full.")
210  self.onBufferFull(data[0])
211  self.onReceiverFull(data[0])
212 
213  self._buffer.put(data[0])
214  self._buffer.advanceWptr()
215  self._buffer.advanceRptr()
216 
217  return self.PORT_OK
218  return self.convertReturn(ret,data[0])
219 
220  except:
221  self._rtcout.RTC_WARN("Exception caught from OutPort.get().")
222  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
223  return self.CONNECTION_LOST
224 
225  self._rtcout.RTC_ERROR("get(): Never comes here.")
226  return self.UNKNOWN_ERROR
227 
228 
229 
252  def subscribeInterface(self, properties):
253  self._rtcout.RTC_TRACE("subscribeInterface()")
254  index = OpenRTM_aist.NVUtil.find_index(properties,"dataport.corba_cdr.outport_ior")
255 
256  if index < 0:
257  self._rtcout.RTC_DEBUG("dataport.corba_cdr.outport_ior not found.")
258  return False
259 
260  if OpenRTM_aist.NVUtil.isString(properties,"dataport.corba_cdr.outport_ior"):
261  self._rtcout.RTC_DEBUG("dataport.corba_cdr.outport_ior found.")
262  ior = ""
263  try:
264  ior = any.from_any(properties[index].value, keep_structs=True)
265  except:
266  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
267 
268  orb = OpenRTM_aist.Manager.instance().getORB()
269  obj = orb.string_to_object(ior)
270  ret = self.setObject(obj)
271  if ret:
272  self._rtcout.RTC_DEBUG("CorbaConsumer was set successfully.")
273  else:
274  self._rtcout.RTC_ERROR("Invalid object reference.")
275 
276  return ret
277 
278  return False
279 
280 
281 
299  def unsubscribeInterface(self, properties):
300  self._rtcout.RTC_TRACE("unsubscribeInterface()")
301  index = OpenRTM_aist.NVUtil.find_index(properties,
302  "dataport.corba_cdr.outport_ref")
303  if index < 0:
304  self._rtcout.RTC_DEBUG("dataport.corba_cdr.outport_ior not found.")
305  return
306 
307  ior = ""
308  try:
309  ior = any.from_any(properties[index].value, keep_structs=True)
310 
311  if ior:
312  self._rtcout.RTC_DEBUG("dataport.corba_cdr.outport_ior found.")
313  orb = OpenRTM_aist.Manager.instance().getORB()
314  obj = orb.string_to_object(ior)
315  if self._ptr()._is_equivalent(obj):
316  self.releaseObject()
317  self._rtcout.RTC_DEBUG("CorbaConsumer's reference was released.")
318  return
319 
320  self._rtcout.RTC_ERROR("hmm. Inconsistent object reference.")
321 
322  except:
323  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
324 
325  return
326 
327 
328 
337  def convertReturn(self, status, data):
338  if status == OpenRTM.PORT_OK:
339  # never comes here
340  return self.PORT_OK
341 
342  elif status == OpenRTM.PORT_ERROR:
343  self.onSenderError()
344  return self.PORT_ERROR
345 
346  elif status == OpenRTM.BUFFER_FULL:
347  # never comes here
348  return self.BUFFER_FULL
349 
350  elif status == OpenRTM.BUFFER_EMPTY:
351  self.onSenderEmpty()
352  return self.BUFFER_EMPTY
353 
354  elif status == OpenRTM.BUFFER_TIMEOUT:
355  self.onSenderTimeout()
356  return self.BUFFER_TIMEOUT
357 
358  elif status == OpenRTM.UNKNOWN_ERROR:
359  self.onSenderError()
360  return self.UNKNOWN_ERROR
361 
362  else:
363  self.onSenderError()
364  return self.UNKNOWN_ERROR
365 
366  self.onSenderError()
367  return self.UNKNOWN_ERROR
368 
369 
370 
374  def onBufferWrite(self, data):
375  if self._listeners is not None and self._profile is not None:
376  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
377 
378  return
379 
380 
381  # inline void onBufferFull(const cdrMemoryStream& data)
382  def onBufferFull(self, data):
383  if self._listeners is not None and self._profile is not None:
384  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL].notify(self._profile, data)
385 
386  return
387 
388 
389  # inline void onReceived(const cdrMemoryStream& data)
390  def onReceived(self, data):
391  if self._listeners is not None and self._profile is not None:
392  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
393 
394  return
395 
396 
397  # inline void onReceiverFull(const cdrMemoryStream& data)
398  def onReceiverFull(self, data):
399  if self._listeners is not None and self._profile is not None:
400  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
401 
402  return
403 
404 
405 
409  def onSenderEmpty(self):
410  if self._listeners is not None and self._profile is not None:
411  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_EMPTY].notify(self._profile)
412 
413  return
414 
415 
416  # inline void onSenderTimeout()
417  def onSenderTimeout(self):
418  if self._listeners is not None and self._profile is not None:
419  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_TIMEOUT].notify(self._profile)
420 
421  return
422 
423 
424  # inline void onSenderError()
425  def onSenderError(self):
426  if self._listeners is not None and self._profile is not None:
427  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_ERROR].notify(self._profile)
428 
429  return
430 
431 
433  factory = OpenRTM_aist.OutPortConsumerFactory.instance()
434  factory.addFactory("corba_cdr",
436  OpenRTM_aist.Delete)
437  return
def subscribeInterface(self, properties)
Subscribe the data receive notification.
def setBuffer(self, buffer)
Setting outside buffer&#39;s pointer.
def setObject(self, obj)
Set CORBA Object.
def find_index(nv, name)
Definition: NVUtil.py:229
def isString(nv, name)
Definition: NVUtil.py:249
int PORT_OK
DataPortStatus return codes.
def convertReturn(self, status, data)
Return codes conversionReturnCode convertReturn(::OpenRTM::PortStatus status, const cdrMemoryStream& ...
def unsubscribeInterface(self, properties)
Unsubscribe the data receive notification.
def _ptr(self)
Get Object reference narrowed as ObjectType.
def onBufferWrite(self, data)
Connector data listener functions.
def __del__(self, CorbaConsumer=OpenRTM_aist.CorbaConsumer)
Destructor.


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34