[openrtm-commit:00345] r453 - branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist
openrtm @ openrtm.org
openrtm @ openrtm.org
2011年 8月 11日 (木) 18:41:06 JST
Author: kurihara
Date: 2011-08-11 18:41:06 +0900 (Thu, 11 Aug 2011)
New Revision: 453
Modified:
branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/PortConnectListener.py
Log:
PortConnectListenerHolder and PortConnectRetListenerHolder have been implemented.
Modified: branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/PortConnectListener.py
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/PortConnectListener.py 2011-08-11 09:39:06 UTC (rev 452)
+++ branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/PortConnectListener.py 2011-08-11 09:41:06 UTC (rev 453)
@@ -13,7 +13,43 @@
# Advanced Industrial Science and Technology (AIST), Japan
# All rights reserved.
+import threading
+class Lock:
+ """
+ """
+
+ ##
+ # @if jp
+ # @brief コンストラクタ
+ #
+ # コンストラクタ
+ #
+ # @param self
+ # @param mutex ロック用ミューテックス
+ #
+ # @else
+ #
+ # @endif
+ def __init__(self, mutex):
+ self.mutex = mutex
+ self.mutex.acquire()
+
+
+ ##
+ # @if jp
+ # @brief デストラクタ
+ #
+ # デストラクタ
+ #
+ # @param self
+ #
+ # @else
+ #
+ # @endif
+ def __del__(self):
+ self.mutex.release()
+
#============================================================
##
@@ -315,6 +351,7 @@
# @endif
def __init__(self):
self._listeners = []
+ self._mutex = threading.RLock()
return
@@ -325,7 +362,12 @@
# @brief Destructor
# @endif
def __del__(self):
- pass
+ guard = Lock(self._mutex)
+ for listener in self._listeners:
+ if listener.listener:
+ listener.listener = None
+ del guard
+ return
##
@@ -350,6 +392,9 @@
# @endif
#void addListener(PortConnectListener* listener, bool autoclean);
def addListener(self, listener, autoclean):
+ guard = Lock(self._mutex)
+ self._listeners.append(Entry(listener, autoclean))
+ del guard
return
@@ -371,6 +416,15 @@
# @endif
#void removeListener(PortConnectListener* listener);
def removeListener(self, listener):
+ guard = Lock(self._mutex)
+ len_ = len(self._listeners)
+ for i in range(len_):
+ if (self._listeners[i].listener == listener) and self._listeners[i].autoclean:
+ self._listeners[i].listener = None
+ del self._listeners[i]
+ del guard
+ return
+ del guard
return
@@ -392,10 +446,13 @@
# @endif
#void notify(const char* portname, RTC::ConnectorProfile& profile);
def notify(self, portname, profile):
- pass
+ guard = Lock(self._mutex)
+ for listener in self._listeners:
+ listener.listener(portname, profile)
+ del guard
+ return
-
##
# @if jp
# @class PortConnectRetListenerHolder
@@ -424,6 +481,7 @@
#PortConnectRetListenerHolder();
def __init__(self):
self._listeners = []
+ self._mutex = threading.RLock()
return
@@ -434,8 +492,14 @@
# @brief Destructor
# @endif
def __del__(self):
- pass
+ guard = Lock(self._mutex)
+ for listener in self._listeners:
+ if listener.listener:
+ listener.listener = None
+ del guard
+ return
+
##
# @if jp
@@ -459,6 +523,9 @@
# @endif
#void addListener(PortConnectRetListener* listener, bool autoclean);
def addListener(self, listener, autoclean):
+ guard = Lock(self._mutex)
+ self._listeners.append(Entry(listener, autoclean))
+ del guard
return
@@ -480,6 +547,15 @@
# @endif
#void removeListener(PortConnectRetListener* listener);
def removeListener(self, listener):
+ guard = Lock(self._mutex)
+ len_ = len(self._listeners)
+ for i in range(len_):
+ if (self._listeners[i].listener == listener) and self._listeners[i].autoclean:
+ self._listeners[i].listener = None
+ del self._listeners[i]
+ del guard
+ return
+ del guard
return
@@ -504,6 +580,10 @@
#void notify(const char* portname, RTC::ConnectorProfile& profile,
# ReturnCode_t ret);
def notify(self, portname, profile, ret):
+ guard = Lock(self._mutex)
+ for listener in self._listeners:
+ listener.listener(portname, profile, ret)
+ del guard
return
openrtm-commit メーリングリストの案内