RTC Toolkit 4.0.1
Loading...
Searching...
No Matches
persistentRepoAdapter.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_PERSISTENTREPOADAPTER_HPP
14#define RTCTK_COMPONENTFRAMEWORK_PERSISTENTREPOADAPTER_HPP
15
16#include <atomic>
17#include <memory>
18#include <mutex>
19#include <string>
20#include <typeindex>
21#include <typeinfo>
22#include <unordered_map>
23
24#include <mal/utility/Uri.hpp>
25
31
33
53public:
54 inline static const std::string SUPPORTED_URI_SCHEME = "cii.config";
55
62 public:
63 explicit ServiceFailureException(const DataPointPath& path);
64 };
65
70 public:
71 explicit InvalidDocumentException(const DataPointPath& path, const elt::mal::Uri& uri);
72 explicit InvalidDocumentException(const DataPointPath& path,
73 const elt::mal::Uri& uri,
74 const std::string& message);
75 };
76
81 public:
82 explicit PathMissingException(const DataPointPath& path);
83 };
84
87
90
93
96
99
110 explicit PersistentRepoAdapter(const elt::mal::Uri& baseuri, bool simple_layout = false);
111
119 elt::mal::Uri GetBaseUri() const {
120 return m_path_mapper.GetBaseUri();
121 }
122
123 virtual ~PersistentRepoAdapter() = default;
124
126 void CreateDataPoint(const DataPointPath& path, const std::type_info& type) override;
127
128 void DeleteDataPoint(const DataPointPath& path) override;
129 const std::type_info& GetDataPointType(const DataPointPath& path) const override;
130 std::size_t GetDataPointSize(const DataPointPath& path) const override;
131 bool DataPointExists(const DataPointPath& path) const override;
132 std::pair<PathList, PathList> GetChildren(const DataPointPath& path) const override;
133 Response SendReadRequest(const ReadRequest& request) const override;
134 Response SendWriteRequest(const WriteRequest& request) override;
135
141 std::uint64_t GetFitsWriteThreshold() const {
142 return m_fits_write_threshold;
143 }
144
149 void SetFitsWriteThreshold(std::uint64_t value) {
150 m_fits_write_threshold = value;
151 }
152
153private:
171 template <typename R, typename F>
172 Response ProcessRequest(const R& request, F dispatch) const;
173
187 template <typename T>
188 static void CheckBufferAndDataPointTypesMatch(const std::type_info& type, const T* node);
189
193 class IoFunctions {
194 public:
195 virtual ~IoFunctions() = default;
196 virtual void
197 CreateDataPoint(const PersistentRepoAdapter* repo, const DataPointPath& path) const = 0;
198 virtual void ReadDataPoint(const PersistentRepoAdapter* repo,
199 const DataPointPath& path,
200 void* buffer) const = 0;
201 virtual void WriteDataPoint(const PersistentRepoAdapter* repo,
202 const DataPointPath& path,
203 const void* buffer) const = 0;
204 };
205
218 template <typename T>
219 class IoFunctionsImpl : public IoFunctions {
220 public:
221 IoFunctionsImpl(const std::string& yaml_type) : m_yaml_type(yaml_type){};
222 virtual ~IoFunctionsImpl() = default;
223 void CreateDataPoint(const PersistentRepoAdapter* repo,
224 const DataPointPath& path) const override;
225 void ReadDataPoint(const PersistentRepoAdapter* repo,
226 const DataPointPath& path,
227 void* buffer) const override;
228 void WriteDataPoint(const PersistentRepoAdapter* repo,
229 const DataPointPath& path,
230 const void* buffer) const override;
231
232 private:
233 std::string m_yaml_type;
234 };
235
236 using IoFunctionMap = std::unordered_map<std::type_index, std::shared_ptr<IoFunctions>>;
237
243 template <typename T>
244 static auto MakeMapEntry(const std::string& yaml_type);
245
246 log4cplus::Logger& m_logger;
247
252 mutable std::mutex m_mutex;
253
255 PathMapper m_path_mapper;
256
261 std::atomic<std::uint64_t> m_fits_write_threshold;
262
263 using TypeMap = std::unordered_map<std::string, const std::type_info&>;
264
266 static const TypeMap S_TYPE_MAP;
267
272 static const IoFunctionMap S_IO_FUNCTIONS;
273};
274
275} // namespace rtctk::componentFramework
276
277#endif // RTCTK_COMPONENTFRAMEWORK_PERSISTENTREPOADAPTER_HPP
This class provides a wrapper for a data point path.
Definition: dataPointPath.hpp:73
const elt::mal::Uri & GetBaseUri() const
Definition: pathMapper.hpp:67
Exception indicating that validation checks of a CII configuration document failed.
Definition: persistentRepoAdapter.hpp:69
Exception indicating a datapoint path does not exist.
Definition: persistentRepoAdapter.hpp:80
Exception indicating a general CII configuration service error.
Definition: persistentRepoAdapter.hpp:61
Implements the Persistent Configuration Repository adapter that uses the CII configuration service as...
Definition: persistentRepoAdapter.hpp:52
std::pair< PathList, PathList > GetChildren(const DataPointPath &path) const override
Queries the datapoints and child paths for a given path.
Definition: persistentRepoAdapter.cpp:847
PersistentRepoAdapter()=delete
Do not allow construction with no arguments.
PersistentRepoAdapter & operator=(PersistentRepoAdapter &&)=default
Objects of this class can be moved with the move assignment operator.
const std::type_info & GetDataPointType(const DataPointPath &path) const override
Fetches the type of the datapoint.
Definition: persistentRepoAdapter.cpp:699
Response SendReadRequest(const ReadRequest &request) const override
Sends a request to read data from the repository.
Definition: persistentRepoAdapter.cpp:901
PersistentRepoAdapter & operator=(const PersistentRepoAdapter &)=delete
This class cannot be copy assigned.
void SetFitsWriteThreshold(std::uint64_t value)
Set the number of elements above which matrices and vectors are written to FITS files.
Definition: persistentRepoAdapter.hpp:149
PersistentRepoAdapter(const PersistentRepoAdapter &)=delete
This class cannot be copy constructed.
elt::mal::Uri GetBaseUri() const
Get the base URI used when creating this adapter object.
Definition: persistentRepoAdapter.hpp:119
void CreateDataPoint(const DataPointPath &path, const std::type_info &type) override
Creates a new datapoint in the repository with a specified type.
Definition: persistentRepoAdapter.cpp:581
PersistentRepoAdapter(PersistentRepoAdapter &&)=default
Objects of this class can be moved.
static const std::string SUPPORTED_URI_SCHEME
Definition: persistentRepoAdapter.hpp:54
void DeleteDataPoint(const DataPointPath &path) override
Deletes a datapoint.
Definition: persistentRepoAdapter.cpp:596
Response SendWriteRequest(const WriteRequest &request) override
Sends a request to write data to the repository.
Definition: persistentRepoAdapter.cpp:908
std::size_t GetDataPointSize(const DataPointPath &path) const override
Fetches the size of the datapoint's data.
Definition: persistentRepoAdapter.cpp:731
std::uint64_t GetFitsWriteThreshold() const
Return the number of elements above which matrices and vectors are written to FITS files.
Definition: persistentRepoAdapter.hpp:141
bool DataPointExists(const DataPointPath &path) const override
Checks for the existence of a datapoint in the repository.
Definition: persistentRepoAdapter.cpp:825
Base interface for all Persistent Configuration Repository adapters.
Definition: persistentRepoIf.hpp:25
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.
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:237
Provides macros and utilities for exception handling.
Declaration of FileRepository that provides a simple file based repository.
Logging Support Library based on log4cplus.
Definition: commandReplier.cpp:22
Header file declaring PathMapper.
Header file for PersistentRepoIf, which defines the API for PersistentRepoAdapter.