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;
std::string GetMsgType() const
Get the typename of the message that is handled.
Definition: CallbackHelper.hh:185
virtual bool HandleData(const std::string &_newdata, boost::function< void(uint32_t)> _cb, uint32_t _id)
Process new incoming data.
Definition: CallbackHelper.hh:191
virtual bool IsLocal() const
Is the callback local?
Definition: CallbackHelper.hh:158
virtual bool HandleMessage(MessagePtr _newMsg)
Process new incoming message.
Definition: CallbackHelper.hh:151
A helper class to handle callbacks when messages arrive.
Definition: CallbackHelper.hh:43
#define gzthrow(msg)
This macro logs an error to the throw stream and throws an exception that contains the file name and ...
Definition: Exception.hh:39
Forward declarations for transport.
Callback helper Template.
Definition: CallbackHelper.hh:107
virtual bool IsLocal() const
Is the callback local?
Definition: CallbackHelper.hh:211
std::string GetMsgType() const
Get the typename of the message that is handled.
Definition: CallbackHelper.hh:128
CallbackHelperT(const boost::function< void(const boost::shared_ptr< M const > &)> &_cb, bool _latching=false)
Constructor.
Definition: CallbackHelper.hh:113
boost::shared_ptr< google::protobuf::Message > MessagePtr
Definition: TransportTypes.hh:45
#define NULL
Definition: CommonTypes.hh:30
RawCallbackHelper(const boost::function< void(const std::string &)> &_cb, bool _latching=false)
Constructor.
Definition: CallbackHelper.hh:177
virtual bool HandleMessage(MessagePtr _newMsg)
Process new incoming message.
Definition: CallbackHelper.hh:201
virtual bool HandleData(const std::string &_newdata, boost::function< void(uint32_t)> _cb, uint32_t _id)
Process new incoming data.
Definition: CallbackHelper.hh:139
Used to connect publishers to subscribers, where the subscriber wants the raw data from the publisher...
Definition: CallbackHelper.hh:171
boost::shared_ptr< CallbackHelper > CallbackHelperPtr
boost shared pointer to transport::CallbackHelper
Definition: CallbackHelper.hh:101
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
bool latching
True means that the callback helper will get the last published message on the topic.
Definition: CallbackHelper.hh:91