RTC Toolkit  2.0.0
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
rtctk::componentFramework::OldbAdapter Class Reference

Provides access to the OLDB to read and write datapoints. More...

#include <oldbAdapter.hpp>

Inheritance diagram for rtctk::componentFramework::OldbAdapter:
rtctk::componentFramework::OldbIf rtctk::componentFramework::RepositoryIf rtctk::componentFramework::RepositorySubscriberIf rtctk::componentFramework::RuntimeRepoAdapter

Public Member Functions

 OldbAdapter ()=delete
 Do not allow construction with no arguments. More...
 
 OldbAdapter (const OldbAdapter &)=delete
 This class cannot be copy constructed. More...
 
OldbAdapteroperator= (const OldbAdapter &)=delete
 This class cannot be copy assigned. More...
 
 OldbAdapter (OldbAdapter &&)=default
 Objects of this class can be moved. More...
 
OldbAdapteroperator= (OldbAdapter &&)=default
 Objects of this class can be moved with the move assignment operator. More...
 
 OldbAdapter (const elt::mal::Uri &baseuri)
 Constructs an adapter for the OLDB service with the default OLDB API interface. More...
 
 OldbAdapter (const elt::mal::Uri &baseuri, const std::shared_ptr< elt::oldb::CiiOldb > &oldb)
 Constructs an adapter for the OLDB service with a specific OLDB API interface. More...
 
virtual ~OldbAdapter ()
 Destroys the adapter for the OLDB service releasing allocated resources. More...
 
void CreateDataPoint (const DataPointPath &path, const std::type_info &type) override
 Creates a new datapoint in the OLDB. More...
 
void DeleteDataPoint (const DataPointPath &path) override
 Deletes a datapoint in the OLDB. More...
 
const std::type_info & GetDataPointType (const DataPointPath &path) const override
 Retrieves the corresponding C++ type for the datapoint from the OLDB. More...
 
std::size_t GetDataPointSize (const DataPointPath &path) const override
 Returns the size of a datapoint in the OLDB. More...
 
bool DataPointExists (const DataPointPath &path) const override
 Checks for the existence of a datapoint in the repository. More...
 
std::pair< PathList, PathListGetChildren (const DataPointPath &path) const override
 Queries the datapoints and child paths for a given path. More...
 
Response SendReadRequest (const ReadRequest &request) const override
 Sends a request to read data from the repository. More...
 
Response SendWriteRequest (const WriteRequest &request) override
 Sends a request to write data to the repository. More...
 
Response SendSubscribeRequest (const SubscribeRequest &request) const override
 This is called to asynchronously send a subscription request for datapoints. More...
 
Response SendUnsubscribeRequest (const UnsubscribeRequest &request) const override
 This is called to asynchronously send a request to unsubscribe from various notifications. More...
 
template<typename T , typename U , typename V >
void CastAndRegisterSubscription (const SubscribeRequest::Parameters &params, const std::shared_ptr< CiiOldbTypedDataBase > &datapoint, std::function< void(T *, const std::shared_ptr< CiiOldbDpValue< U >> &)> write_function) const
 
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::OldbIf
virtual ~OldbIf ()=default
 
- 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::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...
 

Static Public Member Functions

static void InitMetadata ()
 Initialises the type metadata in the CII configuration service for the OLDB. More...
 
- 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...
 

Protected Member Functions

void SetMetadataInstanceMap (const std::map< std::type_index, std::string > &map)
 Sets the type_index to OLDB metadata instance name map. More...
 
void SetTypeInfoMap (const std::map< std::string, const std::type_info & > &map)
 Sets the OLDB metadata instance name to type_info map. More...
 

Additional Inherited Members

- Public Types inherited from rtctk::componentFramework::RepositoryIf
using PathList = std::vector< DataPointPath >
 

Detailed Description

Provides access to the OLDB to read and write datapoints.

Uses the OLDB API under the hood, but standardises the interface to be compatible with other repositories in the RTC Toolkit.

Thread Safety
thread-safe

Constructor & Destructor Documentation

◆ OldbAdapter() [1/5]

rtctk::componentFramework::OldbAdapter::OldbAdapter ( )
delete

Do not allow construction with no arguments.

◆ OldbAdapter() [2/5]

rtctk::componentFramework::OldbAdapter::OldbAdapter ( const OldbAdapter )
delete

