[openrtm-commit:00768] r529 - branches/work/OpenRTM-aist-Python/OpenRTM_aist
openrtm @ openrtm.org
openrtm @ openrtm.org
2012年 3月 13日 (火) 17:04:22 JST
Author: kurihara
Date: 2012-03-13 17:04:22 +0900 (Tue, 13 Mar 2012)
New Revision: 529
Modified:
branches/work/OpenRTM-aist-Python/OpenRTM_aist/StateMachine.py
Log:
[incomaptible impl] worker() has been now divided into three functions: worker_pre(), worker_do(), worker_post(). refs #2320
Modified: branches/work/OpenRTM-aist-Python/OpenRTM_aist/StateMachine.py
===================================================================
--- branches/work/OpenRTM-aist-Python/OpenRTM_aist/StateMachine.py 2012-03-13 07:58:55 UTC (rev 528)
+++ branches/work/OpenRTM-aist-Python/OpenRTM_aist/StateMachine.py 2012-03-13 08:04:22 UTC (rev 529)
@@ -154,6 +154,7 @@
# @endif
def __init__(self, num_of_state):
self._num = num_of_state
+ self._listener = None
self._entry = {}
self._predo = {}
self._do = {}
@@ -166,6 +167,7 @@
self.setNullFunc(self._predo, None)
self.setNullFunc(self._postdo, None)
self._transit = None
+ self._selftrans = False
self._mutex = threading.RLock()
@@ -203,7 +205,9 @@
# @brief Set Listener Object
# @endif
def setListener(self, listener):
+ assert(listener)
self._listener = listener
+ return
##
@@ -225,7 +229,7 @@
if self._entry.has_key(state):
self._entry[state] = call_back
else:
- self._entry.setdefault(state, call_back)
+ return False
return True
@@ -248,7 +252,7 @@
if self._predo.has_key(state):
self._predo[state] = call_back
else:
- self._predo.setdefault(state, call_back)
+ return False
return True
@@ -271,7 +275,7 @@
if self._do.has_key(state):
self._do[state] = call_back
else:
- self._do.setdefault(state, call_back)
+ return False
return True
@@ -294,7 +298,7 @@
if self._postdo.has_key(state):
self._postdo[state] = call_back
else:
- self._postdo.setdefault(state, call_back)
+ return False
return True
@@ -317,7 +321,7 @@
if self._exit.has_key(state):
self._exit[state] = call_back
else:
- self._exit.setdefault(state, call_back)
+ return False
return True
@@ -438,6 +442,9 @@
def goTo(self, state):
guard = OpenRTM_aist.ScopedLock(self._mutex)
self._states.next = state
+ if self._states.curr == state:
+ self._selftrans = True
+ return
##
@@ -461,22 +468,26 @@
# pre-do
if self._predo[states.curr]:
self._predo[states.curr](states)
+
if self.need_trans():
return
# do
if self._do[states.curr]:
self._do[states.curr](states)
+
if self.need_trans():
return
# post-do
if self._postdo[states.curr]:
self._postdo[states.curr](states)
+
# If state transition required, exit current state and enter next state
else:
if self._exit[states.curr]:
self._exit[states.curr](states)
+
self.sync(states)
# If state transition still required, move to the next state
@@ -486,7 +497,52 @@
self._entry[states.curr](states)
self.update_curr(states.curr)
+ return
+
+ # void worker_pre()
+ def worker_pre(self):
+ state = StateHolder()
+ self.sync(state)
+ if state.curr == state.next:
+ if self._predo[state.curr]:
+ self._predo[state.curr](state)
+ return
+
+ # State changed
+ if self._exit[state.curr]:
+ self._exit[state.curr](state)
+
+ self.sync(state)
+ if state.curr != state.next:
+ state.curr = state.next
+ if self._entry[state.curr]:
+ self._entry[state.curr](state)
+ self.update_curr(state.curr)
+
+ return
+
+ # void worker_do()
+ def worker_do(self):
+ state = StateHolder()
+ self.sync(state)
+
+ if self._do[state.curr]:
+ self._do[state.curr](state)
+
+ return
+
+
+ # void worker_post()
+ def worker_post(self):
+ state = StateHolder()
+ self.sync(state)
+ if self._postdo[state.curr]:
+ self._postdo[state.curr](state)
+
+ return
+
+
##
# @if jp
# @brief NOP関数を設定
@@ -506,6 +562,7 @@
s[StateMachine.state_array[i]] = nullfunc
else:
s.setdefault(StateMachine.state_array[i], nullfunc)
+ return
##
openrtm-commit メーリングリストの案内