| Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
00001 //-*-c++-*- 00002 #ifndef INCLUDED_EventBase_h 00003 #define INCLUDED_EventBase_h 00004 00005 #include "Shared/get_time.h" 00006 #include "Shared/LoadSave.h" 00007 #include <string> 00008 00009 //! The basis of events passed around the high level system 00010 /*! Contains the list of 'known' event generators in EventGeneratorID_t 00011 * and EventGeneratorNames[]. If you want to make a new generator, all 00012 * you have to do is add a new entry to the ID list (EventGeneratorID_t) 00013 * and then put it's name in the EventGeneratorNames[] array. 00014 * 00015 * Alternatively, there is an 'unlicensed spectrum' available under 00016 * the unknownEGID. You can send out events from that generator just 00017 * like any other, but it should only be used for quick tests and hacking 00018 * around... 00019 * 00020 * The SourceID is generator specific. A SID of @a i from the button 00021 * generator will refer to a particular button, whereas a SID from vision 00022 * refers to seeing a particular object. These SIDs are usually defined 00023 * in the generators themselves. See the EventGeneratorID_t list for 00024 * links to the generators. 00025 * 00026 * The duration field is also generator specific - some may refer to 00027 * the time since the last activation event (e.g. button events) where 00028 * as others refer to time since last status (e.g. sensors updates) 00029 * 00030 */ 00031 class EventBase : public LoadSave { 00032 public: 00033 //! Lists all possible event generator ids 00034 /*! An event generator is a abstract source of events, used for listening to and parsing certain classes of events 00035 * 00036 * IF YOU ADD AN EVENT GENERATOR, DON'T FORGET TO NAME IT (EventBase::EventGeneratorNames, below)*/ 00037 enum EventGeneratorID_t { 00038 unknownEGID=0, //!< 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 00039 visionEGID, //!< vision processing from camera 00040 buttonEGID, //!< button up, down, and still down, @see ButtonSourceID::ButtonSourceID_t 00041 worldModelEGID, //!< not being used, yet (for when objects are detected/lost?) 00042 aiEGID, //!< not being used, yet (might use this when AI makes decisions?) 00043 audioEGID, //!< Sends an event when a sound starts/ends playback, status events as chained sounds end 00044 sensorEGID, //!< currently only used to alert of new sensor readings, may also want to generate IR proximity warnings? @see SensorSourceID::SensorSourceID_t 00045 powerEGID, //!< used to generate low power warnings, temperature, etc. @see PowerSourceID::PowerSourceID_t 00046 timerEGID, //!< EGID from which timers are sent, you set timers, but you don't have to also listen @see EventRouter::setTimer() 00047 stateMachineEGID, //!< Sends an event upon entering and leaving a StateNode. 00048 locomotionEGID, //!< Sends events regarding transportation in the world; you can/should assume these will all be LocomotionEvent classes 00049 textmsgEGID, //!< Sends events when a text msg is received on console 00050 estopEGID, //!< Sends an event when the estop is turned on or off 00051 motmanEGID, //!< Sends events when a MotionCommand is added or removed 00052 wmVarEGID, //!< Sends an event when a watched memory is changed; source id is pointer to WMEntry 00053 numEGIDs //!< the number of generators available 00054 }; 00055 00056 //! Holds string versions of each of the generator's names, handy for debugging so you can output the events as readable strings 00057 static const char* const EventGeneratorNames[numEGIDs]; 00058 00059 //! 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) 00060 enum EventTypeID_t { 00061 activateETID, //!< e.g. button down 00062 statusETID, //!< e.g. button still down 00063 deactivateETID, //!< e.g. button up 00064 numETIDs //!< the number of different event types 00065 }; 00066 00067 /*! @name Constructors/Destructors */ 00068 //! constructor 00069 /*! @see EventRouter::postEvent() */ 00070 EventBase(); 00071 EventBase(EventGeneratorID_t gid, unsigned int sid, EventTypeID_t tid, unsigned int dur=0); 00072 EventBase(EventGeneratorID_t gid, unsigned int sid, EventTypeID_t tid, unsigned int dur, const std::string& n, float mag); 00073 virtual ~EventBase() {} //!< destructor 00074 //@} 00075 00076 /*! @name Methods */ 00077 virtual const std::string& getName() const { return stim_id; } //!< gets the name of the event - useful for debugging, outputs 00078 virtual EventBase& setName(const std::string& n) { nameisgen=false; stim_id=n; return *this; } //!< sets name to a given string, prevents overwriting by generated names 00079 00080 virtual float getMagnitude() const { return magnitude; } //!< gets "strength" of event - you might have useful values... used by AI 00081 virtual EventBase& setMagnitude(float m) { magnitude=m; return *this; }//!< sets "strength" of event - but you might have useful values... used by AI 00082 00083 virtual unsigned int getTimeStamp() const { return timestamp; } //!< time event was created 00084 00085 virtual EventGeneratorID_t getGeneratorID() const { return genID; } /*!< @brief gets the generator ID for this event @see EventGeneratorID_t */ 00086 virtual EventBase& setGeneratorID(EventGeneratorID_t gid) { genID=gid; genName(); return *this; } /*!< @brief sets the generator ID for this event @see EventGeneratorID_t */ 00087 00088 virtual unsigned int getSourceID() const { return sourceID; } /*!< @brief gets the source ID for this event @see sourceID */ 00089 virtual EventBase& setSourceID(unsigned int gid) { sourceID=gid; genName(); return *this; } /*!< @brief sets the source ID for this event @see sourceID */ 00090 00091 virtual EventTypeID_t getTypeID() const { return typeID; } /*!< @brief gets the type ID @see EventTypeID_t */ 00092 virtual EventBase& setTypeID(EventTypeID_t tid) { typeID=tid; genName(); return *this; } /*!< @brief sets the type ID @see EventTypeID_t */ 00093 00094 virtual unsigned int getDuration() const { return duration; } /*!< @brief OPTIONAL gets the time since the beginning of this sequence (the timestamp of the activate event) @see duration */ 00095 virtual EventBase& setDuration(unsigned int d) { duration = d; return *this; }/*!< @brief OPTIONAL gets the time since the beginning of this sequence (the timestamp of the activate event) @see duration */ 00096 00097 virtual const std::string& resetName() { nameisgen=true; genName(); return stim_id; } //!< resets name to generated form, overwriting any previous name 00098 virtual bool isCustomName() const { return !nameisgen; } //!< returns true if not using the generated name 00099 00100 inline bool operator<(const EventBase& e) const { return timestamp<e.timestamp; } 00101 00102 //! is true if the genID, typeID, and sourceID's all match 00103 virtual bool operator==(const EventBase& eb) const { 00104 return (sourceID==eb.sourceID && genID==eb.genID && typeID==eb.typeID); 00105 } 00106 //!tests to see if events have the same generator and source IDs 00107 bool sameGenSource(const EventBase eb) const { return genID==eb.genID && sourceID==eb.sourceID; } 00108 00109 bool longerThan(const EventBase eb) const { return duration>eb.duration && operator==(eb); } //!< compares event duration and ensures same event generator, source, and type - useful for event masks 00110 bool shorterThan(const EventBase eb) const { return duration<eb.duration && operator==(eb); }//!< compares event duration and ensures same event generator, source, and type - useful for event masks 00111 bool equalOrLongerThan(const EventBase eb) const { return duration>=eb.duration && operator==(eb); }//!< compares event duration and ensures same event generator, source, and type - useful for event masks 00112 bool equalOrShorterThan(const EventBase eb) const { return duration<=eb.duration && operator==(eb); }//!< compares event duration and ensures same event generator, source, and type - useful for event masks 00113 //@} 00114 00115 //! Useful for serializing events to send between processes 00116 /*! @name LoadSave interface */ 00117 virtual unsigned int getBinSize() const; 00118 virtual unsigned int LoadBuffer(const char buf[], unsigned int len); 00119 virtual unsigned int SaveBuffer(char buf[], unsigned int len) const; 00120 //@} 00121 protected: 00122 std::string stim_id; //!< the name of the event, use the same name consistently or else will be seen as different stimuli 00123 float magnitude; //!< the current "strength" of the event/stimuli... MAKE SURE this gets set to ZERO IF event is DEACTIVATE 00124 unsigned int timestamp; //!< the time the event was created - set automatically by constructor 00125 00126 bool nameisgen; //!< tracks whether the current name (stim_id) is generated or set 00127 virtual void genName(); //!< This does the actual generation of names based on genID, sourceID, and typeID 00128 00129 EventGeneratorID_t genID; //!< generator ID, @see EventGeneratorID_t 00130 EventTypeID_t typeID; //!< type ID, @see EventTypeID_t 00131 unsigned int sourceID; /*!< @brief the source ID for this event 00132 * Source IDs are defined by the generator that made it. This should 00133 * give authors flexibility to design their modules without having to 00134 * worry about ID space collision */ 00135 unsigned int duration; /*!< @brief the time since this sequence started (like, how long the button has been pressed) 00136 * ideally, this would be 0 for activate, (activate.timestamp-get_time()) for status and deactivate */ 00137 }; 00138 00139 /*! @file 00140 * @brief Describes EventBase, the basic class for sending events around the system 00141 * @author ejt (Creator) 00142 * 00143 * $Author: ejt $ 00144 * $Name: tekkotsu-1_5 $ 00145 * $Revision: 1.14 $ 00146 * $State: Rel $ 00147 * $Date: 2003/10/07 01:00:28 $ 00148 */ 00149 00150 #endif
|
Tekkotsu v1.5 |
Generated Fri Oct 10 15:51:58 2003 by Doxygen 1.3.4 |