DriverMessaging.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_DriverMessaging_h_
00003 #define INCLUDED_DriverMessaging_h_
00004
00005 #include "Shared/plistCollections.h"
00006 #include "Shared/plistSpecialty.h"
00007 #include <string>
00008 #include <set>
00009 #include <map>
00010
00011
00012
00013
00014 namespace DriverMessaging {
00015
00016 class Message;
00017
00018
00019
00020
00021 class Listener {
00022 public:
00023
00024 virtual ~Listener() {}
00025
00026
00027 virtual void processDriverMessage(const Message& d)=0;
00028 };
00029
00030
00031 void addListener(Listener* l, const char* const t);
00032
00033
00034 void removeListener(Listener* l, const char* const t);
00035
00036
00037 void removeListener(Listener* l);
00038
00039
00040 bool hasListener(const char* const t);
00041
00042
00043
00044 void postMessage(const Message& d);
00045
00046
00047
00048
00049
00050 class Message : public virtual LoadSave {
00051 protected:
00052
00053
00054 explicit Message(const char* const className) : LoadSave(), CLASS_NAME(className) {}
00055
00056 public:
00057
00058
00059 const char* const CLASS_NAME;
00060
00061
00062 Message(const Message& m) : LoadSave(), CLASS_NAME(m.CLASS_NAME) {}
00063
00064
00065 Message& operator=(const Message& m) { return *this; }
00066
00067
00068 virtual ~Message()=0;
00069 };
00070
00071
00072
00073 class LoadPrediction : public Message, public virtual plist::Dictionary {
00074 public:
00075
00076 LoadPrediction() : Message(NAME), loads() {
00077 addEntry("Loads",loads);
00078 setLoadSavePolicy(FIXED,SYNC);
00079 }
00080
00081
00082 plist::DictionaryOf<plist::Primitive<float> > loads;
00083 static const char* const NAME;
00084 };
00085
00086
00087
00088 class SensorPriority : public Message, public virtual plist::Dictionary {
00089 public:
00090
00091 SensorPriority() : Message(NAME), outputs(), buttons(), sensors() {
00092 addEntry("Outputs",outputs);
00093 addEntry("Buttons",buttons);
00094 addEntry("Sensors",sensors);
00095 setLoadSavePolicy(FIXED,SYNC);
00096 }
00097 plist::DictionaryOf<plist::Primitive<float> > outputs;
00098 plist::DictionaryOf<plist::Primitive<float> > buttons;
00099 plist::DictionaryOf<plist::Primitive<float> > sensors;
00100 static const char* const NAME;
00101 };
00102
00103 class ContactPoint : public virtual plist::Dictionary {
00104 public:
00105 ContactPoint() : plist::Dictionary(), frame(), point() { init(); }
00106 template<typename T> ContactPoint(unsigned int offset, const T& p) : plist::Dictionary(), frame(offset), point(p) { init(); }
00107 ContactPoint(unsigned int offset, float x, float y, float z) : plist::Dictionary(), frame(offset), point(x,y,z) { init(); }
00108 plist::OutputSelector frame;
00109 plist::Point point;
00110 protected:
00111 void init() {
00112 addEntry("Frame",frame);
00113 addEntry("Point",point);
00114 frame.setRange(0,-1U);
00115 setLoadSavePolicy(FIXED,SYNC);
00116 }
00117 };
00118
00119
00120 class FixedPoints : public Message, public virtual plist::ArrayOf<ContactPoint> {
00121 public:
00122
00123 FixedPoints() : Message(NAME), flushOnMotionUpdate(true) { setLoadSavePolicy(SYNC,SYNC); }
00124
00125
00126 template<typename T> void addEntry(unsigned int frame, const T& p) {
00127 addEntry(new ContactPoint(frame, p));
00128 }
00129
00130 void addEntry(unsigned int frame, float x, float y, float z) {
00131 addEntry(new ContactPoint(frame, x,y,z));
00132 }
00133 using plist::ArrayOf<ContactPoint>::addEntry;
00134
00135 bool flushOnMotionUpdate;
00136 static const char* const NAME;
00137 };
00138 };
00139
00140
00141
00142
00143
00144
00145 #endif