RTC Toolkit  1.0.0
Public Member Functions | List of all members
rtctk::componentFramework::FileOldbAdapter Class Reference

A file based OLDB adapter that simulates OLDB with a local YAML file. More...

#include <fileOldbAdapter.hpp>

Inheritance diagram for rtctk::componentFramework::FileOldbAdapter:
rtctk::componentFramework::FileRepository rtctk::componentFramework::OldbIf rtctk::componentFramework::RepositoryIf rtctk::componentFramework::RepositoryIf rtctk::componentFramework::RepositorySubscriberIf

Public Member Functions

 FileOldbAdapter ()=delete
 Do not allow construction with no arguments. More...
 
 FileOldbAdapter (const FileOldbAdapter &)=delete
 This class cannot be copy constructed. More...
 
FileOldbAdapteroperator= (const FileOldbAdapter &)=delete
 This class cannot be copy assigned. More...
 
 FileOldbAdapter (FileOldbAdapter &&)=default
 The move constructor. More...
 
FileOldbAdapteroperator= (FileOldbAdapter &&)=default
 The move assignment operator. More...
 
 FileOldbAdapter (const elt::mal::Uri &datauri)
 Constructs a file based OLDB. More...
 
virtual ~FileOldbAdapter ()
 Destroys the file based OLDB. More...
 
RepositoryIf::Response SendSubscribeRequest (const SubscribeRequest &request) const override
 This is called to asynchronously send a subscription request for datapoints. More...
 
RepositoryIf::Response SendUnsubscribeRequest (const UnsubscribeRequest &request) const override
 This is called to asynchronously send a request to unsubscribe from various notifications. More...
 
- Public Member Functions inherited from rtctk::componentFramework::FileRepository
 FileRepository ()=delete
 
 FileRepository (const FileRepository &)=delete
 
FileRepositoryoperator= (const FileRepository &)=delete
 
 FileRepository (const elt::mal::Uri &datauri, const int dirdepth)
 
virtual ~FileRepository () noexcept=default
 
void CreateDataPoint (const DataPointPath &path, const std::type_info &type) override
 Creates a new datapoint in the repository with a specified type. More...
 
void DeleteDataPoint (const DataPointPath &path) override
 Deletes a datapoint. More...
 
const std::type_info & GetDataPointType (const DataPointPath &path) const override
 Fetches the type of the datapoint. More...
 
size_t GetDataPointSize (const DataPointPath &path) const override
 Fetches the size of the datapoint's data. More...
 
bool DataPointExists (const DataPointPath &path) const override
 Checks for the existence of a datapoint in the repository. More...
 
std::pair< StringList, StringListGetChildren (const DataPointPath &path) const override
 Queries the datapoints and child paths for a given path. More...
 
Response SendReadRequest (const Request &request) const override
 Sends a request to read data from the repository. More...
 
Response SendWriteRequest (const Request &request) override
 Sends a request to write data to the repository. More...
 
size_t GetFitsWriteThreshold () const
 
void SetFitsWriteThreshold (size_t value)
 Sets the threshold for storing numerical matrices and vectors in FITS files rather than the YAML file. More...
 
virtual void CreateDataPoint (const DataPointPath &path, const std::type_info &type)=0
 Creates a new datapoint in the repository with a specified type. More...
 
template<typename T >
void CreateDataPoint (const DataPointPath &path)
 Creates a new datapoint in the repository. More...
 
template<typename T >
void CreateDataPoint (const DataPointPath &path, const T default_value)
 Creates a new datapoint in the repository and sets a default value. More...
 
template<>
void CreateDataPoint (const DataPointPath &path, const char *default_value)
 
- Public Member Functions inherited from rtctk::componentFramework::RepositoryIf
virtual ~RepositoryIf ()
 
template<typename T >
void CreateDataPoint (const DataPointPath &path)
 Creates a new datapoint in the repository. More...
 
template<typename T >
void CreateDataPoint (const DataPointPath &path, const T default_value)
 Creates a new datapoint in the repository and sets a default value. More...
 
template<typename T >
GetDataPoint (const DataPointPath &path) const
 Fetches a datapoint from the repository. More...
 
template<typename T >
void SetDataPoint (const DataPointPath &path, const T value)
 Sets a datapoint in the repository. More...
 
template<typename T >
void ReadDataPoint (const DataPointPath &path, T &buffer) const
 Reads a datapoint from the repository. More...
 
template<typename T >
void WriteDataPoint (const DataPointPath &path, const T &buffer)
 Writes a datapoint to the repository. More...
 
void WriteDataPoint (const DataPointPath &path, const char *buffer)
 
template<>
void CreateDataPoint (const DataPointPath &path, const char *default_value)
 
template<>
void SetDataPoint (const DataPointPath &path, const char *value)
 
- Public Member Functions inherited from rtctk::componentFramework::OldbIf
virtual ~OldbIf ()=default
 
- Public Member Functions inherited from rtctk::componentFramework::RepositorySubscriberIf
virtual ~RepositorySubscriberIf ()
 
template<typename T , typename F >
void Subscribe (const DataPointPath &path, T &buffer, F handler) const
 A convenience template function that will register a callback to receive new datapoint values in a synchronous manner. More...
 
void Unsubscribe (const DataPointPath &path) const
 A simple convenience function that will deregister all callbacks for receiving new datapoint values. More...
 

Additional Inherited Members

- Public Types inherited from rtctk::componentFramework::RepositoryIf
using StringList = std::vector< std::string >
 
- Static Public Member Functions inherited from rtctk::componentFramework::OldbIf
static std::unique_ptr< OldbIfCreateAdapter (const elt::mal::Uri &uri)
 Factory method used to create the appropriate OLDB adapter depending on the URI scheme. More...
 

Detailed Description

A file based OLDB adapter that simulates OLDB with a local YAML file.

This class is used to simulate access to OLDB when it is not feasible to provide a full working OLDB and access it through OldbAdapter. Its use should be restricted to development and certain integration testing, since it is not written with scalability and performance in mind.

The data is stored to and read from a local YAML file, who's location is given as a file scheme URI. The YAML file format uses nested dictionaries to represent the hierarchical tree structure that corresponds to the datapoint paths. For example, if we have 3 datapoints, an integer with a path of "topdir/subdir/dp1", a floating point with a path of "topdir/subdir/dp2" and a string with a path of "topdir/dp3", this would correspond to the following YAML:

topdir:
subdir:
dp1:
type: RtcInt32
value: 123
dp2:
type: RtcFloat
value: 4.5
dp3:
type: RtcString
value: "somevalue"

As can be seen in the above example YAML, each datapoint has the fundamental data type stored under the type field and its value is found under the value field.

The allowed values for type are one of the following:

Note that vectors and matrices are both stored as lists in the YAML format. However, matrices will have the additional fields nrows and ncols set. For example:

topdir:
matrix_datapoint:
type: RtcMatrixFloat
nrows: 2
ncols: 3
value: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
Thread Safety
thread-safe – File based locking is used to make all read/write methods synchronous between all processes and threads, in addition to mutex locking to protect the structures of this class.

Constructor & Destructor Documentation

◆ FileOldbAdapter() [1/4]

rtctk::componentFramework::FileOldbAdapter::FileOldbAdapter ( )
delete

Do not allow construction with no arguments.

◆ FileOldbAdapter() [2/4]

rtctk::componentFramework::FileOldbAdapter::FileOldbAdapter ( const FileOldbAdapter )
delete

This class cannot be copy constructed.

◆ FileOldbAdapter() [3/4]

rtctk::componentFramework::FileOldbAdapter::FileOldbAdapter ( FileOldbAdapter &&  )
default

The move constructor.

◆ FileOldbAdapter() [4/4]

rtctk::componentFramework::FileOldbAdapter::FileOldbAdapter ( const elt::mal::Uri &  datauri)
explicit

Constructs a file based OLDB.

Parameters
[in]datauriThe URI to the YAML file that will store the datapoints. This only accepts file scheme URIs on the local file system.
Note
If the YAML file does not yet exist, it will only be created on the first call to RepositoryIf::CreateDataPoint.

◆ ~FileOldbAdapter()

rtctk::componentFramework::FileOldbAdapter::~FileOldbAdapter ( )
virtual

Destroys the file based OLDB.

Note
The YAML file will not be deleted by destroying the FileOldbAdapter object.

Member Function Documentation

◆ operator=() [1/2]

FileOldbAdapter& rtctk::componentFramework::FileOldbAdapter::operator= ( const FileOldbAdapter )
delete

This class cannot be copy assigned.

◆ operator=() [2/2]

FileOldbAdapter& rtctk::componentFramework::FileOldbAdapter::operator= ( FileOldbAdapter &&  )
default

The move assignment operator.

◆ SendSubscribeRequest()

RepositoryIf::Response rtctk::componentFramework::FileOldbAdapter::SendSubscribeRequest ( const SubscribeRequest request) const
overridevirtual

This is called to asynchronously send a subscription request for datapoints.

One or more datapoints can be subscribed to by constructing a SubscribeRequest object and sending it to the repository service with this method. A typical usage is indicated in the following code sample:

void OnRemoved(const DataPointPath& path) {
...
}
void OnNewValue(const DataPointPath& path, int64_t& buffer) {
...
}
RepositorySubscriberIf& repo = ...;
int64_t buffer = ...;
SubscribeRequest request;
request.AddRemoveHandler("/test/datapoint"_dppath, OnRemoved);
request.AddNewValueHandler("/test/datapoint"_dppath, buffer, OnNewValue);
auto response = repo.SendSubscribeRequest(request);
... can do some work here ...
response.Wait();
Note
One must not access the buffers added to a SubscribeRequest object once SendSubscribeRequest has been invoked. At least not without using some form of synchronisation, e.g. a mutex, since the buffers will be updated asynchronously in different threads to the one used by the caller.
Parameters
[in]requestThe subscription request to send to the repository.
Returns
A response object (a future) that is used to wait for completion of the request.
Thread Safety
thread-safe
Exception Safety
basic

Implements rtctk::componentFramework::RepositorySubscriberIf.

◆ SendUnsubscribeRequest()

RepositoryIf::Response rtctk::componentFramework::FileOldbAdapter::SendUnsubscribeRequest ( const UnsubscribeRequest request) const
overridevirtual

This is called to asynchronously send a request to unsubscribe from various notifications.

One can stop receiving notifications for one or more datapoints by constructing a UnsubscribeRequest object and sending it to the repository service with this method. A typical usage is indicated in the following code sample:

void OnRemoved(const DataPointPath& path) {
...
}
void OnNewValue(const DataPointPath& path, int64_t& buffer) {
...
}
RepositorySubscriberIf& repo = ...;
UnsubscribeRequest request;
request.AddRemoveHandler("/test/datapoint"_dppath);
request.AddNewValueHandler("/test/datapoint"_dppath);
auto response = repo.SendUnsubscribeRequest(request);
... can do some work here ...
response.Wait();
Parameters
[in]requestThe request to send to the repository.
Returns
A response object (a future) that is used to wait for completion of the request.
Thread Safety
thread-safe
Exception Safety
basic

Implements rtctk::componentFramework::RepositorySubscriberIf.


The documentation for this class was generated from the following files: