IMS2  Pre-Alpha
An Orbiter add-on to allow on-runtime construction of spacecraft from predefined modules
EventHandler Class Referenceabstract

EventHandler base class. All classes that implement eventhandling must inherit from this class. More...

Inheritance diagram for EventHandler:
GUI_Surface IMS_Module IMS_ModuleFunction_Base IMS_Movable IMS_ModuleFunction_Thruster

Public Member Functions

void ConnectToMyEventGenerator (EventSink *sink, EVENTPIPE pipe)
 connects an EventSink to the EventGenerator of this in the appropriate pipe. More...
 
void ConnectToMyEventSink (EventSink *sink, EVENTPIPE pipe)
 Connects an EventSink on this to the passed event sink. More...
 
void ConnectMySinkToYourNode (EventNode *node, EVENTPIPE pipe)
 Connects an EventSink on this to the passed EventNode, no matter whether generator or another sink. More...
 
EVENTHANDLERTYPE GetEventHandlerType ()
 Returns the EVENTHANDLERTYPE of this event handler.
 
UINT GetUID ()
 Returns the globaly unique identifier of this event handler.
 

Protected Member Functions

EventGeneratorcreateEventGenerator (EVENTPIPE pipe)
 Creates a new EventGenerator for this handler instance. More...
 
EventSinkcreateEventSink (EVENTPIPE pipe)
 creates a new EventSink in this handler instance More...
 
void disconnect (EventHandler *handler, bool bidirectional=true)
 Completely severs connections to and from the passed EventHandler, all sinks, all generators. More...
 
void sendEvents ()
 Tells all event generators in this event handler to advance their event cue. More...
 
void processWaitingQueue ()
 processes all events in the waiting queue. More...
 
void addEvent (Event_Base *_event, EVENTPIPE _pipe=DEFAULT_PIPE)
 Adds an event to the eventcue of an eventpipe. More...
 
void addEventToWaitingQueue (Event_Base *_event)
 Adds an event to this handlers waiting queue. More...
 
void relayEvent (Event_Base *_event, EVENTPIPE _pipe)
 Relays an event to another event pipe. More...
 
EventSinkgetEventSink (EVENTPIPE pipe)
 returns the EventSink on this EventHandler that belongs to the passed event pipe More...
 
EventGeneratorgetEventGenerator (EVENTPIPE pipe)
 Returns the EventGenerator on this EventHandler that belongs to the passed event pipe. More...
 
virtual bool ProcessEvent (Event_Base *e)=0
 Receives all events coming through this EventHandler. More...
 

Protected Attributes

EVENTPIPE defaultpipe = DEFAULT_PIPE
 Use this to set the defualt event pipe of this event handler.
 
EVENTHANDLERTYPE eventhandlertype
 An identifier that offers a group identification.
 

Private Member Functions

void createWaitingQueue ()
 creates the generator and sink for the waiting queue More...
 

Private Attributes

UINT uid
 Globally unique identier, handy mostly for debugging.
 
map< EVENTPIPE, EventGenerator * > eventgenerators
 Stores the event generators of this EventHandler.
 
map< EVENTPIPE, EventSink * > eventsinks
 Stores the EventSinks of this EventHandler.
 
EventGeneratorwaiting_queue = NULL
 The event generator dedicated to processing the waiting queue.
 
EventSinkwaiting_sink = NULL
 The event sink for the waiting queue.
 

Friends

class EventSink
 

Detailed Description

EventHandler base class. All classes that implement eventhandling must inherit from this class.

For a more detailed description of the event engine as a whole, see the file documentation for EventHandler.h

Member Function Documentation

void EventHandler::addEvent ( Event_Base _event,
EVENTPIPE  _pipe = DEFAULT_PIPE 
)
protected

Adds an event to the eventcue of an eventpipe.

Parameters
_eventA pointer to an event. The memory will be freed by the event handler once the event has been processed
_pipeThe event pipe the event should be added to. if _pipe == DEFAULT_PIPE, the event will be sent along this handlers default pipe (i.e. the first generator in the list).
Note
Do NOT add pointers to events received in processEvents(). Those pointers will be deallocated once the event generator in question has finished its business! use RelayEvent() instead.
See also
addEventToWaitingQueue()
relayEvent()
void EventHandler::addEventToWaitingQueue ( Event_Base _event)
protected

Adds an event to this handlers waiting queue.

The waiting queue is a dedicated event generator that will not generate its events when sendEvents() is called, but instead when processWaitingQueue is called.

Parameters
_eventA pointer to an event. The memory will be freed by the event handler once the event has been processed.
Note
Do NOT add pointers to events received in processEvents(). Those pointers will be deallocated once the event generator in question has finished its business!
void EventHandler::ConnectMySinkToYourNode ( EventNode node,
EVENTPIPE  pipe 
)

Connects an EventSink on this to the passed EventNode, no matter whether generator or another sink.

In short, this forms a connection in opposite direction from ConnectToMyEventGenerator and ConnectToMyEventSink

Parameters
nodeThe EventGenerator the Sink on this should connect to
pipeThe Eventpipe the Sink should be a part of. A sink of this pipe must be present on this!
void EventHandler::ConnectToMyEventGenerator ( EventSink sink,
EVENTPIPE  pipe 
)

connects an EventSink to the EventGenerator of this in the appropriate pipe.

Parameters
sinkThe EventSink to be connected to an EventGenerator in this handler instance
pipeThe event pipe the sink should hook into
void EventHandler::ConnectToMyEventSink ( EventSink sink,
EVENTPIPE  pipe 
)

Connects an EventSink on this to the passed event sink.

Parameters
sinkThe EventSink to be connected to a sink in this handler instance
pipeThe event pipe the sink should hook into
EventGenerator * EventHandler::createEventGenerator ( EVENTPIPE  pipe)
protected

Creates a new EventGenerator for this handler instance.

Parameters
pipeThe event pipe this generator services
EventSink * EventHandler::createEventSink ( EVENTPIPE  pipe)
protected

creates a new EventSink in this handler instance

Parameters
pipeThe event pipe this sink should hook into
void EventHandler::createWaitingQueue ( )
private

creates the generator and sink for the waiting queue

Note
The waiting queue is created on demand, since only few EventHandlers will need one. Once created it will last for the remaining lifetime of the handler.
void EventHandler::disconnect ( EventHandler handler,
bool  bidirectional = true 
)
protected

Completely severs connections to and from the passed EventHandler, all sinks, all generators.

Parameters
handlerThe EventHandler instance to disconnect
bidirectionalAlways pass true (default)! This argument is only used to call the function on the opposing handler.
EventGenerator * EventHandler::getEventGenerator ( EVENTPIPE  pipe)
protected

Returns the EventGenerator on this EventHandler that belongs to the passed event pipe.

Parameters
pipeThe event pipe of which to retrieve the sink
Returns
NULL if no generator in this pipe exists in the EventHandler
EventSink * EventHandler::getEventSink ( EVENTPIPE  pipe)
protected

returns the EventSink on this EventHandler that belongs to the passed event pipe

Parameters
pipeThe event pipe of which to retrieve the sink
Returns
NULL if no sink in this pipe exists in the EventHandler
virtual bool EventHandler::ProcessEvent ( Event_Base e)
protectedpure virtual

Receives all events coming through this EventHandler.

Overload to implement event handling in your inheriting class. The function will receive Events one by one as they are coming through your event sinks, regardless of which pipe they belong to. Return true to consume an event, but be sure it was only meant for you when you do that.

Parameters
eThe event coming through the event pipe
Note
Event generators will NOT send events to this function, only sinks.

Implemented in IMS_Module, IMS_PropulsionManager, IMS_RcsManager, and IMS_ModuleFunction_Thruster.

void EventHandler::processWaitingQueue ( )
protected

processes all events in the waiting queue.

The waiting queue stands outside the normal event processing and will only be handled when this method is called. All events in the waiting queue will be processed, regardless of delay, and will be destroyed once finished. The waiting queue will only send events to this eventhandlers processEvent() method.

void EventHandler::relayEvent ( Event_Base _event,
EVENTPIPE  _pipe 
)
protected

Relays an event to another event pipe.

Relaying means that the event will be propagated through the designated pipe IMMEDIATELY, but it will not be consumed by it. The event will still exist after its detour, which would not be the case if it was simply added to another event pipe with no delay

Parameters
_eventThe event to relay.
_pipeThe event pipe the event should be relayed to.
Note
_event: Do not pass a a newly created event to this function! use addEvent to propagate new events. If you relay a new event, you're creating a memory leak! only relay events you get from ProcessEvent()!
_pipe: An EventGenerator belonging to this pipe must exist in the EventHandler!
See also
AddEvent();
void EventHandler::sendEvents ( )
protected

Tells all event generators in this event handler to advance their event cue.

Note
Make sure this is called every frame for every EventHandler.
See also
sendImmediateEvents()

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