coral
A C++ library for distributed co-simulation
|
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::ScalarValue & | Value (const coral::model::Variable &variable) const |
Returns the value of the given variable which was acquired with the last Update() call. More... | |
A class which handles subscriptions to and receiving of variable values.
coral::bus::VariableSubscriber::VariableSubscriber | ( | ) |
Default constructor.
Note that Connect() must be called before any variables can be received.
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.
[in] | endpoints | A pointer to an array of endpoints. |
[in] | endpointsSize | The size of the endpoints array. |
void coral::bus::VariableSubscriber::Subscribe | ( | const coral::model::Variable & | variable | ) |
Subscribes to the given variable.
void coral::bus::VariableSubscriber::Unsubscribe | ( | const coral::model::Variable & | variable | ) |
Unsubscribes from the given variable.
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.
[in] | stepID | The timestep ID for which we should wait for variable data. |
[in] | timeout | How long to wait without receiving any data. A negative value means to wait indefinitely. |
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.
[in] | variable | A variable identifier. The variable must be one which has previously been subscribed to with Subscribe(). |