Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

EventBase Class Reference

#include <EventBase.h>

Inheritance diagram for EventBase:

Inheritance graph
[legend]
List of all members.

Detailed Description

The basis of events passed around the high level system.

Contains the list of 'known' event generators in EventGeneratorID_t and EventGeneratorNames[]. If you want to make a new generator, all you have to do is add a new entry to the ID list (EventGeneratorID_t) and then put it's name in the EventGeneratorNames[] array.

Alternatively, there is an 'unlicensed spectrum' available under the unknownEGID. You can send out events from that generator just like any other, but it should only be used for quick tests and hacking around...

The SourceID is generator specific. A SID of i from the button generator will refer to a particular button, whereas a SID from vision refers to seeing a particular object. These SIDs are usually defined in the generators themselves. See the EventGeneratorID_t list for links to the generators.

The duration field is also generator specific - some may refer to the time since the last activation event (e.g. button events) where as others refer to time since last status (e.g. sensors updates)

Definition at line 31 of file EventBase.h.

Public Types

enum  EventGeneratorID_t {
  unknownEGID = 0, visionEGID, buttonEGID, worldModelEGID,
  aiEGID, audioEGID, sensorEGID, powerEGID,
  timerEGID, stateMachineEGID, locomotionEGID, textmsgEGID,
  estopEGID, motmanEGID, numEGIDs
}
 Lists all possible event generator ids. More...

enum  EventTypeID_t { activateETID, statusETID, deactivateETID, numETIDs }
 an event type id is used to denote whether it's the first in a sequence (button down), in a sequence (button still down), or last (button up) More...


Public Member Functions

Constructors/Destructors
 EventBase ()
 constructor

 EventBase (EventGeneratorID_t gid, unsigned int sid, EventTypeID_t tid, unsigned int dur=0)
 constructor

 EventBase (EventGeneratorID_t gid, unsigned int sid, EventTypeID_t tid, unsigned int dur, const std::string &n, float mag)
 constructor

virtual ~EventBase ()
 destructor

Methods
virtual const std::string & getName () const
 gets the name of the event - useful for debugging, outputs

virtual EventBasesetName (const std::string &n)
 sets name to a given string, prevents overwriting by generated names

virtual float getMagnitude () const
 gets "strength" of event - you might have useful values... used by AI

virtual EventBasesetMagnitude (float m)
 sets "strength" of event - but you might have useful values... used by AI

virtual unsigned int getTimeStamp () const
 time event was created

virtual EventGeneratorID_t getGeneratorID () const
 gets the generator ID for this event

virtual EventBasesetGeneratorID (EventGeneratorID_t gid)
 sets the generator ID for this event

virtual unsigned int getSourceID () const
 gets the source ID for this event

virtual EventBasesetSourceID (unsigned int gid)
 sets the source ID for this event

virtual EventTypeID_t getTypeID () const
 gets the type ID

virtual EventBasesetTypeID (EventTypeID_t tid)
 sets the type ID

virtual unsigned int getDuration () const
 OPTIONAL gets the time since the beginning of this sequence (the timestamp of the activate event).

virtual EventBasesetDuration (unsigned int d)
 OPTIONAL gets the time since the beginning of this sequence (the timestamp of the activate event).

virtual const std::string & resetName ()
 resets name to generated form, overwriting any previous name

virtual bool isCustomName () const
 returns true if not using the generated name

bool operator< (const EventBase &e) const
 gets the name of the event - useful for debugging, outputs

virtual bool operator== (const EventBase &eb) const
 is true if the genID, typeID, and sourceID's all match

bool sameGenSource (const EventBase eb) const
 tests to see if events have the same generator and source IDs

bool longerThan (const EventBase eb) const
 compares event duration and ensures same event generator, source, and type - useful for event masks

bool shorterThan (const EventBase eb) const
 compares event duration and ensures same event generator, source, and type - useful for event masks

bool equalOrLongerThan (const EventBase eb) const
 compares event duration and ensures same event generator, source, and type - useful for event masks

bool equalOrShorterThan (const EventBase eb) const
 compares event duration and ensures same event generator, source, and type - useful for event masks

LoadSave interface
Useful for serializing events to send between processes

virtual unsigned int getBinSize () const
 calculates space needed to save - if you can't precisely add up the size, overestimate and things will still work.

