coral
A C++ library for distributed co-simulation
Public Member Functions | List of all members
coral::bus::VariableSubscriber Class Reference

A class which handles subscriptions to and receiving of variable values. More...

#include "coral/bus/variable_io.hpp"

Public Member Functions

 VariableSubscriber ()
 Default constructor. More...
 
void Connect (const coral::net::Endpoint *endpoints, std::size_t endpointsSize)
 Connects to the remote endpoints from which variable values should be received. More...
 
void Subscribe (const coral::model::Variable &variable)
 Subscribes to the given variable. More...
 
void Unsubscribe (const coral::model::Variable &variable)
 Unsubscribes from the given variable. More...
 
bool Update (coral::model::StepID stepID, std::chrono::milliseconds timeout)
 Waits until the values of all subscribed-to variables have been received for the given time step. More...
 
const coral::model::ScalarValueValue (const coral::model::Variable &variable) const
 Returns the value of the given variable which was acquired with the last Update() call. More...
 

Detailed Description

A class which handles subscriptions to and receiving of variable values.

Constructor & Destructor Documentation

coral::bus::VariableSubscriber::VariableSubscriber ( )

Default constructor.

Note that Connect() must be called before any variables can be received.

Member Function Documentation

void coral::bus::VariableSubscriber::Connect ( const coral::net::Endpoint endpoints,
std::size_t  endpointsSize 
)

Connects to the remote endpoints from which variable values should be received.

Every time this function is called, existing connections are broken and new ones are established. Thus, all endpoints must be specified each time.

Parameters
[in]endpointsA pointer to an array of endpoints.
[in]endpointsSizeThe size of the endpoints array.
void coral::bus::VariableSubscriber::Subscribe ( const coral::model::Variable variable)

Subscribes to the given variable.

Precondition
Connect() has been called successfully on this instance.
void coral::bus::VariableSubscriber::Unsubscribe ( const coral::model::Variable variable)

Unsubscribes from the given variable.

Precondition
Connect() has been called successfully on this instance.
bool coral::bus::VariableSubscriber::Update ( coral::model::StepID  stepID,
std::chrono::milliseconds  timeout 
)

Waits until the values of all subscribed-to variables have been received for the given time step.

Parameters
[in]stepIDThe timestep ID for which we should wait for variable data.
[in]timeoutHow long to wait without receiving any data. A negative value means to wait indefinitely.
Returns
Whether a value has been received for all variables.
Precondition
Connect() has been called successfully on this instance.
const coral::model::ScalarValue& coral::bus::VariableSubscriber::Value ( const coral::model::Variable variable) const

Returns the value of the given variable which was acquired with the last Update() call.

This function may not be called if Update() has not been called yet, or if the last Update() call failed. Furthermore, the returned reference is only guaranteed to be valid until the next Update() call.

Parameters
[in]variableA variable identifier. The variable must be one which has previously been subscribed to with Subscribe().
Precondition
Update() has been called successfully.

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