Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

EventGeneratorBase.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_EventGeneratorBase_h_
00003 #define INCLUDED_EventGeneratorBase_h_
00004 
00005 #include "Behaviors/BehaviorBase.h"
00006 
00007 //! A simple convenience class for event generators
00008 /*! Note that you don't need to inherit from this class to be able to
00009  *  send events!  Any code can send any event any time, just by calling 
00010  *  one of the EventRouter::postEvent() functions.
00011  *  
00012  *  Uses a BehaviorBase base class so that you can start and stop it.
00013  *
00014  *  Allows variable settings of the generator id and source id for
00015  *  outgoing events as well as automatic handling of
00016  *  listening/unlistening for a single optional event source.  If you
00017  *  want something more fancy that that though, you'll have to
00018  *  override DoStart/DoStop yourself. (or extend/modify this class...)
00019  *
00020  */
00021 class EventGeneratorBase : public BehaviorBase {
00022 public:
00023   // Constructors are all protected - doesn't make sense to
00024   // instantiate this class directly, you want to use a subclass
00025 
00026   //! destructor - does nothing
00027   virtual ~EventGeneratorBase() {}
00028   
00029   virtual void DoStart();
00030   
00031   virtual void DoStop();
00032   
00033   //! if autolistening, will receive EventRouter events concerning our own listeners
00034   /*! This will automatically reduce overhead by eliminating chains of events thrown
00035    *  that don't have any end listeners.  However, this might mean your subclass's
00036    *  processEvent will be receiving the events from erouterEGID, and will need
00037    *  to call EventGeneratorBase::processEvent() in order to allow them to be used */
00038   virtual void processEvent(const EventBase& event);
00039   
00040 
00041   //! These concern the events which will be thrown to listeners
00042   //!@name Downstream Settings
00043 
00044   //! return the generator ID that will be broadcast from
00045   virtual EventBase::EventGeneratorID_t getGeneratorID() const { return myGenID; }
00046   //! set the generator ID that will be broadcast from (typically it's a bad idea to call this...)
00047   virtual void setGeneratorID(EventBase::EventGeneratorID_t gid) { myGenID=gid; }
00048 
00049   //! return the source ID that will be broadcast on
00050   virtual unsigned int getSourceID() const { return mySourceID; }
00051   //! set the source ID that will be broadcast on
00052   virtual void setSourceID(unsigned int sid) { mySourceID=sid; }
00053 
00054   //! return true if this generator has listeners
00055   virtual bool hasListeners() const;
00056   //@}
00057 
00058 
00059   //! These help select which events will be received from other generators
00060   //!@name Upstream Settings
00061 
00062   //! lets you specify what level of filtering should be done
00063   enum specificity_t {
00064     GENERATOR, //!< only the generator needs to match, select all sources and types
00065     SOURCE,    //!< both generator and source need to match, select all types
00066     TYPE       //!< explicit event tuple; generator, source, and type must all match
00067   };
00068   //! returns the current specificity level, to modify this, call the appropriate version of setAutoListen()
00069   virtual specificity_t getSpecificity() const { return specificity; }
00070 
00071   //! turns on auto listening to make it easier to set up dependancies between vision filters
00072   virtual void setAutoListen(EventBase::EventGeneratorID_t gid);
00073   //! turns on auto listening to make it easier to set up dependancies between vision filters
00074   virtual void setAutoListen(EventBase::EventGeneratorID_t gid, unsigned int sid);
00075   //! turns on auto listening to make it easier to set up dependancies between vision filters
00076   virtual void setAutoListen(EventBase::EventGeneratorID_t gid, unsigned int sid, EventBase::EventTypeID_t tid);
00077   //! turns off auto listening
00078   virtual void unsetAutoListen();
00079 
00080   //! returns the generator ID that will be listened for (not the generator of the FilterBankEvent to be created - that depends on the subclass)
00081   virtual EventBase::EventGeneratorID_t getListenGeneratorID() const { return srcGenID; }
00082   //! returns the source ID that will be listened for (not the source of the FilterBankEvent to be created - that depends on the subclass)
00083   virtual unsigned int getListenSourceID() const { return srcSourceID; }
00084   //! returns the type ID that will be listened for (not the type of the FilterBankEvent to be created - that depends on the subclass)
00085   virtual EventBase::EventTypeID_t getListenTypeID() const { return srcTypeID; }
00086 
00087   //@}
00088 
00089 protected:
00090   //!@name Constructors
00091   //!
00092   EventGeneratorBase(const std::string& classname, const std::string& instancename, EventBase::EventGeneratorID_t mgid, unsigned int msid)
00093     : BehaviorBase(classname,instancename), myGenID(mgid), mySourceID(msid), autoListen(false), isListening(false), srcGenID(EventBase::numEGIDs), srcSourceID(), srcTypeID(), specificity()
00094   {}
00095   EventGeneratorBase(const std::string& classname, const std::string& instancename, EventBase::EventGeneratorID_t mgid, unsigned int msid,EventBase::EventGeneratorID_t srcgid)
00096     : BehaviorBase(classname,instancename), myGenID(mgid), mySourceID(msid), autoListen(srcgid!=EventBase::numEGIDs), isListening(false), srcGenID(srcgid), srcSourceID(), srcTypeID(), specificity(GENERATOR)
00097   {}
00098   EventGeneratorBase(const std::string& classname, const std::string& instancename, EventBase::EventGeneratorID_t mgid, unsigned int msid,EventBase::EventGeneratorID_t srcgid, unsigned int srcsid)
00099     : BehaviorBase(classname,instancename), myGenID(mgid), mySourceID(msid), autoListen(srcgid!=EventBase::numEGIDs), isListening(false), srcGenID(srcgid), srcSourceID(srcsid), srcTypeID(), specificity(SOURCE)
00100   {}
00101   EventGeneratorBase(const std::string& classname, const std::string& instancename, EventBase::EventGeneratorID_t mgid, unsigned int msid,EventBase::EventGeneratorID_t srcgid, unsigned int srcsid, EventBase::EventTypeID_t srctype)
00102     : BehaviorBase(classname,instancename), myGenID(mgid), mySourceID(msid), autoListen(srcgid!=EventBase::numEGIDs), isListening(false), srcGenID(srcgid), srcSourceID(srcsid), srcTypeID(srctype), specificity(TYPE)
00103   {}
00104   //@}
00105 
00106   //! subscribe this generator to its source
00107   virtual void addSrcListener();
00108 
00109   //! unsubscribe this generator from its source
00110   virtual void removeSrcListener();
00111 
00112   EventBase::EventGeneratorID_t myGenID; //!< the generator ID to broadcast on
00113   unsigned int mySourceID;     //!< the source ID to broadcast on
00114   bool autoListen;          //!< if true, will automatically start listening for EventBase(genID,sourceID) events
00115   bool isListening;         //!< true if listening triggered by autoListen
00116   EventBase::EventGeneratorID_t srcGenID; //!< the generator ID to listen for (typically the source that this filter works on)
00117   unsigned int srcSourceID;    //!< the source ID to listen for
00118   EventBase::EventTypeID_t srcTypeID; //!< the type ID to listen for
00119   specificity_t specificity; //!< the level of event specificity that is being listened for, so when #autoListen is triggered, we can subscribe to the right level of event stream
00120 };
00121 
00122 /*! @file
00123  * @brief 
00124  * @author ejt (Creator)
00125  *
00126  * $Author: ejt $
00127  * $Name: tekkotsu-2_4_1 $
00128  * $Revision: 1.10 $
00129  * $State: Exp $
00130  * $Date: 2005/08/07 04:11:03 $
00131  */
00132 
00133 #endif

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:46 2005 by Doxygen 1.4.4