libcluon
0.0.148
|
#include <OD4Session.hpp>
Public Member Functions | |
OD4Session (uint16_t CID, std::function< void(cluon::data::Envelope &&envelope)> delegate=nullptr) noexcept | |
void | send (cluon::data::Envelope &&envelope) noexcept |
bool | dataTrigger (int32_t messageIdentifier, std::function< void(cluon::data::Envelope &&envelope)> delegate) noexcept |
void | timeTrigger (float freq, std::function< bool()> delegate) noexcept |
template<typename T > | |
void | send (T &message, const cluon::data::TimeStamp &sampleTimeStamp=cluon::data::TimeStamp(), uint32_t senderStamp=0) noexcept |
bool | isRunning () noexcept |
This class provides an interface to an OpenDaVINCI v4 session. An OpenDaVINCI v4 session allows the automatic exchange of time-stamped Envelopes carrying user-defined messages usually using UDP multicast. A running OD4Session will not receive the bytes that itself has sent to other microservices.
There are two ways to participate in an OpenDaVINCI session. Variant A is simply calling a user-supplied lambda whenever a new Envelope is received:
Variant B allows a more fine-grained setup where you specify the Envelopes of interest:
Next to receive Envelopes, OD4Session can call a user-supplied lambda in a time-triggered way. The lambda is executed as long as it does not return false or throws an exception that is then caught in the method timeTrigger and the method is exited:
|
noexcept |
Constructor.
CID | OpenDaVINCI v4 session identifier [1 .. 254] |
delegate | Function to call on newly arriving Envelopes ("catch-all"); if a nullptr is passed, the method dataTrigger can be used to set message specific delegates. Please note that it is NOT possible to have both: a delegate for "catch-all" and the data-triggered ones. |
|
noexcept |
This method sets a delegate to be called data-triggered on arrival of a new Envelope for a given message identifier.
messageIdentifier | Message identifier to assign a delegate. |
delegate | Function to call on newly arriving Envelopes; setting it to nullptr will erase it. |
References cluon::time::convert(), cluon::extractEnvelope(), and retVal.
|
noexcept |
|
noexcept |
This method will send a given Envelope to this OpenDaVINCI v4 session.
envelope | to be sent. |
References cluon::serializeEnvelope().
|
inlinenoexcept |
This method will send a given message to this OpenDaVINCI v4 session.
message | Message to be sent. |
sampleTimeStamp | Time point when this sample to be sent was captured (default = sent time point). |
senderStamp | Optional sender stamp (default = 0). |
References cluon::ToProtoVisitor::encodedData(), and cluon::time::now().
|
noexcept |
This method sets a delegate to be called time-triggered using the specified frequency until the delegate returns false. This method blocks until the delegate has returned false or threw an exception. Thus, this method is typically called as last statement in a main function of a program.
freq | Frequency in Hertz to run the given delegate. |
delegate | Function to call according to the given frequency. |
References cluon::TerminateHandler::instance(), cluon::time::now(), and cluon::time::toMicroseconds().