ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
TransferElementAbstractor.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include "TransferElement.h"
6#include "TransferElementID.h"
7#include "VersionNumber.h"
8
9#include <boost/bind/bind.hpp>
10#include <boost/enable_shared_from_this.hpp>
11#include <boost/shared_ptr.hpp>
12#include <boost/thread.hpp>
13#include <boost/thread/future.hpp>
14
15#include <functional>
16#include <list>
17#include <string>
18#include <typeinfo>
19#include <vector>
20
21namespace ChimeraTK {
22
23 class PersistentDataStorage;
24
25 /********************************************************************************************************************/
26
29 public:
31 explicit TransferElementAbstractor(boost::shared_ptr<TransferElement> impl) : _impl(std::move(impl)) {}
32
35
37 [[nodiscard]] const std::string& getName() const { return _impl->getName(); }
38
41 [[nodiscard]] const std::string& getUnit() const { return _impl->getUnit(); }
42
44 [[nodiscard]] const std::string& getDescription() const { return _impl->getDescription(); }
45
48 [[nodiscard]] const std::type_info& getValueType() const { return _impl->getValueType(); }
49
51 [[nodiscard]] AccessModeFlags getAccessModeFlags() const { return _impl->getAccessModeFlags(); }
52
57 void read() { _impl->read(); }
58
70 bool readNonBlocking() { return _impl->readNonBlocking(); }
71
77 bool readLatest() { return _impl->readLatest(); }
78
83 [[nodiscard]] ChimeraTK::VersionNumber getVersionNumber() const { return _impl->getVersionNumber(); }
84
89 bool write(ChimeraTK::VersionNumber versionNumber = {}) { return _impl->write(versionNumber); }
90
97 bool writeDestructively(ChimeraTK::VersionNumber versionNumber = {});
98
102 [[nodiscard]] bool isReadOnly() const { return _impl->isReadOnly(); }
103
107 [[nodiscard]] bool isReadable() const { return _impl->isReadable(); }
108
112 [[nodiscard]] bool isWriteable() const { return _impl->isWriteable(); }
113
120 std::vector<boost::shared_ptr<TransferElement>> getHardwareAccessingElements();
121
136 std::list<boost::shared_ptr<TransferElement>> getInternalElements();
137
145 const boost::shared_ptr<TransferElement>& getHighLevelImplElement() { return _impl; }
146
152 [[nodiscard]] bool isInitialised() const { return _impl != nullptr; }
153
160 void replace(const TransferElementAbstractor& newAccessor) { _impl = newAccessor._impl; }
161
166 void replace(boost::shared_ptr<TransferElement> newImpl) { _impl = std::move(newImpl); }
167
173 void replaceTransferElement(const boost::shared_ptr<TransferElement>& newElement);
174
183 void setPersistentDataStorage(boost::shared_ptr<ChimeraTK::PersistentDataStorage> storage);
184
192 [[nodiscard]] TransferElementID getId() const { return _impl->getId(); }
193
197 void setDataValidity(DataValidity valid = DataValidity::ok) { _impl->setDataValidity(valid); }
198
202 [[nodiscard]] DataValidity dataValidity() const { return _impl->dataValidity(); }
203
221 void interrupt() { _impl->interrupt(); }
222
224 [[nodiscard]] ReadAnyGroup* getReadAnyGroup() const { return _impl->getReadAnyGroup(); }
225
226 protected:
228 boost::shared_ptr<TransferElement> _impl;
229 };
230
231 /********************************************************************************************************************/
232
234 return _impl->writeDestructively(versionNumber);
235 }
236
237 /********************************************************************************************************************/
238
239} /* namespace ChimeraTK */
Set of AccessMode flags with additional functionality for an easier handling.
Definition AccessMode.h:48
Group several registers (= TransferElement) to allow waiting for an update of any of the registers.
Base class for register accessors abstractors independent of the UserType.
ChimeraTK::VersionNumber getVersionNumber() const
Returns the version number that is associated with the last transfer (i.e.
bool readLatest()
Read the latest value, discarding any other update since the last read if present.
const boost::shared_ptr< TransferElement > & getHighLevelImplElement()
Obtain the highest level implementation TransferElement.
std::list< boost::shared_ptr< TransferElement > > getInternalElements()
Obtain the full list of TransferElements internally used by this TransferElement.
bool write(ChimeraTK::VersionNumber versionNumber={})
Write the data to device.
void interrupt()
Return from a blocking read immediately and throw boost::thread_interrupted.
bool isInitialised() const
Return if the accessor is properly initialised.
const std::type_info & getValueType() const
Returns the std::type_info for the value type of this transfer element.
bool isReadable() const
Check if transfer element is readable.
bool writeDestructively(ChimeraTK::VersionNumber versionNumber={})
Just like write(), but allows the implementation to destroy the content of the user buffer in the pro...
const std::string & getDescription() const
Returns the description of this variable/register.
TransferElementAbstractor(boost::shared_ptr< TransferElement > impl)
Construct from TransferElement implementation.
void read()
Read the data from the device.
bool isWriteable() const
Check if transfer element is writeable.
void setPersistentDataStorage(boost::shared_ptr< ChimeraTK::PersistentDataStorage > storage)
Associate a persistent data storage object to be updated on each write operation of this ProcessArray...
std::vector< boost::shared_ptr< TransferElement > > getHardwareAccessingElements()
Obtain the underlying TransferElements with actual hardware access.
ReadAnyGroup * getReadAnyGroup() const
Obtain the ReadAnyGroup this TransferElement is part of, or nullptr if not in a ReadAnyGroup.
DataValidity dataValidity() const
Return current validity of the data.
void replace(const TransferElementAbstractor &newAccessor)
Assign a new accessor to this TransferElementAbstractor.
void replaceTransferElement(const boost::shared_ptr< TransferElement > &newElement)
Search for all underlying TransferElements which are considered identical (see mayReplaceOther()) wit...
bool readNonBlocking()
Read the next value, if available in the input buffer.
TransferElementAbstractor()=default
Create an uninitialised abstractor - just for late initialisation.
AccessModeFlags getAccessModeFlags() const
Return the AccessModeFlags for this TransferElement.
void setDataValidity(DataValidity valid=DataValidity::ok)
Set the current DataValidity for this TransferElement.
bool isReadOnly() const
Check if transfer element is read only, i.e.
void replace(boost::shared_ptr< TransferElement > newImpl)
Alternative signature of relace() with the same functionality, used when a pointer to the implementat...
boost::shared_ptr< TransferElement > _impl
Untyped pointer to implementation.
TransferElementID getId() const
Obtain unique ID for the actual implementation of this TransferElement.
const std::string & getUnit() const
Returns the engineering unit.
const std::string & getName() const
Returns the name that identifies the process variable.
Simple class holding a unique ID for a TransferElement.
Class for generating and holding version numbers without exposing a numeric representation.
DataValidity
The current state of the data.
STL namespace.