13#ifndef RTCTK_COMPONENTFRAMEWORK_REPOSITORYSUBSCRIBERIF_HPP
14#define RTCTK_COMPONENTFRAMEWORK_REPOSITORYSUBSCRIBERIF_HPP
37 using RtctkException::RtctkException;
121 std::is_convertible_v<F, NotifyCallbackType> or
122 (not std::is_same_v<T, void> and
123 std::is_convertible_v<
186 bool value_requested,
188 const std::type_info& type,
192 , m_value_requested(value_requested)
195 , m_removed_callback(removed_callback)
196 , m_newvalue_callback(newvalue_callback) {
201 const std::type_info& type,
204 :
Parameters(path, true, buffer, type, removed_callback, newvalue_callback) {
211 return m_value_requested;
216 inline const std::type_info&
GetType()
const {
220 return m_removed_callback;
223 return m_newvalue_callback;
231 bool m_value_requested;
237 const std::type_info* m_type;
244 template <
typename F>
245 void AddRemovedHandler(
const DataPointPath& path, F handler);
247 template <
typename T,
typename F>
248 void AddNewValueHandler(
const DataPointPath& path, T& buffer, F handler);
250 template <
typename F>
251 void AddValueChangedHandler(
const DataPointPath& path, F handler);
253 inline const std::vector<Parameters>&
GetParams()
const {
258 std::vector<Parameters> m_params;
286 const bool unsubscribe_removed,
287 const bool unsubscribe_newvalue)
289 , m_unsubscribe_removed(unsubscribe_removed)
290 , m_unsubscribe_newvalue(unsubscribe_newvalue) {
297 return m_unsubscribe_removed;
300 return m_unsubscribe_newvalue;
308 bool m_unsubscribe_removed;
311 bool m_unsubscribe_newvalue;
342 inline const std::vector<Parameters>&
GetParams()
const {
347 std::vector<Parameters> m_params;
429 template <
typename T>
435 std::enable_if_t<not std::is_convertible_v<T, RepositorySubscriberIf::NotifyCallbackType>,
437 void Subscribe(
const DataPointPath& path, T& buffer, F handler)
const;
460 template <
typename F>
463 if constexpr (std::is_convertible_v<F, NotifyHandler>) {
467 static_assert(std::is_convertible_v<F, NotifyHandler>,
"Feature not supported");
469 SendSubscribeRequest(subscribe).Wait();
492 friend class PyRepositorySubscriberIf;
493 std::any m_extra_objects;
496 mutable std::mutex m_subscriptions_mutex;
499 mutable std::map<DataPointPath, std::vector<SubscriptionId>> m_new_value_subscriptions;
500 mutable std::map<DataPointPath, std::vector<SubscriptionId>> m_removed_subscriptions;
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:74
An object used to wait for a request to complete.
Definition repositoryIf.hpp:1354
Abstract interface providing basic read and write facilities to a repository.
Definition repositoryIf.hpp:104
std::function< void(const DataPointPath &)> CallbackType
Signature of the callback functions that can be registered with the repository requests.
Definition repositoryIf.hpp:114
Definition repositorySubscriberIf.hpp:83
Definition repositorySubscriberIf.hpp:40
A structure to hold the arguments passed to the Add method.
Definition repositorySubscriberIf.hpp:167
const std::type_info & GetType() const
Definition repositorySubscriberIf.hpp:216
void * GetBuffer() const
Definition repositorySubscriberIf.hpp:213
const CallbackType & GetRemovedCallback() const
Definition repositorySubscriberIf.hpp:219
const DataPointPath & GetPath() const
Definition repositorySubscriberIf.hpp:207
Parameters(const DataPointPath &path, bool value_requested, void *buffer, const std::type_info &type, const CallbackType &removed_callback, const CallbackType &newvalue_callback)
Allows to explicitly construct a complete parameters structure.
Definition repositorySubscriberIf.hpp:185
Parameters(const DataPointPath &path, void *buffer, const std::type_info &type, const CallbackType &removed_callback, const CallbackType &newvalue_callback)
Definition repositorySubscriberIf.hpp:199
std::function< void(const DataPointPath &)> CallbackType
callback type that is used internally
Definition repositorySubscriberIf.hpp:170
const bool GetValueRequested() const
Definition repositorySubscriberIf.hpp:210
const CallbackType & GetNewValueCallback() const
Definition repositorySubscriberIf.hpp:222
A request object to pass information about datapoints to subscribe to.
Definition repositorySubscriberIf.hpp:161
const std::vector< Parameters > & GetParams() const
Definition repositorySubscriberIf.hpp:253
void AddValueChangedHandler(const DataPointPath &path, F handler)
Adds a request to subscribe to value change notifications for a particular datapoint.
Definition repositorySubscriberIf.ipp:199
Definition repositorySubscriberIf.hpp:35
RAII wrapper class used to manage the life-time of individual subscriptions.
Definition repositorySubscriberIf.hpp:64
std::function< void()> UnsubscribeMethod
Definition repositorySubscriberIf.hpp:66
Subscription(const Subscription &)=delete
Subscription & operator=(const Subscription &)=delete
A structure to hold the arguments passed with one of the Add methods.
Definition repositorySubscriberIf.hpp:273
const DataPointPath & GetPath() const
Definition repositorySubscriberIf.hpp:293
bool GetUnsubscribeRemoved() const
Definition repositorySubscriberIf.hpp:296
bool GetUnsubscribeNewValue() const
Definition repositorySubscriberIf.hpp:299
Parameters(const DataPointPath &path, const bool unsubscribe_removed, const bool unsubscribe_newvalue)
Allows to explicitly construct a complete parameters structure.
Definition repositorySubscriberIf.hpp:285
A request object to pass information about datapoints to unsubscribe from.
Definition repositorySubscriberIf.hpp:267
const std::vector< Parameters > & GetParams() const
Definition repositorySubscriberIf.hpp:342
Abstract interface providing I/O and additional subscription facilities for a repository.
Definition repositorySubscriberIf.hpp:27
std::function< void(std::exception_ptr)> ErrorCallbackType
Definition repositorySubscriberIf.hpp:49
void Subscribe(const DataPointPath &path, F handler) const
A convenience template function that will register a callback to receive datapoint value change notif...
Definition repositorySubscriberIf.hpp:461
std::function< void(const DataPointPath &path, T &value)> ValueHandler
Signature of value callbacks.
Definition repositorySubscriberIf.hpp:430
std::function< void(const DataPointPath &path)> NotifyHandler
Signature of notification callbacks.
Definition repositorySubscriberIf.hpp:426
virtual ~RepositorySubscriberIf()=default
std::function< void(const DataPointPath &, T &, const MetaData &)> ValueCallbackType
Definition repositorySubscriberIf.hpp:46
std::function< void(const DataPointPath &, const MetaData &)> NotifyCallbackType
Definition repositorySubscriberIf.hpp:48
size_t SubscriptionId
Definition repositorySubscriberIf.hpp:51
RepositorySubscriberIf()=default
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
#define RTCTK_API
Helper to indicate that a class or function must be exported in the public symbol table.
Definition config.hpp:33
Definition commandReplier.cpp:22
uint64_t RtcUInt64
Definition repositoryIf.hpp:61
DataPointPath m_path
Definition populateConfig.cpp:165
Header file for RepositoryIf and related base classes.
Implementation file for RepositorySubscriberIf template methods and related classes.
Definition repositorySubscriberIf.ipp:41