PdCom  5.0
Process data communication client
Classes | Public Types | Public Member Functions | List of all members
PdCom::Subscription Class Reference

PdCom Subscription interface. More...

#include <Subscription.h>

Classes

struct  invalid_subscription
 

Public Types

enum  State { Invalid = 0, Pending, Active }
 
enum  SubscriberState { SubscriberState::FullyConstructed, SubscriberState::UnderConstruction }
 

Public Member Functions

 Subscription ()=default
 Default constructor for an empty subscription.
 
 Subscription (Subscription &&) noexcept
 
Subscriptionoperator= (Subscription &&) noexcept
 
 Subscription (Subscriber &subscriber, const Variable &variable, const Selector &selector={})
 Constructor for a known variable. More...
 
 Subscription (Subscriber &subscriber, Process &process, const std::string &path, const Selector &selector={})
 Constructor for an unknown variable. More...
 
void poll ()
 Poll values from the server. More...
 
const void * getData () const
 Get the data Pointer. More...
 
template<typename T >
std::enable_if<!std::is_arithmetic< T >::value, void >::type getValue (T &dest) const
 Copy the values into a custom buffer. More...
 
template<typename T >
std::enable_if< std::is_arithmetic< T >::value, void >::type getValue (T &dest) const
 Copy the values into a custom buffer. More...
 
Variable getVariable () const noexcept
 Access the subscribed variable. More...
 
void print (std::ostream &os, char delimiter) const
 Print the value(s). More...
 
bool empty () const noexcept
 Check whether the subscription is default-constructed. More...
 
State getState () const noexcept
 Get the current state. More...
 

Detailed Description

PdCom Subscription interface.

This class represents a subscription to a variable. It is updated eighter on a periodic base, on an external event (e.g. the value has changed) or as requested with poll().

To cancel a subscription, you have to delete the corresponding subscription instance.

Calling getState() is always allowed, the other member functions need the subscription to be Active.

Examples:
advanced_example.cpp.

Member Enumeration Documentation

◆ SubscriberState

Enumerator
FullyConstructed 

Allow callbacks.

UnderConstruction 

Suppress callbacks.

Constructor & Destructor Documentation

◆ Subscription() [1/2]

PdCom::Subscription::Subscription ( Subscriber subscriber,
const Variable variable,
const Selector selector = {} 
)

Constructor for a known variable.

Parameters
subscriberSubscriber which will recieve the status updates.
variableThe variable to subscribe.
substate(Dis)allow immediate callbacks.
Exceptions
invalid_subscriptionSubscription is already known to be invalid.

◆ Subscription() [2/2]

PdCom::Subscription::Subscription ( Subscriber subscriber,
Process process,
const std::string &  path,
const Selector selector = {} 
)

Constructor for an unknown variable.

Parameters
subscriberSubscriber which will recieve the status updates.
processThe process.
pathPath of the variable to subscribe.
substate(Dis)allow immediate callbacks.
Exceptions
invalid_subscriptionSubscription is already known to be invalid.

Member Function Documentation

◆ empty()

bool PdCom::Subscription::empty ( ) const
inlinenoexcept

Check whether the subscription is default-constructed.

Returns
false The subscription is populated.

◆ getData()

const void* PdCom::Subscription::getData ( ) const

Get the data Pointer.

The subscription has to be Active.

Returns
Pointer to the internal storage.

◆ getState()

State PdCom::Subscription::getState ( ) const
inlinenoexcept

Get the current state.

Returns
The state.
Examples:
advanced_example.cpp.

◆ getValue() [1/2]

template<typename T >
std::enable_if<!std::is_arithmetic<T>::value, void>::type PdCom::Subscription::getValue ( T &  dest) const
inline

Copy the values into a custom buffer.

Up to buf.size() values are converted into the type of the buffer. The subscription has to be Active.

Parameters
destCustom buffer.

◆ getValue() [2/2]

template<typename T >
std::enable_if<std::is_arithmetic<T>::value, void>::type PdCom::Subscription::getValue ( T &  dest) const
inline

Copy the values into a custom buffer.

The subscription has to be Active.

Parameters
destCustom buffer.

◆ getVariable()

Variable PdCom::Subscription::getVariable ( ) const
noexcept

Access the subscribed variable.

The subscription must not be empty().

Returns
The subscribed variable.

◆ poll()

void PdCom::Subscription::poll ( )

Poll values from the server.

The subscription has to be Active.

◆ print()

void PdCom::Subscription::print ( std::ostream &  os,
char  delimiter 
) const

Print the value(s).

Parameters
osStream to print into.
delimiterDelimiter which separates the values.
Examples:
advanced_example.cpp.

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