Gazebo Transport

API Reference

15.1.0
ISubscriptionHandler Class Referenceabstract

Interface class used to manage generic protobuf messages. More...

#include <SubscriptionHandler.hh>

Public Types

using MsgFactory = std::function< std::shared_ptr< ProtoMsg >(const char *_data, std::size_t _size, const std::string &_type)>
 Function type that deserializes a raw buffer into a message.
 

Public Member Functions

 ISubscriptionHandler (const std::string &_pUuid, const std::string &_nUuid, const SubscribeOptions &_opts=SubscribeOptions())
 Constructor.
 
virtual ~ISubscriptionHandler ()=default
 Destructor.
 
virtual const std::shared_ptr< ProtoMsg > CreateMsg (const std::string &_data, const std::string &_type) const =0
 Create a specific protobuf message given its serialized data.
 
const std::shared_ptr< ProtoMsg > CreateMsgFromBuffer (const char *_data, std::size_t _size, const std::string &_type) const
 Create a protobuf message from a raw buffer. Avoids a string copy compared to CreateMsg when the data already lives in a contiguous buffer (e.g. Zenoh SHM). Dispatches to the deserializer registered with SetMsgFactory(); when none was registered (e.g. a handler compiled against older headers), falls back to a string copy + the virtual CreateMsg. Deliberately non-virtual: a new virtual function would change the vtable layout and break ABI within a major release.
 
virtual bool RunLocalCallback (const ProtoMsg &_msg, const MessageInfo &_info)=0
 Executes the local callback registered for this handler.
 
- Public Member Functions inherited from SubscriptionHandlerBase
 SubscriptionHandlerBase (const std::string &_pUuid, const std::string &_nUuid, const SubscribeOptions &_opts=SubscribeOptions())
 Constructor.
 
virtual ~SubscriptionHandlerBase ()
 Destructor.
 
std::string HandlerUuid () const
 Get the unique UUID of this handler.
 
bool IgnoreLocalMessages () const
 Return whether local messages are ignored or not.
 
std::string NodeUuid () const
 Get the node UUID.
 
std::string ProcUuid () const
 Get the process UUID.
 
virtual std::string TypeName ()=0
 Get the type of the messages from which this subscriber handler is subscribed.
 

Protected Member Functions

void SetMsgFactory (MsgFactory _factory)
 Register the deserializer used by CreateMsgFromBuffer(). Concrete handlers call this on construction. A CreateMsg override may only delegate to CreateMsgFromBuffer() when a factory has been registered; otherwise the fallback path would recurse.
 
- Protected Member Functions inherited from SubscriptionHandlerBase
bool UpdateThrottling ()
 Check if message subscription is throttled. If so, verify whether the callback should be executed or not.
 

Additional Inherited Members

- Protected Attributes inherited from SubscriptionHandlerBase
std::unique_ptr< SubscriptionHandlerBasePrivate > dataPtr
 Private data.
 
SubscribeOptions opts
 Subscribe options.
 
double periodNs
 If throttling is enabled, the minimum period for receiving a message in nanoseconds.
 

Detailed Description

Interface class used to manage generic protobuf messages.

gz/transport/SubscriptionHandler.hh

This extends SubscriptionHandlerBase by defining virtual functions for deserializing protobuf message data, and for receiving deserialized messages. Those functions are not needed by the RawSubscriptionHandler class.

Member Typedef Documentation

◆ MsgFactory

using MsgFactory = std::function<std::shared_ptr<ProtoMsg>( const char *_data, std::size_t _size, const std::string &_type)>

Function type that deserializes a raw buffer into a message.

See also
SetMsgFactory

Constructor & Destructor Documentation

◆ ISubscriptionHandler()

ISubscriptionHandler ( const std::string &  _pUuid,
const std::string &  _nUuid,
const SubscribeOptions &  _opts = SubscribeOptions() 
)
explicit

Constructor.

Parameters
[in]_pUuidUUID of the process registering the handler.
[in]_nUuidUUID of the node registering the handler.
[in]_optsSubscription options.

◆ ~ISubscriptionHandler()

virtual ~ISubscriptionHandler ( )
virtualdefault

Destructor.

Member Function Documentation

◆ CreateMsg()

virtual const std::shared_ptr< ProtoMsg > CreateMsg ( const std::string &  _data,
const std::string &  _type 
) const
pure virtual

Create a specific protobuf message given its serialized data.

Parameters
[in]_dataThe serialized data.
[in]_typeThe data type.
Returns
Pointer to the specific protobuf message.

Implemented in SubscriptionHandler< T >, and SubscriptionHandler< ProtoMsg >.

◆ CreateMsgFromBuffer()

const std::shared_ptr< ProtoMsg > CreateMsgFromBuffer ( const char *  _data,
std::size_t  _size,
const std::string &  _type 
) const

Create a protobuf message from a raw buffer. Avoids a string copy compared to CreateMsg when the data already lives in a contiguous buffer (e.g. Zenoh SHM). Dispatches to the deserializer registered with SetMsgFactory(); when none was registered (e.g. a handler compiled against older headers), falls back to a string copy + the virtual CreateMsg. Deliberately non-virtual: a new virtual function would change the vtable layout and break ABI within a major release.

Parameters
[in]_dataPointer to the serialized data.
[in]_sizeNumber of bytes in _data.
[in]_typeThe data type.
Returns
Pointer to the specific protobuf message.

Referenced by SubscriptionHandler< T >::CreateMsg(), and SubscriptionHandler< ProtoMsg >::CreateMsg().

◆ RunLocalCallback()

virtual bool RunLocalCallback ( const ProtoMsg &  _msg,
const MessageInfo &  _info 
)
pure virtual

Executes the local callback registered for this handler.

Parameters
[in]_msgProtobuf message received.
[in]_infoMessage information (e.g.: topic name).
Returns
True when success, false otherwise.

Implemented in SubscriptionHandler< T >, and SubscriptionHandler< ProtoMsg >.

◆ SetMsgFactory()

void SetMsgFactory ( MsgFactory  _factory)
protected

Register the deserializer used by CreateMsgFromBuffer(). Concrete handlers call this on construction. A CreateMsg override may only delegate to CreateMsgFromBuffer() when a factory has been registered; otherwise the fallback path would recurse.

Parameters
[in]_factoryThe deserializer.

Referenced by SubscriptionHandler< T >::SubscriptionHandler(), and SubscriptionHandler< ProtoMsg >::SubscriptionHandler().


The documentation for this class was generated from the following file: