RTC Toolkit  1.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<StringList, StringList> GetChildren(const DataPointPath& path) const override;
152  Response SendReadRequest(const Request& request) const override;
153  Response SendWriteRequest(const Request& request) override;
154  Response SendSubscribeRequest(const SubscribeRequest& request) const override;
155  Response SendUnsubscribeRequest(const UnsubscribeRequest& request) const override;
156 
157 protected:
167  void SetMetadataInstanceMap(const std::map<std::type_index, std::string>& map);
168 
178  void SetTypeInfoMap(const std::map<std::string, const std::type_info&>& map);
179 
180 private:
196  template <typename F>
197  Response ProcessRequest(const Request& request, F selector) const;
198 
205  template <typename T>
206  void ReadData(const DataPointPath& path, T& buffer) const;
207 
214  template <typename T>
215  void WriteData(const DataPointPath& path, const T& buffer) const;
216 
222  template <typename T>
223  void RegisterSubscription(const SubscribeRequest::Parameters& params) const;
224 
226  struct IoFunctionMapEntry {
227  using ReadFunction = std::function<void(const OldbAdapter*, const DataPointPath&, void*)>;
228  using WriteFunction =
229  std::function<void(const OldbAdapter*, const DataPointPath&, const void*)>;
230  using RegisterFunction =
231  std::function<void(const OldbAdapter*, const SubscribeRequest::Parameters&)>;
232 
233  ReadFunction m_read_function;
234  WriteFunction m_write_function;
235  RegisterFunction m_register_function;
236  };
237 
239  using IoFunctionMap = std::map<std::type_index, IoFunctionMapEntry>;
240 
246  template <typename T>
247  static auto MakeMapEntry();
248 
250  struct SubscriptionEntry {
251  std::shared_ptr<elt::oldb::CiiOldbTypedDataBase> m_datapoint;
252  std::shared_ptr<elt::oldb::CiiOldbDpSubscriptionBase> m_subscription;
253 
261  std::function<bool(const SubscriptionEntry&, const UnsubscribeRequest::Parameters&)>
262  m_unregister_callback;
263  };
264 
265  using SubsciptionMap = std::list<SubscriptionEntry>;
266 
277  template <typename T, typename U, typename V>
278  void CastAndRegisterSubscription(
279  const SubscribeRequest::Parameters& params,
280  const std::shared_ptr<elt::oldb::CiiOldbTypedDataBase>& datapoint,
281  std::function<void(T*, const std::shared_ptr<elt::oldb::CiiOldbDpValue<U>>&)>
282  write_function) const;
283 
285  mutable std::shared_ptr<elt::oldb::CiiOldb> m_client;
286 
291  const elt::mal::Uri m_baseuri;
292 
294  mutable std::list<SubscriptionEntry> m_subscriptions;
295 
297  mutable std::mutex m_mutex;
298 
300  const std::map<std::type_index, std::string>* m_metadata_instance_map = nullptr;
301 
303  static const std::map<std::type_index, std::string> S_METADATA_INSTANCE_MAP;
304 
306  const std::map<std::string, const std::type_info&>* m_type_info_map = nullptr;
307 
309  static const std::map<std::string, const std::type_info&> S_TYPE_INFO_MAP;
310 
312  static const IoFunctionMap S_IO_FUNCTIONS;
313 };
314 
315 } // namespace rtctk::componentFramework
316 
317 #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:1034
rtctk::componentFramework::OldbAdapter::DeleteDataPoint
void DeleteDataPoint(const DataPointPath &path) override
Deletes a datapoint in the OLDB.
Definition: oldbAdapter.cpp:318
rtctk::componentFramework::OldbAdapter::operator=
OldbAdapter & operator=(const OldbAdapter &)=delete
This class cannot be copy assigned.
rtctk::componentFramework::OldbAdapter::SendReadRequest
Response SendReadRequest(const Request &request) const override
Sends a request to read data from the repository.
Definition: oldbAdapter.cpp:514
rtctk::componentFramework::RepositoryIf::Request
A request object to pass information about datapoints that should be read (written) from (to) the rep...
Definition: repositoryIf.hpp:45
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:991
rtctk::componentFramework::OldbAdapter::DataPointExists
bool DataPointExists(const DataPointPath &path) const override
Checks for the existence of a datapoint in the repository.
Definition: oldbAdapter.cpp:485
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:695
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::RepositorySubscriberIf::SubscribeRequest
A request object to pass information about datapoints to subscribe to.
Definition: repositorySubscriberIf.hpp:31
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:407
rtctk::componentFramework::OldbAdapter::OldbAdapter
OldbAdapter(const OldbAdapter &)=delete
This class cannot be copy constructed.
rtctk::componentFramework::OldbAdapter::GetChildren
std::pair< StringList, StringList > GetChildren(const DataPointPath &path) const override
Queries the datapoints and child paths for a given path.
Definition: oldbAdapter.cpp:495
rtctk::componentFramework::OldbAdapter::SendWriteRequest
Response SendWriteRequest(const Request &request) override
Sends a request to write data to the repository.
Definition: oldbAdapter.cpp:518
rtctk::componentFramework::RepositorySubscriberIf::UnsubscribeRequest
A request object to pass information about datapoints to unsubscribe from.
Definition: repositorySubscriberIf.hpp:95
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 wraper for DataPoint paths which ensures that they only contain valid character...
Definition: dataPointPath.hpp:34
rtctk::componentFramework::RepositoryIf::Response
An object used to wait for a request to complete.
Definition: repositoryIf.hpp:106
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:676
rtctk::componentFramework::OldbAdapter::~OldbAdapter
virtual ~OldbAdapter()
Destroys the adapter for the OLDB service releasing allocated resources.
Definition: oldbAdapter.cpp:298
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:323
oldbIf.hpp
Header file for OldbIf, which defines the API for OldbAdapters.