virtual unsigned int LoadBuffer (const char buf[], unsigned int len)
 Load from a saved buffer.

virtual unsigned int SaveBuffer (char buf[], unsigned int len) const
 Save to a given buffer.


Static Public Attributes

const char *const EventGeneratorNames [numEGIDs]
 Holds string versions of each of the generator's names, handy for debugging so you can output the events as readable strings.


Protected Member Functions

virtual void genName ()
 This does the actual generation of names based on genID, sourceID, and typeID.


Protected Attributes

std::string stim_id
 the name of the event, use the same name consistently or else will be seen as different stimuli

float magnitude
 the current "strength" of the event/stimuli... MAKE SURE this gets set to ZERO IF event is DEACTIVATE

unsigned int timestamp
 the time the event was created - set automatically by constructor

bool nameisgen
 tracks whether the current name (stim_id) is generated or set

EventGeneratorID_t genID
 generator ID,
See also:
EventGeneratorID_t


EventTypeID_t typeID
 type ID,
See also:
EventTypeID_t


unsigned int sourceID
 the source ID for this event Source IDs are defined by the generator that made it

unsigned int duration
 the time since this sequence started (like, how long the button has been pressed) ideally, this would be 0 for activate, (activate.timestamp-get_time()) for status and deactivate


Member Enumeration Documentation

enum EventBase::EventGeneratorID_t
 

Lists all possible event generator ids.

An event generator is a abstract source of events, used for listening to and parsing certain classes of events

IF YOU ADD AN EVENT GENERATOR, DON'T FORGET TO NAME IT (EventBase::EventGeneratorNames, below)

Enumeration values:
unknownEGID  default EGID, used if you forget to set it, probably not a good idea to use this for anything except errors or testing quick hacks
visionEGID  vision processing from camera
buttonEGID  button up, down, and still down,
See also:
ButtonSourceID::ButtonSourceID_t
worldModelEGID  not being used, yet (for when objects are detected/lost?)
aiEGID  not being used, yet (might use this when AI makes decisions?)
audioEGID  Sends an event when a sound starts/ends playback, status events as chained sounds end.
sensorEGID  currently only used to alert of new sensor readings, may also want to generate IR proximity warnings?
See also:
SensorSourceID::SensorSourceID_t
powerEGID  used to generate low power warnings, temperature, etc.
See also:
PowerSourceID::PowerSourceID_t
timerEGID  EGID from which timers are sent, you set timers, but you don't have to also listen
See also:
EventRouter::setTimer().
stateMachineEGID  Sends an event upon entering and leaving a StateNode.
locomotionEGID  Sends events regarding transportation in the world; you can/should assume these will all be LocomotionEvent classes.
textmsgEGID  Sends events when a text msg is received on console.
estopEGID  Sends an event when the estop is turned on or off.
motmanEGID  Sends events when a MotionCommand is added or removed.
numEGIDs  the number of generators available

Definition at line 37 of file EventBase.h.

enum EventBase::EventTypeID_t
 

an event type id is used to denote whether it's the first in a sequence (button down), in a sequence (button still down), or last (button up)

Enumeration values:
activateETID  e.g. button down
statusETID  e.g. button still down
deactivateETID  e.g. button up
numETIDs  the number of different event types

Definition at line 59 of file EventBase.h.


Constructor & Destructor Documentation

EventBase::EventBase  ) 
 

constructor

See also:
EventRouter::postEvent()

Definition at line 22 of file EventBase.cc.

References genName(), and get_time().

EventBase::EventBase EventGeneratorID_t  gid,
unsigned int  sid,
EventTypeID_t  tid,
unsigned int  dur = 0
 

constructor

See also:
EventRouter::postEvent()

Definition at line 28 of file EventBase.cc.

References deactivateETID, genName(), get_time(), and setMagnitude().

EventBase::EventBase EventGeneratorID_t  gid,
unsigned int  sid,
EventTypeID_t  tid,
unsigned int  dur,
const std::string &  n,
float  mag
 

constructor

See also:
EventRouter::postEvent()

Definition at line 38 of file EventBase.cc.

References get_time().

virtual EventBase::~EventBase  )  [inline, virtual]
 

destructor

Definition at line 72 of file EventBase.h.


Member Function Documentation

bool EventBase::equalOrLongerThan const EventBase  eb  )  const [inline]
 

compares event duration and ensures same event generator, source, and type - useful for event masks

