18 #ifndef __IGN_TRANSPORT_SUBSCRIPTIONHANDLER_HH_INCLUDED__ 19 #define __IGN_TRANSPORT_SUBSCRIPTIONHANDLER_HH_INCLUDED__ 22 #pragma warning(push, 0) 24 #include <google/protobuf/message.h> 50 : hUuid(
Uuid().ToString()),
63 public:
virtual bool RunLocalCallback(
69 public:
virtual const std::shared_ptr<transport::ProtoMsg> CreateMsg(
70 const std::string &_data)
const = 0;
75 public:
virtual std::string TypeName() = 0;
95 private: std::string nUuid;
112 public:
const std::shared_ptr<transport::ProtoMsg>
CreateMsg(
113 const std::string &_data)
const 116 auto msgPtr = std::make_shared<T>();
119 if (!msgPtr->ParseFromString(_data))
121 std::cerr <<
"SubscriptionHandler::CreateMsg() error: ParseFromString" 122 <<
" failed" << std::endl;
131 return T().GetTypeName();
137 public:
void SetCallback(
const std::function <
void(
const T &_msg)> &_cb)
148 #if GOOGLE_PROTOBUF_VERSION > 2999999 149 auto msgPtr = google::protobuf::down_cast<
const T*>(&_msg);
151 auto msgPtr = google::protobuf::internal::down_cast<
const T*>(&_msg);
159 std::cerr <<
"SubscriptionHandler::RunLocalCallback() error: " 160 <<
"Callback is NULL" << std::endl;
168 private: std::function<void(const T &_msg)> cb;
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:56
SubscriptionHandler(const std::string &_nUuid)
Definition: SubscriptionHandler.hh:106
const std::shared_ptr< transport::ProtoMsg > CreateMsg(const std::string &_data) const
Create a specific protobuf message given its serialized data.
Definition: SubscriptionHandler.hh:112
void SetCallback(const std::function< void(const T &_msg)> &_cb)
Set the callback for this handler.
Definition: SubscriptionHandler.hh:137
std::string hUuid
Unique handler's UUID.
Definition: SubscriptionHandler.hh:92
std::string NodeUuid() const
Get the node UUID.
Definition: SubscriptionHandler.hh:79
A portable class for representing a Universally Unique Identifier.
Definition: Uuid.hh:41
bool RunLocalCallback(const transport::ProtoMsg &_msg) const
Executes the local callback registered for this handler.
Definition: SubscriptionHandler.hh:143
google::protobuf::Message ProtoMsg
Definition: TransportTypes.hh:62
std::string TypeName()
Get the type of the messages from which this subscriber handler is subscribed.
Definition: SubscriptionHandler.hh:129
std::string HandlerUuid() const
Get the unique UUID of this handler.
Definition: SubscriptionHandler.hh:86
It creates a subscription handler for a specific protobuf message.
Definition: SubscriptionHandler.hh:102
Definition: AdvertiseOptions.hh:25
ISubscriptionHandler(const std::string &_nUuid)
Constructor.
Definition: SubscriptionHandler.hh:49
ignition/transport/SubscriptionHandler.hh
Definition: SubscriptionHandler.hh:45
virtual ~ISubscriptionHandler()
Destructor.
Definition: SubscriptionHandler.hh:56