RTC Toolkit 4.0.2
Loading...
Searching...
No Matches
fakeRepositoryIf.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_TEST_FAKEREPOSITORYIF_HPP
14#define RTCTK_COMPONENTFRAMEWORK_TEST_FAKEREPOSITORYIF_HPP
15
16#include <any>
17#include <functional>
18#include <map>
19#include <typeinfo>
20#include <unordered_map>
21
23
25
31class FakeRepositoryIf : virtual public RepositoryIf {
32public:
34 void CreateDataPoint(const DataPointPath&, const std::type_info&) override;
35 void DeleteDataPoint(const DataPointPath&) override;
36 const std::type_info& GetDataPointType(const DataPointPath&) const override;
37 std::size_t GetDataPointSize(const DataPointPath&) const override;
38 bool DataPointExists(const DataPointPath&) const override;
39 std::pair<PathList, PathList> GetChildren(const DataPointPath&) const override;
40 Response SendReadRequest(const ReadRequest&) const override;
41 Response SendWriteRequest(const WriteRequest&) override;
42
43protected:
44 using DataPointMap = std::map<DataPointPath, std::any>;
45
47 virtual void PreCreateDataPointHook(const DataPointPath&) const {};
49 virtual void PostCreateDataPointHook(const DataPointPath&) const {};
50
52 virtual void PreDeleteDataPointHook(const DataPointPath&) const {};
54 virtual void PostDeleteDataPointHook(const DataPointPath&) const {};
55
57 virtual void PreWriteDataPointHook(const DataPointPath&) const {};
59 virtual void PostWriteDataPointHook(const DataPointPath&) const {};
60
63
66 using CreateFunction = std::function<void(DataPointMap&, const DataPointPath&)>;
67 using SizeFunction = std::function<std::size_t(const std::any&)>;
68 using ReadFunction = std::function<void(const DataPointMap&, const DataPointPath&, void*)>;
69 using WriteFunction = std::function<void(DataPointMap&, const DataPointPath&, const void*)>;
70
75 };
76
77 static const IoFunctionMapEntry& GetIoFunctions(const std::type_info& type);
78
80 mutable std::mutex m_mutex;
81
82private:
83 template <typename R, typename F>
84 Response ProcessRequest(const R& request, F selector) const;
85
86 template <typename T>
87 static void CreateDataPointImpl(DataPointMap& data, const DataPointPath& path);
88
89 template <typename T>
90 static std::size_t GetDataPointSizeImpl(const std::any& data);
91
92 template <typename T>
93 static void
94 ReadDataPointImpl(const DataPointMap& data, const DataPointPath& path, void* buffer);
95
96 template <typename T>
97 static void
98 WriteDataPointImpl(DataPointMap& data, const DataPointPath& path, const void* buffer);
99
100 template <typename T>
101 static auto MakeMapEntry();
102
103 using IoFunctionMap = std::unordered_map<std::type_index, IoFunctionMapEntry>;
104
106 static const IoFunctionMap S_IO_FUNCTIONS;
107};
108
109} // namespace rtctk::componentFramework::test
110
111#endif // RTCTK_COMPONENTFRAMEWORK_TEST_FAKEREPOSITORYIF_HPP
This class provides a wrapper for a data point path.
Definition: dataPointPath.hpp:73
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
virtual void CreateDataPoint(const DataPointPath &path, const std::type_info &type)=0
Creates a new datapoint in the repository with a specified type.
Implementation of an in-memory fake repository for testing.
Definition: fakeRepositoryIf.hpp:31
virtual void PreDeleteDataPointHook(const DataPointPath &) const
Hook that is run before a DataPoint is deleted with the given DataPointPath.
Definition: fakeRepositoryIf.hpp:52
virtual void PostWriteDataPointHook(const DataPointPath &) const
Hook that is run after a DataPoint is created with the given DataPointPath.
Definition: fakeRepositoryIf.hpp:59
Response SendReadRequest(const ReadRequest &) const override
Sends a request to read data from the repository.
Definition: fakeRepositoryIf.cpp:99
static const IoFunctionMapEntry & GetIoFunctions(const std::type_info &type)
Definition: fakeRepositoryIf.cpp:228
const std::type_info & GetDataPointType(const DataPointPath &) const override
Fetches the type of the datapoint.
Definition: fakeRepositoryIf.cpp:41
Response SendWriteRequest(const WriteRequest &) override
Sends a request to write data to the repository.
Definition: fakeRepositoryIf.cpp:103
virtual void PostCreateDataPointHook(const DataPointPath &) const
Hook that is run after a DataPoint is created with the given DataPointPath.
Definition: fakeRepositoryIf.hpp:49
virtual void PreWriteDataPointHook(const DataPointPath &) const
Hook that is run before a DataPoint is written to with the given DataPointPath.
Definition: fakeRepositoryIf.hpp:57
virtual void PreCreateDataPointHook(const DataPointPath &) const
Hook that is run before a DataPoint is created with the given DataPointPath.
Definition: fakeRepositoryIf.hpp:47
std::size_t GetDataPointSize(const DataPointPath &) const override
Fetches the size of the datapoint's data.
Definition: fakeRepositoryIf.cpp:50
virtual void PostDeleteDataPointHook(const DataPointPath &) const
Hook that is run after a DataPoint is deleted with the given DataPointPath.
Definition: fakeRepositoryIf.hpp:54
bool DataPointExists(const DataPointPath &) const override
Checks for the existence of a datapoint in the repository.
Definition: fakeRepositoryIf.cpp:60
std::mutex m_mutex
Mutex for synchronising access to m_datapoints.
Definition: fakeRepositoryIf.hpp:80
std::map< DataPointPath, std::any > DataPointMap
Definition: fakeRepositoryIf.hpp:44
void DeleteDataPoint(const DataPointPath &) override
Deletes a datapoint.
Definition: fakeRepositoryIf.cpp:28
void CreateDataPoint(const DataPointPath &, const std::type_info &) override
Creates a new datapoint in the repository with a specified type.
Definition: fakeRepositoryIf.cpp:19
std::pair< PathList, PathList > GetChildren(const DataPointPath &) const override
Queries the datapoints and child paths for a given path.
Definition: fakeRepositoryIf.cpp:66
DataPointMap m_datapoints
A map storing the datapoint data in memory.
Definition: fakeRepositoryIf.hpp:62
Definition: fakeClock.cpp:15
Header file for RepositoryIf and related base classes.
Structure defining the contents of an entry in the IoFunctionMap.
Definition: fakeRepositoryIf.hpp:65
std::function< void(DataPointMap &, const DataPointPath &)> CreateFunction
Definition: fakeRepositoryIf.hpp:66
WriteFunction m_write_function
Definition: fakeRepositoryIf.hpp:74
std::function< void(const DataPointMap &, const DataPointPath &, void *)> ReadFunction
Definition: fakeRepositoryIf.hpp:68
SizeFunction m_size_function
Definition: fakeRepositoryIf.hpp:72
std::function< void(DataPointMap &, const DataPointPath &, const void *)> WriteFunction
Definition: fakeRepositoryIf.hpp:69
std::function< std::size_t(const std::any &)> SizeFunction
Definition: fakeRepositoryIf.hpp:67
CreateFunction m_create_function
Definition: fakeRepositoryIf.hpp:71
ReadFunction m_read_function
Definition: fakeRepositoryIf.hpp:73