InPortCorbaCdrProvider.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
17 
18 import sys
19 from omniORB import *
20 from omniORB import any
21 
22 import OpenRTM_aist
23 import OpenRTM__POA,OpenRTM
24 
25 
50 class InPortCorbaCdrProvider(OpenRTM_aist.InPortProvider, OpenRTM__POA.InPortCdr):
51 
52  """
53  """
54 
55 
80  def __init__(self):
81  OpenRTM_aist.InPortProvider.__init__(self)
82 
83  # PortProfile setting
84  self.setInterfaceType("corba_cdr")
85 
86  # ConnectorProfile setting
87  self._objref = self._this()
88 
89  self._buffer = None
90 
91  self._profile = None
92  self._listeners = None
93 
94  # set InPort's reference
95  orb = OpenRTM_aist.Manager.instance().getORB()
96 
97  self._properties.append(OpenRTM_aist.NVUtil.newNV("dataport.corba_cdr.inport_ior",
98  orb.object_to_string(self._objref)))
99  self._properties.append(OpenRTM_aist.NVUtil.newNV("dataport.corba_cdr.inport_ref",
100  self._objref))
101 
102  return
103 
104 
117  def __del__(self):
118  oid = OpenRTM_aist.Manager.instance().getPOA.servant_to_id(self)
119  OpenRTM_aist.Manager.instance().getPOA.deactivate_object(oid)
120  return
121 
122  ## virtual void init(coil::Properties& prop);
123  def init(self, prop):
124  pass
125 
126  ## virtual void setBuffer(BufferBase<cdrMemoryStream>* buffer);
127  def setBuffer(self, buffer):
128  self._buffer = buffer
129  return
130 
131  # void setListener(ConnectorInfo& info,
132  # ConnectorListeners* listeners);
133  def setListener(self, info, listeners):
134  self._profile = info
135  self._listeners = listeners
136  return
137 
138 
157  def put(self, data):
158  try:
159  self._rtcout.RTC_PARANOID("InPortCorbaCdrProvider.put()")
160 
161  if not self._buffer:
162  self.onReceiverError(data)
163  return OpenRTM.PORT_ERROR
164 
165  self._rtcout.RTC_PARANOID("received data size: %d", len(data))
166 
167  self.onReceived(data)
168 
169  if not self._connector:
170  return OpenRTM.PORT_ERROR
171 
172  ret = self._connector.write(data)
173 
174  return self.convertReturn(ret, data)
175 
176  except:
177  self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
178  return OpenRTM.UNKNOWN_ERROR
179  return OpenRTM.UNKNOWN_ERROR
180 
181 
182  def convertReturn(self, status, data):
183  if status == OpenRTM_aist.BufferStatus.BUFFER_OK:
184  self.onBufferWrite(data)
185  return OpenRTM.PORT_OK
186 
187  elif status == OpenRTM_aist.BufferStatus.BUFFER_ERROR:
188  self.onReceiverError(data)
189  return OpenRTM.PORT_ERROR
190 
191  elif status == OpenRTM_aist.BufferStatus.BUFFER_FULL:
192  self.onBufferFull(data)
193  self.onReceiverFull(data)
194  return OpenRTM.BUFFER_FULL
195 
196  elif status == OpenRTM_aist.BufferStatus.BUFFER_EMPTY:
197  return OpenRTM.BUFFER_EMPTY
198 
199  elif status == OpenRTM_aist.BufferStatus.PRECONDITION_NOT_MET:
200  self.onReceiverError(data)
201  return OpenRTM.PORT_ERROR
202 
203  elif status == OpenRTM_aist.BufferStatus.TIMEOUT:
204  self.onBufferWriteTimeout(data)
205  self.onReceiverTimeout(data)
206  return OpenRTM.BUFFER_TIMEOUT
207 
208  else:
209  self.onReceiverError(data)
210  return OpenRTM.UNKNOWN_ERROR
211 
212 
213 
217  def onBufferWrite(self, data):
218  if self._listeners is not None and self._profile is not None:
219  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
220  return
221 
222 
223  ## inline void onBufferFull(const cdrMemoryStream& data)
224  def onBufferFull(self, data):
225  if self._listeners is not None and self._profile is not None:
226  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL].notify(self._profile, data)
227  return
228 
229 
230  ## inline void onBufferWriteTimeout(const cdrMemoryStream& data)
231  def onBufferWriteTimeout(self, data):
232  if self._listeners is not None and self._profile is not None:
233  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT].notify(self._profile, data)
234  return
235 
236  ## inline void onBufferWriteOverwrite(const cdrMemoryStream& data)
237  def onBufferWriteOverwrite(self, data):
238  if self._listeners is not None and self._profile is not None:
239  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE].notify(self._profile, data)
240  return
241 
242 
243  ## inline void onReceived(const cdrMemoryStream& data)
244  def onReceived(self, data):
245  if self._listeners is not None and self._profile is not None:
246  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
247  return
248 
249 
250  ## inline void onReceiverFull(const cdrMemoryStream& data)
251  def onReceiverFull(self, data):
252  if self._listeners is not None and self._profile is not None:
253  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
254  return
255 
256 
257  ## inline void onReceiverTimeout(const cdrMemoryStream& data)
258  def onReceiverTimeout(self, data):
259  if self._listeners is not None and self._profile is not None:
260  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_TIMEOUT].notify(self._profile, data)
261  return
262 
263 
264  ## inline void onReceiverError(const cdrMemoryStream& data)
265  def onReceiverError(self, data):
266  if self._listeners is not None and self._profile is not None:
267  self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_ERROR].notify(self._profile, data)
268  return
269 
270 
272  factory = OpenRTM_aist.InPortProviderFactory.instance()
273  factory.addFactory("corba_cdr",
275  OpenRTM_aist.Delete)
276 
def setInterfaceType(self, interface_type)
def put(self, data)
[CORBA interface] Write data into the buffer
def onReceiverTimeout(self, data)
inline void onReceiverTimeout(const cdrMemoryStream& data)
def onReceiverFull(self, data)
inline void onReceiverFull(const cdrMemoryStream& data)
def onBufferFull(self, data)
inline void onBufferFull(const cdrMemoryStream& data)
def init(self, prop)
virtual void init(coil::Properties& prop);
def onBufferWriteTimeout(self, data)
inline void onBufferWriteTimeout(const cdrMemoryStream& data)
def setBuffer(self, buffer)
virtual void setBuffer(BufferBase<cdrMemoryStream>* buffer);
def onReceived(self, data)
inline void onReceived(const cdrMemoryStream& data)
def onBufferWriteOverwrite(self, data)
inline void onBufferWriteOverwrite(const cdrMemoryStream& data)
def onReceiverError(self, data)
inline void onReceiverError(const cdrMemoryStream& data)
def onBufferWrite(self, data)
Connector data listener functions.
def newNV(name, value)
Create NameVale.
Definition: NVUtil.py:50


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