[openrtm-commit:01706] r650 - trunk/OpenRTM-aist-Python/OpenRTM_aist

openrtm @ openrtm.org openrtm @ openrtm.org
2016年 2月 1日 (月) 20:11:54 JST


Author: miyamoto
Date: 2016-02-01 20:11:54 +0900 (Mon, 01 Feb 2016)
New Revision: 650

Added:
   trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortDirectConsumer.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortDirectProvider.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortDirectConsumer.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortDirectProvider.py
Modified:
   trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/InPort.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortPullConnector.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortBase.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPullConnector.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPushConnector.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
Log:
[incompat,new_func,new_file,->RELENG_1_2] Direct data put functionality between data ports has been implemented. refs #3407

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py	2016-02-01 10:53:09 UTC (rev 649)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -34,4 +34,9 @@
     OpenRTM_aist.InPortCorbaCdrConsumerInit()
     OpenRTM_aist.OutPortCorbaCdrConsumerInit()
     OpenRTM_aist.OutPortCorbaCdrProviderInit()
+    OpenRTM_aist.InPortDirectProviderInit()
+    OpenRTM_aist.InPortDirectConsumerInit()
+    OpenRTM_aist.OutPortDirectProviderInit()
+    OpenRTM_aist.OutPortDirectConsumerInit()
+
     

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/InPort.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/InPort.py	2016-02-01 10:53:09 UTC (rev 649)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/InPort.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -107,7 +107,11 @@
     self._OnRead         = None
     self._OnReadConvert  = None
 
+    self._directNewData = False
+    self._valueMutex = threading.RLock()
+    self._outPortConnectorList = []
 
+
   def __del__(self, InPortBase=OpenRTM_aist.InPortBase):
     InPortBase.__del__(self)
     return
@@ -151,6 +155,13 @@
   def isNew(self):
     self._rtcout.RTC_TRACE("isNew()")
 
+
+    guard = OpenRTM_aist.ScopedLock(self._valueMutex)
+    if self._directNewData == True:
+      self._rtcout.RTC_TRACE("isNew() returns true because of direct write.")
+      return True
+    del guard
+    
     if len(self._connectors) == 0:
       self._rtcout.RTC_DEBUG("no connectors")
       return False
@@ -190,7 +201,8 @@
   # bool isEmpty()
   def isEmpty(self):
     self._rtcout.RTC_TRACE("isEmpty()")
-
+    if self._directNewData == True:
+      return False
     if len(self._connectors) == 0:
       self._rtcout.RTC_DEBUG("no connectors")
       return True
@@ -283,6 +295,31 @@
       self._OnRead()
       self._rtcout.RTC_TRACE("OnRead called")
 
+    guard = OpenRTM_aist.ScopedLock(self._valueMutex)
+    if self._directNewData == True:
+      
+      self._rtcout.RTC_TRACE("Direct data transfer")
+      if self._OnReadConvert is not None:
+        self._value = self._OnReadConvert(self._value)
+        self._rtcout.RTC_TRACE("OnReadConvert for direct data called")
+      self._directNewData = False
+      return self._value
+    del guard
+
+
+    if len(self._outPortConnectorList) > 0:
+      data = self._outPortConnectorList[0].read()
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ].notify(self._profile, data)
+      #self._outPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ].notify(self._profile, data)
+      self._rtcout.RTC_TRACE("ON_BUFFER_READ(InPort,OutPort), ")
+      self._rtcout.RTC_TRACE("callback called in direct mode.")
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
+      #self._outPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
+      self._rtcout.RTC_TRACE("ON_RECEIVED(InPort,OutPort), ")
+      self._rtcout.RTC_TRACE("callback called in direct mode.")
+      self._value = data
+      return self._value
+
     if len(self._connectors) == 0:
       self._rtcout.RTC_DEBUG("no connectors")
       return self._value
@@ -370,3 +407,62 @@
   # @endif
   def setOnReadConvert(self, on_rconvert):
     self._OnReadConvert = on_rconvert
