rad  5.1.0
Public Member Functions | Public Attributes | List of all members
scxml4py.executor.Executor Class Reference

Public Member Functions

def __init__ (self, theStateMachine, theContext, externalEventQueue=None, internalEventQueue=None)
 
def getStatus (self)
 
def getModel (self)
 
def getContext (self)
 
def getEventHandlingPolicy (self)
 
def isRunning (self)
 
def isFinal (self)
 
def isEventProcessable (self, e)
 Check wheter an event enables transitions or not. More...
 
def start (self)
 First perform in-place expansions of states by including SCXML source referenced by URLs (see 3.13 Referencing External Files) and change initial attributes to initial container children with empty transitions to the state from the attribute. More...
 
def stop (self)
 
def postEvent (self, theEvent)
 
def processEvent (self, theEvent)
 
def processEvents (self)
 
def processInternalEvents (self)
 
def exitInterpreter (self)
 The purpose of this procedure is to exit the current SCXML process by exiting all active states. More...
 
def selectEventlessTransitions (self)
 This function selects all transitions that are enabled in the current configuration that do not require an event trigger. More...
 
def selectTransitions (self, e)
 The purpose of the selectTransitions() procedure is to collect the transitions that are enabled by this event in the current configuration. More...
 
def microstep (self, enabledTransitions)
 The purpose of the microStep procedure is to process the set of transitions enabled by an external event, an internal event, or by the presence or absence of certain values in the dataModel at the current point in time. More...
 
def exitStates (self, enabledTransitions)
 Create an empty statesToExit set. More...
 
def executeTransitionContent (self, enabledTransitions)
 
def enterStates (self, enabledTransitions)
 
def addStatesToEnter (self, s, root, statesToEnter, statesForDefaultEntry)
 
def setModel (self, theStateMachine)
 
def setContext (self, theContext)
 
def setEventHandlingPolicy (self, policy)
 
def addEventListener (self, eventListener)
 
def removeEventListener (self, eventListener)
 
def removeAllEventListener (self)
 
def notifyEventListeners (self, theEvent)
 
def addStatusListener (self, statusListener)
 
def removeStatusListener (self, statusListener)
 
def removeAllStatusListener (self)
 
def notifyStatusListeners (self, theStatus)
 

Public Attributes

 mStateMachine
 
 mContext
 
 mEventHandlingPolicy
 
 mEventListeners
 
 mStatusListeners
 
 mCurrentStatus
 
 mPreviousStatus
 
 mStatesToInvoke
 
 mInternalEvents
 
 mExternalEvents
 
 mContinue
 
 mFinal
 

Constructor & Destructor Documentation

◆ __init__()

def scxml4py.executor.Executor.__init__ (   self,
  theStateMachine,
  theContext,
  externalEventQueue = None,
  internalEventQueue = None 
)

Member Function Documentation

◆ addEventListener()

def scxml4py.executor.Executor.addEventListener (   self,
  eventListener 
)

◆ addStatesToEnter()

def scxml4py.executor.Executor.addStatesToEnter (   self,
  s,
  root,
  statesToEnter,
  statesForDefaultEntry 
)

◆ addStatusListener()

def scxml4py.executor.Executor.addStatusListener (   self,
  statusListener 
)

◆ enterStates()

def scxml4py.executor.Executor.enterStates (   self,
  enabledTransitions 
)

◆ executeTransitionContent()

def scxml4py.executor.Executor.executeTransitionContent (   self,
  enabledTransitions 
)

◆ exitInterpreter()

def scxml4py.executor.Executor.exitInterpreter (   self)

The purpose of this procedure is to exit the current SCXML process by exiting all active states.

If the machine is in a top-level final state, a Done event is generated.

◆ exitStates()

def scxml4py.executor.Executor.exitStates (   self,
  enabledTransitions 
)

