Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

DriverMessaging.cc

Go to the documentation of this file.
00001 #include "DriverMessaging.h"
00002 
00003 using namespace std; 
00004 
00005 namespace DriverMessaging {
00006   
00007   typedef std::map<const char* const, std::set<Listener*> > listeners_t;
00008   listeners_t listeners;
00009 
00010   const char* const LoadPrediction::NAME="LoadPrediction";
00011   const char* const SensorPriority::NAME="SensorPriority";
00012   const char* const FixedPoints::NAME="FixedPoints";
00013 
00014   Message::~Message() {}
00015 
00016   void addListener(Listener* l, const char* const t) {
00017     listeners[t].insert(l);
00018   }
00019   
00020   void removeListener(Listener* l, const char* const t) {
00021     listeners[t].erase(l);
00022   }
00023   
00024   void removeListener(Listener* l) {
00025     for(listeners_t::iterator it=listeners.begin(); it!=listeners.end(); ++it)
00026       it->second.erase(l);
00027   }
00028   
00029   bool hasListener(const char* const t) {
00030     return (listeners[t].size() > 0);
00031   }
00032   
00033   void postMessage(const Message& d) {
00034     std::set<Listener*>& live = listeners[d.CLASS_NAME]; // reference to 'live' listener list so we don't have to re-do the map lookup
00035     std::set<Listener*> ls = live; // make a copy so listeners can come and go during processing
00036     for(std::set<Listener*>::const_iterator it=ls.begin(); it!=ls.end(); ++it) {
00037       if(live.find(*it)!=live.end()) {
00038         (*it)->processDriverMessage(d);
00039       }
00040     }
00041   }
00042 }
00043 
00044 /*! @file
00045  * @brief 
00046  * @author Ethan Tira-Thompson (ejt) (Creator)
00047  */

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