Abstract interface providing subscription facilities for a repository.
More...
#include <repositorySubscriberIf.hpp>
Abstract interface providing subscription facilities for a repository.
- Thread Safety
- thread-safe
◆ ~RepositorySubscriberIf()
rtctk::componentFramework::RepositorySubscriberIf::~RepositorySubscriberIf |
( |
| ) |
|
|
virtual |
◆ SendSubscribeRequest()
This is called to asynchronously send a subscription request for datapoints.
One or more datapoints can be subscribed to by constructing a SubscribeRequest object and sending it to the repository service with this method. A typical usage is indicated in the following code sample:
void OnRemoved(const DataPointPath& path) {
...
}
void OnNewValue(const DataPointPath& path, int64_t& buffer) {
...
}
RepositorySubscriberIf& repo = ...;
int64_t buffer = ...;
SubscribeRequest request;
request.AddRemoveHandler("/test/datapoint"_dppath, OnRemoved);
request.AddNewValueHandler("/test/datapoint"_dppath, buffer, OnNewValue);
auto response = repo.SendSubscribeRequest(request);
... can do some work here ...
response.Wait();
- Note
- One must not access the buffers added to a SubscribeRequest object once SendSubscribeRequest has been invoked. At least not without using some form of synchronisation, e.g. a mutex, since the buffers will be updated asynchronously in different threads to the one used by the caller.
- Parameters
-
[in] | request | The subscription request to send to the repository. |
- Returns
- A response object (a future) that is used to wait for completion of the request.
- Thread Safety
- thread-safe
- Exception Safety
- basic
Implemented in rtctk::componentFramework::FileRuntimeRepoAdapter, rtctk::componentFramework::OldbAdapter, and rtctk::componentFramework::FileOldbAdapter.
◆ SendUnsubscribeRequest()
This is called to asynchronously send a request to unsubscribe from various notifications.
One can stop receiving notifications for one or more datapoints by constructing a UnsubscribeRequest object and sending it to the repository service with this method. A typical usage is indicated in the following code sample:
void OnRemoved(const DataPointPath& path) {
...
}
void OnNewValue(const DataPointPath& path, int64_t& buffer) {
...
}
RepositorySubscriberIf& repo = ...;
UnsubscribeRequest request;
request.AddRemoveHandler("/test/datapoint"_dppath);
request.AddNewValueHandler("/test/datapoint"_dppath);
auto response = repo.SendUnsubscribeRequest(request);
... can do some work here ...
response.Wait();
- Parameters
-
[in] | request | The request to send to the repository. |
- Returns
- A response object (a future) that is used to wait for completion of the request.
- Thread Safety
- thread-safe
- Exception Safety
- basic
Implemented in rtctk::componentFramework::FileRuntimeRepoAdapter, rtctk::componentFramework::OldbAdapter, and rtctk::componentFramework::FileOldbAdapter.
◆ Subscribe()
template<typename T , typename F >
void rtctk::componentFramework::RepositorySubscriberIf::Subscribe |
( |
const DataPointPath & |
path, |
|
|
T & |
buffer, |
|
|
F |
handler |
|
) |
| const |
A convenience template function that will register a callback to receive new datapoint values in a synchronous manner.
This function can be used for simple cases to register a callback function that will be called when a new datapoint value is received. The buffer will be filled with the new value before invoking the callback. For a large number of datapoints it is better to use the SendSubscribeRequest method.
- Note
- This method blocks until the registration has been completed for the datapoint.
- Parameters
-
[in] | path | The path of the datapoint to subscribe to. |
[in] | handler | A handler function, lambda or functional to invoke. It must have a signature compatible withvoid(const DataPointPath& path, T& buffer)
. |
- Thread Safety
- thread-safe
- Exception Safety
- basic
◆ Unsubscribe()
void rtctk::componentFramework::RepositorySubscriberIf::Unsubscribe |
( |
const DataPointPath & |
path | ) |
const |
A simple convenience function that will deregister all callbacks for receiving new datapoint values.
This function can be used for simple cases to deregister all callback functions in a synchronous manner. For a large number of unsubscriptions it is better to use the SendUnsubscribeRequest method.
- Note
- This method blocks until the deregistration has been completed for the datapoint.
- Parameters
-
[in] | path | The path of the datapoint to unsubscribe from. |
- Thread Safety
- thread-safe
- Exception Safety
- basic
◆ PyRepositorySubscriberIf
friend class PyRepositorySubscriberIf |
|
friend |
The documentation for this class was generated from the following files: