18 #ifndef GZ_TRANSPORT_SUBSCRIPTIONHANDLER_HH_
19 #define GZ_TRANSPORT_SUBSCRIPTIONHANDLER_HH_
23 #pragma warning(disable: 4251)
25 #include <google/protobuf/message.h>
26 #include <google/protobuf/stubs/common.h>
27 #if GOOGLE_PROTOBUF_VERSION >= 3000000 && GOOGLE_PROTOBUF_VERSION < 4022000
28 #include <google/protobuf/stubs/casts.h>
40 #include <gz/msgs/Factory.hh>
42 #include "gz/transport/config.hh"
43 #include "gz/transport/Export.hh"
54 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
86 protected:
bool UpdateThrottling();
99 #pragma warning(disable: 4251)
139 public:
virtual bool RunLocalCallback(
172 auto msgPtr = std::make_shared<T>();
175 if (!msgPtr->ParseFromString(_data))
177 std::cerr <<
"SubscriptionHandler::CreateMsg() error: ParseFromString"
187 return T().GetTypeName();
204 std::cerr <<
"SubscriptionHandler::RunLocalCallback() error: "
210 if (!this->UpdateThrottling())
213 #if GOOGLE_PROTOBUF_VERSION >= 4022000
214 auto msgPtr = google::protobuf::internal::DownCast<const T*>(&_msg);
215 #elif GOOGLE_PROTOBUF_VERSION >= 3000000
216 auto msgPtr = google::protobuf::down_cast<const T*>(&_msg);
218 auto msgPtr = google::protobuf::internal::down_cast<const T*>(&_msg);
221 this->cb(*msgPtr, _info);
248 const google::protobuf::Descriptor *desc =
249 google::protobuf::DescriptorPool::generated_pool()
250 ->FindMessageTypeByName(_type);
256 msgPtr.
reset(google::protobuf::MessageFactory::generated_factory()
257 ->GetPrototype(desc)->New());
262 msgPtr = gz::msgs::Factory::New(_type);
269 if (!msgPtr->ParseFromString(_data))
298 std::cerr <<
"SubscriptionHandler::RunLocalCallback() "
299 <<
"error: Callback is NULL" <<
std::endl;
304 if (!this->UpdateThrottling())
307 this->cb(_msg, _info);
337 public:
void SetCallback(
const RawCallback &_callback);
345 public:
bool RunRawCallback(
const char *_msgData,
const size_t _size,
351 private:
class Implementation;
356 #pragma warning(push)
357 #pragma warning(disable: 4251)