+
+  ##
+  # @if jp
+  #
+  # @brief データをダイレクトに書き込む
+  #
+  # @param self
+  # @param data 書き込むデータ
+  #
+  # @else
+  # @brief 
+  #
+  # @param self
+  # @param data 
+  # @endif
+  # void write(const DataType& data)
+  def write(self, data):
+    guard = OpenRTM_aist.ScopedLock(self._valueMutex)
+    self._value = data
+    self._directNewData = True
+    del guard
+
+  ##
+  # @if jp
+  # @brief ダイレクト通信用のOutPortPullConnectorを追加
+  # @param self
+  # @param outPortConnector outPortPullConnector
+  # @return OutPortのサーバント(取得に失敗した場合はNone)
+  # @else
+  # @brief Getting local peer InPort if available
+  # @param self
+  # @param profile 
+  # @return 
+  # @endif
+  #
+  # OutPortBase*
+  # setOutPortConnector(const OutPortPullConnector_impl outPortConnector)
+  def addOutPortConnector(self, outPortConnector):
+    self._outPortConnectorList.append(outPortConnector)
+    
+
+
+  ##
+  # @if jp
+  # @brief ダイレクト通信用のOutPortPullConnectorを削除
+  # @param self
+  # @param outPortConnector outPortPullConnector
+  # @else
+  # @brief Getting local peer InPort if available
+  # @param self
+  # @param profile 
+  # @return 
+  # @endif
+  #
+  # OutPortBase*
+  # setOutPortConnector(const OutPortPullConnector_impl outPortConnector)
+  def removeOutPortConnector(self, outPortConnector):
+    self._outPortConnectorList.remove(outPortConnector)
+    
\ No newline at end of file

Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortDirectConsumer.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortDirectConsumer.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortDirectConsumer.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -0,0 +1,206 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+#  @file InPortDirectConsumer.py
+#  @brief InPortDirectConsumer class
+#  @date $Date: 2016/01/08 $
+#  @author Nobuhiko Miyamoto
+# 
+
+
+import sys
+from omniORB import any
+from omniORB import CORBA
+import OpenRTM_aist
+import OpenRTM
+
+##
+# @if jp
+#
+# @class InPortDirectConsumer
+#
+# @brief InPortDirectConsumer クラス
+#
+# データをダイレクトに書き込むpush型通信を実現するInPortコンシュマークラス
+#
+# @else
+# @class InPortDirectConsumer
+#
+# @brief InPortDirectConsumer class
+#
+#
+#
+# @endif
+#
+class InPortDirectConsumer(OpenRTM_aist.InPortConsumer):
+  """
+  """
+
+  ##
+  # @if jp
+  # @brief コンストラクタ
+  #
+  # コンストラクタ
+  #
+  # @param self
+  #
+  # @else
+  # @brief Constructor
+  #
+  # Constructor
+  #
+  # @param self
+  #
+  # @endif
+  #
+  def __init__(self):
+    OpenRTM_aist.InPortConsumer.__init__(self)
+    self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("InPortDirectConsumer")
+    self._properties = None
+    return
+
+  ##
+  # @if jp
+  # @brief デストラクタ
+  #
+  # デストラクタ
+  #
+  # @param self
+  #
+  # @else
+  # @brief Destructor
+  #
+  # Destructor
+  #
+  # @param self
+  #
+  # @endif
+  #
+  def __del__(self):
+    self._rtcout.RTC_PARANOID("~InPortDirectConsumer()")
+    
+    return
+
+  ##
+  # @if jp
+  # @brief 設定初期化
+  #
+  # InPortConsumerの各種設定を行う
+  #
+  # @self
+  # 
+  #
+  # @else
+  # @brief Initializing configuration
+  #
+  #
+  # @endif
+  #
+  # virtual void init(coil::Properties& prop);
+  def init(self, prop):
+    self._rtcout.RTC_TRACE("init()")
+    self._properties = prop
+    return
+
+  ##
+  # @if jp
+  # @brief 
+  #
+  # @param self
+  # @param data
+  # @return 
+  #
+  # @else
+  # @brief 
+  #
+  # @param self
+  # @param data
+  # @return 
+  #
+  # @endif
+  #
+  # virtual ReturnCode put(const cdrMemoryStream& data);
+  def put(self, data):
+    self._rtcout.RTC_PARANOID("put()")
+
+        
+    return self.UNKNOWN_ERROR
+
+  ##
+  # @if jp
+  # @brief InterfaceProfile情報を公開する
+  #
+  #
+  # @param self
+  # @param properties InterfaceProfile情報を受け取るプロパティ
+  #
+  # @else
+  # @brief Publish InterfaceProfile information
+  #
+  #
+  # @param self
+  # @param properties Properties to get InterfaceProfile information
+  #
+  # @endif
+  #
+  # virtual void publishInterfaceProfile(SDOPackage::NVList& properties);
+  def publishInterfaceProfile(self, properties):
+    return
+
+  ##
+  # @if jp
+  # @brief データ送信通知への登録
+  #
+  # @param self
+  # @param properties 登録情報
+  #
+  # @return 登録処理結果(登録成功:true、登録失敗:false)
+  #
+  # @else
+  # @brief Subscribe to the data sending notification
+  #
+  # @param self
+  # @param properties Information for subscription
+  #
+  # @return Subscription result (Successful:true, Failed:false)
+  #
+  # @endif
+  #
+  # virtual bool subscribeInterface(const SDOPackage::NVList& properties);
+  def subscribeInterface(self, properties):
+    self._rtcout.RTC_TRACE("subscribeInterface()")
+    
+    
+    return True
+    
+  ##
+  # @if jp
+  # @brief データ送信通知からの登録解除
+  #
+  # @param self
+  # @param properties 登録解除情報
+  #
+  # @else
+  # @brief Unsubscribe the data send notification
+  #
+  # 
+  # @param self
+  # @param properties Information for unsubscription
+  #
+  # @endif
+  #
+  # virtual void unsubscribeInterface(const SDOPackage::NVList& properties);
+  def unsubscribeInterface(self, properties):
+    self._rtcout.RTC_TRACE("unsubscribeInterface()")
+    
+    return
+
+  
+
+
+def InPortDirectConsumerInit():
+  factory = OpenRTM_aist.InPortConsumerFactory.instance()
+  factory.addFactory("direct",
+                     OpenRTM_aist.InPortDirectConsumer,
+                     OpenRTM_aist.Delete)

Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortDirectProvider.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortDirectProvider.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortDirectProvider.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -0,0 +1,174 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+#  @file InPortDirectProvider.py
+#  @brief InPortDirectProvider class
+#  @date $Date: 2016/01/08 $
+#  @author Nobuhiko Miyamoto
+# 
+
+import sys
+from omniORB import *
+from omniORB import any
+
+import OpenRTM_aist
+import OpenRTM__POA,OpenRTM
+
+##
+# @if jp
+# @class InPortDirectProvider
+# @brief InPortDirectProvider クラス
+#
+# データをダイレクトに書き込むpush型通信を実現するInPortプロバイダクラス
+#
+# @param self
+#
+# @else
+# @class InPortDirectProvider
+# @brief InPortDirectProvider class
+#
+#
+# @param self
+#
+# @endif
+#
+class InPortDirectProvider(OpenRTM_aist.InPortProvider):
+    
+  """
+  """
+
+  ##
+  # @if jp
+  # @brief コンストラクタ
+  #
+  # コンストラクタ
+  #
+  # @param self
+  #
+  # @else
+  # @brief Constructor
+  #
+  # @param self
+  #
+  # @endif
+  #
+  def __init__(self):
+    OpenRTM_aist.InPortProvider.__init__(self)
+
+    # PortProfile setting
+    self.setInterfaceType("direct")
+    
+    
+    
+    self._buffer = None
+
+    self._profile = None
+    self._listeners = None
+    #self._connector = None
+    
+
+    
+    return
+
+  ##
+  # @if jp
+  # @brief デストラクタ
+  #
+  # デストラクタ
+  #
+  # @param self
+  #
+  # @else
+  # @brief Destructor
+  #
+  # Destructor
+  #
+  # @param self
+  #
+  # @endif
+  #
+  def __del__(self):
+    
+    return
+
+  ## void init(coil::Properties& prop);
+  def init(self, prop):
+    pass
+
+  ## void setBuffer(BufferBase<cdrMemoryStream>* buffer);
+  def setBuffer(self, buffer):
+    self._buffer = buffer
+    return
+
+  # void setListener(ConnectorInfo& info,
+  #                  ConnectorListeners* listeners);
+  def setListener(self, info, listeners):
+    self._profile = info
+    self._listeners = listeners
+    return
+
+  
+  ## void onBufferWrite(const cdrMemoryStream& data)
+  def onBufferWrite(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
+    return
+
+
+  ## inline void onBufferFull(const cdrMemoryStream& data)
+  def onBufferFull(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL].notify(self._profile, data)
+    return
+
+
+  ## inline void onBufferWriteTimeout(const cdrMemoryStream& data)
+  def onBufferWriteTimeout(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT].notify(self._profile, data)
+    return
+
+  ## inline void onBufferWriteOverwrite(const cdrMemoryStream& data)
+  def onBufferWriteOverwrite(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE].notify(self._profile, data)
+    return
+
+
+  ## inline void onReceived(const cdrMemoryStream& data)
+  def onReceived(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
+    return
+
+
+  ## inline void onReceiverFull(const cdrMemoryStream& data)
+  def onReceiverFull(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
+    return
+
+
+  ## inline void onReceiverTimeout(const cdrMemoryStream& data)
+  def onReceiverTimeout(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_TIMEOUT].notify(self._profile, data)
+    return
+
+
+  ## inline void onReceiverError(const cdrMemoryStream& data)
+  def onReceiverError(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_ERROR].notify(self._profile, data)
+    return
+  
+
+
+
+
+def InPortDirectProviderInit():
+  factory = OpenRTM_aist.InPortProviderFactory.instance()
+  factory.addFactory("direct",
+                     OpenRTM_aist.InPortDirectProvider,
+                     OpenRTM_aist.Delete)

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortPullConnector.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortPullConnector.py	2016-02-01 10:53:09 UTC (rev 649)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortPullConnector.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -128,6 +128,8 @@
     OpenRTM_aist.InPortConnector.__init__(self, info, buffer)
     self._consumer = consumer
     self._listeners = listeners
+
+
     if buffer == 0:
       self._buffer = self.createBuffer(self._profile)
 
@@ -135,6 +137,7 @@
       raise
         
     self._buffer.init(info.properties.getNode("buffer"))
+    self._consumer.init(info.properties)
     self._consumer.setBuffer(self._buffer)
     self._consumer.setListener(info, self._listeners)
     self.onConnect()
@@ -197,6 +200,8 @@
     if not self._consumer:
       return self.PORT_ERROR
 
+
+
     cdr_data = [None]
     ret = self._consumer.get(cdr_data)
 
@@ -319,3 +324,7 @@
     if self._listeners and self._profile:
       self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT].notify(self._profile)
     return
+
+  
+
+

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortBase.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortBase.py	2016-02-01 10:53:09 UTC (rev 649)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortBase.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -1180,6 +1180,7 @@
     
     if consumer != 0:
       self._rtcout.RTC_DEBUG("consumer created")
+      
       consumer.init(prop.getNode("consumer"))
 
       if not consumer.subscribeInterface(cprof.properties):
@@ -1231,6 +1232,20 @@
       elif provider_ is not None:
         self._rtcout.RTC_TRACE("OutPortPullConnector created")
 
+            
+      if OpenRTM_aist.StringUtil.normalize([prop.getProperty("interface_type")]) == "direct":
+        
+        inport = self.getLocalInPort(profile)
+        
+        if inport is None:
+          self._rtcout.RTC_TRACE("interface_type is direct, ")
+          self._rtcout.RTC_TRACE("but a peer InPort servant could not be obtained.")
+          del connector
+          return 0
+        
+        connector.setInPort(inport)
+
+
       self._connectors.append(connector)
       self._rtcout.RTC_PARANOID("connector push backed: %d", len(self._connectors))
       return connector
@@ -1243,3 +1258,37 @@
 
     self._rtcout.RTC_FATAL("never comes here: createConnector()")
     return 0
+
+
+  ##
+  # @if jp
+  # @brief ローカルのピアInPortを取得
+  # @param self
+  # @param profile コネクタプロファイル
+  # @return InPortのサーバント(取得に失敗した場合はNone)
+  # @else
+  # @brief Getting local peer InPort if available
+  # @param self
+  # @param profile 
+  # @return 
+  # @endif
+  #
+  # InPortBase*
+  # getLocalInPort(const ConnectorInfo& profile)
+  def getLocalInPort(self, profile):
+    self._rtcout.RTC_DEBUG("Trying direct port connection.")
+    orb = OpenRTM_aist.Manager.instance().getORB()
+    self._rtcout.RTC_DEBUG("Current connector profile: name=%s, id=%s" % (profile.name, profile.id))
+    for p in profile.ports:
+      obj = orb.string_to_object(p)
+      if self.getPortRef()._is_equivalent(obj):
+        continue
+      self._rtcout.RTC_DEBUG("Peer port found: %s." % p)
+      try:
+        poa = OpenRTM_aist.Manager.instance().getPOA()
+        inport = poa.reference_to_servant(obj)
+        self._rtcout.RTC_DEBUG("InPortBase servant pointer is obtained.")
+        return inport
+      except:
+        self._rtcout.RTC_DEBUG("Peer port might be a remote port")
+    return None
\ No newline at end of file

Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortDirectConsumer.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortDirectConsumer.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortDirectConsumer.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -0,0 +1,267 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+#  @file OutPortDirectConsumer.py
+#  @brief OutPortDirectConsumer class
+#  @date $Date: 2016/01/08 $
+#  @author Nobuhiko Miyamoto
+# 
+
+
+import sys
+from omniORB import any
+import OpenRTM_aist
+import OpenRTM
+
+##
+# @if jp
+#
+# @class InPortDirectConsumer
+#
+# @brief InPortDirectConsumer クラス
+#
+# データをダイレクトに書き込むpull型通信を実現するOutPortコンシュマークラス
+#
+# @else
+# @class InPortDirectConsumer
+#
+# @brief InPortDirectConsumer class
+#
+#
+#
+# @endif
+#
+class OutPortDirectConsumer(OpenRTM_aist.OutPortConsumer):
+  """
+  """
+
+  ##
+  # @if jp
+  # @brief コンストラクタ
+  #
+  # コンストラクタ
+  #
+  # @param self
+  #
+  # @else
+  # @brief Constructor
+  #
+  # Constructor
+  #
+  # @param self
+  #
+  # @endif
+  #
+  def __init__(self):
+    OpenRTM_aist.OutPortConsumer.__init__(self)
+    self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("OutPortDirectConsumer")
+    self._listeners = None
+    self._profile = None
+    self._properties = None
+    return
+
+  ##
+  # @if jp
+  # @brief デストラクタ
+  #
+  # デストラクタ
+  #
+  # @param self
+  #
+  # @else
+  # @brief Destructor
+  #
+  # Destructor
+  #
+  # @param self
+  #
+  # @endif
+  #
+  def __del__(self, CorbaConsumer=OpenRTM_aist.CorbaConsumer):
+    self._rtcout.RTC_PARANOID("~OutPortDirectConsumer()")
+    
+    pass
+
+
+  ##
+  # @if jp
+  # @brief 設定初期化
+  #
+  # InPortConsumerの各種設定を行う
+  #
+  # @self
+  # 
+  #
+  # @else
+  # @brief Initializing configuration
+  #
+  #
+  # @endif
+  #
+  # virtual void init(coil::Properties& prop);
+  def init(self, prop):
+    self._rtcout.RTC_TRACE("init()")
+    self._properties = prop
+    return
+
+  ##
+  # @if jp
+  # @brief 
+  #
+  # @param self
+  # @param data
+  # @return 
+  #
+  # @else
+  # @brief 
+  #
+  # @param self
+  # @param data
+  # @return 
+  #
+  # @endif
+  #
+  # virtual ReturnCode put(const cdrMemoryStream& data);
+  def get(self, data):
+    self._rtcout.RTC_PARANOID("get()")
+    return self.UNKNOWN_ERROR
+  
+
+  # virtual void setBuffer(CdrBufferBase* buffer);
+  def setBuffer(self, buffer):
+    self._rtcout.RTC_TRACE("setBuffer()")
+    return
+  
+
+  # void OutPortCorbaCdrConsumer::setListener(ConnectorInfo& info,
+  #                                           ConnectorListeners* listeners)
+  def setListener(self, info, listeners):
+    self._rtcout.RTC_TRACE("setListener()")
+    self._listeners = listeners
+    self._profile = info
+    return
+
+
+  
+
+
+  ##
+  # @if jp
+  # @brief InterfaceProfile情報を公開する
+  #
+  #
+  # @param self
+  # @param properties InterfaceProfile情報を受け取るプロパティ
+  #
+  # @else
+  # @brief Publish InterfaceProfile information
+  #
+  #
+  # @param self
+  # @param properties Properties to get InterfaceProfile information
+  #
+  # @endif
+  #
+  # virtual void publishInterfaceProfile(SDOPackage::NVList& properties);
+  def subscribeInterface(self, properties):
+    self._rtcout.RTC_TRACE("subscribeInterface()")
+    
+
+    return True
+
+
+  ##
+  # @if jp
+  # @brief データ送信通知への登録
+  #
+  # @param self
+  # @param properties 登録情報
+  #
+  # @return 登録処理結果(登録成功:true、登録失敗:false)
+  #
+  # @else
+  # @brief Subscribe to the data sending notification
+  #
+  # @param self
+  # @param properties Information for subscription
+  #
+  # @return Subscription result (Successful:true, Failed:false)
+  #
+  # @endif
+  #
+  # virtual bool subscribeInterface(const SDOPackage::NVList& properties);
+  def unsubscribeInterface(self, properties):
+    self._rtcout.RTC_TRACE("unsubscribeInterface()")
+    return
+
+
+  
+
+    
+  
+  # inline void onBufferWrite(const cdrMemoryStream& data)
+  def onBufferWrite(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
+
+    return
+
+
+  # inline void onBufferFull(const cdrMemoryStream& data)
+  def onBufferFull(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL].notify(self._profile, data)
+
+    return
+
+
+  # inline void onReceived(const cdrMemoryStream& data)
+  def onReceived(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
+
+    return
+
+
+  # inline void onReceiverFull(const cdrMemoryStream& data)
+  def onReceiverFull(self, data):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
+
+    return
+
+
+  ##
+  # @brief Connector listener functions
+  #
+  # inline void onSenderEmpty()
+  def onSenderEmpty(self):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_EMPTY].notify(self._profile)
+
+    return
+
+
+  # inline void onSenderTimeout()
+  def onSenderTimeout(self):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_TIMEOUT].notify(self._profile)
+
+    return
+
+      
+  # inline void onSenderError()
+  def onSenderError(self):
+    if self._listeners is not None and self._profile is not None:
+      self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_ERROR].notify(self._profile)
+
+    return
+
+
+def OutPortDirectConsumerInit():
+  factory = OpenRTM_aist.OutPortConsumerFactory.instance()
+  factory.addFactory("direct",
+                     OpenRTM_aist.OutPortDirectConsumer,
+                     OpenRTM_aist.Delete)
+  return

Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortDirectProvider.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortDirectProvider.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortDirectProvider.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -0,0 +1,175 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+#  @file OutPortDirectProvider.py
+#  @brief OutPortDirectProvider class
+#  @date $Date: 2016/01/08 $
+#  @author Nobuhiko Miyamoto
+# 
+
+import sys
+from omniORB import *
+from omniORB import any
+
+import OpenRTM_aist
+import OpenRTM__POA,OpenRTM
+
+##
+# @if jp
+# @class OutPortDirectProvider
+# @brief OutPortDirectProvider クラス
+#
+# データをダイレクトに書き込むpull型通信を実現するOutPortプロバイダクラス
+#
+# @param self
+#
+# @else
+# @class InPortDirectProvider
+# @brief InPortDirectProvider class
+#
+#
+# @param self
+#
+# @endif
+#
+class OutPortDirectProvider(OpenRTM_aist.OutPortProvider):
+  ##
+  # @if jp
+  # @brief コンストラクタ
+  #
+  # コンストラクタ
+  #
+  # @param self
+  #
+  # @else
+  # @brief Constructor
+  #
+  # @param self
+  #
+  # @endif
+  #
+  def __init__(self):
+    OpenRTM_aist.OutPortProvider.__init__(self)
+    self.setInterfaceType("direct")
+
+
+
+    self._listeners = None
+    self._buffer = None
+    self._profile   = None
+    #self._connector = None
+    return
+
+
+  ##
+  # @if jp
+  # @brief デストラクタ
+  #
+  # デストラクタ
+  #
+  # @param self
+  #
+  # @else
+  # @brief Destructor
+  #
+  # Destructor
+  #
+  # @param self
+  #
+  # @endif
+  #
+  def __del__(self):
+
+    return
+
+
+  
+  # void init(coil::Properties& prop);
+  def init(self, prop):
+    pass
+
+
+  
+  # virtual void setBuffer(BufferBase<cdrMemoryStream>* buffer);
+  def setBuffer(self, buffer):
+    self._buffer = buffer
+    return
+
+
+  
+  # virtual void setListener(ConnectorInfo& info,
+  #                          ConnectorListeners* listeners);
+  def setListener(self, info, listeners):
+    self._profile = info
+    self._listeners = listeners
+    return
+
+
+  
+  # virtual void setConnector(OutPortConnector* connector);
+  def setConnector(self, connector):
+    self._connector = connector
+    return
+
+
+
+    
+  
+  # inline void onBufferRead(const cdrMemoryStream& data)
+  def onBufferRead(self, data):
+    if self._listeners and self._profile:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ].notify(self._profile, data)
+    return
+
+  
+  # inline void onSend(const cdrMemoryStream& data)
+  def onSend(self, data):
+    if self._listeners and self._profile:
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_SEND].notify(self._profile, data)
+    return
+
+  
+  # inline void onBufferEmpty()
+  def onBufferEmpty(self):
+    if self._listeners and self._profile:
+      self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_BUFFER_EMPTY].notify(self._profile)
+    return
+
+  
+  # inline void onBufferReadTimeout()
+  def onBufferReadTimeout(self):
+    if self._listeners and self._profile:
+      self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_BUFFER_READ_TIMEOUT].notify(self._profile)
+    return
+
+  
+  # inline void onSenderEmpty()
+  def onSenderEmpty(self):
+    if self._listeners and self._profile:
+      self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_EMPTY].notify(self._profile)
+    return
+
+  
+  # inline void onSenderTimeout()
+  def onSenderTimeout(self):
+    if self._listeners and self._profile:
+      self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_TIMEOUT].notify(self._profile)
+    return
+
+  
+  # inline void onSenderError()
+  def onSenderError(self):
+    if self._listeners and self._profile:
+      self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_ERROR].notify(self._profile)
+    return
+
+
+  
+
+
+def OutPortDirectProviderInit():
+  factory = OpenRTM_aist.OutPortProviderFactory.instance()
+  factory.addFactory("direct",
+                     OpenRTM_aist.OutPortDirectProvider,
+                     OpenRTM_aist.Delete)

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPullConnector.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPullConnector.py	2016-02-01 10:53:09 UTC (rev 649)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPullConnector.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -128,6 +128,13 @@
     self._listeners = listeners
     self._buffer = buffer
 
