RTC Toolkit  2.0.0
oldbAdapter.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_COMPONENTFRAMEWORK_OLDBADAPTER_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_OLDBADAPTER_HPP
14 
15 #include <functional>
16 #include <typeindex>
17 
18 #include <ciiOldb.hpp>
19 #include <ciiOldbSubscription.hpp>
20 #include <ciiOldbTypedDataBase.hpp>
21 
23 
24 namespace rtctk::componentFramework {
25 
34 class OldbAdapter : public OldbIf {
35 public:
37  OldbAdapter() = delete;
38 
40  OldbAdapter(const OldbAdapter&) = delete;
41 
43  OldbAdapter& operator=(const OldbAdapter&) = delete;
44 
46  OldbAdapter(OldbAdapter&&) = default;
47 
50 
56  explicit OldbAdapter(const elt::mal::Uri& baseuri);
57 
64  explicit OldbAdapter(const elt::mal::Uri& baseuri,
65  const std::shared_ptr<elt::oldb::CiiOldb>& oldb);
66 
70  virtual ~OldbAdapter();
71 
73 
92  void CreateDataPoint(const DataPointPath& path, const std::type_info& type) override;
93 
108  void DeleteDataPoint(const DataPointPath& path) override;
109 
126  const std::type_info& GetDataPointType(const DataPointPath& path) const override;
127 
148  std::size_t GetDataPointSize(const DataPointPath& path) const override;
149 
150  bool DataPointExists(const DataPointPath& path) const override;
151  std::pair<PathList, PathList> GetChildren(const DataPointPath& path) const override;
152  Response SendReadRequest(const ReadRequest& request) const override;
153  Response SendWriteRequest(const WriteRequest& request) override;
154  Response SendSubscribeRequest(const SubscribeRequest& request) const override;
155  Response SendUnsubscribeRequest(const UnsubscribeRequest& request) const override;
156 
172  static void InitMetadata();
173 
174 protected:
184  void SetMetadataInstanceMap(const std::map<std::type_index, std::string>& map);
185 
195  void SetTypeInfoMap(const std::map<std::string, const std::type_info&>& map);
196 
197 private:
214  template <typename R, typename F>
215  Response ProcessRequest(const R& request, F selector) const;
216 
223  template <typename T>
224  void ReadData(const DataPointPath& path, T& buffer) const;
225 
232  template <typename T>
233  void WriteData(const DataPointPath& path, const T& buffer) const;
234 
240  template <typename T>
241  void RegisterSubscription(const SubscribeRequest::Parameters& params) const;
242 
244  struct IoFunctionMapEntry {
245  using ReadFunction = std::function<void(const OldbAdapter*, const DataPointPath&, void*)>;
246  using WriteFunction =
247  std::function<void(const OldbAdapter*, const DataPointPath&, const void*)>;
248  using RegisterFunction =
249  std::function<void(const OldbAdapter*, const SubscribeRequest::Parameters&)>;
250 
251  ReadFunction m_read_function;
252  WriteFunction m_write_function;
253  RegisterFunction m_register_function;
254  };
255 
257  using IoFunctionMap = std::map<std::type_index, IoFunctionMapEntry>;
258 
264  template <typename T>
265  static auto MakeMapEntry();
266 
268  struct SubscriptionEntry {
269  std::shared_ptr<elt::oldb::CiiOldbTypedDataBase> m_datapoint;
270  std::shared_ptr<elt::oldb::CiiOldbDpSubscriptionBase> m_subscription;
271 
279  std::function<bool(const SubscriptionEntry&, const UnsubscribeRequest::Parameters&)>
280  m_unregister_callback;
281  };
282 
283  using SubsciptionMap = std::list<SubscriptionEntry>;
284 
295  template <typename T, typename U, typename V>
296  void CastAndRegisterSubscription(
297  const SubscribeRequest::Parameters& params,
298  const std::shared_ptr<elt::oldb::CiiOldbTypedDataBase>& datapoint,
299  std::function<void(T*, const std::shared_ptr<elt::oldb::CiiOldbDpValue<U>>&)>
300  write_function) const;
301 
303  mutable std::shared_ptr<elt::oldb::CiiOldb> m_client;
304 
309  const elt::mal::Uri m_baseuri;
310 
312  mutable std::list<SubscriptionEntry> m_subscriptions;
313 
315  mutable std::mutex m_mutex;
316 
318  const std::map<std::type_index, std::string>* m_metadata_instance_map = nullptr;
319 
321  static const std::map<std::type_index, std::string> S_METADATA_INSTANCE_MAP;
322 
324  const std::map<std::string, const std::type_info&>* m_type_info_map = nullptr;
325 
327  static const std::map<std::string, const std::type_info&> S_TYPE_INFO_MAP;
328 
330  static const IoFunctionMap S_IO_FUNCTIONS;
331 };
332 
333 } // namespace rtctk::componentFramework
334 
335 #endif // RTCTK_COMPONENTFRAMEWORK_OLDBADAPTER_HPP
rtctk::componentFramework::OldbAdapter::operator=
OldbAdapter & operator=(OldbAdapter &&)=default
Objects of this class can be moved with the move assignment operator.
rtctk::componentFramework::OldbAdapter::SetTypeInfoMap
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:1216
rtctk::componentFramework::OldbAdapter::DeleteDataPoint
void DeleteDataPoint(const DataPointPath &path) override
Deletes a datapoint in the OLDB.
Definition: oldbAdapter.cpp:309
rtctk::componentFramework::OldbAdapter::SendWriteRequest
Response SendWriteRequest(const WriteRequest &request) override
Sends a request to write data to the repository.
Definition: oldbAdapter.cpp:509
rtctk::componentFramework::OldbAdapter::operator=
OldbAdapter & operator=(const OldbAdapter &)=delete
This class cannot be copy assigned.
rtctk::componentFramework::RepositoryIf::ReadRequest
A request object to pass information about datapoints that should be read from the repository.
Definition: repositoryIf.hpp:44
rtctk::componentFramework::OldbAdapter
Provides access to the OLDB to read and write datapoints.
Definition: oldbAdapter.hpp:34
rtctk::componentFramework::OldbAdapter::SetMetadataInstanceMap
void SetMetadataInstanceMap(const std::map< std::type_index, std::string > &map)
Sets the type_index to OLDB metadata instance name map.
Definition: oldbAdapter.cpp:1173
rtctk::componentFramework::OldbAdapter::DataPointExists
bool DataPointExists(const DataPointPath &path) const override
Checks for the existence of a datapoint in the repository.
Definition: oldbAdapter.cpp:476
rtctk::componentFramework::OldbAdapter::SendUnsubscribeRequest
Response SendUnsubscribeRequest(const UnsubscribeRequest &request) const override
This is called to asynchronously send a request to unsubscribe from various notifications.
Definition: oldbAdapter.cpp:693
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::RepositorySubscriberIf::SubscribeRequest
A request object to pass information about datapoints to subscribe to.
Definition: repositorySubscriberIf.hpp:33
rtctk::componentFramework::OldbAdapter::GetDataPointSize
std::size_t GetDataPointSize(const DataPointPath &path) const override
Returns the size of a datapoint in the OLDB.
Definition: oldbAdapter.cpp:398
rtctk::componentFramework::OldbAdapter::SendReadRequest
Response SendReadRequest(const ReadRequest &request) const override
Sends a request to read data from the repository.
Definition: oldbAdapter.cpp:505
rtctk::componentFramework::OldbAdapter::OldbAdapter
OldbAdapter(const OldbAdapter &)=delete
This class cannot be copy constructed.
rtctk::componentFramework::OldbAdapter::GetChildren
std::pair< PathList, PathList > GetChildren(const DataPointPath &path) const override
Queries the datapoints and child paths for a given path.
Definition: oldbAdapter.cpp:486
rtctk::componentFramework::RepositoryIf::WriteRequest
A request object to pass information about datapoints that should be written to the repository.
Definition: repositoryIf.hpp:115
rtctk::componentFramework::RepositorySubscriberIf::UnsubscribeRequest
A request object to pass information about datapoints to unsubscribe from.
Definition: repositorySubscriberIf.hpp:115
rtctk::componentFramework::OldbAdapter::InitMetadata
static void InitMetadata()
Initialises the type metadata in the CII configuration service for the OLDB.
Definition: oldbAdapter.cpp:721
rtctk::componentFramework::OldbIf
Definition: oldbIf.hpp:20
rtctk::componentFramework::OldbAdapter::OldbAdapter
OldbAdapter()=delete
Do not allow construction with no arguments.
rtctk::componentFramework::OldbAdapter::OldbAdapter
OldbAdapter(OldbAdapter &&)=default
Objects of this class can be moved.
rtctk::componentFramework::RepositoryIf::CreateDataPoint
virtual void CreateDataPoint(const DataPointPath &path, const std::type_info &type)=0
Creates a new datapoint in the repository with a specified type.
rtctk::componentFramework::DataPointPath
This class provides a wrapper for a data point path.
Definition: dataPointPath.hpp:65
rtctk::componentFramework::RepositoryIf::Response
An object used to wait for a request to complete.
Definition: repositoryIf.hpp:188
rtctk::componentFramework::OldbAdapter::CreateDataPoint
virtual void CreateDataPoint(const DataPointPath &path, const std::type_info &type)=0
Creates a new datapoint in the repository with a specified type.
rtctk::componentFramework::OldbAdapter::SendSubscribeRequest
Response SendSubscribeRequest(const SubscribeRequest &request) const override
This is called to asynchronously send a subscription request for datapoints.
Definition: oldbAdapter.cpp:667
rtctk_config_tool.type
type
List all available datapoint paths under a given path hierarchy.
Definition: rtctk_config_tool.py:44
rtctk::componentFramework::OldbAdapter::~OldbAdapter
virtual ~OldbAdapter()
Destroys the adapter for the OLDB service releasing allocated resources.
Definition: oldbAdapter.cpp:289
rtctk::componentFramework::OldbAdapter::GetDataPointType
const std::type_info & GetDataPointType(const DataPointPath &path) const override
Retrieves the corresponding C++ type for the datapoint from the OLDB.
Definition: oldbAdapter.cpp:314
oldbIf.hpp
Header file for OldbIf, which defines the API for OldbAdapters.