[openrtm-commit:02848] r875 - branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist

openrtm @ openrtm.org openrtm @ openrtm.org
2017年 9月 29日 (金) 15:01:19 JST


Author: miyamoto
Date: 2017-09-29 15:01:19 +0900 (Fri, 29 Sep 2017)
New Revision: 875

Modified:
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort_pyfsm.py
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py
Log:
[incompat,2.0,FSM4RTC] bug fix.

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py	2017-09-29 05:59:45 UTC (rev 874)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py	2017-09-29 06:01:19 UTC (rev 875)
@@ -17,16 +17,25 @@
 import OpenRTM_aist.Macho
 
 
+
+    
+
+
 class EventBinder0(OpenRTM_aist.ConnectorDataListener):
-  def __init__(self, fsm, event_name, handler):
+  def __init__(self, fsm, event_name, handler, ptask=False):
     self._fsm = fsm
     self._eventName = event_name
     self._handler = handler
+    self._ptask = ptask
   def __del__(self):
     pass
   def __call__(self, info, data):
     if info.properties.getProperty("fsm_event_name") == self._eventName or info.name == self._eventName:
-      self._fsm.dispatch(OpenRTM_aist.Macho.Event(self._handler))
+      if not self._ptask:
+        self._fsm.dispatch(OpenRTM_aist.Macho.Event(self._handler))
+      else:
+        task = OpenRTM_aist.Async_tInvoker(self._fsm, OpenRTM_aist.Macho.Machine.dispatch, OpenRTM_aist.Macho.Event(self._handler))
+        task.invoke()
       return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
     return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
 
@@ -33,11 +42,12 @@
     
 
 class EventBinder1(OpenRTM_aist.ConnectorDataListenerT):
-  def __init__(self, fsm, event_name, handler, data_type):
+  def __init__(self, fsm, event_name, handler, data_type, ptask=False):
     self._fsm = fsm
     self._eventName = event_name
     self._handler = handler
     self._data_type = data_type
+    self._ptask = ptask
   def __del__(self):
     pass
   def __call__(self, info, data):
@@ -44,7 +54,11 @@
     data_ = OpenRTM_aist.ConnectorDataListenerT.__call__(self, info, data, self._data_type)
     
     if info.properties.getProperty("fsm_event_name") == self._eventName or info.name == self._eventName:
-      self._fsm.dispatch(OpenRTM_aist.Macho.Event(self._handler, data_))
+      if not self._ptask:
+        self._fsm.dispatch(OpenRTM_aist.Macho.Event(self._handler, data_))
+      else:
+        task = OpenRTM_aist.Async_tInvoker(self._fsm, OpenRTM_aist.Macho.Machine.dispatch, OpenRTM_aist.Macho.Event(self._handler, data_))
+        task.invoke()
       return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
     return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
 
@@ -196,13 +210,13 @@
   def name(self):
     return self._name
 
-  def bindEvent0(self, name, handler):
+  def bindEvent0(self, name, handler, ptask=False):
     self.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
-                                  EventBinder0(self._fsm, name, handler))
+                                  EventBinder0(self._fsm, name, handler, ptask))
     
-  def bindEvent1(self, name, handler, data_type):
+  def bindEvent1(self, name, handler, data_type, ptask=False):
     self.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
-                                  EventBinder1(self._fsm, name, handler, data_type))
+                                  EventBinder1(self._fsm, name, handler, data_type, ptask))
   
 
 

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort_pyfsm.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort_pyfsm.py	2017-09-29 05:59:45 UTC (rev 874)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort_pyfsm.py	2017-09-29 06:01:19 UTC (rev 875)
@@ -19,15 +19,20 @@
 
 
 class EventBinder0(OpenRTM_aist.ConnectorDataListener):
-  def __init__(self, fsm, event_name, handler):
+  def __init__(self, fsm, event_name, handler, ptask=False):
     self._fsm = fsm
     self._eventName = event_name
     self._handler = handler
+    self._ptask = ptask
   def __del__(self):
     pass
   def __call__(self, info, data):
     if info.properties.getProperty("fsm_event_name") == self._eventName or info.name == self._eventName:
-      self._fsm.dispatch(pyfsm.Event(self._handler))
+      if not self._ptask:
+        self._fsm.dispatch(pyfsm.Event(self._handler))
+      else:
+        task = OpenRTM_aist.Async_tInvoker(self._fsm, pyfsm.Machine.dispatch, pyfsm.Event(self._handler))
+        task.invoke()
       return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
     return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
 
@@ -34,11 +39,12 @@
     
 
 class EventBinder1(OpenRTM_aist.ConnectorDataListenerT):
-  def __init__(self, fsm, event_name, handler, data_type):
+  def __init__(self, fsm, event_name, handler, data_type, ptask=False):
     self._fsm = fsm
     self._eventName = event_name
     self._handler = handler
     self._data_type = data_type
+    self._ptask = ptask
   def __del__(self):
     pass
   def __call__(self, info, data):
@@ -45,7 +51,11 @@
     data_ = OpenRTM_aist.ConnectorDataListenerT.__call__(self, info, data, self._data_type)
     
     if info.properties.getProperty("fsm_event_name") == self._eventName or info.name == self._eventName:
-      self._fsm.dispatch(pyfsm.Event(self._handler, data_))
+      if not self._ptask:
+        self._fsm.dispatch(pyfsm.Event(self._handler, data_))
+      else:
+        task = OpenRTM_aist.Async_tInvoker(self._fsm, pyfsm.Machine.dispatch, pyfsm.Event(self._handler, data_))
+        task.invoke()
       return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
     return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
 
@@ -197,13 +207,13 @@
   def name(self):
     return self._name
 
-  def bindEvent0(self, name, handler):
+  def bindEvent0(self, name, handler, ptask=False):
     self.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
-                                  EventBinder0(self._fsm, name, handler))
+                                  EventBinder0(self._fsm, name, handler, ptask))
     
-  def bindEvent1(self, name, handler, data_type):
+  def bindEvent1(self, name, handler, data_type, ptask=False):
     self.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
-                                  EventBinder1(self._fsm, name, handler, data_type))
+                                  EventBinder1(self._fsm, name, handler, data_type, ptask))
   
 
 

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py	2017-09-29 05:59:45 UTC (rev 874)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py	2017-09-29 06:01:19 UTC (rev 875)
@@ -18,6 +18,8 @@
 import types
 import OpenRTM_aist
 
+import threading
+
 class _EmptyBox:
   def __init__(self):
     pass
@@ -237,6 +239,11 @@
   def _saveHistory(self,instance,shallow,deep):
     self._setHistorySuper(instance,deep)
   def __getitem__(self, class_):
+    if isinstance(class_, str):
+      if self.__class__.__name__ == class_:
+        return self
+    elif type(self) == class_:
+      return self
     obj = self
     while hasattr(obj, "super_obj"):
       obj = obj.super_obj
@@ -925,9 +932,11 @@
     self.TOP = TOP
     self.TopBase = TOP.SUPER(TOP._state_name)
     self.init(box=None, initial_state=initial_state, args=args)
+    self._mutex = threading.RLock()
   def __del__(self):
     pass
   def shutdown(self):
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
     self.myCurrentState.shutdown()
     self.free(Machine.theStateCount)
     Machine.theStateCount = 1
@@ -964,6 +973,7 @@
   def __call__(self):
     return AfterAdvice(self)
   def dispatch(self, event, destroy=True):
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
     event.dispatch(self.myCurrentState)
     if destroy:
       del event



More information about the openrtm-commit mailing list