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;
62 public:
virtual bool HandleData(
const std::string &_newdata,
63 boost::function<
void(uint32_t)> _cb, uint32_t _id) = 0;
73 public:
virtual bool IsLocal()
const = 0;
81 public:
unsigned int GetId()
const;
88 private:
static unsigned int idCounter;
91 private:
unsigned int id;
108 void (
const boost::shared_ptr<M const> &)> &_cb,
109 bool _latching =
false)
125 google::protobuf::Message *m;
126 if ((m = dynamic_cast<google::protobuf::Message*>(&test))
128 gzthrow(
"Message type must be a google::protobuf type\n");
129 return m->GetTypeName();
134 boost::function<
void(uint32_t)> _cb, uint32_t _id)
136 boost::shared_ptr<M> m(
new M);
137 m->ParseFromString(_newdata);
147 this->callback(boost::dynamic_pointer_cast<M>(_newMsg));
157 private: boost::function<void (const boost::shared_ptr<M const> &)>
172 const boost::function<
void (
const std::string &)> &_cb,
173 bool _latching =
false)
186 boost::function<
void(uint32_t)> _cb, uint32_t _id)
188 this->callback(_newdata);
198 _newMsg->SerializeToString(&data);
199 this->callback(data);
210 private: boost::function<void (const std::string &)> callback;