Definition at line 110 of file EventBase.h.

References duration, and operator==().

bool EventBase::equalOrShorterThan const EventBase  eb  )  const [inline]
 

compares event duration and ensures same event generator, source, and type - useful for event masks

Definition at line 111 of file EventBase.h.

References duration, and operator==().

void EventBase::genName  )  [protected, virtual]
 

This does the actual generation of names based on genID, sourceID, and typeID.

Definition at line 114 of file EventBase.cc.

References EventGeneratorNames, genID, nameisgen, numEGIDs, sourceID, and stim_id.

unsigned int EventBase::getBinSize  )  const [virtual]
 

calculates space needed to save - if you can't precisely add up the size, overestimate and things will still work.

Returns:
number of bytes read/written, 0 if error (or empty)

Implements LoadSave.

Reimplemented in LocomotionEvent, TextMsgEvent, and VisionEvent.

Definition at line 46 of file EventBase.cc.

References LoadSave::creatorSize(), duration, magnitude, nameisgen, sourceID, stim_id, LoadSave::stringpad, and timestamp.

virtual unsigned int EventBase::getDuration  )  const [inline, virtual]
 

OPTIONAL gets the time since the beginning of this sequence (the timestamp of the activate event).

See also:
duration

Definition at line 93 of file EventBase.h.

References duration.

virtual EventGeneratorID_t EventBase::getGeneratorID  )  const [inline, virtual]
 

gets the generator ID for this event

See also:
EventGeneratorID_t

Definition at line 84 of file EventBase.h.

References EventGeneratorID_t, and genID.

virtual float EventBase::getMagnitude  )  const [inline, virtual]
 

gets "strength" of event - you might have useful values... used by AI

Definition at line 79 of file EventBase.h.

References magnitude.

virtual const std::string& EventBase::getName  )  const [inline, virtual]
 

gets the name of the event - useful for debugging, outputs

Definition at line 76 of file EventBase.h.

References stim_id.

virtual unsigned int EventBase::getSourceID  )  const [inline, virtual]
 

gets the source ID for this event

See also:
sourceID

Definition at line 87 of file EventBase.h.

References sourceID.

virtual unsigned int EventBase::getTimeStamp  )  const [inline, virtual]
 

time event was created

Definition at line 82 of file EventBase.h.

References timestamp.

virtual EventTypeID_t EventBase::getTypeID  )  const [inline, virtual]
 

gets the type ID

See also:
EventTypeID_t

Definition at line 90 of file EventBase.h.

References EventTypeID_t, and typeID.

virtual bool EventBase::isCustomName  )  const [inline, virtual]
 

returns true if not using the generated name

Definition at line 97 of file EventBase.h.

References nameisgen.

unsigned int EventBase::LoadBuffer const char  buf[],
unsigned int  len
[virtual]
 

Load from a saved buffer.

Parameters:
buf pointer to the memory where you should begin loading
len length of buf available (this isn't all yours, might be more stuff saved after yours)
Returns:
the number of bytes actually used

Implements LoadSave.

Reimplemented in LocomotionEvent, TextMsgEvent, and VisionEvent.

Definition at line 61 of file EventBase.cc.

References LoadSave::checkCreator(), LoadSave::decode(), duration, EventGeneratorID_t, EventTypeID_t, genID, magnitude, nameisgen, sourceID, stim_id, timestamp, and typeID.

bool EventBase::longerThan const EventBase  eb  )  const [inline]
 

compares event duration and ensures same event generator, source, and type - useful for event masks

Definition at line 108 of file EventBase.h.

References duration, and operator==().

bool EventBase::operator< const EventBase e  )  const [inline]
 

gets the name of the event - useful for debugging, outputs

Definition at line 99 of file EventBase.h.

References timestamp.

virtual bool EventBase::operator== const EventBase eb  )  const [inline, virtual]
 

is true if the genID, typeID, and sourceID's all match

Definition at line 102 of file EventBase.h.

References genID, sourceID, and typeID.

virtual const std::string& EventBase::resetName  )  [inline, virtual]
 

resets name to generated form, overwriting any previous name

Definition at line 96 of file EventBase.h.

References genName(), nameisgen, and stim_id.

bool EventBase::sameGenSource const EventBase  eb  )  const [inline]
 

tests to see if events have the same generator and source IDs

Definition at line 106 of file EventBase.h.

