add conditional_request

This commit is contained in:
cxgeorge 2002-08-07 00:47:43 +00:00
parent 92330e53eb
commit 9a748df2d5

View File

@ -229,6 +229,45 @@ class FSM(DirectObject):
aStateName)) aStateName))
return 0 return 0
def conditional_request(self, aStateName, enterArgList=[], exitArgList=[]):
"""request(self, string)
Attempt transition from currentState to given one, if it exists.
Return true is transition exists to given state,
false otherwise. It is NOT an error/warning to attempt a cond_request
if the transition doesnt exist. This lets people be sloppy about
FSM transitions, letting the same fn be used for different states
that may not have the same out transitions.
"""
if not self.__currentState:
# Make this a warning for now
FSM.notify.warning("[%s]: request: never entered initial state" %
(self.__name))
self.__currentState = self.__initialState
if isinstance(aStateName, types.StringType):
aState = self.getStateNamed(aStateName)
else:
# Allow the caller to pass in a state in itself, not just
# the name of a state.
aState = aStateName
aStateName = aState.getName()
if aState == None:
FSM.notify.error("[%s]: request: %s, no such state" %
(self.__name, aStateName))
fulltransitionnameset = self.__currentState.getTransitions()
fulltransitionnameset.extend([self.__currentState.getName(),self.__finalState.getName()])
if (aStateName in fulltransitionnameset):
return self.request(aStateName, enterArgList, exitArgList)
else:
FSM.notify.debug("[%s]: condition_request: %s, transition doesnt exist" %
(self.__name, aStateName))
return 0
def view(self): def view(self):
import FSMInspector import FSMInspector
FSMInspector.FSMInspector(self) FSMInspector.FSMInspector(self)