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

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

#include <WireMember.h>

Inheritance diagram for RobotRaconteur::WireBroadcaster< T >:
RobotRaconteur::WireBroadcasterBase

Public Member Functions

 WireBroadcaster ()
 Construct a new WireBroadcaster.
void Init (boost::shared_ptr< Wire< T > > wire)
 Initialize the WireBroadcaster.
void SetOutValue (T value)
 Set the OutValue for all connections.
boost::function< bool(boost::shared_ptr< WireBroadcasterBase > &, uint32_t)> GetPredicate ()
 Get the current predicate callback function.
void SetPredicate (boost::function< bool(const boost::shared_ptr< WireBroadcasterBase > &, uint32_t)> f)
 Set the predicate callback function.
int32_t GetOutValueLifespan ()
 Get the lifespan of OutValue.
void SetOutValueLifespan (int32_t millis)
 Set the lifespan of OutValue.

Detailed Description

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

Broadcaster to send values to all connected clients.

WireBroadcaster is used by services to send values to all connected client endpoints. It attaches to the wire on the service side, and manages the lifecycle of connections. WireBroadcaster should only we used with wires that are declared readonly, since it has no provisions for receiving incoming values from clients.

WireBroadcaster is initialized by the user, or by default implementation classes generated by RobotRaconteurGen (_default_impl). Default implementation classes will automatically instantiate broadcasters for wires 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 wires have been instantiated by the service.

Use SetOutValue() to broadcast values to all connected clients.

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 value data type

Constructor & Destructor Documentation

◆ WireBroadcaster()

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

Construct a new WireBroadcaster.

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

Member Function Documentation

◆ GetOutValueLifespan()

int32_t RobotRaconteur::WireBroadcasterBase::GetOutValueLifespan ( )
inherited

Get the lifespan of OutValue.

OutValue may optionally have a finite lifespan specified in milliseconds. Once the lifespan after sending has expired, the OutValue is cleared, and becomes invalid. Attempts to access OutValue will result in a ValueNotSetException.

Returns
int32_t The lifespan in milliseconds

◆ GetPredicate()

boost::function< bool(boost::shared_ptr< WireBroadcasterBase > &, uint32_t)> RobotRaconteur::WireBroadcasterBase::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::WireBroadcaster< T >::Init ( boost::shared_ptr< Wire< T > > wire)
inline

Initialize the WireBroadcaster.

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

Parameters
wireThe wire to use for broadcasting. Must be a wire from a service object. Specifying a client wire will result in an exception.

◆ SetOutValue()

template<typename T>
void RobotRaconteur::WireBroadcaster< T >::SetOutValue ( T value)
inline

Set the OutValue for all connections.

Sets the OutValue for all connections. This will transmit the value to all connected clients using packets. The value will become the clients' InValue.

The value will be returned when clients call Wire::PeekInValue() or Wire::AsyncPeekInValue()

Parameters
valueThe new OutValue

◆ SetOutValueLifespan()

void RobotRaconteur::WireBroadcasterBase::SetOutValueLifespan ( int32_t millis)
inherited

Set the lifespan of OutValue.

OutValue may optionally have a finite lifespan specified in milliseconds. Once the lifespan after sending has expired, the OutValue is cleared and becomes invalid. Attempts to access OutValue will result in ValueNotSetException.

OutValue lifespans may be used to avoid using a stale value sent by the wire. If the lifespan is not set, the wire will continue to return the last sent value, even if the value is old.

Parameters
millisThe lifespan in millisecond, or RR_VALUE_LIFESPAN_INFINITE for infinite lifespan

◆ SetPredicate()

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

Set the predicate callback function.

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

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

bool broadcaster_predicate(WireBroadcasterBasePtr& broadcaster, uint32_t client_endpoint);

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

Parameters
fThe predicate callback function

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