North State Framework in C#  V3.0.0
An object-oriented framework for implementing UML state machines.
Public Member Functions | Public Attributes | Protected Member Functions | Properties | List of all members
NSFStateMachine Class Reference

Represents a state machine. More...

Inheritance diagram for NSFStateMachine:
NSFCompositeState INSFEventHandler NSFState INSFNamedObject NSFTaggedObject NSFUniquelyNumberedObject INSFNamedObject

Public Member Functions

 NSFStateMachine (NSFString name, NSFEventThread thread)
 Creates a state machine More...
 
 NSFStateMachine (NSFString name, NSFRegion parentRegion)
 Creates a state machine. More...
 
 NSFStateMachine (NSFString name, NSFCompositeState parentState)
 Creates a state machine. More...
 
bool Never (NSFStateMachineContext context)
 Provides a syntactical method for specifying "Never" as a transition guard, effectively blocking the transition from ever occuring. More...
 
void forceStateMachineEvaluation ()
 Forces the state machine to evaluate transitions. More...
 
NSFEventStatus handleEvent (NSFEvent nsfEvent)
 Handles an event. More...
 
void queueEvent (NSFEvent nsfEvent)
 Queues an event for the handler. More...
 
void queueEvent (NSFEvent nsfEvent, INSFNamedObject source)
 Queues an event for the handler. More...
 
void resetStateMachine ()
 Resets the state machine back to its initial default state. More...
 
void startEventHandler ()
 Starts event processing. More...
 
void stopEventHandler ()
 Stops event processing. More...
 
void startStateMachine ()
 
void stopStateMachine ()
 
void terminate (bool waitForTerminated)
 Terminates the event handler, so that it can be garbage collected. More...
 
- Public Member Functions inherited from NSFCompositeState
 NSFCompositeState (NSFString name, NSFRegion parentRegion, NSFVoidAction< NSFStateMachineContext > entryAction, NSFVoidAction< NSFStateMachineContext > exitAction)
 Creates a composite state. More...
 
 NSFCompositeState (NSFString name, NSFCompositeState parentState, NSFVoidAction< NSFStateMachineContext > entryAction, NSFVoidAction< NSFStateMachineContext > exitAction)
 Creates a composite state. More...
 
override bool isInState (NSFState state)
 Indicates if the specified state is active, i.e. is "in" the specified state. More...
 
override bool isInState (NSFString stateName)
 Indicates if the specified state is active, i.e. is "in" the specified state. More...
 
- Public Member Functions inherited from NSFState
 NSFState (NSFString name, NSFRegion parentRegion, NSFVoidAction< NSFStateMachineContext > entryAction, NSFVoidAction< NSFStateMachineContext > exitAction)
 Creates a state. More...
 
 NSFState (NSFString name, NSFCompositeState parentState, NSFVoidAction< NSFStateMachineContext > entryAction, NSFVoidAction< NSFStateMachineContext > exitAction)
 Creates a state. More...
 
bool isActive ()
 Indicates if the state is currently active. More...
 
- Public Member Functions inherited from NSFTaggedObject
 NSFTaggedObject (NSFString name)
 Creates an object with a unique id and a name. More...
 
- Public Member Functions inherited from NSFUniquelyNumberedObject
 NSFUniquelyNumberedObject ()
 Creates a uniquely numbered object. More...
 
bool isSameObject (NSFUniquelyNumberedObject other)
 Checks if this object is the same as another object. More...
 

Public Attributes

NSFVoidActions
< NSFExceptionContext
ExceptionActions = new NSFVoidActions<NSFExceptionContext>()
 Actions to execute if an exception is encountered by the state machine. More...
 
NSFVoidActions
< NSFStateMachineContext
StateChangeActions = new NSFVoidActions<NSFStateMachineContext>()
 Actions to execute whenever a new state is entered. More...
 
NSFVoidActions
< NSFStateMachineContext
ConsecutiveLoopLimitActions = new NSFVoidActions<NSFStateMachineContext>()
 Actions to execute if consecutive loop limit is reached. More...
 
NSFVoidActions
< NSFStateMachineContext
EventLimitActions = new NSFVoidActions<NSFStateMachineContext>()
 Actions to execute if consecutive loop limit is reached. More...
 
- Public Attributes inherited from NSFState
NSFVoidActions
< NSFStateMachineContext
EntryActions = new NSFVoidActions<NSFStateMachineContext>()
 Actions to be executed whenever the state is entered. More...
 
NSFVoidActions
< NSFStateMachineContext
ExitActions = new NSFVoidActions<NSFStateMachineContext>()
 Actions to be executed whenever the state is exited. More...
 

Protected Member Functions

bool hasEvent (NSFEvent nsfEvent)
 Checks if an event is queued for processing. More...
 
bool isTopStateMachine ()
 Checks if the state machine is the top state machine in a nested heirarchy. More...
 
void rerouteTransition (NSFTransition transition, NSFState source, NSFState target)
 Re-routes a transition between a specified source and destination More...
 

Properties

bool ConsecutiveLoopDetectionEnabled [get, set]
 Gets or sets the flag indicating if consecutive loop detection is enabled. More...
 
int ConsecutiveLoopLimit [get, set]
 Gets or sets the maximum number of transitions without a pause allowed by consecutive loop detection. More...
 
bool EventLimitDetectionEnabled [get, set]
 Gets or sets the flag indicating if event limit detection is enabled. More...
 
int EventLimit [get, set]
 Gets or sets the maximum number of transitions without a pause allowed by consecutive loop detection. More...
 
NSFBoolGuard
< NSFStateMachineContext
Else [get]
 Provides a syntactical method for specifying "Else" as a transition guard. More...
 
NSFEventThread EventThread [get, set]
 Gets or sets the state machine's event thread. More...
 
Int32 QueuedEvents [get, set]
 Gets or sets the number of events currently queued in state machine's event thread. More...
 
bool LoggingEnabled [get, set]
 Gets or sets the flag indicating if state machine event logging is enabled. More...
 
NSFEventHandlerRunStatus RunStatus [get, set]
 
NSFEventHandlerTerminationStatus TerminationStatus [get, set]
 
static uint TerminationSleepTime [get, set]
 Gets the amount of time (mS) the terminate method sleeps between checks for state machine termination. More...
 
static int TerminationTimeout [get, set]
 The amount of time the terminate method will wait for event processing to complete. More...
 
override NSFStateMachine TopStateMachine [get]
 
- Properties inherited from NSFState
bool LogEntry [get, set]
 Gets or sets the flag indicating if trace logging is enabled or disabled for the state. More...
 
virtual NSFStateMachine TopStateMachine [get]
 Gets the top state machine encompassing the state. More...
 
- Properties inherited from NSFTaggedObject
NSFString Name [get, set]
 
- Properties inherited from NSFUniquelyNumberedObject
NSFId UniqueId [get]
 Gets or sets the unique id of the object. More...
 
- Properties inherited from INSFNamedObject
NSFString Name [get]
 Gets the name of the object. More...
 
- Properties inherited from INSFEventHandler
NSFEventHandlerRunStatus RunStatus [get]
 Gets the run status of the event handler. More...
 
NSFEventHandlerTerminationStatus TerminationStatus [get]
 Gets the termination status of the event handler. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from NSFUniquelyNumberedObject
static NSFId getNextUniqueId ()
 Gets the next unique id. More...
 

Detailed Description

Represents a state machine.

Constructor & Destructor Documentation

NSFStateMachine ( NSFString  name,
NSFEventThread  thread 
)

Creates a state machine

Parameters
nameThe user defined name for the state machine.
threadThe thread on which events for the state machine are queued.
NSFStateMachine ( NSFString  name,
NSFRegion  parentRegion 
)

Creates a state machine.

