PdCom  4.2
Process data communication client
Public Member Functions | List of all members
PdCom::Subscriber Struct Referenceabstract

Class required to receive subscribed variables. More...

#include <Subscriber.h>

Public Member Functions

virtual ~Subscriber ()
 Destructor. More...
 
virtual void newGroupValue (uint64_t time_ns)=0
 New values for all active signal subscriptions. More...
 
virtual void newValue (const Variable::Subscription *subscription)=0
 New values for a single subscription is available. More...
 
virtual void active (const std::string &path, const Variable::Subscription *subscription)=0
 Subscription is active. More...
 
virtual void invalid (PdCom::Process *process, const std::string &path, int id)
 Subscription request invalid. More...
 

Detailed Description

Class required to receive subscribed variables.

Subscribed variables require a Subscriber instance to supply new values. A subscriber can have any number of subscriptions, event more than one subscription to the same variable.

To use this class, you will need to reimplement the following pure virtual methods:

A variable is subscribed using the Process::subscribe() method. A call to subscribe() is always acknowledged with a call to active() or invalid():

The replies can come within the context of subscribe() if the variable is known. If unknown, the library discovers it dynamically and replies within the context of Process::asyncData().

If the variable is available, the class is informed by using active() with the subscription. The subscription can be used immediately, although the value is probably rubbish.

When the value of a subscription changes, newValue() or newGroupValue() is called within the context of asyncData().

newValue() is called when a single irregular subscription's value changes, such as a parameter change, a polled signal (interval < 0) or a signal with event subscription rate (interval = 0).

newGroupValue() is called when new values for recurring subscriptions of signals with interval > 0 arrive.

Although a single subscriber could be used for all subscriptions, it it makes sense to group similar recurring subscriptions using multible Subscriber's. If a subscriber only contains signal subscriptions from the same task with the same subscription interval (>= 0) from the same Process, then all active subscriptions are guaranteed to have a new value from the same task calculation cycle during the call to newGroupValue(). A notable example where this can be used is in a XY plotter.

A Subscriber is also required when Process::parameterMonitor() is used.

To cancel a subscription, cancel() it. It is safe to call cancel within newValue() or active().

Examples:
example.cpp.

Constructor & Destructor Documentation

◆ ~Subscriber()

virtual PdCom::Subscriber::~Subscriber ( )
virtual

Destructor.

Do not destroy a subscriber with active subscriptions. You will crash! Use Process::unsubscribe() to remove all subscriptions before destroying.

Member Function Documentation

◆ active()

virtual void PdCom::Subscriber::active ( const std::string &  path,
const Variable::Subscription subscription 
)
pure virtual

Subscription is active.

Parameters
pathpath as specified during subscribe()
subscriptionSubscription

subscription must be saved for later use when receiving a fixed interval subscription during newGroupValue(). There is no way of finding out which subscriptions a Subscriber has.

Although path could be retrieved from the subscription, it may differ from the path used in the call to Process::subscribe().

Examples:
example.cpp.

◆ invalid()

virtual void PdCom::Subscriber::invalid ( PdCom::Process process,
const std::string &  path,
int  id 
)
virtual

Subscription request invalid.

Parameters
processcalling process
pathpath as specified during subscribe()
idid as specified during subscribe()
Examples:
example.cpp.

◆ newGroupValue()

virtual void PdCom::Subscriber::newGroupValue ( uint64_t  time_ns)
pure virtual

New values for all active signal subscriptions.

This method is called when the Subscriber has active subscriptions with a continuous subscription rate with interval > 0 are available.

Parameters
time_nsNanoseconds since epoch.
Examples:
example.cpp.

◆ newValue()

virtual void PdCom::Subscriber::newValue ( const Variable::Subscription subscription)
pure virtual

New values for a single subscription is available.

This is the case for:

  • parameter subscriptions
  • signal subscriptions when the interval <= 0.
Parameters
subscriptionsubscription of changed variable
Examples:
example.cpp.

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