[openrtm-commit:03101] r920 - trunk/OpenRTM-aist-Python/OpenRTM_aist
openrtm @ openrtm.org
openrtm @ openrtm.org
2018年 1月 23日 (火) 09:25:20 JST
Author: miyamoto
Date: 2018-01-23 09:25:20 +0900 (Tue, 23 Jan 2018)
New Revision: 920
Modified:
trunk/OpenRTM-aist-Python/OpenRTM_aist/InPort.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortBase.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortPullConnector.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPort.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
Log:
[incompat,->RELENG_1_2] refs #4429
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/InPort.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/InPort.py 2018-01-22 04:04:41 UTC (rev 919)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/InPort.py 2018-01-23 00:25:20 UTC (rev 920)
@@ -109,7 +109,6 @@
self._directNewData = False
self._valueMutex = threading.RLock()
- self._outPortConnectorList = []
def __del__(self, InPortBase=OpenRTM_aist.InPortBase):
@@ -307,16 +306,8 @@
del guard
- if len(self._outPortConnectorList) > 0:
- ret, data = self._outPortConnectorList[0].read()
-
- if ret:
- self._value = data
- if self._OnReadConvert is not None:
- self._value = self._OnReadConvert(self._value)
- self._rtcout.RTC_TRACE("OnReadConvert for direct data called")
- return self._value
+
if len(self._connectors) == 0:
self._rtcout.RTC_DEBUG("no connectors")
return self._value
@@ -426,40 +417,5 @@
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
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortBase.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortBase.py 2018-01-22 04:04:41 UTC (rev 919)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortBase.py 2018-01-23 00:25:20 UTC (rev 920)
@@ -1274,6 +1274,18 @@
elif consumer_ is not None:
self._rtcout.RTC_TRACE("InPortPullConnector created")
+ if OpenRTM_aist.StringUtil.normalize([prop.getProperty("interface_type")]) == "direct":
+ if consumer_ is not None:
+ outport = self.getLocalOutPort(profile)
+
+ if outport is None:
+ self._rtcout.RTC_TRACE("interface_type is direct, ")
+ self._rtcout.RTC_TRACE("but a peer OutPort servant could not be obtained.")
+ del connector
+ return None
+ connector.setOutPort(outport)
+
+
# guard = OpenRTM_aist.ScopedLock(self._connector_mutex)
self._connectors.append(connector)
self._rtcout.RTC_PARANOID("connector push backed: %d", len(self._connectors))
@@ -1284,3 +1296,35 @@
return None
+ ##
+ # @if jp
+ # @brief ¥í¡¼¥«¥ë¤Î¥Ô¥¢OutPort¤ò¼èÆÀ
+ # @param self
+ # @param profile ¥³¥Í¥¯¥¿¥×¥í¥Õ¥¡¥¤¥ë
+ # @return OutPort¤Î¥µ¡¼¥Ð¥ó¥È(¼èÆÀ¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¤ÏNone)
+ # @else
+ # @brief Getting local peer OutPort if available
+ # @param self
+ # @param profile
+ # @return
+ # @endif
+ #
+ # OutPortBase*
+ # getLocalOutPort(const ConnectorInfo& profile)
+ def getLocalOutPort(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()
+ outport = poa.reference_to_servant(obj)
+ self._rtcout.RTC_DEBUG("OutPortBase servant pointer is obtained.")
+ return outport
+ except:
+ self._rtcout.RTC_DEBUG("Peer port might be a remote port")
+ return None
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortPullConnector.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortPullConnector.py 2018-01-22 04:04:41 UTC (rev 919)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortPullConnector.py 2018-01-23 00:25:20 UTC (rev 920)
@@ -128,6 +128,8 @@
OpenRTM_aist.InPortConnector.__init__(self, info, buffer)
self._consumer = consumer
self._listeners = listeners
+ self._directOutPort = None
+ self._outPortListeners = None
if buffer == 0:
@@ -197,6 +199,32 @@
# virtual ReturnCode read(cdrMemoryStream& data);
def read(self, data):
self._rtcout.RTC_TRACE("InPortPullConnector.read()")
+
+ if self._directOutPort is not None:
+ if self._directOutPort.isEmpty():
+ self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_BUFFER_EMPTY].notify(self._profile)
+ self._outPortListeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_EMPTY].notify(self._profile)
+ self._rtcout.RTC_TRACE("ON_BUFFER_EMPTY(InPort,OutPort), ")
+ self._rtcout.RTC_TRACE("ON_SENDER_EMPTY(InPort,OutPort) ")
+ self._rtcout.RTC_TRACE("callback called in direct mode.")
+
+ self._directOutPort.read(data)
+ #self._outPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ].notify(self._profile, data[0])
+ self._rtcout.RTC_TRACE("ON_BUFFER_READ(OutPort), ")
+ self._rtcout.RTC_TRACE("callback called in direct mode.")
+ #self._outPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_SEND].notify(self._profile, data[0])
+ self._rtcout.RTC_TRACE("ON_SEND(OutPort), ")
+ self._rtcout.RTC_TRACE("callback called in direct mode.")
+ #self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data[0])
+ self._rtcout.RTC_TRACE("ON_RECEIVED(InPort), ")
+ self._rtcout.RTC_TRACE("callback called in direct mode.")
+ #self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_SEND].notify(self._profile, data[0])
+ self._rtcout.RTC_TRACE("ON_BUFFER_WRITE(InPort), ")
+ self._rtcout.RTC_TRACE("callback called in direct mode.")
+ return self.PORT_OK
+
+
+
if not self._consumer:
return self.PORT_ERROR
@@ -325,6 +353,29 @@
self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT].notify(self._profile)
return
-
+ ##
+ # @if jp
+ # @brief ¥Ç¡¼¥¿¤ò¥À¥¤¥ì¥¯¥È¤Ë½ñ¤¹þ¤à¤¿¤á¤ÎOutPort¤Î¥µ¡¼¥Ð¥ó¥È¤òÀßÄꤹ¤ë
+ #
+ # @param self
+ # @param directOutPort OutPort¤Î¥µ¡¼¥Ð¥ó¥È
+ # @return True: ÀßÄê¤ËÀ®¸ù False: ´û¤ËÀßÄêºÑ¤ß¤Î¤¿¤á¼ºÇÔ
+ # @else
+ # @brief
+ #
+ # @param self
+ # @param directOutPort
+ # @return
+ # @endif
+ #
+ # bool setOutPort(setOutPort* directOutPort);
+ def setOutPort(self, directOutPort):
+ if self._directOutPort is not None:
+ return False
+ self._directOutPort = directOutPort
+ self._outPortListeners = self._directOutPort._listeners
+ return True
+
+
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPort.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPort.py 2018-01-22 04:04:41 UTC (rev 919)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPort.py 2018-01-23 00:25:20 UTC (rev 920)
@@ -21,6 +21,7 @@
from omniORB import any
import OpenRTM_aist
+import threading
##
@@ -101,6 +102,8 @@
#self._OnUnderflow = None
#self._OnConnect = None
#self._OnDisconnect = None
+ self._directNewData = False
+ self._valueMutex = threading.RLock()
def __del__(self, OutPortBase=OpenRTM_aist.OutPortBase):
@@ -152,6 +155,7 @@
# @endif
# bool operator<<(DataType& value)
def write(self, value=None):
+ guard = OpenRTM_aist.ScopedLock(self._valueMutex)
if not value:
value=self._value
@@ -183,6 +187,7 @@
result = False
if ret == self.CONNECTION_LOST:
self.disconnect(con.id())
+ del guard
return result
@@ -288,7 +293,33 @@
return str(val.typecode().name())
+ ##
+ # @if jp
+ #
+ # @brief ¥Ç¡¼¥¿¤ò¥À¥¤¥ì¥¯¥È¤ËÆɤ߹þ¤à
+ #
+ # @param self
+ # @param data Æɤ߹þ¤à¥Ç¡¼¥¿
+ #
+ # @else
+ # @brief
+ #
+ # @param self
+ # @param data
+ # @endif
+ # void read(const DataType& data)
+ def read(self, data):
+ guard = OpenRTM_aist.ScopedLock(self._valueMutex)
+ self._directNewData = False
+ data[0] = self._value
+ if self._OnWriteConvert:
+ data[0] = self._OnWriteConvert(data[0])
+ del guard
+ def isEmpty(self):
+ return False
+
+
class subscribe:
def __init__(self, prof, subs = None):
if subs:
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortBase.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortBase.py 2018-01-22 04:04:41 UTC (rev 919)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortBase.py 2018-01-23 00:25:20 UTC (rev 920)
@@ -1290,20 +1290,23 @@
if OpenRTM_aist.StringUtil.normalize([prop.getProperty("interface_type")]) == "direct":
+ if consumer_ is not None:
+ inport = self.getLocalInPort(profile)
- 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
+ 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 None
- connector.setInPort(inport)
+ connector.setInPort(inport)
#if consumer_ is not None:
# connector.setInPort(inport)
#elif provider_ is not None:
# connector.setInPort(inport)
+ else:
+ connector.setDirectMode()
+
self._connectors.append(connector)
@@ -1313,7 +1316,7 @@
except:
self._rtcout.RTC_ERROR("Exeption: OutPortPushConnector creation failed")
self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
- return 0
+ return None
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPullConnector.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPullConnector.py 2018-01-22 04:04:41 UTC (rev 919)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPullConnector.py 2018-01-23 00:25:20 UTC (rev 920)
@@ -128,13 +128,9 @@
self._provider = provider
self._listeners = listeners
self._buffer = buffer
+ self._directMode = False
- 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)
@@ -189,14 +185,7 @@
#
# virtual ReturnCode write(const cdrMemoryStream& data);
def write(self, data):
- if self._directInPort is not None:
-
- guard = OpenRTM_aist.ScopedLock(self._valueMutex)
- self._value = data
- self._directNewData = True
-
- del guard
-
+ if self._directMode:
return self.PORT_OK
# data -> (conversion) -> CDR stream
cdr_data = None
@@ -242,10 +231,8 @@
OpenRTM_aist.CdrBufferFactory.instance().deleteObject(self._buffer)
self._buffer = 0
- if self._directInPort:
- self._directInPort.removeOutPortConnector(self)
- self._directInPort = None
+
return self.PORT_OK
@@ -343,77 +330,15 @@
self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT].notify(self._profile)
return
-
##
# @if jp
- # @brief ¥Ç¡¼¥¿¤ò¥À¥¤¥ì¥¯¥È¤Ë½ñ¤¹þ¤à¤¿¤á¤ÎInPort¤Î¥µ¡¼¥Ð¥ó¥È¤òÀßÄꤹ¤ë
- #
- # @param self
- # @param directInPort InPort¤Î¥µ¡¼¥Ð¥ó¥È
- # @return True: ÀßÄê¤ËÀ®¸ù False: ´û¤ËÀßÄêºÑ¤ß¤Î¤¿¤á¼ºÇÔ
+ # @brief ¥À¥¤¥ì¥¯¥ÈÀܳ¥â¡¼¥É¤ËÀßÄê
# @else
# @brief
- #
- # @param self
- # @param directInPort
- # @return
# @endif
- #
- # bool setPorts(InPortBase* directInPort, OutPortBase* outPort);
- 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
+ # void onDisconnect()
+ def setDirectMode(self):
+ self._directMode = True
+
- ##
- # @if jp
- #
- # @brief ¥Ç¡¼¥¿¤ò¥À¥¤¥ì¥¯¥È¤ËÆɤ߹þ¤à
- #
- # @param self
- # @return ȽÄê(¥Ç¡¼¥¿¤¬½ñ¤¹þ¤Þ¤ì¤Æ¤¤¤Ê¤±¤ì¤ÐTrue)¡¢Æɤ߹þ¤à¥Ç¡¼¥¿
- #
- # @else
- # @brief
- #
- # @param self
- # @param data
- # @endif
- # DataType* read()
- def read(self):
- guard = OpenRTM_aist.ScopedLock(self._valueMutex)
- if not self.isNew():
- self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_BUFFER_EMPTY].notify(self._profile)
- self._inPortListeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_EMPTY].notify(self._profile)
- self._rtcout.RTC_TRACE("ON_BUFFER_EMPTY(OutPort), ")
- self._rtcout.RTC_TRACE("ON_SENDER_EMPTY(InPort) ")
- self._rtcout.RTC_TRACE("callback called in direct mode.")
- return False, ""
-
- data = self._value
- ret = self._directNewData
- self._directNewData = False
- del guard
-
-
- self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ].notify(self._profile, data)
- self._rtcout.RTC_TRACE("ON_BUFFER_READ(OutPort), ")
- self._rtcout.RTC_TRACE("callback called in direct mode.")
- self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_SEND].notify(self._profile, data)
- self._rtcout.RTC_TRACE("ON_SEND(OutPort), ")
- self._rtcout.RTC_TRACE("callback called in direct mode.")
- self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
- self._rtcout.RTC_TRACE("ON_RECEIVED(InPort), ")
- self._rtcout.RTC_TRACE("callback called in direct mode.")
- self._inPortListeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
- self._rtcout.RTC_TRACE("ON_BUFFER_WRITE(InPort), ")
- self._rtcout.RTC_TRACE("callback called in direct mode.")
-
- return ret, 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 2018-01-22 04:04:41 UTC (rev 919)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortPushConnector.py 2018-01-23 00:25:20 UTC (rev 920)
@@ -239,20 +239,20 @@
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._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._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._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
More information about the openrtm-commit
mailing list