Parameters
nameThe user defined name for the state machine.
parentRegionThe parent region of the state machine.
NSFStateMachine ( NSFString  name,
NSFCompositeState  parentState 
)

Creates a state machine.

Parameters
nameThe user defined name for the state machine.
parentStateThe parent composite state for the state machine.

Member Function Documentation

void forceStateMachineEvaluation ( )

Forces the state machine to evaluate transitions.

This method is rarely needed, but can be used, for example, to force evaluation if a guard condition has changed.

NSFEventStatus handleEvent ( NSFEvent  nsfEvent)

Handles an event.

Parameters
nsfEventThe event to handle.
Returns
Status indicating if the event was handled or not.

This method is for use only by the North State Framework's internal logic. It processes the event using UML defined behavior, including run to completion.

Implements INSFEventHandler.

bool hasEvent ( NSFEvent  nsfEvent)
protected

Checks if an event is queued for processing.

Parameters
nsfEventThe event in queustion.
Returns
True if the event is the in queue, otherwise false.
bool isTopStateMachine ( )
protected

Checks if the state machine is the top state machine in a nested heirarchy.

Returns
True if the state machine is the top state machine, otherwise false.
bool Never ( NSFStateMachineContext  context)

Provides a syntactical method for specifying "Never" as a transition guard, effectively blocking the transition from ever occuring.

void queueEvent ( NSFEvent  nsfEvent)

Queues an event for the handler.

Parameters
nsfEventThe event to queue.

Implements INSFEventHandler.

void queueEvent ( NSFEvent  nsfEvent,
INSFNamedObject  source 
)

Queues an event for the handler.

Parameters
nsfEventThe event to queue.
sourceThe source of the event.

Implements INSFEventHandler.

void rerouteTransition ( NSFTransition  transition,
NSFState  source,
NSFState  target 
)
protected

Re-routes a transition between a specified source and destination

Parameters
transitionThe transition to re-route.
sourceThe new source for the transition.
targetThe new target for the transition.

This method can be used when extending state machines. Careful design consideration should be made before using this method. Never change a state machines structure while it is running.

void resetStateMachine ( )

Resets the state machine back to its initial default state.

If the state machine is currently running (started), it will process all events currently in its queue before resetting and it will continue running after the reset. If the state machine is currently stopped, it will continue to be stopped after the reset. While a state machine is stopped, all events are dropped from its queue.

void startEventHandler ( )

Starts event processing.

When stopped, events queued prior to calling the method startEventHandler() will be dropped. Events queued after calling the method startEventHandler() will be processed, until the next call to stopEventHandler(). When started, events queued prior to calling the method stopEventHandler() will be processed. Events queued after calling the method stopEventHandler() will be dropped, until the next call to startEventHandler().

Implements INSFEventHandler.

void startStateMachine ( )
void stopEventHandler ( )

Stops event processing.

When stopped, events queued prior to calling the method startEventHandler() will be dropped. Events queued after calling the method startEventHandler() will be processed, until the next call to stopEventHandler(). When started, events queued prior to calling the method stopEventHandler() will be processed. Events queued after calling the method stopEventHandler() will be dropped, until the next call to startEventHandler().

Implements INSFEventHandler.

void stopStateMachine ( )
void terminate ( bool  waitForTerminated)

Terminates the event handler, so that it can be garbage collected.

Parameters
waitForTerminatedFlag indicating if the method should wait until the event handler is terminated (true), or if it should return immediately (false).

This method terminates the event handler in a coordinated fashion, making sure all remaining events are cleared, so that it can be garbage collected. After calling this method, the event handler cannot be restarted. This method should only be called if the event handler should be garbage collected. If the waitForTerminated flag is set true, this method must not be called from the event handler's thread of execution.

Implements INSFEventHandler.

Member Data Documentation

NSFVoidActions<NSFStateMachineContext> ConsecutiveLoopLimitActions = new NSFVoidActions<NSFStateMachineContext>()

