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

Represents a light-weight event handler. More...

Inheritance diagram for NSFEventHandler:
NSFTaggedObject INSFEventHandler NSFUniquelyNumberedObject INSFNamedObject INSFNamedObject

Public Member Functions

 NSFEventHandler (NSFString name, NSFEventThread thread)
 Creates an event handler More...
 
void addEventReaction (NSFEvent nsfEvent, NSFVoidAction< NSFEventContext > action)
 Adds a reaction to a specified event. More...
 
NSFEventStatus handleEvent (NSFEvent nsfEvent)
 Handles an event. More...
 
bool hasEvent (NSFEvent nsfEvent)
 Checks if an event is queued for handling. More...
 
bool hasEvent ()
 Checks if any events are queued for handling. 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 removeEventReaction (NSFEvent nsfEvent, NSFVoidAction< NSFEventContext > action)
 Removes a reaction to a specified event. More...
 
void startEventHandler ()
 Starts event processing. More...
 
void stopEventHandler ()
 Stops event processing. More...
 
void terminate (bool waitForTerminated)
 Terminates the event handler, so that it can be garbage collected. 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...
 

Properties

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 event handler termination. More...
 
static int TerminationTimeout [get, set]
 The amount of time the terminate method will wait for event processing to complete. More...
 
NSFEventThread EventThread [get, set]
 Gets or sets the event handler's thread. More...
 
bool LoggingEnabled [get, set]
 Gets or sets the flag indicating if event logging is enabled. 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 light-weight event handler.

This class associates actions with events, executing the actions when the event is handled. Events are queued to the specified thread and handled in the order they are received. Actions execute on the specified thread. This class is a light-weight event handler which can be used instead of a state machine.

Constructor & Destructor Documentation

NSFEventHandler ( NSFString  name,
NSFEventThread  thread 
)

Creates an event handler

Parameters
nameThe user defined name for the state machine.
threadThe thread on which events for the state machine are queued.

Member Function Documentation

void addEventReaction ( NSFEvent  nsfEvent,
NSFVoidAction< NSFEventContext action 
)

Adds a reaction to a specified event.

Parameters
nsfEventThe event causing the action.
actionThe action taken as a result of the event.
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 calls the actions associated with the event, if any.

Implements INSFEventHandler.

bool hasEvent ( NSFEvent  nsfEvent)

Checks if an event is queued for handling.

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

Checks if any events are queued for handling.

Returns
True if there are events queued for handling, otherwise false.
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 removeEventReaction ( NSFEvent  nsfEvent,
NSFVoidAction< NSFEventContext action 
)

Removes a reaction to a specified event.

Parameters
nsfEventThe event causing the action.
actionThe action taken as a result of the event.
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 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 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.

Property Documentation

NSFEventThread EventThread
getset

Gets or sets the event handler's thread.

bool LoggingEnabled
getset

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

NSFEventHandlerRunStatus RunStatus
getset
uint TerminationSleepTime
staticgetset

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

NSFEventHandlerTerminationStatus TerminationStatus
getset
int TerminationTimeout
staticgetset

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




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