OutPortBase.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
16 
17 import copy
18 import threading
19 import OpenRTM_aist
20 import RTC
21 
22 
207  """
208  """
209 
210 
218  def __init__(self):
219  self._factory = OpenRTM_aist.OutPortProviderFactory.instance()
220 
221  def __call__(self, p):
222  self._factory.deleteObject(p)
223 
224 
232  def __init__(self):
233  pass
234 
235  def __call__(self, c):
236  del c
237 
238 
239 
256  def __init__(self, name, data_type):
257  OpenRTM_aist.PortBase.__init__(self,name)
258  self._rtcout.RTC_DEBUG("Port name: %s", name)
259 
260  self._rtcout.RTC_DEBUG("setting port.port_type: DataOutPort")
261  self.addProperty("port.port_type", "DataOutPort")
262 
263  self._rtcout.RTC_DEBUG("setting dataport.data_type: %s", data_type)
264  self.addProperty("dataport.data_type", data_type)
265 
266  # publisher list
267  factory = OpenRTM_aist.PublisherFactory.instance()
268  pubs = OpenRTM_aist.flatten(factory.getIdentifiers())
269 
270  # blank characters are deleted for RTSE's bug
271  pubs = pubs.lstrip()
272 
273  self._rtcout.RTC_DEBUG("available subscription_type: %s", pubs)
274  self.addProperty("dataport.subscription_type", pubs)
275 
277  self._name = name
278  self._connectors = []
279  self._consumers = []
280  self._providerTypes = ""
281  self._consumerTypes = ""
282  self._connector_mutex = threading.RLock()
283 
285  return
286 
287 
288 
304  def __del__(self, PortBase=OpenRTM_aist.PortBase):
305  self._rtcout.RTC_TRACE("OutPortBase destructor")
306  # connector のクリーンナップ OpenRTM_aist.CORBA_SeqUtil.for_each(self._connectors, self.connector_cleanup()) PortBase.__del__(self) return ## # @if jp # @brief プロパティの初期化 # # OutPortのプロパティを初期化する # # @else # # @brief Initializing properties # # This operation initializes outport's properties # # @endif # # void init(coil::Properties& prop); def init(self, prop): self._rtcout.RTC_TRACE("init()") self._properties.mergeProperties(prop) self.configure() self.initConsumers() self.initProviders() num = [-1] if not OpenRTM_aist.stringTo(num, self._properties.getProperty("connection_limit","-1")): self._rtcout.RTC_ERROR("invalid connection_limit value: %s", self._properties.getProperty("connection_limit")) self.setConnectionLimit(num[0]) return ## # @if jp # # @brief データ書き込み # # ポートへデータを書き込む。 # バインドされた変数に設定された値をポートに書き込む。 # # @return 書き込み処理結果(書き込み成功:true、書き込み失敗:false) # # @else # # @brief Write data # # Write data to the port. # Write the value, which was set to the bound variable, to the port. # # @return Writing result (Successful:true, Failed:false) # # @endif # # virtual bool write() = 0; def write(self): pass ## # @if jp # # @brief [CORBA interface] Port の接続を行う # # 与えられた ConnectoionProfile の情報に基づき、Port間の接続を確立 # する。この関数は主にアプリケーションプログラムやツールから呼び出 # すことを前提としている。 # # @param connector_profile ConnectorProfile # @return ReturnCode_t 型のリターンコード # # @else # # @brief [CORBA interface] Connect the Port # # This operation establishes connection according to the given # ConnectionProfile inforamtion. This function is premised on # calling from mainly application program or tools. # # @param connector_profile The ConnectorProfile. # @return ReturnCode_t The return code of ReturnCode_t type. # # @endif # def connect(self, connector_profile): self._rtcout.RTC_TRACE("OutPortBase.connect()") if OpenRTM_aist.NVUtil.find_index(connector_profile.properties, "dataport.serializer.cdr.endian") is -1: self._rtcout.RTC_TRACE("ConnectorProfile dataport.serializer.cdr.endian set.") connector_profile.properties.append(OpenRTM_aist.NVUtil.newNV("dataport.serializer.cdr.endian","little,big")) return OpenRTM_aist.PortBase.connect(self, connector_profile) ## # @if jp # @brief プロパティを取得する # # OutPortのプロパティを取得する。 # # @return プロパティ # # @else # # @brief Get properties # # Getting properties of this OutPort # # @return OutPort's properties # # @endif # # coil::Properties& OutPortBase::properties() def properties(self): self._rtcout.RTC_TRACE("properties()") return self._properties ## # @if jp # @brief Connector を取得 # @else # @brief Connector list # @endif # # const std::vector<OutPortConnector*>& OutPortBase::connectors() def connectors(self): self._rtcout.RTC_TRACE("connectors(): size = %d", len(self._connectors)) return self._connectors ## # @if jp # @brief ConnectorProfile を取得 # @else # @brief ConnectorProfile list # @endif # # ConnectorBase::ConnectorInfoList OutPortBase::getConnectorProfiles() def getConnectorProfiles(self): self._rtcout.RTC_TRACE("getConnectorProfiles(): size = %d", len(self._connectors)) profs = [] for con in self._connectors: profs.append(con.profile()) return profs ## # @if jp # @brief ConnectorId を取得 # @else # @brief ConnectorId list # @endif # # coil::vstring OutPortBase::getConnectorIds() def getConnectorIds(self): ids = [] for con in self._connectors: ids.append(con.id()) self._rtcout.RTC_TRACE("getConnectorIds(): %s", OpenRTM_aist.flatten(ids)) return ids ## # @if jp # @brief Connectorの名前を取得 # @else # @brief Connector name list # @endif # # coil::vstring OutPortBase::getConnectorNames() def getConnectorNames(self): names = [] for con in self._connectors: names.append(con.name()) self._rtcout.RTC_TRACE("getConnectorNames(): %s", OpenRTM_aist.flatten(names)) return names ## # @if jp # @brief ConnectorProfileをIDで取得 # # 現在所有しているコネクタをIDで取得する。 # # @param id Connector ID # @return コネクタへのポインタ # # @else # # @brief Getting ConnectorProfile by ID # # This operation returns Connector specified by ID. # # @param id Connector ID # @return A pointer to connector # # @endif # # OutPortConnector* getConnectorById(const char* id); def getConnectorById(self, id): self._rtcout.RTC_TRACE("getConnectorById(id = %s)", id) for (i,con) in enumerate(self._connectors): if id == con.id(): return self._connectors[i] self._rtcout.RTC_WARN("ConnectorProfile with the id(%s) not found.", id) return 0 ## # @if jp # @brief ConnectorProfileを名前で取得 # # 現在所有しているコネクタを名前で取得する。 # # @param name Connector name # @return コネクタへのポインタ # # @else # # @brief Getting Connector by name # # This operation returns Connector specified by name. # # @param id Connector ID # @return A pointer to connector # # @endif # # OutPortConnector* getConnectorByName(const char* name); def getConnectorByName(self, name): self._rtcout.RTC_TRACE("getConnectorByName(name = %s)", name) for (i,con) in enumerate(self._connectors): if name == con.name(): return self._connectors[i] self._rtcout.RTC_WARN("ConnectorProfile with the name(%s) not found.", name) return 0 ## # @if jp # @brief ConnectorProfileをIDで取得 # @else # @brief Getting ConnectorProfile by name # @endif # # bool OutPortBase::getConnectorProfileById(const char* id, # ConnectorInfo& prof) def getConnectorProfileById(self, id, prof): self._rtcout.RTC_TRACE("getConnectorProfileById(id = %s)", id) conn = self.getConnectorById(id) if not conn: return False prof[0] = conn.profile() return True ## # @if jp # @brief ConnectorProfileを名前で取得 # @else # @brief Getting ConnectorProfile by name # @endif # # bool OutPortBase::getConnectorProfileByName(const char* name, # ConnectorInfo& prof) def getConnectorProfileByName(self, name, prof): self._rtcout.RTC_TRACE("getConnectorProfileByName(name = %s)", name) conn = self.getConnectorByName(name) if not conn: return False prof[0] = conn.profile() return True ## # @if jp # @brief OutPortを activates する # @else # @brief Activate all Port interfaces # @endif # # void OutPortBase::activateInterfaces() def activateInterfaces(self): self._rtcout.RTC_TRACE("activateInterfaces()") for con in self._connectors: con.activate() ## # @if jp # @brief 全ての Port のインターフェースを deactivates する # @else # @brief Deactivate all Port interfaces # @endif # # void OutPortBase::deactivateInterfaces() def deactivateInterfaces(self): self._rtcout.RTC_TRACE("deactivateInterfaces()") for con in self._connectors: con.deactivate() ## # @if jp # @brief ConnectorDataListener リスナを追加する # # バッファ書き込みまたは読み出しイベントに関連する各種リスナを設定する。 # # 設定できるリスナのタイプとコールバックイベントは以下の通り # # - ON_BUFFER_WRITE: バッファ書き込み時 # - ON_BUFFER_FULL: バッファフル時 # - ON_BUFFER_WRITE_TIMEOUT: バッファ書き込みタイムアウト時 # - ON_BUFFER_OVERWRITE: バッファ上書き時 # - ON_BUFFER_READ: バッファ読み出し時 # - ON_SEND: InProtへの送信時 # - ON_RECEIVED: InProtへの送信完了時 # - ON_SEND_ERTIMEOUT: OutPort側タイムアウト時 # - ON_SEND_ERERROR: OutPort側エラー時 # - ON_RECEIVER_FULL: InProt側バッファフル時 # - ON_RECEIVER_TIMEOUT: InProt側バッファタイムアウト時 # - ON_RECEIVER_ERROR: InProt側エラー時 # # リスナは ConnectorDataListener を継承し、以下のシグニチャを持つ # operator() を実装している必要がある。 # # ConnectorDataListener:: # operator()(const ConnectorProfile&, const cdrStream&) # # デフォルトでは、この関数に与えたリスナオブジェクトの所有権は # OutPortに移り、OutPort解体時もしくは、 # removeConnectorDataListener() により削除時に自動的に解体される。 # リスナオブジェクトの所有権を呼び出し側で維持したい場合は、第3引 # 数に false を指定し、自動的な解体を抑制することができる。 # # @param listener_type リスナタイプ # @param listener リスナオブジェクトへのポインタ # @param autoclean リスナオブジェクトの自動的解体を行うかどうかのフラグ # # @else # @brief Adding BufferDataListener type listener # # This operation adds certain listeners related to buffer writing and # reading events. # The following listener types are available. # # - ON_BUFFER_WRITE: At the time of buffer write # - ON_BUFFER_FULL: At the time of buffer full # - ON_BUFFER_WRITE_TIMEOUT: At the time of buffer write timeout # - ON_BUFFER_OVERWRITE: At the time of buffer overwrite # - ON_BUFFER_READ: At the time of buffer read # - ON_SEND: At the time of sending to InPort # - ON_RECEIVED: At the time of finishing sending to InPort # - ON_SENDER_TIMEOUT: At the time of timeout of OutPort # - ON_SENDER_ERROR: At the time of error of OutPort # - ON_RECEIVER_FULL: At the time of bufferfull of InPort # - ON_RECEIVER_TIMEOUT: At the time of timeout of InPort # - ON_RECEIVER_ERROR: At the time of error of InPort # # Listeners should have the following function operator(). # # ConnectorDataListener:: # operator()(const ConnectorProfile&, const cdrStream&) # # The ownership of the given listener object is transferred to # this OutPort object in default. The given listener object will # be destroied automatically in the OutPort's dtor or if the # listener is deleted by removeConnectorDataListener() function. # If you want to keep ownership of the listener object, give # "false" value to 3rd argument to inhibit automatic destruction. # # @param listener_type A listener type # @param listener A pointer to a listener object # @param autoclean A flag for automatic listener destruction # # @endif # # void addConnectorDataListener(ConnectorDataListenerType listener_type, # ConnectorDataListener* listener, # bool autoclean = true); def addConnectorDataListener(self, listener_type, listener, autoclean = True): self._rtcout.RTC_TRACE("addConnectorDataListener()") if listener_type < OpenRTM_aist.ConnectorDataListenerType.CONNECTOR_DATA_LISTENER_NUM: self._rtcout.RTC_TRACE("addConnectorDataListener(%s)", OpenRTM_aist.ConnectorDataListener.toString(listener_type)) self._listeners.connectorData_[listener_type].addListener(listener, autoclean) return self._rtcout.RTC_ERROR("addConnectorDataListener(): Unknown Listener Type") return ## # @if jp # @brief ConnectorDataListener リスナを削除する # # 設定した各種リスナを削除する。 # # @param listener_type リスナタイプ # @param listener リスナオブジェクトへのポインタ # # @else # @brief Removing BufferDataListener type listener # # This operation removes a specified listener. # # @param listener_type A listener type # @param listener A pointer to a listener object # # @endif # # void removeConnectorDataListener(ConnectorDataListenerType listener_type, # ConnectorDataListener* listener); def removeConnectorDataListener(self, listener_type, listener): self._rtcout.RTC_TRACE("removeConnectorDataListener()") if listener_type < OpenRTM_aist.ConnectorDataListenerType.CONNECTOR_DATA_LISTENER_NUM: self._rtcout.RTC_TRACE("removeConnectorDataListener(%s)", OpenRTM_aist.ConnectorDataListener.toString(listener_type)) self._listeners.connectorData_[listener_type].removeListener(listener) return self._rtcout.RTC_ERROR("removeConnectorDataListener(): Unknown Listener Type") return ## # @if jp # @brief ConnectorListener リスナを追加する # # バッファ書き込みまたは読み出しイベントに関連する各種リスナを設定する。 # # 設定できるリスナのタイプは # # - ON_BUFFER_EMPTY: バッファが空の場合 # - ON_BUFFER_READTIMEOUT: バッファが空でタイムアウトした場合 # # リスナは以下のシグニチャを持つ operator() を実装している必要がある。 # # ConnectorListener::operator()(const ConnectorProfile&) # # デフォルトでは、この関数に与えたリスナオブジェクトの所有権は # OutPortに移り、OutPort解体時もしくは、 # removeConnectorListener() により削除時に自動的に解体される。 # リスナオブジェクトの所有権を呼び出し側で維持したい場合は、第3引 # 数に false を指定し、自動的な解体を抑制することができる。 # # @param listener_type リスナタイプ # @param listener リスナオブジェクトへのポインタ # @param autoclean リスナオブジェクトの自動的解体を行うかどうかのフラグ # # @else # @brief Adding ConnectorListener type listener # # This operation adds certain listeners related to buffer writing and # reading events. # The following listener types are available. # # - ON_BUFFER_EMPTY: At the time of buffer empty # - ON_BUFFER_READTIMEOUT: At the time of buffer read timeout # # Listeners should have the following function operator(). # # ConnectorListener::operator()(const ConnectorProfile&) # # The ownership of the given listener object is transferred to # this OutPort object in default. The given listener object will # be destroied automatically in the OutPort's dtor or if the # listener is deleted by removeConnectorListener() function. # If you want to keep ownership of the listener object, give # "false" value to 3rd argument to inhibit automatic destruction. # # @param listener_type A listener type # @param listener A pointer to a listener object # @param autoclean A flag for automatic listener destruction # # @endif # # void addConnectorListener(ConnectorListenerType callback_type, # ConnectorListener* listener, # bool autoclean = true); def addConnectorListener(self, callback_type, listener, autoclean = True): self._rtcout.RTC_TRACE("addConnectorListener()") if callback_type < OpenRTM_aist.ConnectorListenerType.CONNECTOR_LISTENER_NUM: self._rtcout.RTC_TRACE("addConnectorListener(%s)", OpenRTM_aist.ConnectorListener.toString(callback_type)) self._listeners.connector_[callback_type].addListener(listener, autoclean) return self._rtcout.RTC_ERROR("addConnectorListener(): Unknown Listener Type") return ## # @if jp # @brief ConnectorDataListener リスナを削除する # # 設定した各種リスナを削除する。 # # @param listener_type リスナタイプ # @param listener リスナオブジェクトへのポインタ # # @else # @brief Removing BufferDataListener type listener # # This operation removes a specified listener. # # @param listener_type A listener type # @param listener A pointer to a listener object # # @endif # # void removeConnectorListener(ConnectorListenerType callback_type, # ConnectorListener* listener); def removeConnectorListener(self, callback_type, listener): self._rtcout.RTC_TRACE("removeConnectorListener()") if callback_type < OpenRTM_aist.ConnectorListenerType.CONNECTOR_LISTENER_NUM: self._rtcout.RTC_TRACE("removeConnectorListener(%s)", OpenRTM_aist.ConnectorListener.toString(callback_type)) self._listeners.connector_[callback_type].removeListener(listener) return self._rtcout.RTC_ERROR("removeConnectorListener(): Unknown Listener Type") return ## # @if jp # @brief OutPortの設定を行う # @else # @brief Configureing outport # @endif # #void OutPortBase::configure() def configure(self): pass ## # @if jp # @brief Interface情報を公開する # @else # @brief Publish interface information # @endif # # ReturnCode_t OutPortBase::publishInterfaces(ConnectorProfile& cprof) def publishInterfaces(self, cprof): self._rtcout.RTC_TRACE("publishInterfaces()") retval = self._publishInterfaces() if retval != RTC.RTC_OK: return retval # prop: [port.outport]. prop = copy.deepcopy(self._properties) conn_prop = OpenRTM_aist.Properties() OpenRTM_aist.NVUtil.copyToProperties(conn_prop, cprof.properties) prop.mergeProperties(conn_prop.getNode("dataport")) # marge ConnectorProfile """ # marge ConnectorProfile for buffer property. # e.g. # prof[buffer.write.full_policy] # << cprof[dataport.outport.buffer.write.full_policy] # """ prop.mergeProperties(conn_prop.getNode("dataport.outport")) # # ここで, ConnectorProfile からの properties がマージされたため、 # prop["dataflow_type"]: データフロータイプ # prop["interface_type"]: インターフェースタイプ # などがアクセス可能になる。 dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")]) if dflow_type == "push": self._rtcout.RTC_PARANOID("dataflow_type = push .... do nothing") return RTC.RTC_OK elif dflow_type == "pull": self._rtcout.RTC_PARANOID("dataflow_type = pull .... create PullConnector") provider = self.createProvider(cprof, prop) if not provider: return RTC.BAD_PARAMETER # create InPortPushConnector connector = self.createConnector(cprof, prop, provider_ = provider) if not connector: return RTC.RTC_ERROR # connector set provider.setConnector(connector) self._rtcout.RTC_DEBUG("publishInterface() successfully finished.") return RTC.RTC_OK self._rtcout.RTC_ERROR("unsupported dataflow_type") return RTC.BAD_PARAMETER ## # @if jp # @brief Interface情報を取得する # @else # @brief Subscribe interface # @endif # # ReturnCode_t OutPortBase::subscribeInterfaces(const ConnectorProfile& cprof) def subscribeInterfaces(self, cprof): self._rtcout.RTC_TRACE("subscribeInterfaces()") # prop: [port.outport]. prop = copy.deepcopy(self._properties) conn_prop = OpenRTM_aist.Properties() OpenRTM_aist.NVUtil.copyToProperties(conn_prop, cprof.properties) prop.mergeProperties(conn_prop.getNode("dataport")) # marge ConnectorProfile """ # marge ConnectorProfile for buffer property. # e.g. # prof[buffer.write.full_policy] # << cprof[dataport.outport.buffer.write.full_policy] """ prop.mergeProperties(conn_prop.getNode("dataport.outport")) # # ここで, ConnectorProfile からの properties がマージされたため、 # prop["dataflow_type"]: データフロータイプ # prop["interface_type"]: インターフェースタイプ # などがアクセス可能になる。 # dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")]) profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) if dflow_type == "push": self._rtcout.RTC_PARANOID("dataflow_type = push .... create PushConnector") # interface consumer = self.createConsumer(cprof, prop) if not consumer: return RTC.BAD_PARAMETER # create OutPortPushConnector connector = self.createConnector(cprof, prop, consumer_ = consumer) if not connector: return RTC.RTC_ERROR ret = connector.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret elif dflow_type == "pull": self._rtcout.RTC_PARANOID("dataflow_type = pull.") conn = self.getConnectorById(cprof.connector_id) if not conn: self._rtcout.RTC_ERROR("specified connector not found: %s", cprof.connector_id) return RTC.RTC_ERROR ret = conn.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret self._rtcout.RTC_ERROR("unsupported dataflow_type") return RTC.BAD_PARAMETER ## # @if jp # @brief 登録されているInterface情報を解除する # @else # @brief Unsubscribe interface # @endif # # void # OutPortBase::unsubscribeInterfaces(const ConnectorProfile& connector_profile) def unsubscribeInterfaces(self, connector_profile): self._rtcout.RTC_TRACE("unsubscribeInterfaces()") id = connector_profile.connector_id self._rtcout.RTC_PARANOID("connector_id: %s", id) len_ = len(self._connectors) for i in range(len_): idx = (len_ - 1) - i if id == self._connectors[idx].id(): # Connector's dtor must call disconnect() self._connectors[idx].deactivate() self._connectors[idx].disconnect() del self._connectors[idx] self._rtcout.RTC_TRACE("delete connector: %s", id) return self._rtcout.RTC_ERROR("specified connector not found: %s", id) return ## # @if jp # @brief OutPort provider の初期化 # @else # @brief OutPort provider initialization # @endif # # void OutPortBase::initProviders() def initProviders(self): self._rtcout.RTC_TRACE("initProviders()") # create OutPort providers factory = OpenRTM_aist.OutPortProviderFactory.instance() provider_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available OutPortProviders: %s", OpenRTM_aist.flatten(provider_types)) if self._properties.hasKey("provider_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("provider_types")) != "all": self._rtcout.RTC_DEBUG("allowed providers: %s", self._properties.getProperty("provider_types")) temp_types = provider_types provider_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("provider_types"), ",") temp_types.sort() active_types.sort() set_ptypes = set(temp_types).intersection(set(active_types)) provider_types = provider_types + list(set_ptypes) # OutPortProvider supports "pull" dataflow type if len(provider_types) > 0: self._rtcout.RTC_DEBUG("dataflow_type pull is supported") self.appendProperty("dataport.dataflow_type", "pull") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(provider_types)) self._providerTypes = provider_types ## # @if jp # @brief InPort consumer の初期化 # @else # @brief InPort consumer initialization # @endif # # void OutPortBase::initConsumers() def initConsumers(self): self._rtcout.RTC_TRACE("initConsumers()") # create InPort consumers factory = OpenRTM_aist.InPortConsumerFactory.instance() consumer_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available InPortConsumer: %s", OpenRTM_aist.flatten(consumer_types)) if self._properties.hasKey("consumer_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("consumer_types")) != "all": self._rtcout.RTC_DEBUG("allowed consumers: %s", self._properties.getProperty("consumer_types")) temp_types = consumer_types consumer_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("consumer_types"), ",") temp_types.sort() active_types.sort() set_ctypes = set(temp_types).intersection(set(active_types)) consumer_types = consumer_types + list(set_ctypes) # InPortConsumer supports "push" dataflow type if len(consumer_types) > 0: self._rtcout.RTC_PARANOID("dataflow_type push is supported") self.appendProperty("dataport.dataflow_type", "push") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(consumer_types)) self._consumerTypes = consumer_types ## # @if jp # @brief OutPort provider の生成 # @else # @brief OutPort provider creation # @endif # # OutPortProvider* # OutPortBase::createProvider(ConnectorProfile& cprof, coil::Properties& prop) def createProvider(self, cprof, prop): if prop.getProperty("interface_type") and \ not OpenRTM_aist.includes(self._providerTypes, prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no provider found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._providerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) provider = OpenRTM_aist.OutPortProviderFactory.instance().createObject(prop.getProperty("interface_type")) if provider != 0: self._rtcout.RTC_DEBUG("provider created") provider.init(prop.getNode("provider")) if not provider.publishInterface(cprof.properties): self._rtcout.RTC_ERROR("publishing interface information error") OpenRTM_aist.OutPortProviderFactory.instance().deleteObject(provider) return 0 return provider self._rtcout.RTC_ERROR("provider creation failed") return 0 ## # @if jp # @brief InPort consumer の生成 # @else # @brief InPort consumer creation # @endif # # InPortConsumer* OutPortBase::createConsumer(const ConnectorProfile& cprof, # coil::Properties& prop) def createConsumer(self, cprof, prop): if prop.getProperty("interface_type") and \ not self._consumerTypes.count(prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no consumer found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._consumerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) consumer = OpenRTM_aist.InPortConsumerFactory.instance().createObject(prop.getProperty("interface_type")) if consumer != 0: self._rtcout.RTC_DEBUG("consumer created") consumer.init(prop.getNode("consumer")) if not consumer.subscribeInterface(cprof.properties): self._rtcout.RTC_ERROR("interface subscription failed.") OpenRTM_aist.InPortConsumerFactory.instance().deleteObject(consumer) return 0 return consumer self._rtcout.RTC_ERROR("consumer creation failed") return 0 ## # @if jp # @brief OutPortPushConnector の生成 # @else # @brief OutPortPushConnector creation # @endif # # OutPortConnector* # OutPortBase::createConnector(const ConnectorProfile& cprof, # coil::Properties& prop, # InPortConsumer* consumer) def createConnector(self, cprof, prop, provider_ = None, consumer_ = None): profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) connector = None try: if consumer_ is not None: connector = OpenRTM_aist.OutPortPushConnector(profile, consumer_, self._listeners) elif provider_ is not None: connector = OpenRTM_aist.OutPortPullConnector(profile, provider_, self._listeners) else: self._rtcout.RTC_ERROR("provider or consumer is not passed. returned 0;") return 0 if connector is None: self._rtcout.RTC_ERROR("OutPortConnector creation failed") return 0 if consumer_ is not None: self._rtcout.RTC_TRACE("OutPortPushConnector created") elif provider_ is not None: self._rtcout.RTC_TRACE("OutPortPullConnector created") self._connectors.append(connector) self._rtcout.RTC_PARANOID("connector push backed: %d", len(self._connectors)) return connector except: self._rtcout.RTC_ERROR("Exeption: OutPortPushConnector creation failed") self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) return 0 self._rtcout.RTC_FATAL("never comes here: createConnector()") return 0
308  self.connector_cleanup())
309  PortBase.__del__(self)
310  return
311 
312 
313 
328  def init(self, prop):
329  self._rtcout.RTC_TRACE("init()")
330 
331  self._properties.mergeProperties(prop)
332 
333  self.configure()
334 
335  self.initConsumers()
336  self.initProviders()
337 
338  num = [-1]
339  if not OpenRTM_aist.stringTo(num, self._properties.getProperty("connection_limit","-1")):
340  self._rtcout.RTC_ERROR("invalid connection_limit value: %s",
341  self._properties.getProperty("connection_limit"))
342 
343  self.setConnectionLimit(num[0])
344  return
345 
346 
368  def write(self):
369  pass
370 
371 
372 
397  def connect(self, connector_profile):
398  self._rtcout.RTC_TRACE("OutPortBase.connect()")
399 
400  if OpenRTM_aist.NVUtil.find_index(connector_profile.properties,
401  "dataport.serializer.cdr.endian") is -1:
402  self._rtcout.RTC_TRACE("ConnectorProfile dataport.serializer.cdr.endian set.")
403  connector_profile.properties.append(OpenRTM_aist.NVUtil.newNV("dataport.serializer.cdr.endian","little,big"))
404 
405  return OpenRTM_aist.PortBase.connect(self, connector_profile)
406 
407 
408 
427  def properties(self):
428  self._rtcout.RTC_TRACE("properties()")
429  return self._properties
430 
431 
432 
440  def connectors(self):
441  self._rtcout.RTC_TRACE("connectors(): size = %d", len(self._connectors))
442  return self._connectors
443 
444 
445 
454  self._rtcout.RTC_TRACE("getConnectorProfiles(): size = %d", len(self._connectors))
455  profs = []
456  for con in self._connectors:
457  profs.append(con.profile())
458 
459  return profs
460 
461 
462 
470  def getConnectorIds(self):
471  ids = []
472 
473  for con in self._connectors:
474  ids.append(con.id())
475 
476  self._rtcout.RTC_TRACE("getConnectorIds(): %s", OpenRTM_aist.flatten(ids))
477  return ids
478 
479 
480 
488  def getConnectorNames(self):
489  names = []
490  for con in self._connectors:
491  names.append(con.name())
492 
493  self._rtcout.RTC_TRACE("getConnectorNames(): %s", OpenRTM_aist.flatten(names))
494  return names
495 
496 
497 
518  def getConnectorById(self, id):
519  self._rtcout.RTC_TRACE("getConnectorById(id = %s)", id)
520 
521  for (i,con) in enumerate(self._connectors):
522  if id == con.id():
523  return self._connectors[i]
524 
525  self._rtcout.RTC_WARN("ConnectorProfile with the id(%s) not found.", id)
526  return 0
527 
528 
549  def getConnectorByName(self, name):
550  self._rtcout.RTC_TRACE("getConnectorByName(name = %s)", name)
551 
552  for (i,con) in enumerate(self._connectors):
553  if name == con.name():
554  return self._connectors[i]
555 
556  self._rtcout.RTC_WARN("ConnectorProfile with the name(%s) not found.", name)
557  return 0
558 
559 
560 
569  def getConnectorProfileById(self, id, prof):
570  self._rtcout.RTC_TRACE("getConnectorProfileById(id = %s)", id)
571 
572  conn = self.getConnectorById(id)
573 
574  if not conn:
575  return False
576 
577  prof[0] = conn.profile()
578  return True
579 
580 
581 
590  def getConnectorProfileByName(self, name, prof):
591  self._rtcout.RTC_TRACE("getConnectorProfileByName(name = %s)", name)
592 
593  conn = self.getConnectorByName(name)
594 
595  if not conn:
596  return False
597 
598  prof[0] = conn.profile()
599  return True
600 
601 
602 
611  self._rtcout.RTC_TRACE("activateInterfaces()")
612  for con in self._connectors:
613  con.activate()
614 
615 
616 
625  self._rtcout.RTC_TRACE("deactivateInterfaces()")
626  for con in self._connectors:
627  con.deactivate()
628 
629 
630 
708  def addConnectorDataListener(self, listener_type, listener, autoclean = True):
709  self._rtcout.RTC_TRACE("addConnectorDataListener()")
710  if listener_type < OpenRTM_aist.ConnectorDataListenerType.CONNECTOR_DATA_LISTENER_NUM:
711  self._rtcout.RTC_TRACE("addConnectorDataListener(%s)",
712  OpenRTM_aist.ConnectorDataListener.toString(listener_type))
713  self._listeners.connectorData_[listener_type].addListener(listener, autoclean)
714  return
715 
716  self._rtcout.RTC_ERROR("addConnectorDataListener(): Unknown Listener Type")
717  return
718 
719 
720 
741  def removeConnectorDataListener(self, listener_type, listener):
742  self._rtcout.RTC_TRACE("removeConnectorDataListener()")
743 
744  if listener_type < OpenRTM_aist.ConnectorDataListenerType.CONNECTOR_DATA_LISTENER_NUM:
745  self._rtcout.RTC_TRACE("removeConnectorDataListener(%s)",
746  OpenRTM_aist.ConnectorDataListener.toString(listener_type))
747  self._listeners.connectorData_[listener_type].removeListener(listener)
748  return
749 
750  self._rtcout.RTC_ERROR("removeConnectorDataListener(): Unknown Listener Type")
751  return
752 
753 
754 
809  def addConnectorListener(self, callback_type, listener, autoclean = True):
810  self._rtcout.RTC_TRACE("addConnectorListener()")
811 
812  if callback_type < OpenRTM_aist.ConnectorListenerType.CONNECTOR_LISTENER_NUM:
813  self._rtcout.RTC_TRACE("addConnectorListener(%s)",
814  OpenRTM_aist.ConnectorListener.toString(callback_type))
815  self._listeners.connector_[callback_type].addListener(listener, autoclean)
816  return
817  self._rtcout.RTC_ERROR("addConnectorListener(): Unknown Listener Type")
818  return
819 
820 
821 
842  def removeConnectorListener(self, callback_type, listener):
843  self._rtcout.RTC_TRACE("removeConnectorListener()")
844 
845  if callback_type < OpenRTM_aist.ConnectorListenerType.CONNECTOR_LISTENER_NUM:
846  self._rtcout.RTC_TRACE("removeConnectorListener(%s)",
847  OpenRTM_aist.ConnectorListener.toString(callback_type))
848  self._listeners.connector_[callback_type].removeListener(listener)
849  return
850  self._rtcout.RTC_ERROR("removeConnectorListener(): Unknown Listener Type")
851  return
852 
853 
854 
862  def configure(self):
863  pass
864 
865 
866 
874  def publishInterfaces(self, cprof):
875  self._rtcout.RTC_TRACE("publishInterfaces()")
876 
877  retval = self._publishInterfaces()
878  if retval != RTC.RTC_OK:
879  return retval
880 
881  # prop: [port.outport].
882  prop = copy.deepcopy(self._properties)
883 
884  conn_prop = OpenRTM_aist.Properties()
885 
886  OpenRTM_aist.NVUtil.copyToProperties(conn_prop, cprof.properties)
887  prop.mergeProperties(conn_prop.getNode("dataport")) # marge ConnectorProfile
888 
889  """
890  # marge ConnectorProfile for buffer property.
891  # e.g.
892  # prof[buffer.write.full_policy]
893  # << cprof[dataport.outport.buffer.write.full_policy]
894  #
895  """
896  prop.mergeProperties(conn_prop.getNode("dataport.outport"))
897 
898 
899  #
900  # ここで, ConnectorProfile からの properties がマージされたため、
901  # prop["dataflow_type"]: データフロータイプ # prop["interface_type"]: インターフェースタイプ # などがアクセス可能になる。 dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")]) if dflow_type == "push": self._rtcout.RTC_PARANOID("dataflow_type = push .... do nothing") return RTC.RTC_OK elif dflow_type == "pull": self._rtcout.RTC_PARANOID("dataflow_type = pull .... create PullConnector") provider = self.createProvider(cprof, prop) if not provider: return RTC.BAD_PARAMETER # create InPortPushConnector connector = self.createConnector(cprof, prop, provider_ = provider) if not connector: return RTC.RTC_ERROR # connector set provider.setConnector(connector) self._rtcout.RTC_DEBUG("publishInterface() successfully finished.") return RTC.RTC_OK self._rtcout.RTC_ERROR("unsupported dataflow_type") return RTC.BAD_PARAMETER ## # @if jp # @brief Interface情報を取得する # @else # @brief Subscribe interface # @endif # # ReturnCode_t OutPortBase::subscribeInterfaces(const ConnectorProfile& cprof) def subscribeInterfaces(self, cprof): self._rtcout.RTC_TRACE("subscribeInterfaces()") # prop: [port.outport]. prop = copy.deepcopy(self._properties) conn_prop = OpenRTM_aist.Properties() OpenRTM_aist.NVUtil.copyToProperties(conn_prop, cprof.properties) prop.mergeProperties(conn_prop.getNode("dataport")) # marge ConnectorProfile """ # marge ConnectorProfile for buffer property. # e.g. # prof[buffer.write.full_policy] # << cprof[dataport.outport.buffer.write.full_policy] """ prop.mergeProperties(conn_prop.getNode("dataport.outport")) # # ここで, ConnectorProfile からの properties がマージされたため、 # prop["dataflow_type"]: データフロータイプ # prop["interface_type"]: インターフェースタイプ # などがアクセス可能になる。 # dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")]) profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) if dflow_type == "push": self._rtcout.RTC_PARANOID("dataflow_type = push .... create PushConnector") # interface consumer = self.createConsumer(cprof, prop) if not consumer: return RTC.BAD_PARAMETER # create OutPortPushConnector connector = self.createConnector(cprof, prop, consumer_ = consumer) if not connector: return RTC.RTC_ERROR ret = connector.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret elif dflow_type == "pull": self._rtcout.RTC_PARANOID("dataflow_type = pull.") conn = self.getConnectorById(cprof.connector_id) if not conn: self._rtcout.RTC_ERROR("specified connector not found: %s", cprof.connector_id) return RTC.RTC_ERROR ret = conn.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret self._rtcout.RTC_ERROR("unsupported dataflow_type") return RTC.BAD_PARAMETER ## # @if jp # @brief 登録されているInterface情報を解除する # @else # @brief Unsubscribe interface # @endif # # void # OutPortBase::unsubscribeInterfaces(const ConnectorProfile& connector_profile) def unsubscribeInterfaces(self, connector_profile): self._rtcout.RTC_TRACE("unsubscribeInterfaces()") id = connector_profile.connector_id self._rtcout.RTC_PARANOID("connector_id: %s", id) len_ = len(self._connectors) for i in range(len_): idx = (len_ - 1) - i if id == self._connectors[idx].id(): # Connector's dtor must call disconnect() self._connectors[idx].deactivate() self._connectors[idx].disconnect() del self._connectors[idx] self._rtcout.RTC_TRACE("delete connector: %s", id) return self._rtcout.RTC_ERROR("specified connector not found: %s", id) return ## # @if jp # @brief OutPort provider の初期化 # @else # @brief OutPort provider initialization # @endif # # void OutPortBase::initProviders() def initProviders(self): self._rtcout.RTC_TRACE("initProviders()") # create OutPort providers factory = OpenRTM_aist.OutPortProviderFactory.instance() provider_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available OutPortProviders: %s", OpenRTM_aist.flatten(provider_types)) if self._properties.hasKey("provider_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("provider_types")) != "all": self._rtcout.RTC_DEBUG("allowed providers: %s", self._properties.getProperty("provider_types")) temp_types = provider_types provider_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("provider_types"), ",") temp_types.sort() active_types.sort() set_ptypes = set(temp_types).intersection(set(active_types)) provider_types = provider_types + list(set_ptypes) # OutPortProvider supports "pull" dataflow type if len(provider_types) > 0: self._rtcout.RTC_DEBUG("dataflow_type pull is supported") self.appendProperty("dataport.dataflow_type", "pull") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(provider_types)) self._providerTypes = provider_types ## # @if jp # @brief InPort consumer の初期化 # @else # @brief InPort consumer initialization # @endif # # void OutPortBase::initConsumers() def initConsumers(self): self._rtcout.RTC_TRACE("initConsumers()") # create InPort consumers factory = OpenRTM_aist.InPortConsumerFactory.instance() consumer_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available InPortConsumer: %s", OpenRTM_aist.flatten(consumer_types)) if self._properties.hasKey("consumer_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("consumer_types")) != "all": self._rtcout.RTC_DEBUG("allowed consumers: %s", self._properties.getProperty("consumer_types")) temp_types = consumer_types consumer_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("consumer_types"), ",") temp_types.sort() active_types.sort() set_ctypes = set(temp_types).intersection(set(active_types)) consumer_types = consumer_types + list(set_ctypes) # InPortConsumer supports "push" dataflow type if len(consumer_types) > 0: self._rtcout.RTC_PARANOID("dataflow_type push is supported") self.appendProperty("dataport.dataflow_type", "push") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(consumer_types)) self._consumerTypes = consumer_types ## # @if jp # @brief OutPort provider の生成 # @else # @brief OutPort provider creation # @endif # # OutPortProvider* # OutPortBase::createProvider(ConnectorProfile& cprof, coil::Properties& prop) def createProvider(self, cprof, prop): if prop.getProperty("interface_type") and \ not OpenRTM_aist.includes(self._providerTypes, prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no provider found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._providerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) provider = OpenRTM_aist.OutPortProviderFactory.instance().createObject(prop.getProperty("interface_type")) if provider != 0: self._rtcout.RTC_DEBUG("provider created") provider.init(prop.getNode("provider")) if not provider.publishInterface(cprof.properties): self._rtcout.RTC_ERROR("publishing interface information error") OpenRTM_aist.OutPortProviderFactory.instance().deleteObject(provider) return 0 return provider self._rtcout.RTC_ERROR("provider creation failed") return 0 ## # @if jp # @brief InPort consumer の生成 # @else # @brief InPort consumer creation # @endif # # InPortConsumer* OutPortBase::createConsumer(const ConnectorProfile& cprof, # coil::Properties& prop) def createConsumer(self, cprof, prop): if prop.getProperty("interface_type") and \ not self._consumerTypes.count(prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no consumer found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._consumerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) consumer = OpenRTM_aist.InPortConsumerFactory.instance().createObject(prop.getProperty("interface_type")) if consumer != 0: self._rtcout.RTC_DEBUG("consumer created") consumer.init(prop.getNode("consumer")) if not consumer.subscribeInterface(cprof.properties): self._rtcout.RTC_ERROR("interface subscription failed.") OpenRTM_aist.InPortConsumerFactory.instance().deleteObject(consumer) return 0 return consumer self._rtcout.RTC_ERROR("consumer creation failed") return 0 ## # @if jp # @brief OutPortPushConnector の生成 # @else # @brief OutPortPushConnector creation # @endif # # OutPortConnector* # OutPortBase::createConnector(const ConnectorProfile& cprof, # coil::Properties& prop, # InPortConsumer* consumer) def createConnector(self, cprof, prop, provider_ = None, consumer_ = None): profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) connector = None try: if consumer_ is not None: connector = OpenRTM_aist.OutPortPushConnector(profile, consumer_, self._listeners) elif provider_ is not None: connector = OpenRTM_aist.OutPortPullConnector(profile, provider_, self._listeners) else: self._rtcout.RTC_ERROR("provider or consumer is not passed. returned 0;") return 0 if connector is None: self._rtcout.RTC_ERROR("OutPortConnector creation failed") return 0 if consumer_ is not None: self._rtcout.RTC_TRACE("OutPortPushConnector created") elif provider_ is not None: self._rtcout.RTC_TRACE("OutPortPullConnector created") self._connectors.append(connector) self._rtcout.RTC_PARANOID("connector push backed: %d", len(self._connectors)) return connector except: self._rtcout.RTC_ERROR("Exeption: OutPortPushConnector creation failed") self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) return 0 self._rtcout.RTC_FATAL("never comes here: createConnector()") return 0
902  # prop["interface_type"]: インターフェースタイプ # などがアクセス可能になる。 dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")]) if dflow_type == "push": self._rtcout.RTC_PARANOID("dataflow_type = push .... do nothing") return RTC.RTC_OK elif dflow_type == "pull": self._rtcout.RTC_PARANOID("dataflow_type = pull .... create PullConnector") provider = self.createProvider(cprof, prop) if not provider: return RTC.BAD_PARAMETER # create InPortPushConnector connector = self.createConnector(cprof, prop, provider_ = provider) if not connector: return RTC.RTC_ERROR # connector set provider.setConnector(connector) self._rtcout.RTC_DEBUG("publishInterface() successfully finished.") return RTC.RTC_OK self._rtcout.RTC_ERROR("unsupported dataflow_type") return RTC.BAD_PARAMETER ## # @if jp # @brief Interface情報を取得する # @else # @brief Subscribe interface # @endif # # ReturnCode_t OutPortBase::subscribeInterfaces(const ConnectorProfile& cprof) def subscribeInterfaces(self, cprof): self._rtcout.RTC_TRACE("subscribeInterfaces()") # prop: [port.outport]. prop = copy.deepcopy(self._properties) conn_prop = OpenRTM_aist.Properties() OpenRTM_aist.NVUtil.copyToProperties(conn_prop, cprof.properties) prop.mergeProperties(conn_prop.getNode("dataport")) # marge ConnectorProfile """ # marge ConnectorProfile for buffer property. # e.g. # prof[buffer.write.full_policy] # << cprof[dataport.outport.buffer.write.full_policy] """ prop.mergeProperties(conn_prop.getNode("dataport.outport")) # # ここで, ConnectorProfile からの properties がマージされたため、 # prop["dataflow_type"]: データフロータイプ # prop["interface_type"]: インターフェースタイプ # などがアクセス可能になる。 # dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")]) profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) if dflow_type == "push": self._rtcout.RTC_PARANOID("dataflow_type = push .... create PushConnector") # interface consumer = self.createConsumer(cprof, prop) if not consumer: return RTC.BAD_PARAMETER # create OutPortPushConnector connector = self.createConnector(cprof, prop, consumer_ = consumer) if not connector: return RTC.RTC_ERROR ret = connector.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret elif dflow_type == "pull": self._rtcout.RTC_PARANOID("dataflow_type = pull.") conn = self.getConnectorById(cprof.connector_id) if not conn: self._rtcout.RTC_ERROR("specified connector not found: %s", cprof.connector_id) return RTC.RTC_ERROR ret = conn.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret self._rtcout.RTC_ERROR("unsupported dataflow_type") return RTC.BAD_PARAMETER ## # @if jp # @brief 登録されているInterface情報を解除する # @else # @brief Unsubscribe interface # @endif # # void # OutPortBase::unsubscribeInterfaces(const ConnectorProfile& connector_profile) def unsubscribeInterfaces(self, connector_profile): self._rtcout.RTC_TRACE("unsubscribeInterfaces()") id = connector_profile.connector_id self._rtcout.RTC_PARANOID("connector_id: %s", id) len_ = len(self._connectors) for i in range(len_): idx = (len_ - 1) - i if id == self._connectors[idx].id(): # Connector's dtor must call disconnect() self._connectors[idx].deactivate() self._connectors[idx].disconnect() del self._connectors[idx] self._rtcout.RTC_TRACE("delete connector: %s", id) return self._rtcout.RTC_ERROR("specified connector not found: %s", id) return ## # @if jp # @brief OutPort provider の初期化 # @else # @brief OutPort provider initialization # @endif # # void OutPortBase::initProviders() def initProviders(self): self._rtcout.RTC_TRACE("initProviders()") # create OutPort providers factory = OpenRTM_aist.OutPortProviderFactory.instance() provider_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available OutPortProviders: %s", OpenRTM_aist.flatten(provider_types)) if self._properties.hasKey("provider_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("provider_types")) != "all": self._rtcout.RTC_DEBUG("allowed providers: %s", self._properties.getProperty("provider_types")) temp_types = provider_types provider_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("provider_types"), ",") temp_types.sort() active_types.sort() set_ptypes = set(temp_types).intersection(set(active_types)) provider_types = provider_types + list(set_ptypes) # OutPortProvider supports "pull" dataflow type if len(provider_types) > 0: self._rtcout.RTC_DEBUG("dataflow_type pull is supported") self.appendProperty("dataport.dataflow_type", "pull") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(provider_types)) self._providerTypes = provider_types ## # @if jp # @brief InPort consumer の初期化 # @else # @brief InPort consumer initialization # @endif # # void OutPortBase::initConsumers() def initConsumers(self): self._rtcout.RTC_TRACE("initConsumers()") # create InPort consumers factory = OpenRTM_aist.InPortConsumerFactory.instance() consumer_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available InPortConsumer: %s", OpenRTM_aist.flatten(consumer_types)) if self._properties.hasKey("consumer_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("consumer_types")) != "all": self._rtcout.RTC_DEBUG("allowed consumers: %s", self._properties.getProperty("consumer_types")) temp_types = consumer_types consumer_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("consumer_types"), ",") temp_types.sort() active_types.sort() set_ctypes = set(temp_types).intersection(set(active_types)) consumer_types = consumer_types + list(set_ctypes) # InPortConsumer supports "push" dataflow type if len(consumer_types) > 0: self._rtcout.RTC_PARANOID("dataflow_type push is supported") self.appendProperty("dataport.dataflow_type", "push") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(consumer_types)) self._consumerTypes = consumer_types ## # @if jp # @brief OutPort provider の生成 # @else # @brief OutPort provider creation # @endif # # OutPortProvider* # OutPortBase::createProvider(ConnectorProfile& cprof, coil::Properties& prop) def createProvider(self, cprof, prop): if prop.getProperty("interface_type") and \ not OpenRTM_aist.includes(self._providerTypes, prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no provider found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._providerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) provider = OpenRTM_aist.OutPortProviderFactory.instance().createObject(prop.getProperty("interface_type")) if provider != 0: self._rtcout.RTC_DEBUG("provider created") provider.init(prop.getNode("provider")) if not provider.publishInterface(cprof.properties): self._rtcout.RTC_ERROR("publishing interface information error") OpenRTM_aist.OutPortProviderFactory.instance().deleteObject(provider) return 0 return provider self._rtcout.RTC_ERROR("provider creation failed") return 0 ## # @if jp # @brief InPort consumer の生成 # @else # @brief InPort consumer creation # @endif # # InPortConsumer* OutPortBase::createConsumer(const ConnectorProfile& cprof, # coil::Properties& prop) def createConsumer(self, cprof, prop): if prop.getProperty("interface_type") and \ not self._consumerTypes.count(prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no consumer found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._consumerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) consumer = OpenRTM_aist.InPortConsumerFactory.instance().createObject(prop.getProperty("interface_type")) if consumer != 0: self._rtcout.RTC_DEBUG("consumer created") consumer.init(prop.getNode("consumer")) if not consumer.subscribeInterface(cprof.properties): self._rtcout.RTC_ERROR("interface subscription failed.") OpenRTM_aist.InPortConsumerFactory.instance().deleteObject(consumer) return 0 return consumer self._rtcout.RTC_ERROR("consumer creation failed") return 0 ## # @if jp # @brief OutPortPushConnector の生成 # @else # @brief OutPortPushConnector creation # @endif # # OutPortConnector* # OutPortBase::createConnector(const ConnectorProfile& cprof, # coil::Properties& prop, # InPortConsumer* consumer) def createConnector(self, cprof, prop, provider_ = None, consumer_ = None): profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) connector = None try: if consumer_ is not None: connector = OpenRTM_aist.OutPortPushConnector(profile, consumer_, self._listeners) elif provider_ is not None: connector = OpenRTM_aist.OutPortPullConnector(profile, provider_, self._listeners) else: self._rtcout.RTC_ERROR("provider or consumer is not passed. returned 0;") return 0 if connector is None: self._rtcout.RTC_ERROR("OutPortConnector creation failed") return 0 if consumer_ is not None: self._rtcout.RTC_TRACE("OutPortPushConnector created") elif provider_ is not None: self._rtcout.RTC_TRACE("OutPortPullConnector created") self._connectors.append(connector) self._rtcout.RTC_PARANOID("connector push backed: %d", len(self._connectors)) return connector except: self._rtcout.RTC_ERROR("Exeption: OutPortPushConnector creation failed") self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) return 0 self._rtcout.RTC_FATAL("never comes here: createConnector()") return 0
903  # などがアクセス可能になる。
904  dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")])
905 
906  if dflow_type == "push":
907  self._rtcout.RTC_PARANOID("dataflow_type = push .... do nothing")
908  return RTC.RTC_OK
909 
910  elif dflow_type == "pull":
911  self._rtcout.RTC_PARANOID("dataflow_type = pull .... create PullConnector")
912 
913  provider = self.createProvider(cprof, prop)
914  if not provider:
915  return RTC.BAD_PARAMETER
916 
917  # create InPortPushConnector
918  connector = self.createConnector(cprof, prop, provider_ = provider)
919  if not connector:
920  return RTC.RTC_ERROR
921 
922  # connector set
923  provider.setConnector(connector)
924 
925  self._rtcout.RTC_DEBUG("publishInterface() successfully finished.")
926  return RTC.RTC_OK
927 
928  self._rtcout.RTC_ERROR("unsupported dataflow_type")
929 
930  return RTC.BAD_PARAMETER
931 
932 
933 
941  def subscribeInterfaces(self, cprof):
942  self._rtcout.RTC_TRACE("subscribeInterfaces()")
943 
944  # prop: [port.outport].
945  prop = copy.deepcopy(self._properties)
946 
947  conn_prop = OpenRTM_aist.Properties()
948  OpenRTM_aist.NVUtil.copyToProperties(conn_prop, cprof.properties)
949  prop.mergeProperties(conn_prop.getNode("dataport")) # marge ConnectorProfile
950  """
951  # marge ConnectorProfile for buffer property.
952  # e.g.
953  # prof[buffer.write.full_policy]
954  # << cprof[dataport.outport.buffer.write.full_policy]
955  """
956  prop.mergeProperties(conn_prop.getNode("dataport.outport"))
957 
958  #
959  # ここで, ConnectorProfile からの properties がマージされたため、
960  # prop["dataflow_type"]: データフロータイプ # prop["interface_type"]: インターフェースタイプ # などがアクセス可能になる。 # dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")]) profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) if dflow_type == "push": self._rtcout.RTC_PARANOID("dataflow_type = push .... create PushConnector") # interface consumer = self.createConsumer(cprof, prop) if not consumer: return RTC.BAD_PARAMETER # create OutPortPushConnector connector = self.createConnector(cprof, prop, consumer_ = consumer) if not connector: return RTC.RTC_ERROR ret = connector.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret elif dflow_type == "pull": self._rtcout.RTC_PARANOID("dataflow_type = pull.") conn = self.getConnectorById(cprof.connector_id) if not conn: self._rtcout.RTC_ERROR("specified connector not found: %s", cprof.connector_id) return RTC.RTC_ERROR ret = conn.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret self._rtcout.RTC_ERROR("unsupported dataflow_type") return RTC.BAD_PARAMETER ## # @if jp # @brief 登録されているInterface情報を解除する # @else # @brief Unsubscribe interface # @endif # # void # OutPortBase::unsubscribeInterfaces(const ConnectorProfile& connector_profile) def unsubscribeInterfaces(self, connector_profile): self._rtcout.RTC_TRACE("unsubscribeInterfaces()") id = connector_profile.connector_id self._rtcout.RTC_PARANOID("connector_id: %s", id) len_ = len(self._connectors) for i in range(len_): idx = (len_ - 1) - i if id == self._connectors[idx].id(): # Connector's dtor must call disconnect() self._connectors[idx].deactivate() self._connectors[idx].disconnect() del self._connectors[idx] self._rtcout.RTC_TRACE("delete connector: %s", id) return self._rtcout.RTC_ERROR("specified connector not found: %s", id) return ## # @if jp # @brief OutPort provider の初期化 # @else # @brief OutPort provider initialization # @endif # # void OutPortBase::initProviders() def initProviders(self): self._rtcout.RTC_TRACE("initProviders()") # create OutPort providers factory = OpenRTM_aist.OutPortProviderFactory.instance() provider_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available OutPortProviders: %s", OpenRTM_aist.flatten(provider_types)) if self._properties.hasKey("provider_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("provider_types")) != "all": self._rtcout.RTC_DEBUG("allowed providers: %s", self._properties.getProperty("provider_types")) temp_types = provider_types provider_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("provider_types"), ",") temp_types.sort() active_types.sort() set_ptypes = set(temp_types).intersection(set(active_types)) provider_types = provider_types + list(set_ptypes) # OutPortProvider supports "pull" dataflow type if len(provider_types) > 0: self._rtcout.RTC_DEBUG("dataflow_type pull is supported") self.appendProperty("dataport.dataflow_type", "pull") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(provider_types)) self._providerTypes = provider_types ## # @if jp # @brief InPort consumer の初期化 # @else # @brief InPort consumer initialization # @endif # # void OutPortBase::initConsumers() def initConsumers(self): self._rtcout.RTC_TRACE("initConsumers()") # create InPort consumers factory = OpenRTM_aist.InPortConsumerFactory.instance() consumer_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available InPortConsumer: %s", OpenRTM_aist.flatten(consumer_types)) if self._properties.hasKey("consumer_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("consumer_types")) != "all": self._rtcout.RTC_DEBUG("allowed consumers: %s", self._properties.getProperty("consumer_types")) temp_types = consumer_types consumer_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("consumer_types"), ",") temp_types.sort() active_types.sort() set_ctypes = set(temp_types).intersection(set(active_types)) consumer_types = consumer_types + list(set_ctypes) # InPortConsumer supports "push" dataflow type if len(consumer_types) > 0: self._rtcout.RTC_PARANOID("dataflow_type push is supported") self.appendProperty("dataport.dataflow_type", "push") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(consumer_types)) self._consumerTypes = consumer_types ## # @if jp # @brief OutPort provider の生成 # @else # @brief OutPort provider creation # @endif # # OutPortProvider* # OutPortBase::createProvider(ConnectorProfile& cprof, coil::Properties& prop) def createProvider(self, cprof, prop): if prop.getProperty("interface_type") and \ not OpenRTM_aist.includes(self._providerTypes, prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no provider found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._providerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) provider = OpenRTM_aist.OutPortProviderFactory.instance().createObject(prop.getProperty("interface_type")) if provider != 0: self._rtcout.RTC_DEBUG("provider created") provider.init(prop.getNode("provider")) if not provider.publishInterface(cprof.properties): self._rtcout.RTC_ERROR("publishing interface information error") OpenRTM_aist.OutPortProviderFactory.instance().deleteObject(provider) return 0 return provider self._rtcout.RTC_ERROR("provider creation failed") return 0 ## # @if jp # @brief InPort consumer の生成 # @else # @brief InPort consumer creation # @endif # # InPortConsumer* OutPortBase::createConsumer(const ConnectorProfile& cprof, # coil::Properties& prop) def createConsumer(self, cprof, prop): if prop.getProperty("interface_type") and \ not self._consumerTypes.count(prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no consumer found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._consumerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) consumer = OpenRTM_aist.InPortConsumerFactory.instance().createObject(prop.getProperty("interface_type")) if consumer != 0: self._rtcout.RTC_DEBUG("consumer created") consumer.init(prop.getNode("consumer")) if not consumer.subscribeInterface(cprof.properties): self._rtcout.RTC_ERROR("interface subscription failed.") OpenRTM_aist.InPortConsumerFactory.instance().deleteObject(consumer) return 0 return consumer self._rtcout.RTC_ERROR("consumer creation failed") return 0 ## # @if jp # @brief OutPortPushConnector の生成 # @else # @brief OutPortPushConnector creation # @endif # # OutPortConnector* # OutPortBase::createConnector(const ConnectorProfile& cprof, # coil::Properties& prop, # InPortConsumer* consumer) def createConnector(self, cprof, prop, provider_ = None, consumer_ = None): profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) connector = None try: if consumer_ is not None: connector = OpenRTM_aist.OutPortPushConnector(profile, consumer_, self._listeners) elif provider_ is not None: connector = OpenRTM_aist.OutPortPullConnector(profile, provider_, self._listeners) else: self._rtcout.RTC_ERROR("provider or consumer is not passed. returned 0;") return 0 if connector is None: self._rtcout.RTC_ERROR("OutPortConnector creation failed") return 0 if consumer_ is not None: self._rtcout.RTC_TRACE("OutPortPushConnector created") elif provider_ is not None: self._rtcout.RTC_TRACE("OutPortPullConnector created") self._connectors.append(connector) self._rtcout.RTC_PARANOID("connector push backed: %d", len(self._connectors)) return connector except: self._rtcout.RTC_ERROR("Exeption: OutPortPushConnector creation failed") self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) return 0 self._rtcout.RTC_FATAL("never comes here: createConnector()") return 0
961  # prop["interface_type"]: インターフェースタイプ # などがアクセス可能になる。 # dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")]) profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) if dflow_type == "push": self._rtcout.RTC_PARANOID("dataflow_type = push .... create PushConnector") # interface consumer = self.createConsumer(cprof, prop) if not consumer: return RTC.BAD_PARAMETER # create OutPortPushConnector connector = self.createConnector(cprof, prop, consumer_ = consumer) if not connector: return RTC.RTC_ERROR ret = connector.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret elif dflow_type == "pull": self._rtcout.RTC_PARANOID("dataflow_type = pull.") conn = self.getConnectorById(cprof.connector_id) if not conn: self._rtcout.RTC_ERROR("specified connector not found: %s", cprof.connector_id) return RTC.RTC_ERROR ret = conn.setConnectorInfo(profile) if ret == RTC.RTC_OK: self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.") return ret self._rtcout.RTC_ERROR("unsupported dataflow_type") return RTC.BAD_PARAMETER ## # @if jp # @brief 登録されているInterface情報を解除する # @else # @brief Unsubscribe interface # @endif # # void # OutPortBase::unsubscribeInterfaces(const ConnectorProfile& connector_profile) def unsubscribeInterfaces(self, connector_profile): self._rtcout.RTC_TRACE("unsubscribeInterfaces()") id = connector_profile.connector_id self._rtcout.RTC_PARANOID("connector_id: %s", id) len_ = len(self._connectors) for i in range(len_): idx = (len_ - 1) - i if id == self._connectors[idx].id(): # Connector's dtor must call disconnect() self._connectors[idx].deactivate() self._connectors[idx].disconnect() del self._connectors[idx] self._rtcout.RTC_TRACE("delete connector: %s", id) return self._rtcout.RTC_ERROR("specified connector not found: %s", id) return ## # @if jp # @brief OutPort provider の初期化 # @else # @brief OutPort provider initialization # @endif # # void OutPortBase::initProviders() def initProviders(self): self._rtcout.RTC_TRACE("initProviders()") # create OutPort providers factory = OpenRTM_aist.OutPortProviderFactory.instance() provider_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available OutPortProviders: %s", OpenRTM_aist.flatten(provider_types)) if self._properties.hasKey("provider_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("provider_types")) != "all": self._rtcout.RTC_DEBUG("allowed providers: %s", self._properties.getProperty("provider_types")) temp_types = provider_types provider_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("provider_types"), ",") temp_types.sort() active_types.sort() set_ptypes = set(temp_types).intersection(set(active_types)) provider_types = provider_types + list(set_ptypes) # OutPortProvider supports "pull" dataflow type if len(provider_types) > 0: self._rtcout.RTC_DEBUG("dataflow_type pull is supported") self.appendProperty("dataport.dataflow_type", "pull") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(provider_types)) self._providerTypes = provider_types ## # @if jp # @brief InPort consumer の初期化 # @else # @brief InPort consumer initialization # @endif # # void OutPortBase::initConsumers() def initConsumers(self): self._rtcout.RTC_TRACE("initConsumers()") # create InPort consumers factory = OpenRTM_aist.InPortConsumerFactory.instance() consumer_types = factory.getIdentifiers() self._rtcout.RTC_PARANOID("available InPortConsumer: %s", OpenRTM_aist.flatten(consumer_types)) if self._properties.hasKey("consumer_types") and \ OpenRTM_aist.normalize(self._properties.getProperty("consumer_types")) != "all": self._rtcout.RTC_DEBUG("allowed consumers: %s", self._properties.getProperty("consumer_types")) temp_types = consumer_types consumer_types = [] active_types = OpenRTM_aist.split(self._properties.getProperty("consumer_types"), ",") temp_types.sort() active_types.sort() set_ctypes = set(temp_types).intersection(set(active_types)) consumer_types = consumer_types + list(set_ctypes) # InPortConsumer supports "push" dataflow type if len(consumer_types) > 0: self._rtcout.RTC_PARANOID("dataflow_type push is supported") self.appendProperty("dataport.dataflow_type", "push") self.appendProperty("dataport.interface_type", OpenRTM_aist.flatten(consumer_types)) self._consumerTypes = consumer_types ## # @if jp # @brief OutPort provider の生成 # @else # @brief OutPort provider creation # @endif # # OutPortProvider* # OutPortBase::createProvider(ConnectorProfile& cprof, coil::Properties& prop) def createProvider(self, cprof, prop): if prop.getProperty("interface_type") and \ not OpenRTM_aist.includes(self._providerTypes, prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no provider found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._providerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) provider = OpenRTM_aist.OutPortProviderFactory.instance().createObject(prop.getProperty("interface_type")) if provider != 0: self._rtcout.RTC_DEBUG("provider created") provider.init(prop.getNode("provider")) if not provider.publishInterface(cprof.properties): self._rtcout.RTC_ERROR("publishing interface information error") OpenRTM_aist.OutPortProviderFactory.instance().deleteObject(provider) return 0 return provider self._rtcout.RTC_ERROR("provider creation failed") return 0 ## # @if jp # @brief InPort consumer の生成 # @else # @brief InPort consumer creation # @endif # # InPortConsumer* OutPortBase::createConsumer(const ConnectorProfile& cprof, # coil::Properties& prop) def createConsumer(self, cprof, prop): if prop.getProperty("interface_type") and \ not self._consumerTypes.count(prop.getProperty("interface_type")): self._rtcout.RTC_ERROR("no consumer found") self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) self._rtcout.RTC_DEBUG("interface_types: %s", OpenRTM_aist.flatten(self._consumerTypes)) return 0 self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type")) consumer = OpenRTM_aist.InPortConsumerFactory.instance().createObject(prop.getProperty("interface_type")) if consumer != 0: self._rtcout.RTC_DEBUG("consumer created") consumer.init(prop.getNode("consumer")) if not consumer.subscribeInterface(cprof.properties): self._rtcout.RTC_ERROR("interface subscription failed.") OpenRTM_aist.InPortConsumerFactory.instance().deleteObject(consumer) return 0 return consumer self._rtcout.RTC_ERROR("consumer creation failed") return 0 ## # @if jp # @brief OutPortPushConnector の生成 # @else # @brief OutPortPushConnector creation # @endif # # OutPortConnector* # OutPortBase::createConnector(const ConnectorProfile& cprof, # coil::Properties& prop, # InPortConsumer* consumer) def createConnector(self, cprof, prop, provider_ = None, consumer_ = None): profile = OpenRTM_aist.ConnectorInfo(cprof.name, cprof.connector_id, OpenRTM_aist.CORBA_SeqUtil.refToVstring(cprof.ports), prop) connector = None try: if consumer_ is not None: connector = OpenRTM_aist.OutPortPushConnector(profile, consumer_, self._listeners) elif provider_ is not None: connector = OpenRTM_aist.OutPortPullConnector(profile, provider_, self._listeners) else: self._rtcout.RTC_ERROR("provider or consumer is not passed. returned 0;") return 0 if connector is None: self._rtcout.RTC_ERROR("OutPortConnector creation failed") return 0 if consumer_ is not None: self._rtcout.RTC_TRACE("OutPortPushConnector created") elif provider_ is not None: self._rtcout.RTC_TRACE("OutPortPullConnector created") self._connectors.append(connector) self._rtcout.RTC_PARANOID("connector push backed: %d", len(self._connectors)) return connector except: self._rtcout.RTC_ERROR("Exeption: OutPortPushConnector creation failed") self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) return 0 self._rtcout.RTC_FATAL("never comes here: createConnector()") return 0
962  # などがアクセス可能になる。
963  #
964  dflow_type = OpenRTM_aist.normalize([prop.getProperty("dataflow_type")])
965 
966  profile = OpenRTM_aist.ConnectorInfo(cprof.name,
967  cprof.connector_id,
969  prop)
970  if dflow_type == "push":
971  self._rtcout.RTC_PARANOID("dataflow_type = push .... create PushConnector")
972 
973  # interface
974  consumer = self.createConsumer(cprof, prop)
975  if not consumer:
976  return RTC.BAD_PARAMETER
977 
978  # create OutPortPushConnector
979  connector = self.createConnector(cprof, prop, consumer_ = consumer)
980  if not connector:
981  return RTC.RTC_ERROR
982 
983  ret = connector.setConnectorInfo(profile)
984 
985  if ret == RTC.RTC_OK:
986  self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.")
987 
988  return ret
989 
990  elif dflow_type == "pull":
991  self._rtcout.RTC_PARANOID("dataflow_type = pull.")
992 
993  conn = self.getConnectorById(cprof.connector_id)
994  if not conn:
995  self._rtcout.RTC_ERROR("specified connector not found: %s",
996  cprof.connector_id)
997  return RTC.RTC_ERROR
998 
999  ret = conn.setConnectorInfo(profile)
1000 
1001  if ret == RTC.RTC_OK:
1002  self._rtcout.RTC_DEBUG("subscribeInterfaces() successfully finished.")
1003 
1004  return ret
1005 
1006  self._rtcout.RTC_ERROR("unsupported dataflow_type")
1007  return RTC.BAD_PARAMETER
1008 
1009 
1010 
1019  def unsubscribeInterfaces(self, connector_profile):
1020  self._rtcout.RTC_TRACE("unsubscribeInterfaces()")
1021 
1022  id = connector_profile.connector_id
1023  self._rtcout.RTC_PARANOID("connector_id: %s", id)
1024 
1025  len_ = len(self._connectors)
1026  for i in range(len_):
1027  idx = (len_ - 1) - i
1028  if id == self._connectors[idx].id():
1029  # Connector's dtor must call disconnect()
1030  self._connectors[idx].deactivate()
1031  self._connectors[idx].disconnect()
1032  del self._connectors[idx]
1033  self._rtcout.RTC_TRACE("delete connector: %s", id)
1034  return
1035 
1036  self._rtcout.RTC_ERROR("specified connector not found: %s", id)
1037  return
1038 
1039 
1040 
1048  def initProviders(self):
1049  self._rtcout.RTC_TRACE("initProviders()")
1050 
1051  # create OutPort providers
1052  factory = OpenRTM_aist.OutPortProviderFactory.instance()
1053  provider_types = factory.getIdentifiers()
1054  self._rtcout.RTC_PARANOID("available OutPortProviders: %s",
1055  OpenRTM_aist.flatten(provider_types))
1056 
1057  if self._properties.hasKey("provider_types") and \
1058  OpenRTM_aist.normalize(self._properties.getProperty("provider_types")) != "all":
1059  self._rtcout.RTC_DEBUG("allowed providers: %s",
1060  self._properties.getProperty("provider_types"))
1061 
1062  temp_types = provider_types
1063  provider_types = []
1064  active_types = OpenRTM_aist.split(self._properties.getProperty("provider_types"), ",")
1065 
1066  temp_types.sort()
1067  active_types.sort()
1068 
1069  set_ptypes = set(temp_types).intersection(set(active_types))
1070  provider_types = provider_types + list(set_ptypes)
1071 
1072  # OutPortProvider supports "pull" dataflow type
1073  if len(provider_types) > 0:
1074  self._rtcout.RTC_DEBUG("dataflow_type pull is supported")
1075  self.appendProperty("dataport.dataflow_type", "pull")
1076  self.appendProperty("dataport.interface_type",
1077  OpenRTM_aist.flatten(provider_types))
1078 
1079  self._providerTypes = provider_types
1080 
1081 
1082 
1090  def initConsumers(self):
1091  self._rtcout.RTC_TRACE("initConsumers()")
1092 
1093  # create InPort consumers
1094  factory = OpenRTM_aist.InPortConsumerFactory.instance()
1095  consumer_types = factory.getIdentifiers()
1096  self._rtcout.RTC_PARANOID("available InPortConsumer: %s",
1097  OpenRTM_aist.flatten(consumer_types))
1098 
1099  if self._properties.hasKey("consumer_types") and \
1100  OpenRTM_aist.normalize(self._properties.getProperty("consumer_types")) != "all":
1101  self._rtcout.RTC_DEBUG("allowed consumers: %s",
1102  self._properties.getProperty("consumer_types"))
1103 
1104  temp_types = consumer_types
1105  consumer_types = []
1106  active_types = OpenRTM_aist.split(self._properties.getProperty("consumer_types"), ",")
1107 
1108  temp_types.sort()
1109  active_types.sort()
1110 
1111  set_ctypes = set(temp_types).intersection(set(active_types))
1112  consumer_types = consumer_types + list(set_ctypes)
1113 
1114  # InPortConsumer supports "push" dataflow type
1115  if len(consumer_types) > 0:
1116  self._rtcout.RTC_PARANOID("dataflow_type push is supported")
1117  self.appendProperty("dataport.dataflow_type", "push")
1118  self.appendProperty("dataport.interface_type",
1119  OpenRTM_aist.flatten(consumer_types))
1120 
1121  self._consumerTypes = consumer_types
1122 
1123 
1124 
1133  def createProvider(self, cprof, prop):
1134  if prop.getProperty("interface_type") and \
1135  not OpenRTM_aist.includes(self._providerTypes, prop.getProperty("interface_type")):
1136  self._rtcout.RTC_ERROR("no provider found")
1137  self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type"))
1138  self._rtcout.RTC_DEBUG("interface_types: %s",
1139  OpenRTM_aist.flatten(self._providerTypes))
1140  return 0
1141 
1142  self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type"))
1143  provider = OpenRTM_aist.OutPortProviderFactory.instance().createObject(prop.getProperty("interface_type"))
1144 
1145  if provider != 0:
1146  self._rtcout.RTC_DEBUG("provider created")
1147  provider.init(prop.getNode("provider"))
1148 
1149  if not provider.publishInterface(cprof.properties):
1150  self._rtcout.RTC_ERROR("publishing interface information error")
1151  OpenRTM_aist.OutPortProviderFactory.instance().deleteObject(provider)
1152  return 0
1153 
1154  return provider
1155 
1156  self._rtcout.RTC_ERROR("provider creation failed")
1157  return 0
1158 
1159 
1160 
1169  def createConsumer(self, cprof, prop):
1170  if prop.getProperty("interface_type") and \
1171  not self._consumerTypes.count(prop.getProperty("interface_type")):
1172  self._rtcout.RTC_ERROR("no consumer found")
1173  self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type"))
1174  self._rtcout.RTC_DEBUG("interface_types: %s",
1175  OpenRTM_aist.flatten(self._consumerTypes))
1176  return 0
1177 
1178  self._rtcout.RTC_DEBUG("interface_type: %s", prop.getProperty("interface_type"))
1179  consumer = OpenRTM_aist.InPortConsumerFactory.instance().createObject(prop.getProperty("interface_type"))
1180 
1181  if consumer != 0:
1182  self._rtcout.RTC_DEBUG("consumer created")
1183  consumer.init(prop.getNode("consumer"))
1184 
1185  if not consumer.subscribeInterface(cprof.properties):
1186  self._rtcout.RTC_ERROR("interface subscription failed.")
1187  OpenRTM_aist.InPortConsumerFactory.instance().deleteObject(consumer)
1188  return 0
1189 
1190  return consumer
1191 
1192  self._rtcout.RTC_ERROR("consumer creation failed")
1193  return 0
1194 
1195 
1196 
1207  def createConnector(self, cprof, prop, provider_ = None, consumer_ = None):
1208  profile = OpenRTM_aist.ConnectorInfo(cprof.name,
1209  cprof.connector_id,
1211  prop)
1212 
1213  connector = None
1214  try:
1215 
1216  if consumer_ is not None:
1217  connector = OpenRTM_aist.OutPortPushConnector(profile, consumer_, self._listeners)
1218  elif provider_ is not None:
1219  connector = OpenRTM_aist.OutPortPullConnector(profile, provider_, self._listeners)
1220 
1221  else:
1222  self._rtcout.RTC_ERROR("provider or consumer is not passed. returned 0;")
1223  return 0
1224 
1225  if connector is None:
1226  self._rtcout.RTC_ERROR("OutPortConnector creation failed")
1227  return 0
1228 
1229  if consumer_ is not None:
1230  self._rtcout.RTC_TRACE("OutPortPushConnector created")
1231  elif provider_ is not None:
1232  self._rtcout.RTC_TRACE("OutPortPullConnector created")
1233 
1234  self._connectors.append(connector)
1235  self._rtcout.RTC_PARANOID("connector push backed: %d", len(self._connectors))
1236  return connector
1237 
1238  except:
1239  self._rtcout.RTC_ERROR("Exeption: OutPortPushConnector creation failed")
1240  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
1241  return 0
1242 
1243 
1244  self._rtcout.RTC_FATAL("never comes here: createConnector()")
1245  return 0
def refToVstring(objlist)
coil::vstring refToVstring(const CorbaRefSequence& objlist)
def deactivateInterfaces(self)
Deactivate all Port interfacesvoid OutPortBase::deactivateInterfaces()
Definition: OutPortBase.py:624
def disconnect(self, connector_id)
[CORBA interface] Disconnect the Port
Definition: PortBase.py:815
def removeConnectorListener(self, callback_type, listener)
Removing BufferDataListener type listener.
Definition: OutPortBase.py:842
def initConsumers(self)
InPort consumer initializationvoid OutPortBase::initConsumers()
def getConnectorIds(self)
ConnectorId listcoil::vstring OutPortBase::getConnectorIds()
Definition: OutPortBase.py:470
def addConnectorListener(self, callback_type, listener, autoclean=True)
Adding ConnectorListener type listener.
Definition: OutPortBase.py:809
def addProperty(self, key, value)
Add NameValue data to PortProfile&#39;s properties.
Definition: PortBase.py:2184
def setConnectionLimit(self, limit_value)
Set the maximum number of connections.
Definition: PortBase.py:1760
def for_each(seq, f)
Apply the functor to all CORBA sequence elements.
def getConnectorById(self, id)
Getting ConnectorProfile by ID.
Definition: OutPortBase.py:518
def copyToProperties(prop, nvlist)
Copy to Proeprties from NVList.
Definition: NVUtil.py:118
def connect(self, connector_profile)
[CORBA interface] Connect the Port
Definition: OutPortBase.py:397
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
def initProviders(self)
OutPort provider initializationvoid OutPortBase::initProviders()
def removeConnectorDataListener(self, listener_type, listener)
Removing BufferDataListener type listener.
Definition: OutPortBase.py:741
def unsubscribeInterfaces(self, connector_profile)
Unsubscribe interfacevoid OutPortBase::unsubscribeInterfaces(const ConnectorProfile& connector_profil...
def getConnectorProfileByName(self, name, prof)
Getting ConnectorProfile by namebool OutPortBase::getConnectorProfileByName(const char* name...
Definition: OutPortBase.py:590
def subscribeInterfaces(self, cprof)
Subscribe interfaceReturnCode_t OutPortBase::subscribeInterfaces(const ConnectorProfile& cprof) ...
Definition: OutPortBase.py:941
def appendProperty(self, key, value)
Append NameValue data to PortProfile&#39;s properties.
Definition: PortBase.py:2209
def createProvider(self, cprof, prop)
OutPort provider creationOutPortProvider* OutPortBase::createProvider(ConnectorProfile& cprof...
def getConnectorNames(self)
Connector name listcoil::vstring OutPortBase::getConnectorNames()
Definition: OutPortBase.py:488
def activateInterfaces(self)
Activate all Port interfacesvoid OutPortBase::activateInterfaces()
Definition: OutPortBase.py:610
def addConnectorDataListener(self, listener_type, listener, autoclean=True)
Adding BufferDataListener type listener.
Definition: OutPortBase.py:708
def getConnectorProfiles(self)
ConnectorProfile listConnectorBase::ConnectorInfoList OutPortBase::getConnectorProfiles() ...
Definition: OutPortBase.py:453
def connectors(self)
Connector listconst std::vector<OutPortConnector*>& OutPortBase::connectors()
Definition: OutPortBase.py:440
def getConnectorProfileById(self, id, prof)
Getting ConnectorProfile by namebool OutPortBase::getConnectorProfileById(const char* id...
Definition: OutPortBase.py:569
def find_index(nv, name)
Definition: NVUtil.py:229
def configure(self)
Configureing outportvoid OutPortBase::configure()
Definition: OutPortBase.py:862
def createConnector(self, cprof, prop, provider_=None, consumer_=None)
OutPortPushConnector creationOutPortConnector* OutPortBase::createConnector(const ConnectorProfile& c...
def properties(self)
Get properties.
Definition: OutPortBase.py:427
def __init__(self, name, data_type)
A constructor of OutPortBase class.
Definition: OutPortBase.py:256
def createConsumer(self, cprof, prop)
InPort consumer creationInPortConsumer* OutPortBase::createConsumer(const ConnectorProfile& cprof...
def getConnectorByName(self, name)
Getting Connector by name.
Definition: OutPortBase.py:549
def _publishInterfaces(self)
Publish interface information.
Definition: PortBase.py:1786
def init(self, prop)
Initializing properties.
Definition: OutPortBase.py:328
def publishInterfaces(self, cprof)
Publish interface informationReturnCode_t OutPortBase::publishInterfaces(ConnectorProfile& cprof) ...
Definition: OutPortBase.py:874
def __del__(self, PortBase=OpenRTM_aist.PortBase)
destructor
Definition: OutPortBase.py:304
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