Create an empty statesToExit set.

   For each transition t in enabledTransitions, if t is targetLess then do nothing,
   else let LCA be the least common ancestor state of the source state and target states of t.
   Add to the statesToExit set all states in the configuration that are descendants of LCA.
   Convert the statesToExit set to a list and sort it in exitOrder.

   For each state s in the list, if s has a deep history state h, set the history value
   of h to be the list of all atomic descendants of s that are members in the current
   configuration, else set its value to be the list of all immediate children of s that
   are members of the current configuration.

   Again for each state s in the list, first execute any onExit handlers, then cancel any
   ongoing invocations, and finally remove s from the current configuration.

   procedure exitStates(enabledTransitions):
       statesToExit = new Set()
       for t in enabledTransitions:
          if (t.attribute('target') != null):
LCA = findLCA([t.parent()].append(getTargetStates(t)))

for s in configuration.toList(): if (isDescendant(s,LCA)):

statesToExit.add(s)
statesToExit = statesToExit.toList().sort(exitOrder)

for s in statesToExit: for h in s.history: f = (h.attribute('type') == "deep") ? lambda isAtomicState(s0) && isDescendant(s0,s) : lambda s0.parent() == s

historyValue[h.attribute('id')] = configuration.toList().filter(f)

for s in statesToExit: for content in s.onexit:

executeContent(content)

for inv in s.invoke: cancelInvoke(inv)

configuration.delete(s)

◆ getContext()

def scxml4py.executor.Executor.getContext (   self)

◆ getEventHandlingPolicy()

def scxml4py.executor.Executor.getEventHandlingPolicy (   self)

◆ getModel()

def scxml4py.executor.Executor.getModel (   self)

◆ getStatus()

def scxml4py.executor.Executor.getStatus (   self)

◆ isEventProcessable()

def scxml4py.executor.Executor.isEventProcessable (   self,
  e 
)

Check wheter an event enables transitions or not.

This method can be used to implement event processing policy such as:

  • SILENT simply ignore the event
  • REJECT return an error message
  • DEFERRED leave the event in the queue until it can be process

◆ isFinal()

def scxml4py.executor.Executor.isFinal (   self)

◆ isRunning()

def scxml4py.executor.Executor.isRunning (   self)

◆ microstep()

def scxml4py.executor.Executor.microstep (   self,
  enabledTransitions 
)

The purpose of the microStep procedure is to process the set of transitions enabled by an external event, an internal event, or by the presence or absence of certain values in the dataModel at the current point in time.

The processing of the enabled transitions must be done in parallel ('lock step') in the sense that their source states must first be exited, then their actions must be executed, and finally their target states entered.

◆ notifyEventListeners()

def scxml4py.executor.Executor.notifyEventListeners (   self,
  theEvent 
)

◆ notifyStatusListeners()

def scxml4py.executor.Executor.notifyStatusListeners (   self,
  theStatus 
)

◆ postEvent()

def scxml4py.executor.Executor.postEvent (   self,
  theEvent 
)

◆ processEvent()

def scxml4py.executor.Executor.processEvent (   self,
  theEvent 
)

◆ processEvents()

def scxml4py.executor.Executor.processEvents (   self)
  • This loop runs until we enter a top-level final state or an external
    • entity cancels processing.
    • In either case 'continue' will be set to false (see EnterStates, below,
    • for termination by entering
    • a top-level final state.)
    • Each iteration through the loop consists of three main steps:
    • 1) execute any <invoke> tags for atomic states that we entered on the
    • last iteration through the loop
    • 2) Wait for an external event and then execute any transitions that it triggers
    • 3) Take any subsequent internally enabled transitions, namely those that
    • don't require an event or that
    • are triggered by an internal event.
    • This event loop thus enforces run-to-completion semantics, in which the
    • system process an external event and then takes all the 'follow-up'
    • transitions that the processing has enabled before looking for another
    • external event.
    • For example, suppose that the external event queue contains events e1 and
    • e2 and the machine is in state s1. If processing e1 takes the machine to
    • s2 and generates internal event e3, and s2 contains a transition t triggered
    • by e3, the system is guaranteed to take t, no matter what transitions
    • s2 or other states have that would be triggered by e2. Note that this is
    • true even though e2 was already in the external event queue when e3 was
    • generated. In effect, the algorithm treats the processing of e3 as
    • finishing up the processing of e1. */

      replaced while loop with processEvent method which has to be called by the client every time there is an external event. This allows the client to implement the event loop

