RTC Toolkit 4.0.1
Loading...
Searching...
No Matches
fileRepository.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_FILEREPOSITORY_HPP
14#define RTCTK_COMPONENTFRAMEWORK_FILEREPOSITORY_HPP
15
16#include <exception>
17#include <functional>
18#include <mutex>
19#include <thread>
20
21#include <boost/filesystem.hpp>
22#include <mal/utility/Uri.hpp>
23
26
28
34public:
35 explicit PathMissingException(const std::string& path);
36};
37
43public:
44 explicit FileFormatError(const boost::filesystem::path& filepath);
45};
46
52public:
53 explicit InvalidUriInFileError(const boost::filesystem::path& filepath, const std::string& uri);
54};
55
61public:
62 explicit DirCreationError(const boost::filesystem::path& path);
63};
64
88class FileRepository : virtual public RepositoryIf {
89public:
90 FileRepository() = delete;
93 explicit FileRepository(const elt::mal::Uri& datauri, const int dirdepth);
94 virtual ~FileRepository() noexcept = default;
95
97 void CreateDataPoint(const DataPointPath& path, const std::type_info& type) override;
98
99 void DeleteDataPoint(const DataPointPath& path) override;
100 const std::type_info& GetDataPointType(const DataPointPath& path) const override;
101 size_t GetDataPointSize(const DataPointPath& path) const override;
102 bool DataPointExists(const DataPointPath& path) const override;
103 std::pair<PathList, PathList> GetChildren(const DataPointPath& path) const override;
104 Response SendReadRequest(const ReadRequest& request) const override;
105 Response SendWriteRequest(const WriteRequest& request) override;
106
114 inline size_t GetFitsWriteThreshold() const {
115 std::scoped_lock lck(m_mutex);
116 return m_fits_write_threshold;
117 }
118
129 inline void SetFitsWriteThreshold(size_t value) {
130 std::scoped_lock lck(m_mutex);
131 m_fits_write_threshold = value;
132 }
133
134protected:
145 std::string GetServerAlias(const DataPointPath& path) const;
146
156 void SetServerAlias(const DataPointPath& path, const std::string& server_alias);
157
158private:
175 template <typename R, typename F>
176 Response ProcessRequest(const R& request, F selector) const;
177
186 template <typename T>
187 void ReadData(const DataPointPath& path, T& buffer, const std::string& typestr) const;
188
197 template <typename T>
198 void WriteData(const DataPointPath& path, const T& buffer, const std::string& typestr) const;
199
201 struct IoFunctionMapEntry {
202 using ReadFunction =
203 std::function<void(const FileRepository*, const DataPointPath&, void*)>;
204 using WriteFunction =
205 std::function<void(const FileRepository*, const DataPointPath&, const void*)>;
206
207 ReadFunction m_read_function;
208 WriteFunction m_write_function;
209 };
210
212 using IoFunctionMap = std::map<std::type_index, IoFunctionMapEntry>;
213
222 template <typename T>
223 static auto MakeMapEntry(const std::string& typestr);
224
231 mutable std::mutex m_mutex;
232 boost::filesystem::path m_datapath;
233 std::string m_defaultfile;
234 int m_dirdepth;
235 size_t m_fits_write_threshold;
236
238 static const IoFunctionMap S_IO_FUNCTIONS;
239};
240
241} // namespace rtctk::componentFramework
242
243#endif // RTCTK_COMPONENTFRAMEWORK_FILEREPOSITORY_HPP
This class provides a wrapper for a data point path.
Definition: dataPointPath.hpp:73
Definition: fileRepository.hpp:60
Definition: fileRepository.hpp:42
Implements a file based repository that stores datapoints in local YAML and FITS files.
Definition: fileRepository.hpp:88
size_t GetDataPointSize(const DataPointPath &path) const override
Fetches the size of the datapoint's data.
Definition: fileRepository.cpp:1009
FileRepository(const FileRepository &)=delete
const std::type_info & GetDataPointType(const DataPointPath &path) const override
Fetches the type of the datapoint.
Definition: fileRepository.cpp:973
void SetFitsWriteThreshold(size_t value)
Sets the threshold for storing numerical matrices and vectors in FITS files rather than the YAML file...
Definition: fileRepository.hpp:129
size_t GetFitsWriteThreshold() const
Definition: fileRepository.hpp:114
std::pair< PathList, PathList > GetChildren(const DataPointPath &path) const override
Queries the datapoints and child paths for a given path.
Definition: fileRepository.cpp:1191
FileRepository & operator=(const FileRepository &)=delete
bool DataPointExists(const DataPointPath &path) const override
Checks for the existence of a datapoint in the repository.
Definition: fileRepository.cpp:1103
std::string GetServerAlias(const DataPointPath &path) const
Fetches the server alias string encoded for a datapoint.
Definition: fileRepository.cpp:1259
virtual ~FileRepository() noexcept=default
Response SendReadRequest(const ReadRequest &request) const override
Sends a request to read data from the repository.
Definition: fileRepository.cpp:1232
Response SendWriteRequest(const WriteRequest &request) override
Sends a request to write data to the repository.
Definition: fileRepository.cpp:1236
void SetServerAlias(const DataPointPath &path, const std::string &server_alias)
Encodes the server alias string for a datapoint.
Definition: fileRepository.cpp:1273
void CreateDataPoint(const DataPointPath &path, const std::type_info &type) override
Creates a new datapoint in the repository with a specified type.
Definition: fileRepository.cpp:871
void DeleteDataPoint(const DataPointPath &path) override
Deletes a datapoint.
Definition: fileRepository.cpp:929
Definition: fileRepository.hpp:51
Definition: fileRepository.hpp:33
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
Abstract interface providing basic read and write facilities to a repository.
Definition: repositoryIf.hpp:38
std::vector< DataPointPath > PathList
Definition: repositoryIf.hpp:40
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:237
Provides macros and utilities for exception handling.
Definition: commandReplier.cpp:22
Header file for RepositoryIf and related base classes.