InPortPushConnector.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
19 
20 
21 from omniORB import *
22 from omniORB import any
23 
24 import OpenRTM_aist
25 
26 
27 
77  """
78  """
79 
80 
122  def __init__(self, info, provider, listeners, buffer = 0):
123  OpenRTM_aist.InPortConnector.__init__(self, info, buffer)
124  self._provider = provider
125  self._listeners = listeners
126 
127  if buffer:
128  self._deleteBuffer = True
129  else:
130  self._deleteBuffer = False
131 
132  if self._buffer == 0:
133  self._buffer = self.createBuffer(info)
134 
135  if self._buffer == 0 or not self._provider:
136  raise
137 
138  self._buffer.init(info.properties.getNode("buffer"))
139  self._provider.init(info.properties)
140  self._provider.setBuffer(self._buffer)
141  self._provider.setListener(info, self._listeners)
142 
143  self.onConnect()
144  return
145 
146 
147 
162  def __del__(self):
163  return
164 
165 
166 
199  def read(self, data):
200  self._rtcout.RTC_TRACE("read()")
201 
202 
209  if not self._buffer:
210  return self.PRECONDITION_NOT_MET
211 
212  if type(data) == list:
213  ret = self._buffer.read(data)
214  else:
215  tmp = [data]
216  ret = self._buffer.read(tmp)
217 
218 
219  if ret == OpenRTM_aist.BufferStatus.BUFFER_OK:
220  return self.PORT_OK
221 
222  elif ret == OpenRTM_aist.BufferStatus.BUFFER_EMPTY:
223  return self.BUFFER_EMPTY
224 
225  elif ret == OpenRTM_aist.BufferStatus.TIMEOUT:
226  return self.BUFFER_TIMEOUT
227 
228  elif ret == OpenRTM_aist.BufferStatus.PRECONDITION_NOT_MET:
229  return self.PRECONDITION_NOT_MET
230 
231  return self.PORT_ERROR
232 
233 
234 
254  def disconnect(self):
255  self._rtcout.RTC_TRACE("disconnect()")
256  self.onDisconnect()
257  # delete consumer
258  if self._provider:
259  cfactory = OpenRTM_aist.InPortProviderFactory.instance()
260  cfactory.deleteObject(self._provider)
261 
262  self._provider = 0
263 
264  # delete buffer
265  if self._buffer and self._deleteBuffer == True:
266  bfactory = OpenRTM_aist.CdrBufferFactory.instance()
267  bfactory.deleteObject(self._buffer)
268 
269  self._buffer = 0
270 
271  return self.PORT_OK
272 
273 
288  def activate(self): # do nothing
289  pass
290 
291 
306  def deactivate(self): # do nothing
307  pass
308 
309 
310 
330  def createBuffer(self, profile):
331  buf_type = profile.properties.getProperty("buffer_type","ring_buffer")
332  return OpenRTM_aist.CdrBufferFactory.instance().createObject(buf_type)
333 
334 
335 
367  def write(self, data):
368  if not self._dataType:
369  return OpenRTM_aist.BufferStatus.PRECONDITION_NOT_MET
370 
371  _data = None
372  # CDR -> (conversion) -> data
373  if self._endian is not None:
374  _data = cdrUnmarshal(any.to_any(self._dataType).typecode(),data,self._endian)
375 
376  else:
377  self._rtcout.RTC_ERROR("unknown endian from connector")
378  return OpenRTM_aist.BufferStatus.PRECONDITION_NOT_MET
379 
380  return self._buffer.write(_data)
381 
382 
383 
390  def onConnect(self):
391  if self._listeners and self._profile:
392  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_CONNECT].notify(self._profile)
393  return
394 
395 
402  def onDisconnect(self):
403  if self._listeners and self._profile:
404  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT].notify(self._profile)
405  return
def onDisconnect(self)
Invoke callback when connection is destroied void onDisconnect()
def __init__(self, info, provider, listeners, buffer=0)
InPortPushConnector(ConnectorInfo info, InPortProvider* provider, ConnectorListeners listeners...
def onConnect(self)
Invoke callback when connection is established void onConnect()
int PORT_OK
DataPortStatus return codes.


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