RTC Toolkit  2.0.0
fileRepository.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_COMPONENTFRAMEWORK_FILEREPOSITORY_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_FILEREPOSITORY_HPP
14 
15 #include <exception>
16 #include <functional>
17 #include <mutex>
18 #include <thread>
19 
20 #include <boost/filesystem.hpp>
21 #include <mal/utility/Uri.hpp>
22 
25 
26 namespace rtctk::componentFramework {
27 
29 public:
30  explicit PathMissingException(const std::string& path);
31 };
32 
34 public:
35  explicit FileFormatError(const boost::filesystem::path& filepath);
36 };
37 
39 public:
40  explicit InvalidUriInFileError(const boost::filesystem::path& filepath, const std::string& uri);
41 };
42 
44 public:
45  explicit DirCreationError(const boost::filesystem::path& path);
46 };
47 
68 class FileRepository : virtual public RepositoryIf {
69 public:
70  FileRepository() = delete;
71  FileRepository(const FileRepository&) = delete;
73  explicit FileRepository(const elt::mal::Uri& datauri, const int dirdepth);
74  virtual ~FileRepository() noexcept = default;
75 
77  void CreateDataPoint(const DataPointPath& path, const std::type_info& type) override;
78 
79  void DeleteDataPoint(const DataPointPath& path) override;
80  const std::type_info& GetDataPointType(const DataPointPath& path) const override;
81  size_t GetDataPointSize(const DataPointPath& path) const override;
82  bool DataPointExists(const DataPointPath& path) const override;
83  std::pair<PathList, PathList> GetChildren(const DataPointPath& path) const override;
84  Response SendReadRequest(const ReadRequest& request) const override;
85  Response SendWriteRequest(const WriteRequest& request) override;
86 
94  inline size_t GetFitsWriteThreshold() const {
95  std::scoped_lock lck(m_mutex);
96  return m_fits_write_threshold;
97  }
98 
109  inline void SetFitsWriteThreshold(size_t value) {
110  std::scoped_lock lck(m_mutex);
111  m_fits_write_threshold = value;
112  }
113 
114 private:
131  template <typename R, typename F>
132  Response ProcessRequest(const R& request, F selector) const;
133 
142  template <typename T>
143  void ReadData(const DataPointPath& path, T& buffer, const std::string& typestr) const;
144 
153  template <typename T>
154  void WriteData(const DataPointPath& path, const T& buffer, const std::string& typestr) const;
155 
157  struct IoFunctionMapEntry {
158  using ReadFunction =
159  std::function<void(const FileRepository*, const DataPointPath&, void*)>;
160  using WriteFunction =
161  std::function<void(const FileRepository*, const DataPointPath&, const void*)>;
162 
163  ReadFunction m_read_function;
164  WriteFunction m_write_function;
165  };
166 
168  using IoFunctionMap = std::map<std::type_index, IoFunctionMapEntry>;
169 
178  template <typename T>
179  static auto MakeMapEntry(const std::string& typestr);
180 
187  mutable std::mutex m_mutex;
188  boost::filesystem::path m_datapath;
189  std::string m_defaultfile;
190  int m_dirdepth;
191  size_t m_fits_write_threshold;
192 
194  static const IoFunctionMap S_IO_FUNCTIONS;
195 };
196 
197 } // namespace rtctk::componentFramework
198 
199 #endif // RTCTK_COMPONENTFRAMEWORK_FILEREPOSITORY_HPP
rtctk::componentFramework::FileRepository::DeleteDataPoint
void DeleteDataPoint(const DataPointPath &path) override
Deletes a datapoint.
Definition: fileRepository.cpp:900
exceptions.hpp
Provides macros and utilities for exception handling.
rtctk::componentFramework::InvalidUriInFileError::InvalidUriInFileError
InvalidUriInFileError(const boost::filesystem::path &filepath, const std::string &uri)
Definition: fileRepository.cpp:802
rtctk::componentFramework::DirCreationError::DirCreationError
DirCreationError(const boost::filesystem::path &path)
Definition: fileRepository.cpp:809
rtctk::componentFramework::PathMissingException
Definition: fileRepository.hpp:28
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::FileRepository::FileRepository
FileRepository(const FileRepository &)=delete
rtctk::componentFramework::FileRepository
Implements a file based repository that stores datapoints in local YAML and FITS files.
Definition: fileRepository.hpp:68
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::FileFormatError
Definition: fileRepository.hpp:33
rtctk::componentFramework::PathMissingException::PathMissingException
PathMissingException(const std::string &path)
Definition: fileRepository.cpp:794
rtctk::componentFramework::RtctkException
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:207
rtctk::componentFramework::FileRepository::GetChildren
std::pair< PathList, PathList > GetChildren(const DataPointPath &path) const override
Queries the datapoints and child paths for a given path.
Definition: fileRepository.cpp:1083
rtctk::componentFramework::FileRepository::operator=
FileRepository & operator=(const FileRepository &)=delete
rtctk::componentFramework::FileRepository::GetFitsWriteThreshold
size_t GetFitsWriteThreshold() const
Definition: fileRepository.hpp:94
rtctk::componentFramework::FileRepository::GetDataPointType
const std::type_info & GetDataPointType(const DataPointPath &path) const override
Fetches the type of the datapoint.
Definition: fileRepository.cpp:944
rtctk::componentFramework::FileRepository::FileRepository
FileRepository()=delete
repositoryIf.hpp
Header file for RepositoryIf and related base classes.
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::FileRepository::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::FileRepository::SendWriteRequest
Response SendWriteRequest(const WriteRequest &request) override
Sends a request to write data to the repository.
Definition: fileRepository.cpp:1150
rtctk::componentFramework::FileRepository::SetFitsWriteThreshold
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:109
rtctk::componentFramework::RepositoryIf
Abstract interface providing basic read and write facilities to a repository.
Definition: repositoryIf.hpp:34
rtctk::componentFramework::FileRepository::SendReadRequest
Response SendReadRequest(const ReadRequest &request) const override
Sends a request to read data from the repository.
Definition: fileRepository.cpp:1146
rtctk::componentFramework::DirCreationError
Definition: fileRepository.hpp:43
rtctk::componentFramework::FileRepository::GetDataPointSize
size_t GetDataPointSize(const DataPointPath &path) const override
Fetches the size of the datapoint's data.
Definition: fileRepository.cpp:976
rtctk::componentFramework::FileRepository::~FileRepository
virtual ~FileRepository() noexcept=default
std
Definition: mudpiProcessingError.hpp:119
rtctk::componentFramework::FileFormatError::FileFormatError
FileFormatError(const boost::filesystem::path &filepath)
Definition: fileRepository.cpp:798
rtctk::componentFramework::RepositoryIf::PathList
std::vector< DataPointPath > PathList
Definition: repositoryIf.hpp:36
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::FileRepository::DataPointExists
bool DataPointExists(const DataPointPath &path) const override
Checks for the existence of a datapoint in the repository.
Definition: fileRepository.cpp:1062
rtctk_config_tool.type
type
List all available datapoint paths under a given path hierarchy.
Definition: rtctk_config_tool.py:44
rtctk::componentFramework::InvalidUriInFileError
Definition: fileRepository.hpp:38
rtctk_config_tool.default
default
Enter an interactive shell.
Definition: rtctk_config_tool.py:119