References genID, and sourceID.

unsigned int EventBase::SaveBuffer char  buf[],
unsigned int  len
const [virtual]
 

Save to a given buffer.

Parameters:
buf pointer to the memory where you should begin writing
len length of buf available. (this isn't all yours, constrain yourself to what you returned in getBinSize() )
Returns:
the number of bytes actually used

Implements LoadSave.

Reimplemented in LocomotionEvent, TextMsgEvent, and VisionEvent.

Definition at line 89 of file EventBase.cc.

References duration, LoadSave::encode(), genID, magnitude, nameisgen, LoadSave::saveCreator(), sourceID, stim_id, timestamp, and typeID.

virtual EventBase& EventBase::setDuration unsigned int  d  )  [inline, virtual]
 

OPTIONAL gets the time since the beginning of this sequence (the timestamp of the activate event).

See also:
duration

Definition at line 94 of file EventBase.h.

References duration.

virtual EventBase& EventBase::setGeneratorID EventGeneratorID_t  gid  )  [inline, virtual]
 

sets the generator ID for this event

See also:
EventGeneratorID_t

Definition at line 85 of file EventBase.h.

References genID, and genName().

virtual EventBase& EventBase::setMagnitude float  m  )  [inline, virtual]
 

sets "strength" of event - but you might have useful values... used by AI

Definition at line 80 of file EventBase.h.

References magnitude.

virtual EventBase& EventBase::setName const std::string &  n  )  [inline, virtual]
 

sets name to a given string, prevents overwriting by generated names

Definition at line 77 of file EventBase.h.

References nameisgen, and stim_id.

virtual EventBase& EventBase::setSourceID unsigned int  gid  )  [inline, virtual]
 

sets the source ID for this event

See also:
sourceID

Definition at line 88 of file EventBase.h.

References genName(), and sourceID.

virtual EventBase& EventBase::setTypeID EventTypeID_t  tid  )  [inline, virtual]
 

sets the type ID

See also:
EventTypeID_t

Definition at line 91 of file EventBase.h.

References genName(), and typeID.

bool EventBase::shorterThan const EventBase  eb  )  const [inline]
 

compares event duration and ensures same event generator, source, and type - useful for event masks

Definition at line 109 of file EventBase.h.

References duration, and operator==().


Member Data Documentation

unsigned int EventBase::duration [protected]
 

the time since this sequence started (like, how long the button has been pressed) ideally, this would be 0 for activate, (activate.timestamp-get_time()) for status and deactivate

Definition at line 134 of file EventBase.h.

const char *const EventBase::EventGeneratorNames [static]
 

Initial value:

 {
  "UnknownGen",
  "Vision",
  "Button",
  "WorldModel",
  "AI",
  "Audio",
  "Sensor",
  "Power",
  "Timer",
  "StateMachine",
  "Locomotion",
  "TextMsg",
  "EStop",
  "MotionManager"
}
Holds string versions of each of the generator's names, handy for debugging so you can output the events as readable strings.

Definition at line 4 of file EventBase.cc.

EventGeneratorID_t EventBase::genID [protected]
 

generator ID,

See also:
EventGeneratorID_t

Definition at line 128 of file EventBase.h.

float EventBase::magnitude [protected]
 

the current "strength" of the event/stimuli... MAKE SURE this gets set to ZERO IF event is DEACTIVATE

Definition at line 122 of file EventBase.h.

bool EventBase::nameisgen [protected]
 

tracks whether the current name (stim_id) is generated or set

Definition at line 125 of file EventBase.h.

unsigned int EventBase::sourceID [protected]
 

the source ID for this event Source IDs are defined by the generator that made it

This should give authors flexibility to design their modules without having to worry about ID space collision

Definition at line 130 of file EventBase.h.

std::string EventBase::stim_id [protected]
 

the name of the event, use the same name consistently or else will be seen as different stimuli

Definition at line 121 of file EventBase.h.

unsigned int EventBase::timestamp [protected]
 

the time the event was created - set automatically by constructor

Definition at line 123 of file EventBase.h.

EventTypeID_t EventBase::typeID [protected]
 

type ID,

See also:
EventTypeID_t

Definition at line 129 of file EventBase.h.


The documentation for this class was generated from the following files:
Tekkotsu v1.4
Generated Sat Jul 19 00:08:55 2003 by Doxygen 1.3.2