This class cannot be copy constructed.

◆ OldbAdapter() [3/5]

rtctk::componentFramework::OldbAdapter::OldbAdapter ( OldbAdapter &&  )
default

Objects of this class can be moved.

◆ OldbAdapter() [4/5]

rtctk::componentFramework::OldbAdapter::OldbAdapter ( const elt::mal::Uri &  baseuri)
explicit

Constructs an adapter for the OLDB service with the default OLDB API interface.

Parameters
[in]baseuriThe OLDB URI containing a base path where the datapoints are stored. The URI must use the cii.oldb scheme.

◆ OldbAdapter() [5/5]

rtctk::componentFramework::OldbAdapter::OldbAdapter ( const elt::mal::Uri &  baseuri,
const std::shared_ptr< elt::oldb::CiiOldb > &  oldb 
)
explicit

Constructs an adapter for the OLDB service with a specific OLDB API interface.

Parameters
[in]baseuriThe OLDB URI containing a base path where the datapoints are stored. The URI must use the cii.oldb scheme.
[in]oldbThe OLDB API client object to use under the hood.

◆ ~OldbAdapter()

rtctk::componentFramework::OldbAdapter::~OldbAdapter ( )
virtual

Destroys the adapter for the OLDB service releasing allocated resources.

Member Function Documentation

◆ CastAndRegisterSubscription()

template<typename T , typename U , typename V >
void rtctk::componentFramework::OldbAdapter::CastAndRegisterSubscription ( const SubscribeRequest::Parameters &  params,
const std::shared_ptr< CiiOldbTypedDataBase > &  datapoint,
std::function< void(T *, const std::shared_ptr< CiiOldbDpValue< U >> &)>  write_function 
) const

◆ CreateDataPoint() [1/5]

template<typename T >
void rtctk::componentFramework::RepositoryIf::CreateDataPoint ( typename T  )

Creates a new datapoint in the repository.

The type of the datapoint is derived from the template argument type.

Template Parameters
TThe type of the datapoint to create.
Parameters
[in]pathThe datapoint path that should be created.
Thread Safety
thread-safe
Exception Safety
basic

◆ CreateDataPoint() [2/5]

template<>
void rtctk::componentFramework::RepositoryIf::CreateDataPoint ( )

◆ CreateDataPoint() [3/5]

void rtctk::componentFramework::OldbAdapter::CreateDataPoint ( const DataPointPath path,
const std::type_info &  type 
)
overridevirtual

Creates a new datapoint in the OLDB.

Parameters
[in]pathThe path of the new datapoint.
[in]typeThe data type of the datapoint. More specifically this corresponds to the metadata instance name as configured in the CII configuration service that is supported by OLDB.
Exceptions
CiiOldbDpExistsExceptionIf there is already a datapoint with the given path.
CiiOldbInvalidUriExceptionIf the path is in violation of OLDB URI rules.
CiiOldbUndefinedMetadataExceptionIf datapoint info does not exist.
CiiOldbStorageErrorIf the data provider has problems with reading/storing datapoints.
CiiOldbExceptionIf an unknown OLDB error occurs.
Thread Safety
thread-safe
Exception Safety
basic

Implements rtctk::componentFramework::RepositoryIf.

◆ CreateDataPoint() [4/5]

virtual void rtctk::componentFramework::RepositoryIf::CreateDataPoint

Creates a new datapoint in the repository with a specified type.

Parameters
[in]pathThe datapoint path that should be created.
[in]typeA type identifier object returned by typeid indicating the type of the new datapoint. Supported values are indicated below.

The following are the supported values for the type argument:

  • typeid(bool)
  • typeid(int32_t)
  • typeid(int64_t)
  • typeid(float)
  • typeid(double)
  • typeid(std::string)
  • typeid(std::vector<bool>)
  • typeid(std::vector<int32_t>)
  • typeid(std::vector<int64_t>)
  • typeid(std::vector<float>)
  • typeid(std::vector<double>)
  • typeid(std::vector<std::string>)
  • typeid(MatrixBuffer<bool>)
  • typeid(MatrixBuffer<int32_t>)
  • typeid(MatrixBuffer<int64_t>)
  • typeid(MatrixBuffer<float>)
  • typeid(MatrixBuffer<double>)
  • typeid(MatrixBuffer<std::string>)
