RTC Toolkit 4.0.1
Loading...
Searching...
No Matches
oldbAdapter.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_OLDBADAPTER_HPP
14#define RTCTK_COMPONENTFRAMEWORK_OLDBADAPTER_HPP
15
16#include <functional>
17#include <typeindex>
18
19#include <ciiOldb.hpp>
20#include <ciiOldbSubscription.hpp>
21#include <ciiOldbTypedDataBase.hpp>
22
24
26
38class OldbAdapter : public OldbIf {
39public:
40 inline static const std::string SUPPORTED_URI_SCHEME = "cii.oldb";
41
43 OldbAdapter() = delete;
44
46 OldbAdapter(const OldbAdapter&) = delete;
47
50
53
56
62 explicit OldbAdapter(const elt::mal::Uri& baseuri);
63
70 explicit OldbAdapter(const elt::mal::Uri& baseuri,
71 const std::shared_ptr<elt::oldb::CiiOldb>& oldb);
72
76 virtual ~OldbAdapter();
77
85 elt::mal::Uri GetBaseUri() const {
86 return m_baseuri;
87 }
88
90
108 void CreateDataPoint(const DataPointPath& path, const std::type_info& type) override;
109
124 void DeleteDataPoint(const DataPointPath& path) override;
125
142 const std::type_info& GetDataPointType(const DataPointPath& path) const override;
143
164 std::size_t GetDataPointSize(const DataPointPath& path) const override;
165
166 bool DataPointExists(const DataPointPath& path) const override;
167 std::pair<PathList, PathList> GetChildren(const DataPointPath& path) const override;
168 Response SendReadRequest(const ReadRequest& request) const override;
169 Response SendWriteRequest(const WriteRequest& request) override;
170 Response SendSubscribeRequest(const SubscribeRequest& request) const override;
171 Response SendUnsubscribeRequest(const UnsubscribeRequest& request) const override;
172
188 static void InitMetadata();
189
190protected:
200 void SetMetadataInstanceMap(const std::map<std::type_index, std::string>& map);
201
211 void SetTypeInfoMap(const std::map<std::string, const std::type_info&>& map);
212
220 elt::oldb::CiiOldbDpCreateContext GetDataPointCreateContext() const;
221
229 void SetDataPointCreateContext(elt::oldb::CiiOldbDpCreateContext& context);
230
231private:
248 template <typename R, typename F>
249 Response ProcessRequest(const R& request, F selector) const;
250
257 template <typename T>
258 void ReadData(const DataPointPath& path, T& buffer) const;
259
266 template <typename T>
267 void WriteData(const DataPointPath& path, const T& buffer) const;
268
274 template <typename T>
275 void RegisterSubscription(const SubscribeRequest::Parameters& params) const;
276
278 struct IoFunctionMapEntry {
279 using ReadFunction = std::function<void(const OldbAdapter*, const DataPointPath&, void*)>;
280 using WriteFunction =
281 std::function<void(const OldbAdapter*, const DataPointPath&, const void*)>;
282 using RegisterFunction =
283 std::function<void(const OldbAdapter*, const SubscribeRequest::Parameters&)>;
284
285 ReadFunction m_read_function;
286 WriteFunction m_write_function;
287 RegisterFunction m_register_function;
288 };
289
291 using IoFunctionMap = std::map<std::type_index, IoFunctionMapEntry>;
292
298 template <typename T>
299 static auto MakeMapEntry();
300
302 struct SubscriptionEntry {
303 std::shared_ptr<elt::oldb::CiiOldbTypedDataBase> m_datapoint;
304 std::shared_ptr<elt::oldb::CiiOldbDpSubscriptionBase> m_subscription;
305
313 std::function<bool(const SubscriptionEntry&, const UnsubscribeRequest::Parameters&)>
314 m_unregister_callback;
315 };
316
317 using SubsciptionMap = std::list<SubscriptionEntry>;
318
329 template <typename T, typename U, typename V>
330 void CastAndRegisterSubscription(
331 const SubscribeRequest::Parameters& params,
332 const std::shared_ptr<elt::oldb::CiiOldbTypedDataBase>& datapoint,
333 std::function<void(T*, const std::shared_ptr<elt::oldb::CiiOldbDpValue<U>>&)>
334 write_function) const;
335
337 mutable std::shared_ptr<elt::oldb::CiiOldb> m_client;
338
343 const elt::mal::Uri m_baseuri;
344
346 mutable std::list<SubscriptionEntry> m_subscriptions;
347
349 mutable std::mutex m_mutex;
350
352 const std::map<std::type_index, std::string>* m_metadata_instance_map = nullptr;
353
355 static const std::map<std::type_index, std::string> S_METADATA_INSTANCE_MAP;
356
358 const std::map<std::string, const std::type_info&>* m_type_info_map = nullptr;
359
361 static const std::map<std::string, const std::type_info&> S_TYPE_INFO_MAP;
362
364 static const IoFunctionMap S_IO_FUNCTIONS;
365};
366
367} // namespace rtctk::componentFramework
368
369#endif // RTCTK_COMPONENTFRAMEWORK_OLDBADAPTER_HPP
This class provides a wrapper for a data point path.
Definition: dataPointPath.hpp:73
Provides access to the OLDB to read and write datapoints.
Definition: oldbAdapter.hpp:38
Response SendReadRequest(const ReadRequest &request) const override
Sends a request to read data from the repository.
Definition: oldbAdapter.cpp:560
std::size_t GetDataPointSize(const DataPointPath &path) const override
Returns the size of a datapoint in the OLDB.
Definition: oldbAdapter.cpp:457
OldbAdapter(const OldbAdapter &)=delete
This class cannot be copy constructed.
void SetTypeInfoMap(const std::map< std::string, const std::type_info & > &map)
Sets the OLDB metadata instance name to type_info map.
Definition: oldbAdapter.cpp:1278
static void InitMetadata()
Initialises the type metadata in the CII configuration service for the OLDB.
Definition: oldbAdapter.cpp:778
OldbAdapter & operator=(const OldbAdapter &)=delete
This class cannot be copy assigned.
std::pair< PathList, PathList > GetChildren(const DataPointPath &path) const override
Queries the datapoints and child paths for a given path.
Definition: oldbAdapter.cpp:540
static const std::string SUPPORTED_URI_SCHEME
Definition: oldbAdapter.hpp:40
OldbAdapter()=delete
Do not allow construction with no arguments.
virtual ~OldbAdapter()
Destroys the adapter for the OLDB service releasing allocated resources.
Definition: oldbAdapter.cpp:348
Response SendSubscribeRequest(const SubscribeRequest &request) const override
This is called to asynchronously send a subscription request for datapoints.
Definition: oldbAdapter.cpp:723
const std::type_info & GetDataPointType(const DataPointPath &path) const override
Retrieves the corresponding C++ type for the datapoint from the OLDB.
Definition: oldbAdapter.cpp:373
void CreateDataPoint(const DataPointPath &path, const std::type_info &type) override
Creates a new datapoint in the OLDB.
Definition: oldbAdapter.cpp:351
elt::oldb::CiiOldbDpCreateContext GetDataPointCreateContext() const
Get the datapoint creation context used by the underlying OLDB client object.
Definition: oldbAdapter.cpp:1282
OldbAdapter & operator=(OldbAdapter &&)=default
Objects of this class can be moved with the move assignment operator.
void DeleteDataPoint(const DataPointPath &path) override
Deletes a datapoint in the OLDB.
Definition: oldbAdapter.cpp:368
Response SendUnsubscribeRequest(const UnsubscribeRequest &request) const override
This is called to asynchronously send a request to unsubscribe from various notifications.
Definition: oldbAdapter.cpp:749
void SetDataPointCreateContext(elt::oldb::CiiOldbDpCreateContext &context)
Sets a new datapoint creation context on the underlying OLDB client object.
Definition: oldbAdapter.cpp:1286
bool DataPointExists(const DataPointPath &path) const override
Checks for the existence of a datapoint in the repository.
Definition: oldbAdapter.cpp:535
void SetMetadataInstanceMap(const std::map< std::type_index, std::string > &map)
Sets the type_index to OLDB metadata instance name map.
Definition: oldbAdapter.cpp:1235
elt::mal::Uri GetBaseUri() const
Get the base URI used when creating this adapter object.
Definition: oldbAdapter.hpp:85
OldbAdapter(OldbAdapter &&)=default
Objects of this class can be moved.
Response SendWriteRequest(const WriteRequest &request) override
Sends a request to write data to the repository.
Definition: oldbAdapter.cpp:564
Base interface for all OLDB adapters.
Definition: oldbIf.hpp:26
A request object to pass information about datapoints that should be read from the repository.
Definition: repositoryIf.hpp:49
An object used to wait for a request to complete.
Definition: repositoryIf.hpp:197
A request object to pass information about datapoints that should be written to the repository.
Definition: repositoryIf.hpp:122
virtual void CreateDataPoint(const DataPointPath &path, const std::type_info &type)=0
Creates a new datapoint in the repository with a specified type.
Definition: commandReplier.cpp:22
Header file for OldbIf, which defines the API for OldbAdapters.