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

Subscription for wire members that aggregates the values from client wire connections. More...

#include <Subscription.h>

Inheritance diagram for RobotRaconteur::WireSubscription< T >:
RobotRaconteur::WireSubscriptionBase

Public Member Functions

GetInValue (TimeSpec *time=NULL, typename boost::shared_ptr< WireConnection< T > > *connection=NULL)
 Get the current InValue and metadata.
bool TryGetInValue (T &val, TimeSpec *time=NULL, typename boost::shared_ptr< WireConnection< T > > *connection=NULL)
 Try getting the current InValue and metadata.
void SetOutValueAll (const T &val)
 Set the OutValue for all active wire connections.
event_connection AddWireValueChangedListener (boost::function< void(const boost::shared_ptr< WireSubscription< T > > &, const T &, const TimeSpec &)> f)
 Adds a wire value changed event listener function.
bool WaitInValueValid (int32_t timeout=RR_TIMEOUT_INFINITE)
 Wait for a valid InValue to be received from a client.
size_t GetActiveWireConnectionCount ()
 Get the number of wire connections currently connected.
bool GetIgnoreInValue ()
 Get if InValue is currently being ignored.
void SetIgnoreInValue (bool ignore)
 Set if InValue should be ignored.
int32_t GetInValueLifespan ()
 Get the InValue lifespan in milliseconds.
void SetInValueLifespan (int32_t millis)
 Set the InValue lifespan in milliseconds.
void Close ()
 Closes the wire subscription.

Detailed Description

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

Subscription for wire members that aggregates the values from client wire connections.

Wire subscriptions are created using the ServiceSubscription::SubscribeWire() function. This function takes the type of the wire value, the name of the wire member, and an optional service path of the service object that owns the wire member.

Wire subscriptions aggregate the InValue from all active wire connections. When a client connects, the wire subscriptions will automatically create wire connections to the wire member specified when the WireSubscription was created using ServiceSubscription::SubscribeWire(). The InValue of all the active wire connections are collected, and the most recent one is used as the current InValue of the wire subscription. The current value, the timespec, and the wire connection can be accessed using GetInValue() or TryGetInValue().

The lifespan of the InValue can be configured using SetInValueLifespan(). It is recommended that the lifespan be configured, so that the value will expire if the subscription stops receiving fresh in values.

The wire subscription can also be used to set the OutValue of all active wire connections. This behaves similar to a "reverse broadcaster", sending the same value to all connected services.

Template Parameters
TThe value type used by the wire

Member Function Documentation

◆ AddWireValueChangedListener()

template<typename T>
event_connection RobotRaconteur::WireSubscription< T >::AddWireValueChangedListener ( boost::function< void(const boost::shared_ptr< WireSubscription< T > > &, const T &, const TimeSpec &)> f)
inline

Adds a wire value changed event listener function.

Add a listener function that is called when the InValue changes. The callback should have the signature:

void cb(WireSubscriptionPtr<T> wire_connection, const T& val, const TimeSpec& ts)
Parameters
fThe callback function
Returns
event_connection The Boost.Signals2 connection

◆ Close()

void RobotRaconteur::WireSubscriptionBase::Close ( )
inherited

Closes the wire subscription.

Wire subscriptions are automatically closed when the parent ServiceSubscription is closed or when the node is shut down.

◆ GetActiveWireConnectionCount()

size_t RobotRaconteur::WireSubscriptionBase::GetActiveWireConnectionCount ( )
inherited

Get the number of wire connections currently connected.

Returns
size_t The number of active connections

◆ GetIgnoreInValue()

bool RobotRaconteur::WireSubscriptionBase::GetIgnoreInValue ( )
inherited

Get if InValue is currently being ignored.

Returns
true InValue is being ignored
false InValue is not being ignored

◆ GetInValue()

template<typename T>
T RobotRaconteur::WireSubscription< T >::GetInValue ( TimeSpec * time = NULL,
typename boost::shared_ptr< WireConnection< T > > * connection = NULL )
inline

Get the current InValue and metadata.

Throws ValueNotSetException if no valid value is available

Parameters
time[out] the LastValueReceivedTime of the InValue
connection[out] the wire connection that received the InValue
Returns
T the current InValue

◆ GetInValueLifespan()

int32_t RobotRaconteur::WireSubscriptionBase::GetInValueLifespan ( )
inherited

Get the InValue lifespan in milliseconds.

Get the lifespan of InValue in milliseconds. The value will expire after the specified lifespan, becoming invalid. Use -1 for infinite lifespan.

Returns
int32_t The lifespan in milliseconds. -1 for infinite

◆ SetIgnoreInValue()

void RobotRaconteur::WireSubscriptionBase::SetIgnoreInValue ( bool ignore)
inherited

Set if InValue should be ignored.

See WireConnection::SetIgnoreInValue()

If true, InValue will be ignored for all wire connections.

Parameters
ignore

◆ SetInValueLifespan()

void RobotRaconteur::WireSubscriptionBase::SetInValueLifespan ( int32_t millis)
inherited

Set the InValue lifespan in milliseconds.

Set the lifespan of InValue in milliseconds. The value will expire after the specified lifespan, becoming invalid. Use -1 for infinite lifespan.

See also WireConnection::SetInValueLifespan()

Parameters
millisThe lifespan in milliseconds. -1 for infinite

◆ SetOutValueAll()

template<typename T>
void RobotRaconteur::WireSubscription< T >::SetOutValueAll ( const T & val)
inline

Set the OutValue for all active wire connections.

Behaves like a "reverse broadcaster". Calls WireConnection::SetOutValue() for all connected wire connections.

Template Parameters
TThe type of the value
Parameters
valThe new OutValue

◆ TryGetInValue()

template<typename T>
bool RobotRaconteur::WireSubscription< T >::TryGetInValue ( T & val,
TimeSpec * time = NULL,
typename boost::shared_ptr< WireConnection< T > > * connection = NULL )
inline

Try getting the current InValue and metadata.

Same as GetInValue(), but returns a bool for success or failure instead of throwing an exception.

Parameters
val[out] the current InValue
time[out] the LastValueReceivedTime of the InValue
connection[out] the wire connection that received the InValue
Returns
true Getting the InValue was successful
false There is no valid InValue

◆ WaitInValueValid()

bool RobotRaconteur::WireSubscriptionBase::WaitInValueValid ( int32_t timeout = RR_TIMEOUT_INFINITE)
inherited

Wait for a valid InValue to be received from a client.

Blocks the current thread until value is received or timeout

Parameters
timeoutThe timeout in milliseconds
Returns
true A value was received
false The wait timed out, or RR_TIMEOUT_INFINITE for no timeout

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