Thread Safety
thread-safe
Exception Safety
basic

◆ CreateDataPoint() [5/5]

template<typename T >
void rtctk::componentFramework::RepositoryIf::CreateDataPoint ( typename T  )

Creates a new datapoint in the repository and sets a default value.

The type of the datapoint is derived from the template argument type.

Template Parameters
TThe type of the datapoint to create.
Parameters
[in]pathThe datapoint path that should be created.
[in]default_valueThe default value that should be set for the new datapoint.
Thread Safety
thread-safe
Exception Safety
basic

◆ DataPointExists()

bool rtctk::componentFramework::OldbAdapter::DataPointExists ( const DataPointPath path) const
overridevirtual

Checks for the existence of a datapoint in the repository.

Parameters
[in]pathThe datapoint path to check.
Returns
true if the datapoint path exists in the repository and false otherwise.
Thread Safety
thread-safe
Exception Safety
strong

Implements rtctk::componentFramework::RepositoryIf.

◆ DeleteDataPoint()

void rtctk::componentFramework::OldbAdapter::DeleteDataPoint ( const DataPointPath path)
overridevirtual

Deletes a datapoint in the OLDB.

Parameters
[in]pathThe path of an existing datapoint to delete.
Exceptions
CiiOldbDpUndefinedExceptionIf there is no datapoint with the specified path. Either such URL does not exist, or the URL is not a datapoint but a hierarchy element (folder).
CiiOldbStorageErrorIf the data provider has problems with reading/writing datapoints.
CiiOldbExceptionIf an unknown OLDB error occurs.
Thread Safety
thread-safe
Exception Safety
basic

Implements rtctk::componentFramework::RepositoryIf.

◆ GetChildren()

std::pair< PathList, PathList > rtctk::componentFramework::OldbAdapter::GetChildren ( const DataPointPath path) const
overridevirtual

Queries the datapoints and child paths for a given path.

This method will query all the available datapoints that are leaf nodes immediately below the given path and also the child paths, i.e. sub-folders when interpreting the repository as a hierarchical folder like structure. The set of immediate datapoint and child paths is returned as two separate lists.

If an error occurs when querying the the repository a rtctk::componentFramework::RtctkException is thrown.

Parameters
[in]pathThe path in which to search for datapoints and child paths.
Returns
A std::pair of path lists, i.e. std::vector<DataPointPath>, with the first list in the pair containing the datapoints found and the second list containing the child paths found. If no datapoints are found then the list for datapoints is empty. Similarly if not child paths are found then the child path list is empty.
Thread Safety
thread-safe
Exception Safety
strong

Implements rtctk::componentFramework::RepositoryIf.

◆ GetDataPointSize()

std::size_t rtctk::componentFramework::OldbAdapter::GetDataPointSize ( const DataPointPath path) const
overridevirtual

Returns the size of a datapoint in the OLDB.

This method will return the size in bytes for all scalar types. For strings it returns the number of characters in the string. For vectors and matrices it returns the total number of elements. For binary blobs it returns the total number of bytes.

Parameters
[in]pathThe path of the datapoint.
Returns
The size of the datapoint.
Exceptions
CiiOldbInvalidUriExceptionIf the path is in violation of OLDB URI rules.
CiiOldbDpUndefinedExceptionIf there is no datapoint with the specified path. Either such URL does not exist, or the URL is not a datapoint but a hierarchy element (folder).
CiiOldbStorageErrorIf the data provider has problems with reading/storing datapoints.
CiiOldbExceptionIf an unknown OLDB error occurs.
Thread Safety
thread-safe
Exception Safety
strong

Implements rtctk::componentFramework::RepositoryIf.

◆ GetDataPointType()

const std::type_info & rtctk::componentFramework::OldbAdapter::GetDataPointType ( const DataPointPath path) const
overridevirtual

Retrieves the corresponding C++ type for the datapoint from the OLDB.

Parameters
[in]pathThe path of the datapoint.
Returns
The type_info corresponding to the type that was used during datapoint creation.
Exceptions
CiiOldbInvalidUriExceptionIf the path is in violation of OLDB URI rules.
CiiOldbDpUndefinedExceptionIf there is no datapoint with the specified path. Either such URL does not exist, or the URL is not a datapoint but a hierarchy element (folder).
CiiOldbStorageErrorIf the data provider has problems with reading/storing datapoints.
CiiOldbExceptionIf an unknown OLDB error occurs.
Thread Safety
thread-safe
Exception Safety
strong

