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>
55 public:
virtual std::string GetMsgType()
const;
63 public:
virtual bool HandleData(
const std::string &_newdata,
64 boost::function<
void(uint32_t)> _cb, uint32_t _id) = 0;
69 public:
virtual bool HandleMessage(
MessagePtr _newMsg) = 0;
74 public:
virtual bool IsLocal()
const = 0;
78 public:
bool GetLatching()
const;
83 public:
void SetLatching(
bool _latch);
87 public:
unsigned int GetId()
const;
94 private:
static unsigned int idCounter;
97 private:
unsigned int id;
114 void (
const boost::shared_ptr<M const> &)> &_cb,
115 bool _latching =
false)
131 google::protobuf::Message *m;
132 if ((m = dynamic_cast<google::protobuf::Message*>(&test))
134 gzthrow(
"Message type must be a google::protobuf type\n");
135 return m->GetTypeName();
140 boost::function<
void(uint32_t)> _cb, uint32_t _id)
142 boost::shared_ptr<M> m(
new M);
143 m->ParseFromString(_newdata);
153 this->callback(boost::dynamic_pointer_cast<M>(_newMsg));
163 private: boost::function<void (const boost::shared_ptr<M const> &)>
178 const boost::function<
void (
const std::string &)> &_cb,
179 bool _latching =
false)
192 boost::function<
void(uint32_t)> _cb, uint32_t _id)
194 this->callback(_newdata);
204 _newMsg->SerializeToString(&data);
205 this->callback(data);
216 private: boost::function<void (const std::string &)> callback;