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

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:38 2016 by Doxygen 1.6.3