ChimeraTK-DeviceAccess
03.26.00
Loading...
Searching...
No Matches
DeviceBackendImpl.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 "
DeviceBackendImpl.h
"
5
6
#include <unistd.h>
7
8
namespace
ChimeraTK
{
9
10
/********************************************************************************************************************/
11
12
void
DeviceBackendImpl::setOpenedAndClearException
() noexcept {
13
// busy-wait until all exceptions have been distributed to the AsyncAccessors
14
while
(
_asyncDomainsContainer
.
isSendingExceptions
()) {
15
usleep(10000);
16
}
17
18
_versionOnOpen =
ChimeraTK::VersionNumber
{};
19
_opened
=
true
;
20
_hasActiveException =
false
;
21
std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
22
_activeExceptionMessage =
"(exception cleared)"
;
23
}
24
25
/********************************************************************************************************************/
26
27
void
DeviceBackendImpl::setException
(
const
std::string& message)
noexcept
{
28
// set exception flag and atomically get the previous state
29
bool
hadExceptionBefore = _hasActiveException.exchange(
true
);
30
31
// if previously backend was already in exception state, don't continue here
32
if
(hadExceptionBefore) {
33
return
;
34
}
35
36
// set exception message
37
{
38
std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
39
_activeExceptionMessage = message;
40
}
41
42
// execute backend-specific code
43
setExceptionImpl();
44
45
// finally turn off all async accessors and distribute the exception to them
46
_asyncDomainsContainer.sendExceptions(message);
47
}
48
49
/********************************************************************************************************************/
50
51
std::string
DeviceBackendImpl::getActiveExceptionMessage
() noexcept {
52
std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
53
return
_activeExceptionMessage;
54
}
55
56
/********************************************************************************************************************/
57
58
std::set<DeviceBackend::BackendID>
DeviceBackendImpl::getInvolvedBackendIDs
() {
59
return
{
getBackendID
()};
60
}
61
62
/********************************************************************************************************************/
63
64
ChimeraTK::VersionNumber
DeviceBackendImpl::getVersionOnOpen
()
const
{
65
return
_versionOnOpen;
66
}
67
68
/********************************************************************************************************************/
69
70
}
// namespace ChimeraTK
DeviceBackendImpl.h
ChimeraTK::DeviceBackend::getBackendID
BackendID getBackendID()
Get a unique ID for this backend instance.
Definition
DeviceBackend.h:112
ChimeraTK::DeviceBackendImpl::_asyncDomainsContainer
async::DomainsContainer _asyncDomainsContainer
Container for async::Domains to support wait_for_new_data.
Definition
DeviceBackendImpl.h:69
ChimeraTK::DeviceBackendImpl::setOpenedAndClearException
void setOpenedAndClearException() noexcept
Backends should call this function at the end of a (successful) open() call.
Definition
DeviceBackendImpl.cc:12
ChimeraTK::DeviceBackendImpl::getActiveExceptionMessage
std::string getActiveExceptionMessage() noexcept
Definition
DeviceBackendImpl.cc:51
ChimeraTK::DeviceBackendImpl::getVersionOnOpen
ChimeraTK::VersionNumber getVersionOnOpen() const override
Get the version number which was set during the open process.
Definition
DeviceBackendImpl.cc:64
ChimeraTK::DeviceBackendImpl::setException
void setException(const std::string &message) noexcept final
Set the backend into an exception state.
Definition
DeviceBackendImpl.cc:27
ChimeraTK::DeviceBackendImpl::getInvolvedBackendIDs
std::set< DeviceBackend::BackendID > getInvolvedBackendIDs() override
Get the backend IDs of all involved backends.
Definition
DeviceBackendImpl.cc:58
ChimeraTK::DeviceBackendImpl::_opened
std::atomic< bool > _opened
flag if backend is opened
Definition
DeviceBackendImpl.h:63
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition
VersionNumber.h:24
ChimeraTK::async::DomainsContainer::isSendingExceptions
bool isSendingExceptions()
Check whether an exception distribution is started and not completed yet.
Definition
DomainsContainer.h:45
ChimeraTK
Definition
DummyBackend.h:16
sources
ChimeraTK-DeviceAccess
src
DeviceBackendImpl.cc
Generated by
1.9.8