OutPortPushConnector.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
5 
19 
20 from omniORB import *
21 from omniORB import any
22 
23 import OpenRTM_aist
24 
25 
26 
81  """
82  """
83 
84 
128  def __init__(self, info, consumer, listeners, buffer = 0):
129  OpenRTM_aist.OutPortConnector.__init__(self, info)
130 
131  self._buffer = buffer
132  self._consumer = consumer
133  self._listeners = listeners
134 
135  # publisher/buffer creation. This may throw std::bad_alloc;
136  self._publisher = self.createPublisher(info)
137  if not self._buffer:
138  self._buffer = self.createBuffer(info)
139 
140 
141  if not self._publisher or not self._buffer or not self._consumer:
142  raise
143 
144  if self._publisher.init(info.properties) != self.PORT_OK:
145  raise
146 
147  if self._profile.properties.hasKey("serializer"):
148  endian = self._profile.properties.getProperty("serializer.cdr.endian")
149  if not endian:
150  self._rtcout.RTC_ERROR("write(): endian is not set.")
151  raise
152 
153  endian = OpenRTM_aist.split(endian, ",") # Maybe endian is ["little","big"]
154  endian = OpenRTM_aist.normalize(endian) # Maybe self._endian is "little" or "big"
155  if endian == "little":
156  self._endian = True
157  elif endian == "big":
158  self._endian = False
159  else:
160  self._endian = None
161 
162  else:
163  self._endian = True # little endian
164 
165  self._buffer.init(info.properties.getNode("buffer"))
166  self._consumer.init(info.properties)
167  self._publisher.setConsumer(self._consumer)
168  self._publisher.setBuffer(self._buffer)
169  self._publisher.setListener(self._profile, self._listeners)
170 
171  self.onConnect()
172  return
173 
174 
175 
190  def __del__(self):
191  return
192 
193 
234  def write(self, data):
235  self._rtcout.RTC_TRACE("write()")
236 
237  # data -> (conversion) -> CDR stream
238  cdr_data = None
239  if self._endian is not None:
240  cdr_data = cdrMarshal(any.to_any(data).typecode(), data, self._endian)
241  else:
242  self._rtcout.RTC_ERROR("write(): endian %s is not support.",self._endian)
243  return self.UNKNOWN_ERROR
244 
245  return self._publisher.write(cdr_data, 0, 0)
246 
247 
248 
264  def disconnect(self):
265  self._rtcout.RTC_TRACE("disconnect()")
266  self.onDisconnect()
267  # delete publisher
268  if self._publisher:
269  self._rtcout.RTC_DEBUG("delete publisher")
270  pfactory = OpenRTM_aist.PublisherFactory.instance()
271  pfactory.deleteObject(self._publisher)
272 
273  self._publisher = 0
274 
275  # delete consumer
276  if self._consumer:
277  self._rtcout.RTC_DEBUG("delete consumer")
278  cfactory = OpenRTM_aist.InPortConsumerFactory.instance()
279  cfactory.deleteObject(self._consumer)
280 
281  self._consumer = 0
282 
283  # delete buffer
284  if self._buffer:
285  self._rtcout.RTC_DEBUG("delete buffer")
286  bfactory = OpenRTM_aist.CdrBufferFactory.instance()
287  bfactory.deleteObject(self._buffer)
288 
289  self._buffer = 0
290  self._rtcout.RTC_TRACE("disconnect() done")
291 
292  return self.PORT_OK
293 
294 
295 
310  def activate(self):
311  self._publisher.activate()
312  return
313 
314 
315 
330  def deactivate(self):
331  self._publisher.deactivate()
332  return
333 
334 
335 
349  def getBuffer(self):
350  return self._buffer
351 
352 
353 
373  def createPublisher(self, info):
374  pub_type = info.properties.getProperty("subscription_type","flush")
375  pub_type = OpenRTM_aist.normalize([pub_type])
376  return OpenRTM_aist.PublisherFactory.instance().createObject(pub_type)
377 
378 
379 
399  def createBuffer(self, info):
400  buf_type = info.properties.getProperty("buffer_type",
401  "ring_buffer")
402 
403  return OpenRTM_aist.CdrBufferFactory.instance().createObject(buf_type)
404 
405 
406 
413  def onConnect(self):
414  if self._listeners and self._profile:
415  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_CONNECT].notify(self._profile)
416  return
417 
418 
425  def onDisconnect(self):
426  if self._listeners and self._profile:
427  self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT].notify(self._profile)
428  return
def onConnect(self)
Invoke callback when connection is established void onConnect()
def onDisconnect(self)
Invoke callback when connection is destroied void onDisconnect()
def __init__(self, info, consumer, listeners, buffer=0)
Constructor.
int PORT_OK
DataPortStatus return codes.


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