ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
DeviceBackendImpl.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
6#include "DeviceBackend.h"
7#include "Exception.h"
8
9#include <ChimeraTK/cppext/finally.hpp>
10
11#include <atomic>
12#include <condition_variable>
13#include <list>
14#include <mutex>
15#include <shared_mutex>
16
17namespace ChimeraTK {
18
19 /********************************************************************************************************************/
20
26 public:
27 bool isOpen() override { return _opened; }
28
29 bool isConnected() final {
30 std::cerr << "Removed function DeviceBackendImpl::isConnected() called." << std::endl;
31 std::cerr << "Do not use. This function has no valid meaning." << std::endl;
32 std::terminate();
33 }
34
35 MetadataCatalogue getMetadataCatalogue() const override { return {}; }
36
41 virtual void setExceptionImpl() noexcept {}
42
47 void checkActiveException() final;
48
49 void setException(const std::string& message) noexcept final;
50
51 bool isFunctional() const noexcept final;
52
53 std::string getActiveExceptionMessage() noexcept;
55
56 protected:
58 void setOpenedAndClearException() noexcept;
59
61 std::atomic<bool> _opened{false};
62
68
69 private:
71 std::atomic<bool> _hasActiveException{false};
72
77 std::string _activeExceptionMessage;
78
80 std::mutex _mx_activeExceptionMessage;
81 };
82
83 /********************************************************************************************************************/
84
85 // This function is rather often called and hence implemented as inline in the header for performance reasons.
86 inline bool DeviceBackendImpl::isFunctional() const noexcept {
87 if(!_opened) return false;
88 if(_hasActiveException) return false;
89 return true;
90 }
91
92 /********************************************************************************************************************/
93
94 // This function is rather often called and hence implemented as inline in the header for performance reasons.
96 if(_hasActiveException) {
97 std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
98 throw ChimeraTK::runtime_error(_activeExceptionMessage);
99 }
100 }
101
102 /********************************************************************************************************************/
103
104} // namespace ChimeraTK
The base class for backends providing IO functionality for the Device class.
DeviceBackendImpl implements some basic functionality which should be available for all backends.
async::DomainsContainer _asyncDomainsContainer
Container for async::Domains to support wait_for_new_data.
bool isFunctional() const noexcept final
Return whether a device is working as intended, usually this means it is opened and does not have any...
void setOpenedAndClearException() noexcept
Backends should call this function at the end of a (successful) open() call.
std::string getActiveExceptionMessage() noexcept
bool isConnected() final
Deprecated since 2022-03-03.
virtual void setExceptionImpl() noexcept
Function to be (optionally) implemented by backends if additional actions are needed when switching t...
MetadataCatalogue getMetadataCatalogue() const override
Return the device metadata catalogue.
void setException(const std::string &message) noexcept final
Set the backend into an exception state.
void checkActiveException() final
Function to be called by backends when needing to check for an active exception.
std::set< DeviceBackend::BackendID > getInvolvedBackendIDs() override
Get the backend IDs of all involved backends.
bool isOpen() override
Return whether a device has been opened or not.
std::atomic< bool > _opened
flag if backend is opened
Container for backend metadata.
The DomainsContainer has a container with Domains and is performing actions on all of them.
Exception thrown when a runtime error has occured.
Definition Exception.h:18
STL namespace.