Robot Raconteur Core C++ Library
Loading...
Searching...
No Matches
RobotRaconteur::PipeBroadcaster< T > Class Template Reference

Broadcaster to send packets to all connected clients. More...

#include <PipeMember.h>

Inheritance diagram for RobotRaconteur::PipeBroadcaster< T >:
RobotRaconteur::PipeBroadcasterBase

Public Member Functions

 PipeBroadcaster ()
 Construct a new PipeBroadcaster.
void Init (boost::shared_ptr< Pipe< T > > pipe, int32_t maximum_backlog=-1)
 Initialize the PipeBroadcaster.
void SendPacket (T packet)
 Send a packet to all connected pipe endpoint clients.
void AsyncSendPacket (T packet, boost::function< void()> handler)
 Asynchronously send packet to all connected pipe endpoint clients.
boost::shared_ptr< Pipe< T > > GetPipe ()
 Get the associated pipe.
boost::function< bool(const boost::shared_ptr< PipeBroadcasterBase > &, uint32_t, int32_t)> GetPredicate ()
 Get the current predicate callback function.
void SetPredicate (boost::function< bool(const boost::shared_ptr< PipeBroadcasterBase > &, uint32_t, int32_t)> f)
 Set the predicate callback function.
int32_t GetMaxBacklog ()
 Gets the currently configured maximum backlog.
void SetMaxBacklog (int32_t maximum_backlog)
 Set the maximum backlog.

Detailed Description

template<typename T>
class RobotRaconteur::PipeBroadcaster< T >

Broadcaster to send packets to all connected clients.

PipeBroadcaster is used by services to send packets to all connected client endpoints. It attaches to the pipe on the service side, and manages the lifecycle of connected endpoints. PipeBroadcaster should only be used with pipes that are declared readonly, since it has no provisions for receiving incoming packets from the client.

PipeBroadcaster is initialized by the user, or by default implementation classes generated by RobotRaconteurGen (_default_impl). Default implementation classes will automatically instantiate broadcasters for pipes marked *readonly. If default implementation classes are not used, the broadcaster must be instantiated manually. It is recommended this be done using the IRRServiceObject interface in the overridden IRRServiceObject::RRServiceObjectInit() function. This function is called after the pipes have been instantiated by the service.

Use SendPacket() or AsyncSendPacket() to broadcast packets to all connected clients.

PipeBroadcaster provides flow control by optionally tracking how many packets are in flight to each client pipe endpoint. (This is accomplished using packet acks.) If a maximum backlog is specified, pipe endpoints exceeding this count will stop sending packets. Specify the maximum backlog using the Init() function or the SetMaxBacklog() function.

The rate that packets are sent can be regulated using a callback function configured with the SetPredicate() function, or using the BroadcastDownsampler class.

Template Parameters
TThe packet data type

Constructor & Destructor Documentation

◆ PipeBroadcaster()

template<typename T>
RobotRaconteur::PipeBroadcaster< T >::PipeBroadcaster ( )
inline

Construct a new PipeBroadcaster.

Must use boost::make_shared<PipeBroadcaster<T> >() to construct. Must call Init() after construction.

Member Function Documentation

◆ AsyncSendPacket()

template<typename T>
void RobotRaconteur::PipeBroadcaster< T >::AsyncSendPacket ( T packet,
boost::function< void()> handler )
inline

Asynchronously send packet to all connected pipe endpoint clients.

Asynchronous version of SendPacket()

Parameters
packetThe packet to send
handlerA handler function for when packet has been sent by all endpoints

◆ GetMaxBacklog()

int32_t RobotRaconteur::PipeBroadcasterBase::GetMaxBacklog ( )
inherited

Gets the currently configured maximum backlog.

Returns
int32_t The maximum backlog

◆ GetPipe()

template<typename T>
boost::shared_ptr< Pipe< T > > RobotRaconteur::PipeBroadcaster< T >::GetPipe ( )
inline

Get the associated pipe.

Returns
RR_SHARED_PTR<Pipe<T> >

◆ GetPredicate()

boost::function< bool(const boost::shared_ptr< PipeBroadcasterBase > &, uint32_t, int32_t)> RobotRaconteur::PipeBroadcasterBase::GetPredicate ( )
inherited

Get the current predicate callback function.

Returns
boost::function<bool(RR_SHARED_PTR<PipeBroadcasterBase>&, uint32_t, int32_t) > The predicate callback function

◆ Init()

template<typename T>
void RobotRaconteur::PipeBroadcaster< T >::Init ( boost::shared_ptr< Pipe< T > > pipe,
int32_t maximum_backlog = -1 )
inline

Initialize the PipeBroadcaster.

Initialize the PipeBroadcaster for use. Must be called after construction.

Parameters
pipeThe pipe to use for broadcasting. Must be a pipe from a service object. Specifying a client pipe will result in an exception.
maximum_backlogThe maximum number of packets in flight, or -1 for unlimited

◆ SendPacket()

template<typename T>
void RobotRaconteur::PipeBroadcaster< T >::SendPacket ( T packet)
inline

Send a packet to all connected pipe endpoint clients.

Blocks until packet has been sent by all endpoints

Parameters
packetThe packet to send

◆ SetMaxBacklog()

void RobotRaconteur::PipeBroadcasterBase::SetMaxBacklog ( int32_t maximum_backlog)
inherited

Set the maximum backlog.

PipeBroadcaster provides flow control by optionally tracking how many packets are in flight to each client pipe endpoint. (This is accomplished using packet acks.) If a maximum backlog is specified, pipe endpoints exceeding this count will stop sending packets.

Parameters
maximum_backlogThe maximum number of packets in flight, or -1 for unlimited

◆ SetPredicate()

void RobotRaconteur::PipeBroadcasterBase::SetPredicate ( boost::function< bool(const boost::shared_ptr< PipeBroadcasterBase > &, uint32_t, int32_t)> f)
inherited

Set the predicate callback function.

A predicate is optionally used to regulate when packets are sent to clients. This is used by the BroadcastDownsampler to regulate update rates of packets sent to clients.

The predicate callback is invoked before the broadcaster sends a packet to an endpoint. If the predicate returns true, the packet will be sent. If it is false, the packet will not be sent to that endpoint. The predicate callback must have the following signature:

bool broadcaster_predicate(PipeBroadcasterBasePtr& broadcaster, uint32_t client_endpoint, int32_t

pipe_endpoint_index);

It receives the broadcaster, the client endpoint ID, and the pipe endpoint index. It returns true to send the packet, or false to not send the packet.

Parameters
fThe predicate callback function

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