Go to the first, previous, next, last section, table of contents.


CNEventHandler -- Abstract Base Class for Event Handlers

SYNOPSIS

#include <CNCL/EventHandler.h>

TYPE

CN_EVENTHANDLER

BASE CLASSES

CNObject

DERIVED CLASSES

CNEventExploder

RELATED CLASSES

CNEvent, CNEventScheduler, CNSimTime

DESCRIPTION

CNEventHandler is a base class for creating simulation event handler. Deriving an event handler class from CNEventHandler is necessary for the simulation programm.

Each derived event handler must at least provide the function event_handler(), which is defined as pure virtual in class CNEventHandler.

Constructors:

CNEventHandler();
CNEventHandler(CNParam *param);
Initializes the event handler.
CNEventHandler(CNStringR name);
Initializes the event handler, setting the name to name.

In addition to the member functions required by CNCL, CNEventHandler provides the following protected member functions available to all derived classes:

virtual void event_handler(const CNEvent *ev) = 0;
This function must be defined in the derived classes. It should determine what should happen to the transfered Events. Please see the example at the end of this chapter.
CNEventScheduler *scheduler() const;
Returns the scheduler, which called this event handler.
int state() const;
int state(int new_state);
int get_state() const;
int set_state(int new_state);
Gets/sets the event handler's state.
CNSimTime now() const;
Returns the current simulation time.
CNEventID send_event(CNEvent *ev);
CNEventID send(CNEvent *ev);
Send an event to the scheduler. Members left uninitialized in the event are set to default values (scheduled time = current time, addressed event handler = this event handler, sending event handler = this event handler). Returns the event's ID.
CNEventID send_now(CNEvent *ev);
Send an event to the scheduler. Same as send_event(), but scheduled time is set to the current time. Returns the event's ID.
CNEventID send_delay(CNEvent *ev, double dt);
Send an event to the scheduler. Same as send_event(), but scheduled time is set to the current time plus a time delay dt. Returns the event's ID.
void delete_event(CNEventID id);
Deletes event with ID id from the scheduler's event list.
void delete_events(CNEventHandler *evh);
Deletes all events from the list that are addressed to event handler evh. If evh is NIL, it deletes all events addressed to this event handler.


Go to the first, previous, next, last section, table of contents.