ChimeraTK-DeviceAccess  03.18.00
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 
11 namespace ChimeraTK {
12 
13  /********************************************************************************************************************/
14 
15  Device::Device(const std::string& aliasName) {
16  BackendFactory& factoryInstance = BackendFactory::getInstance();
17  _deviceBackendPointer = factoryInstance.createBackend(aliasName);
18  }
19 
20  /********************************************************************************************************************/
21 
24  return _deviceBackendPointer->getRegisterCatalogue();
25  }
26 
27  /********************************************************************************************************************/
28 
31  return _deviceBackendPointer->getMetadataCatalogue();
32  }
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 
51  void Device::open() {
53  _deviceBackendPointer->open();
54  }
55 
56  /********************************************************************************************************************/
57 
58  void Device::open(std::string const& aliasName) {
59  BackendFactory& factoryInstance = BackendFactory::getInstance();
60  _deviceBackendPointer = factoryInstance.createBackend(aliasName);
61  _deviceBackendPointer->open();
62  }
63 
64  /********************************************************************************************************************/
65 
66  void Device::close() {
68  _deviceBackendPointer->close();
69  }
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() {
112  return _deviceBackendPointer;
113  }
114 
115  /********************************************************************************************************************/
116 
117 } // namespace ChimeraTK
ChimeraTK::Void
Wrapper Class for void.
Definition: SupportedUserTypes.h:71
ChimeraTK::BackendFactory::createBackend
boost::shared_ptr< DeviceBackend > createBackend(const std::string &aliasOrUri)
Create a new backend and return the instance as a shared pointer.
Definition: BackendFactory.cc:201
DeviceBackend.h
ChimeraTK::Device::close
void close()
Close the device.
Definition: Device.cc:66
ChimeraTK::Device::getBackend
boost::shared_ptr< DeviceBackend > getBackend()
Obtain the backend.
Definition: Device.cc:111
ChimeraTK::BackendFactory::getInstance
static BackendFactory & getInstance()
Static function to get an instance of factory.
Definition: BackendFactory.cc:191
ChimeraTK::Device::getVoidRegisterAccessor
VoidRegisterAccessor getVoidRegisterAccessor(const RegisterPath &registerPathName, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a VoidRegisterAccessor object for the given register.
Definition: Device.cc:103
ChimeraTK::MetadataCatalogue
Container for backend metadata.
Definition: MetadataCatalogue.h:17
ChimeraTK::Device::Device
Device()=default
Create device instance without associating a backend yet.
ChimeraTK::Device::readDeviceInfo
std::string readDeviceInfo() const
Return a device information string.
Definition: Device.cc:36
ChimeraTK::RegisterCatalogue
Catalogue of register information.
Definition: RegisterCatalogue.h:20
ChimeraTK::Device::open
void open()
Re-open the device after previously closeing it by calling close(), or when it was constructed with a...
Definition: Device.cc:51
ChimeraTK::Device::activateAsyncRead
void activateAsyncRead() noexcept
Activate asyncronous read for all transfer elements where AccessMode::wait_for_new_data is set.
Definition: Device.cc:91
ChimeraTK::Device::_deviceBackendPointer
boost::shared_ptr< DeviceBackend > _deviceBackendPointer
Definition: Device.h:255
ChimeraTK::BackendFactory
BackendFactory is a the factory class to create devices.
Definition: BackendFactory.h:26
Device.h
ChimeraTK::VoidRegisterAccessor
Accessor class to read and write void-typed registers.
Definition: VoidRegisterAccessor.h:14
ChimeraTK::Device::getRegisterCatalogue
RegisterCatalogue getRegisterCatalogue() const
Return the register catalogue with detailed information on all registers.
Definition: Device.cc:22
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
ChimeraTK::Device::isOpened
bool isOpened() const
Check if the device is currently opened.
Definition: Device.cc:73
ChimeraTK::Device::checkPointersAreNotNull
void checkPointersAreNotNull() const
Definition: Device.cc:43
ChimeraTK::Device::getMetadataCatalogue
MetadataCatalogue getMetadataCatalogue() const
Return the register catalogue with detailed information on all registers.
Definition: Device.cc:29
ChimeraTK::AccessModeFlags
Set of AccessMode flags with additional functionality for an easier handling.
Definition: AccessMode.h:48
ChimeraTK::Device::isFunctional
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
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51
ChimeraTK::Device::setException
void setException(const std::string &message)
Set the device into an exception state.
Definition: Device.cc:97