RTC Toolkit  1.0.0
Classes | Public Member Functions | List of all members
rtctk::componentFramework::RepositorySubscriberIf Class Referenceabstract

Abstract interface providing subscription facilities for a repository. More...

#include <repositorySubscriberIf.hpp>

Inheritance diagram for rtctk::componentFramework::RepositorySubscriberIf:
rtctk::componentFramework::OldbIf rtctk::componentFramework::RuntimeRepoIf rtctk::componentFramework::FileOldbAdapter rtctk::componentFramework::OldbAdapter rtctk::componentFramework::FileRuntimeRepoAdapter rtctk::componentFramework::RuntimeRepoAdapter rtctk::componentFramework::RuntimeRepoAdapter

Classes

class  SubscribeRequest
 A request object to pass information about datapoints to subscribe to. More...
 
class  UnsubscribeRequest
 A request object to pass information about datapoints to unsubscribe from. More...
 

Public Member Functions

virtual ~RepositorySubscriberIf ()
 
virtual RepositoryIf::Response SendSubscribeRequest (const SubscribeRequest &request) const =0
 This is called to asynchronously send a subscription request for datapoints. More...
 
virtual RepositoryIf::Response SendUnsubscribeRequest (const UnsubscribeRequest &request) const =0
 This is called to asynchronously send a request to unsubscribe from various notifications. More...
 
template<typename T , typename F >
void 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. More...
 
void Unsubscribe (const DataPointPath &path) const
 A simple convenience function that will deregister all callbacks for receiving new datapoint values. More...
 

Detailed Description

Abstract interface providing subscription facilities for a repository.

Thread Safety
thread-safe

Constructor & Destructor Documentation

◆ ~RepositorySubscriberIf()

rtctk::componentFramework::RepositorySubscriberIf::~RepositorySubscriberIf ( )
virtual

Member Function Documentation

◆ SendSubscribeRequest()

virtual RepositoryIf::Response rtctk::componentFramework::RepositorySubscriberIf::SendSubscribeRequest ( const SubscribeRequest request) const
pure virtual

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]requestThe 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()

virtual RepositoryIf::Response rtctk::componentFramework::RepositorySubscriberIf::SendUnsubscribeRequest ( const UnsubscribeRequest request) const
pure virtual

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]requestThe 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,
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]pathThe path of the datapoint to subscribe to.
[in]handlerA handler function, lambda or functional to invoke. It must have a signature compatible with
void(const DataPointPath& path)
.
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]pathThe path of the datapoint to unsubscribe from.
Thread Safety
thread-safe
Exception Safety
basic

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