OutPortCorbaCdrProvider.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
18 
19 import sys
20 from omniORB import *
21 from omniORB import any
22 
23 import OpenRTM_aist
24 import OpenRTM__POA,OpenRTM
25 
26 
50 class OutPortCorbaCdrProvider(OpenRTM_aist.OutPortProvider, OpenRTM__POA.OutPortCdr):
51 
68  def __init__(self):
69  OpenRTM_aist.OutPortProvider.__init__(self)
70  self.setInterfaceType("corba_cdr")
71 
72  # ConnectorProfile setting
73  self._objref = self._this()
74 
75  self._buffer = None
76 
77  # set outPort's reference
78  orb = OpenRTM_aist.Manager.instance().getORB()
79 
80  self._properties.append(OpenRTM_aist.NVUtil.newNV("dataport.corba_cdr.outport_ior",
81  orb.object_to_string(self._objref)))
82  self._properties.append(OpenRTM_aist.NVUtil.newNV("dataport.corba_cdr.outport_ref",
83  self._objref))
84 
85  self._listeners = None
86  self._connector = None
87  self._profile = None
88  return
89 
90 
91 
104  def __del__(self):
105  oid = self._default_POA().servant_to_id(self)
106  self._default_POA().deactivate_object(oid)
107  return
108 
109 
110 
138  def init(self, prop):
139  pass
140 
141 
142 
168  def setBuffer(self, buffer):
169  self._buffer = buffer
170  return
171 
172 
173 
219  def setListener(self, info, listeners):
220  self._profile = info
221  self._listeners = listeners
222  return
223 
224 
225 
250  def setConnector(self, connector):
251  self._connector = connector
252  return
253 
254 
255 
273  def get(self):
274  self._rtcout.RTC_PARANOID("OutPortCorbaCdrProvider.get()")
275  if not self._buffer:
276  self.onSenderError()
277  return (OpenRTM.UNKNOWN_ERROR, None)
278 
279  try:
280  if self._buffer.empty():
281  self._rtcout.RTC_ERROR("buffer is empty.")
282  return (OpenRTM.BUFFER_EMPTY, None)
283 
284  cdr = [None]
285  ret = self._buffer.read(cdr)
286 
287  if ret == OpenRTM_aist.BufferStatus.BUFFER_OK:
288  if not cdr:
289  self._rtcout.RTC_ERROR("buffer is empty.")
290  return (OpenRTM.BUFFER_EMPTY, None)
291 
292  except:
293  self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
294  return (OpenRTM.UNKNOWN_ERROR, None)
295 
296  return self.convertReturn(ret, cdr[0])
297 
298 
308  def onBufferRead(self, data):
309  if self._listeners and self._profile:
310  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ].notify(self._profile, data)
311  return
312 
313 
323  def onSend(self, data):
324  if self._listeners and self._profile:
325  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_SEND].notify(self._profile, data)
326  return
327 
328 
336  def onBufferEmpty(self):
337  if self._listeners and self._profile:
338  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_BUFFER_EMPTY].notify(self._profile)
339  return
340 
341 
349  def onBufferReadTimeout(self):
350  if self._listeners and self._profile:
351  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_BUFFER_READ_TIMEOUT].notify(self._profile)
352  return
353 
354 
362  def onSenderEmpty(self):
363  if self._listeners and self._profile:
364  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_EMPTY].notify(self._profile)
365  return
366 
367 
375  def onSenderTimeout(self):
376  if self._listeners and self._profile:
377  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_TIMEOUT].notify(self._profile)
378  return
379 
380 
388  def onSenderError(self):
389  if self._listeners and self._profile:
390  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_ERROR].notify(self._profile)
391  return
392 
393 
394 
403  def convertReturn(self, status, data):
404  if status == OpenRTM_aist.BufferStatus.BUFFER_OK:
405  self.onBufferRead(data)
406  self.onSend(data)
407  return (OpenRTM.PORT_OK, data)
408 
409  elif status == OpenRTM_aist.BufferStatus.BUFFER_ERROR:
410  self.onSenderError()
411  return (OpenRTM.PORT_ERROR, data)
412 
413  elif status == OpenRTM_aist.BufferStatus.BUFFER_FULL:
414  # never come here
415  return (OpenRTM.BUFFER_FULL, data)
416 
417  elif status == OpenRTM_aist.BufferStatus.BUFFER_EMPTY:
418  self.onBufferEmpty()
419  self.onSenderEmpty()
420  return (OpenRTM.BUFFER_EMPTY, data)
421 
422  elif status == OpenRTM_aist.BufferStatus.PRECONDITION_NOT_MET:
423  self.onSenderError()
424  return (OpenRTM.PORT_ERROR, data)
425 
426  elif status == OpenRTM_aist.BufferStatus.TIMEOUT:
427  self.onBufferReadTimeout()
428  self.onSenderTimeout()
429  return (OpenRTM.BUFFER_TIMEOUT, data)
430 
431  else:
432  return (OpenRTM.UNKNOWN_ERROR, data)
433 
434  self.onSenderError()
435  return (OpenRTM.UNKNOWN_ERROR, data)
436 
437 
439  factory = OpenRTM_aist.OutPortProviderFactory.instance()
440  factory.addFactory("corba_cdr",
442  OpenRTM_aist.Delete)
443 
def setBuffer(self, buffer)
Setting outside buffer's pointer.
def convertReturn(self, status, data)
Return codes conversion::OpenRTM::PortStatus convertReturn(BufferStatus::Enum status, const cdrMemoryStream& data);.
def setListener(self, info, listeners)
Set the listener.
def onBufferReadTimeout(self)
Notify an ON_BUFFER_READ_TIMEOUT event to listenersinline void onBufferReadTimeout() ...
def onSenderEmpty(self)
Notify an ON_SENDER_EMPTY event to listenersinline void onSenderEmpty()
def onBufferEmpty(self)
Notify an ON_BUFFER_EMPTY event to listenersinline void onBufferEmpty()
def onSenderError(self)
Notify an ON_SENDER_ERROR event to listenersinline void onSenderError()
def onSend(self, data)
Notify an ON_SEND event to listeners.
def onBufferRead(self, data)
Notify an ON_BUFFER_READ event to listeners.
def onSenderTimeout(self)
Notify an ON_SENDER_TIMEOUT event to listenersinline void onSenderTimeout()
def append(dest, src)
Definition: NVUtil.py:386
def get(self)
[CORBA interface] Get data from the buffer
def newNV(name, value)
Create NameVale.
Definition: NVUtil.py:50


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Feb 28 2022 23:01:06