17 #ifndef _CALLBACKHELPER_HH_
18 #define _CALLBACKHELPER_HH_
20 #include <google/protobuf/message.h>
21 #include <boost/function.hpp>
22 #include <boost/shared_ptr.hpp>
54 public:
virtual std::string
GetMsgType()
const;
59 public:
virtual bool HandleData(
const std::string &_newdata) = 0;
69 public:
virtual bool IsLocal()
const = 0;
77 public:
unsigned int GetId()
const;
84 private:
static unsigned int idCounter;
87 private:
unsigned int id;
104 void (
const boost::shared_ptr<M const> &)> &_cb,
105 bool _latching =
false)
121 google::protobuf::Message *m;
122 if ((m = dynamic_cast<google::protobuf::Message*>(&test))
124 gzthrow(
"Message type must be a google::protobuf type\n");
125 return m->GetTypeName();
131 boost::shared_ptr<M> m(
new M);
132 m->ParseFromString(_newdata);
140 this->callback(boost::dynamic_pointer_cast<M>(_newMsg));
150 private: boost::function<void (const boost::shared_ptr<M const> &)>
165 const boost::function<
void (
const std::string &)> &_cb,
166 bool _latching =
false)
180 this->callback(_newdata);
188 _newMsg->SerializeToString(&data);
189 this->callback(data);
200 private: boost::function<void (const std::string &)> callback;