ChimeraTK-DeviceAccess  03.18.00
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 
21 namespace ChimeraTK {
22 
23  class PersistentDataStorage;
24 
25  /********************************************************************************************************************/
26 
29  public:
31  explicit TransferElementAbstractor(boost::shared_ptr<TransferElement> impl) : _impl(std::move(impl)) {}
32 
34  TransferElementAbstractor() = default;
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 
223  protected:
225  boost::shared_ptr<TransferElement> _impl;
226  };
227 
228  /********************************************************************************************************************/
229 
231  return _impl->writeDestructively(versionNumber);
232  }
233 
234  /********************************************************************************************************************/
235 
236 } /* namespace ChimeraTK */
ChimeraTK::TransferElementAbstractor::getId
TransferElementID getId() const
Obtain unique ID for the actual implementation of this TransferElement.
Definition: TransferElementAbstractor.h:192
ChimeraTK::TransferElementAbstractor::getAccessModeFlags
AccessModeFlags getAccessModeFlags() const
Return the AccessModeFlags for this TransferElement.
Definition: TransferElementAbstractor.h:51
ChimeraTK::TransferElementAbstractor::readLatest
bool readLatest()
Read the latest value, discarding any other update since the last read if present.
Definition: TransferElementAbstractor.h:77
ChimeraTK::TransferElementAbstractor::writeDestructively
bool writeDestructively(ChimeraTK::VersionNumber versionNumber={})
Just like write(), but allows the implementation to destroy the content of the user buffer in the pro...
Definition: TransferElementAbstractor.h:230
ChimeraTK::TransferElementAbstractor::isReadOnly
bool isReadOnly() const
Check if transfer element is read only, i.e.
Definition: TransferElementAbstractor.h:102
ChimeraTK::TransferElementAbstractor::isWriteable
bool isWriteable() const
Check if transfer element is writeable.
Definition: TransferElementAbstractor.h:112
VersionNumber.h
ChimeraTK::TransferElementAbstractor::dataValidity
DataValidity dataValidity() const
Return current validity of the data.
Definition: TransferElementAbstractor.h:202
ChimeraTK::TransferElementAbstractor::replace
void replace(const TransferElementAbstractor &newAccessor)
Assign a new accessor to this TransferElementAbstractor.
Definition: TransferElementAbstractor.h:160
ChimeraTK::TransferElementAbstractor::getHardwareAccessingElements
std::vector< boost::shared_ptr< TransferElement > > getHardwareAccessingElements()
Obtain the underlying TransferElements with actual hardware access.
Definition: TransferElementAbstractor.cc:10
TransferElement.h
ChimeraTK::TransferElementAbstractor::TransferElementAbstractor
TransferElementAbstractor(boost::shared_ptr< TransferElement > impl)
Construct from TransferElement implementation.
Definition: TransferElementAbstractor.h:31
ChimeraTK::TransferElementAbstractor::readNonBlocking
bool readNonBlocking()
Read the next value, if available in the input buffer.
Definition: TransferElementAbstractor.h:70
ChimeraTK::TransferElementAbstractor::isInitialised
bool isInitialised() const
Return if the accessor is properly initialised.
Definition: TransferElementAbstractor.h:152
TransferElementID.h
ChimeraTK::TransferElementAbstractor::setDataValidity
void setDataValidity(DataValidity valid=DataValidity::ok)
Set the current DataValidity for this TransferElement.
Definition: TransferElementAbstractor.h:197
ChimeraTK::TransferElementAbstractor::setPersistentDataStorage
void setPersistentDataStorage(boost::shared_ptr< ChimeraTK::PersistentDataStorage > storage)
Associate a persistent data storage object to be updated on each write operation of this ProcessArray...
Definition: TransferElementAbstractor.cc:37
ChimeraTK::TransferElementAbstractor::getDescription
const std::string & getDescription() const
Returns the description of this variable/register.
Definition: TransferElementAbstractor.h:44
ChimeraTK::TransferElementAbstractor
Base class for register accessors abstractors independent of the UserType.
Definition: TransferElementAbstractor.h:28
ChimeraTK::TransferElementAbstractor::isReadable
bool isReadable() const
Check if transfer element is readable.
Definition: TransferElementAbstractor.h:107
ChimeraTK::DataValidity::ok
@ ok
ChimeraTK::DataValidity
DataValidity
The current state of the data.
Definition: TransferElement.h:41
ChimeraTK::TransferElementAbstractor::TransferElementAbstractor
TransferElementAbstractor()=default
Create an uninitialised abstractor - just for late initialisation.
ChimeraTK::TransferElementAbstractor::getUnit
const std::string & getUnit() const
Returns the engineering unit.
Definition: TransferElementAbstractor.h:41
ChimeraTK::TransferElementAbstractor::replaceTransferElement
void replaceTransferElement(const boost::shared_ptr< TransferElement > &newElement)
Search for all underlying TransferElements which are considered identical (see mayReplaceOther()) wit...
Definition: TransferElementAbstractor.cc:24
ChimeraTK::TransferElementAbstractor::getInternalElements
std::list< boost::shared_ptr< TransferElement > > getInternalElements()
Obtain the full list of TransferElements internally used by this TransferElement.
Definition: TransferElementAbstractor.cc:16
ChimeraTK::TransferElementAbstractor::getHighLevelImplElement
const boost::shared_ptr< TransferElement > & getHighLevelImplElement()
Obtain the highest level implementation TransferElement.
Definition: TransferElementAbstractor.h:145
ChimeraTK::TransferElementAbstractor::replace
void replace(boost::shared_ptr< TransferElement > newImpl)
Alternative signature of relace() with the same functionality, used when a pointer to the implementat...
Definition: TransferElementAbstractor.h:166
ChimeraTK::TransferElementAbstractor::getName
const std::string & getName() const
Returns the name that identifies the process variable.
Definition: TransferElementAbstractor.h:37
ChimeraTK::TransferElementAbstractor::interrupt
void interrupt()
Return from a blocking read immediately and throw boost::thread_interrupted.
Definition: TransferElementAbstractor.h:221
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
ChimeraTK::TransferElementAbstractor::getValueType
const std::type_info & getValueType() const
Returns the std::type_info for the value type of this transfer element.
Definition: TransferElementAbstractor.h:48
ChimeraTK::AccessModeFlags
Set of AccessMode flags with additional functionality for an easier handling.
Definition: AccessMode.h:48
ChimeraTK::TransferElementAbstractor::_impl
boost::shared_ptr< TransferElement > _impl
Untyped pointer to implementation.
Definition: TransferElementAbstractor.h:225
ChimeraTK::TransferElementAbstractor::write
bool write(ChimeraTK::VersionNumber versionNumber={})
Write the data to device.
Definition: TransferElementAbstractor.h:89
ChimeraTK::TransferElementID
Simple class holding a unique ID for a TransferElement.
Definition: TransferElementID.h:17
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::TransferElementAbstractor::getVersionNumber
ChimeraTK::VersionNumber getVersionNumber() const
Returns the version number that is associated with the last transfer (i.e.
Definition: TransferElementAbstractor.h:83
ChimeraTK::TransferElementAbstractor::read
void read()
Read the data from the device.
Definition: TransferElementAbstractor.h:57