Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

EventGeneratorBase.cc

Go to the documentation of this file.
00001 #include "EventGeneratorBase.h"
00002 #include "Events/EventRouter.h"
00003 
00004 using namespace std;
00005 
00006 void
00007 EventGeneratorBase::doStart() {
00008   BehaviorBase::doStart();
00009   if(autoListen && getGeneratorID()!=EventBase::numEGIDs) {
00010     erouter->addListener(this,EventBase::erouterEGID,getGeneratorID());
00011     if(hasListeners())
00012       addSrcListener();
00013   }
00014 }
00015 
00016 void
00017 EventGeneratorBase::doStop() {
00018   erouter->removeListener(this);
00019   isListening=false;
00020   BehaviorBase::doStop();
00021 }
00022 
00023 void
00024 EventGeneratorBase::processEvent(const EventBase& ev) {
00025   if(!autoListen || getGeneratorID()==EventBase::numEGIDs) {
00026     BehaviorBase::processEvent(ev);
00027     return;
00028   }
00029   if(ev.getGeneratorID()!=EventBase::erouterEGID) {
00030     BehaviorBase::processEvent(ev); // trap erouter events for ourselves
00031   } else {
00032     if(hasListeners()) {
00033       addSrcListener();
00034     } else {
00035       removeSrcListener();
00036     }
00037   }
00038 }
00039 
00040 void
00041 EventGeneratorBase::setAutoListen(EventBase::EventGeneratorID_t gid) {
00042   removeSrcListener();
00043   autoListen=true;
00044   srcGenID=gid;
00045   specificity=GENERATOR;
00046   if(gid==EventBase::numEGIDs) {
00047     autoListen=false;
00048     return;
00049   }
00050   if(isActive())
00051     erouter->addListener(this,EventBase::erouterEGID,getGeneratorID());
00052   if(hasListeners())
00053     addSrcListener();
00054 }
00055 
00056 void
00057 EventGeneratorBase::setAutoListen(EventBase::EventGeneratorID_t gid, size_t sid) {
00058   removeSrcListener();
00059   autoListen=true;
00060   srcGenID=gid;
00061   srcSourceID=sid;
00062   specificity=SOURCE;
00063   if(gid==EventBase::numEGIDs) {
00064     autoListen=false;
00065     return;
00066   }
00067   if(isActive())
00068     erouter->addListener(this,EventBase::erouterEGID,getGeneratorID());
00069   if(hasListeners())
00070     addSrcListener();
00071 }
00072 
00073 void
00074 EventGeneratorBase::setAutoListen(EventBase::EventGeneratorID_t gid, size_t sid, EventBase::EventTypeID_t tid) {
00075   removeSrcListener();
00076   autoListen=true;
00077   srcGenID=gid;
00078   srcSourceID=sid;
00079   srcTypeID=tid;
00080   specificity=TYPE;
00081   if(gid==EventBase::numEGIDs || tid==EventBase::numETIDs) {
00082     autoListen=false;
00083     return;
00084   }
00085   if(isActive())
00086     erouter->addListener(this,EventBase::erouterEGID,getGeneratorID());
00087   if(hasListeners())
00088     addSrcListener();
00089 }
00090 
00091 void
00092 EventGeneratorBase::unsetAutoListen() {
00093   removeSrcListener();
00094   autoListen=false;
00095 }
00096 
00097 bool
00098 EventGeneratorBase::hasListeners() const {
00099   return erouter->hasListeners(getGeneratorID(),getSourceID());
00100 }
00101 
00102 void
00103 EventGeneratorBase::addSrcListener() {
00104   if(isListening || getListenGeneratorID()==EventBase::numEGIDs)
00105     return;
00106   isListening=true;
00107   switch(specificity) {
00108   case GENERATOR:
00109     erouter->addListener(this,getListenGeneratorID());
00110     break;
00111   case SOURCE:
00112     erouter->addListener(this,getListenGeneratorID(),getListenSourceID());
00113     break;
00114   case TYPE:
00115     if(getListenTypeID()==EventBase::numETIDs)
00116       return;
00117     erouter->addListener(this,getListenGeneratorID(),getListenSourceID(),getListenTypeID());
00118     break;
00119   }
00120 }
00121 
00122 void
00123 EventGeneratorBase::removeSrcListener() {
00124   if(!isListening)
00125     return;
00126   isListening=false;
00127   switch(specificity) {
00128   case GENERATOR:
00129     erouter->removeListener(this,getListenGeneratorID());
00130     break;
00131   case SOURCE:
00132     erouter->removeListener(this,getListenGeneratorID(),getListenSourceID());
00133     break;
00134   case TYPE:
00135     erouter->removeListener(this,getListenGeneratorID(),getListenSourceID(),getListenTypeID());
00136     break;
00137   }
00138 }
00139 
00140 
00141 
00142 /*! @file
00143  * @brief 
00144  * @author ejt (Creator)
00145  */
00146 

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