PdCom  5.3
Process data communication client
Public Types | Public Member Functions | Friends | List of all members
PdCom::Variable Class Reference

PdCom Variable interface. More...

#include <Variable.h>

Public Types

using PollFuture = Future< PdCom::Exception const &, VariablePollResult, std::chrono::nanoseconds >
 
using SetValueFuture = Future< PdCom::Exception const & >
 

Public Member Functions

 Variable ()=default
 Constructs an empty variable.
 
template<typename T >
std::enable_if<!std::is_arithmetic< T >::value, SetValueFuture >::type setValue (T const &data, const Selector &selector={nullptr}) const
 Write to a variable. More...
 
template<typename T >
std::enable_if< std::is_arithmetic< T >::value, SetValueFuture >::type setValue (T const &data, const Selector &selector={nullptr}) const
 Write to a variable. More...
 
template<typename T , size_t M, size_t N>
SetValueFuture setValue (const T(&data)[M][N], const Selector &selector={nullptr}) const
 Write to a variable. More...
 
SetValueFuture setValue (const void *src, TypeInfo::DataType src_type, size_t count, const Selector &selector={nullptr}) const
 Write to a variable. More...
 
PdCom::Variable::SetValueFuture setValue (const void *src, TypeInfo::DataType src_type, size_t count, size_t offset) const
 Write to a variable. More...
 
TypeInfo getTypeInfo () const
 Get details about the variable type. More...
 
SizeInfo getSizeInfo () const
 Get details about the variable shape. More...
 
std::string getPath () const
 The Path of the variable. More...
 
std::string getName () const
 The name of the variable. More...
 
std::string getAlias () const
 The alias of the variable, if set. More...
 
int getTaskId () const
 The task id of the variable. More...
 
bool isWriteable () const
 
std::chrono::duration< double > getSampleTime () const
 
bool empty () const noexcept
 Checks whether this instance is empty. More...
 
PollFuture poll () const
 Read a variable without subscription. More...
 
ProcessgetProcess () const
 Get the assigned Process. More...
 

Friends

class impl::Variable
 

Detailed Description

PdCom Variable interface.

This class represents a variable (signal or parameter). It contains information about the datatype and the shape of a variable.

If you default-construct a Variable instance, it does not contain any information. Calling any other member function than empty() is forbidden. To get a valid variable instance, call Process::find().

setValue() returns a Future, which takes up to two callbacks to notify about the parameter update operation. If the server does not support these notifications, the Future is empty and no callbacks can be passed to it.

Examples:
advanced_example.cpp.

Member Function Documentation

◆ empty()

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

Checks whether this instance is empty.

Default-constructed variables are empty per default, calling any other member function than empty() will crash.

Returns
false if this instance is alive.
Examples:
advanced_example.cpp.

◆ getAlias()

std::string PdCom::Variable::getAlias ( ) const

The alias of the variable, if set.

The variable must not be empty!

Returns
the alias.

◆ getName()

std::string PdCom::Variable::getName ( ) const

The name of the variable.

The variable must not be empty!

Returns
the name, without the path components.

◆ getPath()

std::string PdCom::Variable::getPath ( ) const

The Path of the variable.

The variable must not be empty!

Returns
The full path.

◆ getProcess()

Process* PdCom::Variable::getProcess ( ) const

Get the assigned Process.

Returns
The Process.

◆ getSampleTime()

std::chrono::duration<double> PdCom::Variable::getSampleTime ( ) const
Returns
sample time, 0 for parameters.

◆ getSizeInfo()

SizeInfo PdCom::Variable::getSizeInfo ( ) const

Get details about the variable shape.

The variable must not be empty!

Returns
Variable shape info.

◆ getTaskId()

int PdCom::Variable::getTaskId ( ) const

The task id of the variable.

The variable must not be empty!

Returns
the task id.

◆ getTypeInfo()

TypeInfo PdCom::Variable::getTypeInfo ( ) const

Get details about the variable type.

The variable must not be empty!

Returns
Variable type info.

◆ isWriteable()

bool PdCom::Variable::isWriteable ( ) const
Returns
whether the variable is writeable.

◆ poll()

PollFuture PdCom::Variable::poll ( ) const

Read a variable without subscription.

This method returns a Future. To get the actual result, set a callback function using Future::then(). You can use Lambdas to capture local variables in the callback. The callback gets two arguments: a VariablePollResult instance and a timestamp. Make sure to keep the Future until it is resolved, otherwise the poll request will be dropped. So this is not fire-and-forget.

auto handle = ...;
const auto future = var.poll().then([&handle](VariablePollResult res,
std::chrono::nanoseconds ts)
{
double val;
res.getValue(val);
handle.processValue(val);
});

◆ setValue() [1/5]

template<typename T >
std::enable_if<!std::is_arithmetic<T>::value, SetValueFuture>::type PdCom::Variable::setValue ( T const &  data,
const Selector selector = {nullptr} 
) const
inline

Write to a variable.

This function is also asynchronous, so the server might still use the old value when this function returns. This overload is for any container of arithmetic types (e.g. std::vector<int>).

T must be a contiguous container (must have a size() method and a value_type typedef).

Parameters
dataData.
selectorOptional selector.
Returns
empty Future if server does not support variable update feedback.
Examples:
advanced_example.cpp.

◆ setValue() [2/5]

template<typename T >
std::enable_if<std::is_arithmetic<T>::value, SetValueFuture>::type PdCom::Variable::setValue ( T const &  data,
const Selector selector = {nullptr} 
) const
inline

Write to a variable.

This function is also asynchronous, so the server might still use the old value when this function returns. This overload is for any arithmetic type (int, double, etc.). The variable must not be empty!

Parameters
dataData.
selectorOptional selector.
Returns
empty Future if server does not support variable update feedback.

◆ setValue() [3/5]

template<typename T , size_t M, size_t N>
SetValueFuture PdCom::Variable::setValue ( const T(&)  data[M][N],
const Selector selector = {nullptr} 
) const
inline

Write to a variable.

This function is also asynchronous, so the server might still use the old value when this function returns. This overload is for any arithmetic type (int, double, etc.). The variable must not be empty!

Parameters
dataData.
selectorOptional selector.
Returns
empty Future if server does not support variable update feedback.

◆ setValue() [4/5]

SetValueFuture PdCom::Variable::setValue ( const void *  src,
TypeInfo::DataType  src_type,
size_t  count,
const Selector selector = {nullptr} 
) const

Write to a variable.

This function is also asynchronous, so the server might still use the old value when this function returns. The variable must not be empty!

Parameters
srcPointer to one or more values.
src_typeType of the source.
countNumber of values.
selectorOptional selector.
Returns
empty Future if server does not support variable update feedback.

◆ setValue() [5/5]

PdCom::Variable::SetValueFuture PdCom::Variable::setValue ( const void *  src,
TypeInfo::DataType  src_type,
size_t  count,
size_t  offset 
) const

Write to a variable.

This function is also asynchronous, so the server might still use the old value when this function returns. The variable must not be empty!

Parameters
srcPointer to one or more values.
src_typeType of the source.
countNumber of values.
offsetOptional offset in the destination.
Returns
empty Future if server does not support variable update feedback.

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