Actions to execute if consecutive loop limit is reached.

State machines have the ability to detect if they are ill-formed by way of consecutive loop detection. This mechanism looks for repeated transitions without a pause (as defined by the condition when there are no more events queued to the state machine, and the final run-to-completion step has occurred). If more than the specified number of transitions occur without a pause, the state machine will remove its queued events, call the consecutive loop limit actions, and stop after executing any events queued by the limit actions.

NSFVoidActions<NSFStateMachineContext> EventLimitActions = new NSFVoidActions<NSFStateMachineContext>()

Actions to execute if consecutive loop limit is reached.

State machines have the ability to detect if they are not processing messages in a timely fashion by way of event limit detection. This mechanism looks at the number of events in the state machine's event queue. If the more than the specified number of events are queued, the state machine will remove its queued events, call the event limit actions, and stop after executing any events queued by the limit actions.

NSFVoidActions<NSFExceptionContext> ExceptionActions = new NSFVoidActions<NSFExceptionContext>()

Actions to execute if an exception is encountered by the state machine.

NSFVoidActions<NSFStateMachineContext> StateChangeActions = new NSFVoidActions<NSFStateMachineContext>()

Actions to execute whenever a new state is entered.

Property Documentation

bool ConsecutiveLoopDetectionEnabled
getset

Gets or sets the flag indicating if consecutive loop detection is enabled.

State machines have the ability to detect if they are ill-formed by way of consecutive loop detection. This mechanism looks for repeated transitions without a pause (as defined by the condition when there are no more events queued to the state machine, and the final run-to-completion step has occurred). If more than the specified number of transitions occur without a pause, the state machine will remove its queued events, call the consecutive loop limit actions, and stop after executing any events queued by the actions.

int ConsecutiveLoopLimit
getset

Gets or sets the maximum number of transitions without a pause allowed by consecutive loop detection.

State machines have the ability to detect if they are ill-formed by way of consecutive loop detection. This mechanism looks for repeated transitions without a pause (as defined by the condition when there are no more events queued to the state machine, and the final run-to-completion step has occurred). If more than the specified number of transitions occur without a pause, the state machine will remove its queued events, call the consecutive loop limit actions, and stop after executing any events queued by the actions.

NSFBoolGuard<NSFStateMachineContext> Else
get

Provides a syntactical method for specifying "Else" as a transition guard.

int EventLimit
getset

Gets or sets the maximum number of transitions without a pause allowed by consecutive loop detection.

State machines have the ability to detect if they are not processing messages in a timely fashion by way of event limit detection. This mechanism looks at the number of events in the state machine's event queue. If the more than the specified number of events are queued, the state machine will remove its queued events, call the event limit actions, and stop after executing any events queued by the limit actions.

bool EventLimitDetectionEnabled
getset

Gets or sets the flag indicating if event limit detection is enabled.

State machines have the ability to detect if they are not processing messages in a timely fashion by way of event limit detection. This mechanism looks at the number of events in the state machine's event queue. If the more than the specified number of events are queued, the state machine will remove its queued events, call the event limit actions, and stop after executing any events queued by the limit actions.

NSFEventThread EventThread
getset

Gets or sets the state machine's event thread.

bool LoggingEnabled
getset

Gets or sets the flag indicating if state machine event logging is enabled.

Int32 QueuedEvents
getset

Gets or sets the number of events currently queued in state machine's event thread.

This mechanism only works if events are queued throught the state machine's queueEvent methods.

NSFEventHandlerRunStatus RunStatus
getset
uint TerminationSleepTime
staticgetset

Gets the amount of time (mS) the terminate method sleeps between checks for state machine termination.

NSFEventHandlerTerminationStatus TerminationStatus
getset
int TerminationTimeout
staticgetset

The amount of time the terminate method will wait for event processing to complete.

override NSFStateMachine TopStateMachine
get



Copyright 2004-2014, North State Software, LLC. All rights reserved.