|
PdCom
4.2
Process data communication client
|
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... | |
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().
|
virtual |
Destructor.
Do not destroy a subscriber with active subscriptions. You will crash! Use Process::unsubscribe() to remove all subscriptions before destroying.
|
pure virtual |
Subscription is active.
| path | path as specified during subscribe() |
| subscription | Subscription |
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().
|
virtual |
Subscription request invalid.
| process | calling process |
| path | path as specified during subscribe() |
| id | id as specified during subscribe() |
|
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.
| time_ns | Nanoseconds since epoch. |
|
pure virtual |
New values for a single subscription is available.
This is the case for:
interval <= 0.| subscription | subscription of changed variable |
1.8.14