Implements rtctk::componentFramework::RepositoryIf.

◆ InitMetadata()

void rtctk::componentFramework::OldbAdapter::InitMetadata ( )
static

Initialises the type metadata in the CII configuration service for the OLDB.

Default metadata related to standard data types needs to be initialised in the CII configuration service before the OldbAdapter can be used properly. This function will create the needed metadata if it is missing. If the metadata for the types already exists then this function will reset the values.

Note
This method normally only needs to be called in the context of unit tests that are using an in-memory OLDB. A proper OLDB service should have the metadata for standard types initialised as part of the installation of the service, independently of the RTC Toolkit.
Exceptions
InitialisationExceptionFor any error that occurs in the CII system.

◆ operator=() [1/2]

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

This class cannot be copy assigned.

◆ operator=() [2/2]

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

Objects of this class can be moved with the move assignment operator.

◆ SendReadRequest()

Response rtctk::componentFramework::OldbAdapter::SendReadRequest ( const ReadRequest request) const
overridevirtual

Sends a request to read data from the repository.

This method allows non-blocking and asynchronous reading of datapoints form the repository. The method returns immediately, allowing other work to be done in the calling thread while the read request is completed in the background. If any callback handlers were registered in request, they will be called as soon as the data is available for the respective datapoint.

Note
The buffers for the datapoints added to request must not be accessed until the Wait method of the response object returns successfully, i.e. without a timeout.

If an error occurs then a rtctk::componentFramework::RtctkException is thrown.

Note
This method is not transactional or fully atomic. If an error occurs while reading the datapoints, some or all of the datapoint buffers registered with the read request may be left unmodified. It is however guaranteed that any particular datapoint buffer is either updated completely or not modified at all.
Parameters
[in]requestThe request object that contains all the datapoints to read.
Returns
A response object that must be used to synchronise with the completion of the read request.

Implements rtctk::componentFramework::RepositoryIf.

◆ SendSubscribeRequest()

Response rtctk::componentFramework::OldbAdapter::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()

Response rtctk::componentFramework::OldbAdapter::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.

◆ SendWriteRequest()

Response rtctk::componentFramework::OldbAdapter::SendWriteRequest ( const WriteRequest request)
overridevirtual

Sends a request to write data to the repository.

This method allows non-blocking writing of datapoints to the repository. The method returns immediately, allowing other work to be done in the calling thread while the write request is completed in the background. If any callback handlers were registered in request, they will be called as soon as the respective datapoint's data has been sent and the buffer will no longer be accessed by the API, i.e. the caller can modify or release the buffer from that point on.

Note
The buffers for the datapoints added to request must not be modified or released until the Wait method of the response object returns successfully, i.e. without a timeout.

If an error occurs then a rtctk::componentFramework::RtctkException is thrown.

Note
This method is not transactional or fully atomic. If an error occurs while writing the datapoints, only some of the datapoints registered with the write request may be actually updated in the repository. It is however guaranteed that any particular datapoint is either updated completely in the repository or not at all.
Parameters
[in]requestThe request object that contains all the datapoints to write.
Returns
A response object that must be used to synchronise with the completion of the write request.

Implements rtctk::componentFramework::RepositoryIf.

◆ SetMetadataInstanceMap()

void rtctk::componentFramework::OldbAdapter::SetMetadataInstanceMap ( const std::map< std::type_index, std::string > &  map)
protected

Sets the type_index to OLDB metadata instance name map.

Parameters
[in]mapThe new map to use. This object must be kept alive and unmodified for the lifetime of all OldbAdapter instances.
Note
This method should only be used in the constructor of the child class.
Thread Safety
thread-hostile
Exception Safety
basic

◆ SetTypeInfoMap()

void rtctk::componentFramework::OldbAdapter::SetTypeInfoMap ( const std::map< std::string, const std::type_info & > &  map)
protected

Sets the OLDB metadata instance name to type_info map.

Parameters
[in]mapThe new map to use. This object must be kept alive and unmodified for the lifetime of all OldbAdapter instances.
Note
This method should only be used in the constructor of the child class.
Thread Safety
thread-hostile
Exception Safety
basic

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