+    self._directInPort = None
+    self._inPortListeners = None
+    
+    self._directNewData = False
+    self._valueMutex = threading.RLock()
+    self._value = None
+
     if not self._buffer:
       self._buffer = self.createBuffer(info)
 
@@ -136,6 +143,7 @@
       raise
 
     self._buffer.init(info.properties.getNode("buffer"))
+    self._provider.init(info.properties)
     self._provider.setBuffer(self._buffer)
     self._provider.setConnector(self)
     self._provider.setListener(info, self._listeners)
@@ -180,6 +188,28 @@
   #
   # virtual ReturnCode write(const cdrMemoryStream& data);
   def write(self, data):
+    if self._directInPort is not None:
+      if self.isNew():
+        #self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE].notify(self._profile, data)
+        self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE].notify(self._profile, data)
+        #self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
+        self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
+        self._rtcout.RTC_TRACE("ONBUFFER_OVERWRITE(InPort,OutPort), ")
+        self._rtcout.RTC_TRACE("ON_RECEIVER_FULL(InPort,OutPort) ")
+        self._rtcout.RTC_TRACE("callback called in direct mode.")
+      #self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
+      self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
+      self._rtcout.RTC_TRACE("ON_BUFFER_WRITE(InPort,OutPort), ")
+      self._rtcout.RTC_TRACE("callback called in direct mode.")
+      guard = OpenRTM_aist.ScopedLock(self._valueMutex)
+      self._value = data
+      self._directNewData = True
+      del guard
+      #self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
+      self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
+      self._rtcout.RTC_TRACE("ON_RECEIVED(InPort,OutPort), ")
+      self._rtcout.RTC_TRACE("callback called in direct mode.")
+      return self.PORT_OK
     # data -> (conversion) -> CDR stream
     cdr_data = None
     if self._endian is not None:
@@ -221,6 +251,10 @@
       OpenRTM_aist.CdrBufferFactory.instance().deleteObject(self._buffer)
     self._buffer = 0
 
+    if self._directInPort:
+      self._directInPort.removeOutPortConnector(self)
+      self._directInPort = None
+
     return self.PORT_OK
 
 
@@ -317,3 +351,53 @@
     if self._listeners and self._profile:
       self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT].notify(self._profile)
     return
+
+
+  ##
+  # @if jp
+  # @brief データをダイレクトに書き込むためのInPortのサーバントを設定する
+  #
+  # @param self
+  # @param directInPort InPortのサーバント
+  # @return True: 設定に成功 False: 既に設定済みのため失敗
+  # @else
+  # @brief 
+  #
+  # @param self
+  # @param directInPort 
+  # @return 
+  # @endif
+  #
+  # bool setInPort(InPortBase* directInPort);
+  def setInPort(self, directInPort):
+    if self._directInPort is not None:
+      return False
+    self._directInPort = directInPort
+    self._inPortListeners = self._directInPort._listeners
+    self._directInPort.addOutPortConnector(self)
+    return True
+
+  ##
+  # @if jp
+  #
+  # @brief データをダイレクトに読み込む
+  #
+  # @param self
+  # @return 読み込むデータ
+  #
+  # @else
+  # @brief 
+  #
+  # @param self
+  # @param data 
+  # @endif
+  # void write(const DataType& data)
+  def read(self):
+    guard = OpenRTM_aist.ScopedLock(self._valueMutex)
+    data = self._value
+    self._directNewData = False
+    del guard
+    return data
+
+  def isNew(self):
+    return self._directNewData
\ No newline at end of file

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPushConnector.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPushConnector.py	2016-02-01 10:53:09 UTC (rev 649)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPushConnector.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -132,6 +132,9 @@
     self._consumer = consumer
     self._listeners = listeners
 
+    self._directInPort = None
+    self._inPortListeners = None
+
     # publisher/buffer creation. This may throw std::bad_alloc;
     self._publisher = self.createPublisher(info)
     if not self._buffer:
@@ -234,6 +237,25 @@
   def write(self, data):
     self._rtcout.RTC_TRACE("write()")
 
+    if self._directInPort is not None:
+      if self._directInPort.isNew():
+        self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE].notify(self._profile, data)
+        self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE].notify(self._profile, data)
+        self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
+        self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
+        self._rtcout.RTC_TRACE("ONBUFFER_OVERWRITE(InPort,OutPort), ")
+        self._rtcout.RTC_TRACE("ON_RECEIVER_FULL(InPort,OutPort) ")
+        self._rtcout.RTC_TRACE("callback called in direct mode.")
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
+      self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
+      self._rtcout.RTC_TRACE("ON_BUFFER_WRITE(InPort,OutPort), ")
+      self._rtcout.RTC_TRACE("callback called in direct mode.")
+      self._directInPort.write(data)
+      self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
+      self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
+      self._rtcout.RTC_TRACE("ON_RECEIVED(InPort,OutPort), ")
+      self._rtcout.RTC_TRACE("callback called in direct mode.")
+      return self.PORT_OK
     # data -> (conversion) -> CDR stream
     cdr_data = None
     if self._endian is not None:
@@ -426,3 +448,26 @@
     if self._listeners and self._profile:
       self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT].notify(self._profile)
     return
+
+  ##
+  # @if jp
+  # @brief データをダイレクトに書き込むためのInPortのサーバントを設定する
+  #
+  # @param self
+  # @param directInPort InPortのサーバント
+  # @return True: 設定に成功 False: 既に設定済みのため失敗
+  # @else
+  # @brief 
+  #
+  # @param self
+  # @param directInPort 
+  # @return 
+  # @endif
+  #
+  # bool setInPort(InPortBase* directInPort);
+  def setInPort(self, directInPort):
+    if self._directInPort is not None:
+      return False
+    self._directInPort = directInPort
+    self._inPortListeners = self._directInPort._listeners
+    return True
\ No newline at end of file

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py	2016-02-01 10:53:09 UTC (rev 649)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py	2016-02-01 11:11:54 UTC (rev 650)
@@ -100,4 +100,8 @@
 from PublisherNew import *
 from PublisherPeriodic import *
 from FactoryInit import *
+from InPortDirectConsumer import *
+from InPortDirectProvider import *
+from OutPortDirectConsumer import *
+from OutPortDirectProvider import *
 from CORBA_RTCUtil import *



More information about the openrtm-commit mailing list