RTC Toolkit  2.0.0
persistentRepoAdapter.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_COMPONENTFRAMEWORK_PERSISTENTREPOADAPTER_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_PERSISTENTREPOADAPTER_HPP
14 
15 #include <mal/utility/Uri.hpp>
16 #include <memory>
17 #include <mutex>
18 #include <string>
19 #include <typeindex>
20 #include <typeinfo>
21 #include <unordered_map>
22 
27 
28 namespace rtctk::componentFramework {
29 
51 public:
58  public:
59  explicit ServiceFailureException(const DataPointPath& path);
60  };
61 
66  public:
67  explicit InvalidDocumentException(const DataPointPath& path,
68  const elt::mal::Uri& uri,
69  const std::string& message);
70  };
71 
76  public:
77  explicit PathMissingException(const DataPointPath& path);
78  };
79 
82 
85 
88 
91 
94 
102  explicit PersistentRepoAdapter(const elt::mal::Uri& baseuri);
103 
104  virtual ~PersistentRepoAdapter() = default;
105 
107  void CreateDataPoint(const DataPointPath& path, const std::type_info& type) override;
108 
109  void DeleteDataPoint(const DataPointPath& path) override;
110  const std::type_info& GetDataPointType(const DataPointPath& path) const override;
111  std::size_t GetDataPointSize(const DataPointPath& path) const override;
112  bool DataPointExists(const DataPointPath& path) const override;
113  std::pair<PathList, PathList> GetChildren(const DataPointPath& path) const override;
114  Response SendReadRequest(const ReadRequest& request) const override;
115  Response SendWriteRequest(const WriteRequest& request) override;
116 
117 private:
135  template <typename R, typename F>
136  Response ProcessRequest(const R& request, F dispatch) const;
137 
141  class IoFunctions {
142  public:
143  virtual ~IoFunctions() = default;
144  virtual void
145  CreateDataPoint(const PersistentRepoAdapter* repo, const DataPointPath& path) const = 0;
146  virtual void ReadDataPoint(const PersistentRepoAdapter* repo,
147  const DataPointPath& path,
148  void* buffer) const = 0;
149  virtual void WriteDataPoint(const PersistentRepoAdapter* repo,
150  const DataPointPath& path,
151  const void* buffer) const = 0;
152  };
153 
166  template <typename T>
167  class IoFunctionsImpl : public IoFunctions {
168  public:
169  IoFunctionsImpl(const std::string& yaml_type) : m_yaml_type(yaml_type){};
170  virtual ~IoFunctionsImpl() = default;
171  void CreateDataPoint(const PersistentRepoAdapter* repo,
172  const DataPointPath& path) const override;
173  void ReadDataPoint(const PersistentRepoAdapter* repo,
174  const DataPointPath& path,
175  void* buffer) const override;
176  void WriteDataPoint(const PersistentRepoAdapter* repo,
177  const DataPointPath& path,
178  const void* buffer) const override;
179 
180  private:
181  std::string m_yaml_type;
182  };
183 
184  using IoFunctionMap = std::unordered_map<std::type_index, std::shared_ptr<IoFunctions>>;
185 
191  template <typename T>
192  static auto MakeMapEntry(const std::string& yaml_type);
193 
194  using TypeMap = std::unordered_map<std::string, const std::type_info&>;
195 
200  mutable std::mutex m_mutex;
201 
203  PathMapper m_path_mapper;
204 
206  static const TypeMap S_TYPE_MAP;
207 
212  static const IoFunctionMap S_IO_FUNCTIONS;
213 };
214 
215 } // namespace rtctk::componentFramework
216 
217 #endif // RTCTK_COMPONENTFRAMEWORK_PERSISTENTREPOADAPTER_HPP
rtctk::componentFramework::PersistentRepoAdapter::ServiceFailureException
Exception indicating a general CII configuration service error.
Definition: persistentRepoAdapter.hpp:57
exceptions.hpp
Provides macros and utilities for exception handling.
rtctk::componentFramework::PersistentRepoAdapter::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::PersistentRepoIf
Definition: persistentRepoIf.hpp:19
rtctk::componentFramework::PersistentRepoAdapter::PersistentRepoAdapter
PersistentRepoAdapter(PersistentRepoAdapter &&)=default
Objects of this class can be moved.
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::PersistentRepoAdapter::InvalidDocumentException
Exception indicating that validation checks of a CII configuration document failed.
Definition: persistentRepoAdapter.hpp:65
persistentRepoIf.hpp
Header file for PersistentRepoIf, which defines the API for PersistentRepoAdapter.
pathMapper.hpp
Header file declaring PathMapper.
rtctk::componentFramework::PersistentRepoAdapter::operator=
PersistentRepoAdapter & operator=(const PersistentRepoAdapter &)=delete
This class cannot be copy assigned.
rtctk::componentFramework::PersistentRepoAdapter
Implements the Persistent Configuration Repository adapter that uses the CII configuration service as...
Definition: persistentRepoAdapter.hpp:50
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::RtctkException
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:207
rtctk::componentFramework::PersistentRepoAdapter::DataPointExists
bool DataPointExists(const DataPointPath &path) const override
Checks for the existence of a datapoint in the repository.
Definition: persistentRepoAdapter.cpp:527
rtctk::componentFramework::PersistentRepoAdapter::GetDataPointType
const std::type_info & GetDataPointType(const DataPointPath &path) const override
Fetches the type of the datapoint.
Definition: persistentRepoAdapter.cpp:401
rtctk::componentFramework::PersistentRepoAdapter::SendWriteRequest
Response SendWriteRequest(const WriteRequest &request) override
Sends a request to write data to the repository.
Definition: persistentRepoAdapter.cpp:630
rtctk::componentFramework::PersistentRepoAdapter::SendReadRequest
Response SendReadRequest(const ReadRequest &request) const override
Sends a request to read data from the repository.
Definition: persistentRepoAdapter.cpp:623
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::PersistentRepoAdapter::PathMissingException
Exception indicating a datapoint path does not exist.
Definition: persistentRepoAdapter.hpp:75
rtctk_config_tool.message
message
Definition: rtctk_config_tool.py:42
rtctk::componentFramework::PersistentRepoAdapter::PersistentRepoAdapter
PersistentRepoAdapter()=delete
Do not allow construction with no arguments.
rtctk::componentFramework::RepositoryIf::ReadDataPoint
void ReadDataPoint(const DataPointPath &path, T &buffer) const
Reads a datapoint from the repository.
Definition: repositoryIf.hpp:592
fileRepository.hpp
Declaration of FileRepository that provides a simple file based repository.
rtctk::componentFramework::RepositoryIf::WriteDataPoint
void WriteDataPoint(const DataPointPath &path, const T &buffer)
Writes a datapoint to the repository.
Definition: repositoryIf.hpp:617
rtctk::componentFramework::PersistentRepoAdapter::ServiceFailureException::ServiceFailureException
ServiceFailureException(const DataPointPath &path)
Definition: persistentRepoAdapter.cpp:231
rtctk::componentFramework::PersistentRepoAdapter::~PersistentRepoAdapter
virtual ~PersistentRepoAdapter()=default
rtctk::componentFramework::PersistentRepoAdapter::PersistentRepoAdapter
PersistentRepoAdapter(const PersistentRepoAdapter &)=delete
This class cannot be copy constructed.
rtctk::componentFramework::PersistentRepoAdapter::GetChildren
std::pair< PathList, PathList > GetChildren(const DataPointPath &path) const override
Queries the datapoints and child paths for a given path.
Definition: persistentRepoAdapter.cpp:549
rtctk::componentFramework::PersistentRepoAdapter::PathMissingException::PathMissingException
PathMissingException(const DataPointPath &path)
Definition: persistentRepoAdapter.cpp:246
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::PersistentRepoAdapter::GetDataPointSize
std::size_t GetDataPointSize(const DataPointPath &path) const override
Fetches the size of the datapoint's data.
Definition: persistentRepoAdapter.cpp:433
rtctk::componentFramework::PersistentRepoAdapter::InvalidDocumentException::InvalidDocumentException
InvalidDocumentException(const DataPointPath &path, const elt::mal::Uri &uri, const std::string &message)
Definition: persistentRepoAdapter.cpp:237
rtctk::componentFramework::PersistentRepoAdapter::operator=
PersistentRepoAdapter & operator=(PersistentRepoAdapter &&)=default
Objects of this class can be moved with the move assignment operator.
rtctk_config_tool.type
type
List all available datapoint paths under a given path hierarchy.
Definition: rtctk_config_tool.py:44
rtctk::componentFramework::PersistentRepoAdapter::DeleteDataPoint
void DeleteDataPoint(const DataPointPath &path) override
Deletes a datapoint.
Definition: persistentRepoAdapter.cpp:286