ChimeraTK-DeviceAccess 03.20.00
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Device.cc
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
4#include "Device.h"
5
6#include "DeviceBackend.h"
7
8#include <cmath>
9#include <cstring>
10
11namespace ChimeraTK {
12
13 /********************************************************************************************************************/
14
15 Device::Device(const std::string& aliasName) {
17 _deviceBackendPointer = factoryInstance.createBackend(aliasName);
18 }
19
20 /********************************************************************************************************************/
21
26
27 /********************************************************************************************************************/
28
33
34 /********************************************************************************************************************/
35
36 std::string Device::readDeviceInfo() const {
38 return _deviceBackendPointer->readDeviceInfo();
39 }
40
41 /********************************************************************************************************************/
42
44 if(!static_cast<bool>(_deviceBackendPointer)) {
45 throw ChimeraTK::logic_error("Device has not been opened correctly");
46 }
47 }
48
49 /********************************************************************************************************************/
50
55
56 /********************************************************************************************************************/
57
58 void Device::open(std::string const& aliasName) {
60 _deviceBackendPointer = factoryInstance.createBackend(aliasName);
62 }
63
64 /********************************************************************************************************************/
65
70
71 /********************************************************************************************************************/
72
73 bool Device::isOpened() const {
74 if(static_cast<bool>(_deviceBackendPointer)) {
75 return _deviceBackendPointer->isOpen();
76 }
77 return false; // no backend is assigned: the device is not opened
78 }
79
80 /********************************************************************************************************************/
81
82 bool Device::isFunctional() const {
83 if(static_cast<bool>(_deviceBackendPointer)) {
84 return _deviceBackendPointer->isFunctional();
85 }
86 return false; // no backend is assigned: the device is not opened
87 }
88
89 /********************************************************************************************************************/
90
91 void Device::activateAsyncRead() noexcept {
92 _deviceBackendPointer->activateAsyncRead();
93 }
94
95 /********************************************************************************************************************/
96
97 void Device::setException(const std::string& message) {
98 _deviceBackendPointer->setException(message);
99 }
100
101 /********************************************************************************************************************/
102
104 const RegisterPath& registerPathName, const AccessModeFlags& flags) const {
106 return {_deviceBackendPointer->getRegisterAccessor<Void>(registerPathName, 0, 0, flags)};
107 }
108
109 /********************************************************************************************************************/
110
111 boost::shared_ptr<DeviceBackend> Device::getBackend() {
113 }
114
115 /********************************************************************************************************************/
116
117 std::set<DeviceBackend::BackendID> Device::getInvolvedBackendIDs() {
119 return _deviceBackendPointer->getInvolvedBackendIDs();
120 }
121
122 /*******************************************************************************************************************/
123
124} // namespace ChimeraTK
Set of AccessMode flags with additional functionality for an easier handling.
Definition AccessMode.h:48
BackendFactory is a the factory class to create devices.
static BackendFactory & getInstance()
Static function to get an instance of factory.
boost::shared_ptr< DeviceBackend > createBackend(const std::string &aliasOrUri)
Create a new backend and return the instance as a shared pointer.
bool isOpened() const
Check if the device is currently opened.
Definition Device.cc:73
std::set< DeviceBackend::BackendID > getInvolvedBackendIDs()
Recursively obtain the set of all backend IDs that are used withing the device.
Definition Device.cc:117
void open()
Re-open the device after previously closeing it by calling close(), or when it was constructed with a...
Definition Device.cc:51
MetadataCatalogue getMetadataCatalogue() const
Return the register catalogue with detailed information on all registers.
Definition Device.cc:29
boost::shared_ptr< DeviceBackend > _deviceBackendPointer
Definition Device.h:258
void close()
Close the device.
Definition Device.cc:66
void setException(const std::string &message)
Set the device into an exception state.
Definition Device.cc:97
boost::shared_ptr< DeviceBackend > getBackend()
Obtain the backend.
Definition Device.cc:111
VoidRegisterAccessor getVoidRegisterAccessor(const RegisterPath &registerPathName, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a VoidRegisterAccessor object for the given register.
Definition Device.cc:103
void checkPointersAreNotNull() const
Definition Device.cc:43
RegisterCatalogue getRegisterCatalogue() const
Return the register catalogue with detailed information on all registers.
Definition Device.cc:22
std::string readDeviceInfo() const
Return a device information string.
Definition Device.cc:36
bool isFunctional() const
Return wether a device is working as intended, usually this means it is opened and does not have any ...
Definition Device.cc:82
void activateAsyncRead() noexcept
Activate asyncronous read for all transfer elements where AccessMode::wait_for_new_data is set.
Definition Device.cc:91
Device()=default
Create device instance without associating a backend yet.
Container for backend metadata.
Catalogue of register information.
Class to store a register path name.
Wrapper Class for void.
Accessor class to read and write void-typed registers.
Exception thrown when a logic error has occured.
Definition Exception.h:51