◆ processInternalEvents()

def scxml4py.executor.Executor.processInternalEvents (   self)

◆ removeAllEventListener()

def scxml4py.executor.Executor.removeAllEventListener (   self)

◆ removeAllStatusListener()

def scxml4py.executor.Executor.removeAllStatusListener (   self)

◆ removeEventListener()

def scxml4py.executor.Executor.removeEventListener (   self,
  eventListener 
)

◆ removeStatusListener()

def scxml4py.executor.Executor.removeStatusListener (   self,
  statusListener 
)

◆ selectEventlessTransitions()

def scxml4py.executor.Executor.selectEventlessTransitions (   self)

This function selects all transitions that are enabled in the current configuration that do not require an event trigger.

First test if the state has been preempted by a transition that has already been selected and that will cause the state to be exited when the transition is taken. If the state has not been preempted, find a transition with no 'event' attribute whose condition evaluates to true. If multiple matching transitions are present, take the first in document order. If none are present, search in the state's ancestors in ancestory order until one is found. As soon as such a transition is found, add it to enabledTransitions, and proceed to the next atomic state in the configuration. If no such transition is found in the state or its ancestors, proceed to the next state in the configuration. When all atomic states have been visited and transitions selected, return the set of enabled transitions.

◆ selectTransitions()

def scxml4py.executor.Executor.selectTransitions (   self,
  e 
)

The purpose of the selectTransitions() procedure is to collect the transitions that are enabled by this event in the current configuration.

Create an empty set of enabledTransitions. For each atomic state in the configuration, first check if the event is the result of an <invoke> in this state. If so, apply any <finalize> code in the state. Next test if the state has been preempted by a transition that has already been selected and that will cause the state to be exited when the transition is taken. If the state has not been preempted, find a transition whose 'event' attribute matches event and whose condition evaluates to true. If multiple matching transitions are present, take the first in document order. If none are present, search in the state's ancestors in ancestory order until one is found. As soon as such a transition is found, add it to enabledTransitions, and proceed to the next atomic state in the configuration. If no such transition is found in the state or its ancestors, proceed to the next state in the configuration. When all atomic states have been visited and transitions selected, return the set of enabled transitions.

◆ setContext()

def scxml4py.executor.Executor.setContext (   self,
  theContext 
)

◆ setEventHandlingPolicy()

def scxml4py.executor.Executor.setEventHandlingPolicy (   self,
  policy 
)

◆ setModel()

def scxml4py.executor.Executor.setModel (   self,
  theStateMachine 
)

◆ start()

def scxml4py.executor.Executor.start (   self)

First perform in-place expansions of states by including SCXML source referenced by URLs (see 3.13 Referencing External Files) and change initial attributes to initial container children with empty transitions to the state from the attribute.

@TODO

expandScxmlSource(doc)

Then (optionally) validate the resulting SCXML, and throw an exception if validation fails. @TODO if !(valid(doc)) {fail with error}

◆ stop()

def scxml4py.executor.Executor.stop (   self)

Member Data Documentation

◆ mContext

scxml4py.executor.Executor.mContext

◆ mContinue

scxml4py.executor.Executor.mContinue

◆ mCurrentStatus

scxml4py.executor.Executor.mCurrentStatus

◆ mEventHandlingPolicy

scxml4py.executor.Executor.mEventHandlingPolicy

◆ mEventListeners

scxml4py.executor.Executor.mEventListeners

◆ mExternalEvents

scxml4py.executor.Executor.mExternalEvents

◆ mFinal

scxml4py.executor.Executor.mFinal

◆ mInternalEvents

scxml4py.executor.Executor.mInternalEvents

◆ mPreviousStatus

scxml4py.executor.Executor.mPreviousStatus

◆ mStateMachine

scxml4py.executor.Executor.mStateMachine

◆ mStatesToInvoke

scxml4py.executor.Executor.mStatesToInvoke

◆ mStatusListeners

scxml4py.executor.Executor.mStatusListeners

The documentation for this class was generated from the following file: