ChimeraTK-DeviceAccess
03.29.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 "
SharedAccessor.h
"
7
8
#include <unistd.h>
9
10
namespace
ChimeraTK
{
11
12
/********************************************************************************************************************/
13
14
void
DeviceBackendImpl::setOpenedAndClearException
() noexcept {
15
// busy-wait until all exceptions have been distributed to the AsyncAccessors
16
while
(
_asyncDomainsContainer
.
isSendingExceptions
()) {
17
usleep(10000);
18
}
19
20
_versionOnOpen =
ChimeraTK::VersionNumber
{};
21
_opened
=
true
;
22
_hasActiveException =
false
;
23
std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
24
_activeExceptionMessage =
"(exception cleared)"
;
25
}
26
27
/********************************************************************************************************************/
28
29
void
DeviceBackendImpl::setException
(
const
std::string& message)
noexcept
{
30
// set exception flag and atomically get the previous state
31
bool
hadExceptionBefore = _hasActiveException.exchange(
true
);
32
33
// if previously backend was already in exception state, don't continue here
34
if
(hadExceptionBefore) {
35
return
;
36
}
37
38
// set exception message
39
{
40
std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
41
_activeExceptionMessage = message;
42
}
43
44
// execute backend-specific code
45
setExceptionImpl();
46
47
// finally turn off all async accessors and distribute the exception to them
48
_asyncDomainsContainer.sendExceptions(message);
49
}
50
51
/********************************************************************************************************************/
52
53
std::string
DeviceBackendImpl::getActiveExceptionMessage
() noexcept {
54
std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
55
return
_activeExceptionMessage;
56
}
57
58
/********************************************************************************************************************/
59
60
std::set<DeviceBackend::BackendID>
DeviceBackendImpl::getInvolvedBackendIDs
() {
61
return
{
getBackendID
()};
62
}
63
64
/********************************************************************************************************************/
65
66
ChimeraTK::VersionNumber
DeviceBackendImpl::getVersionOnOpen
()
const
{
67
return
_versionOnOpen;
68
}
69
70
/********************************************************************************************************************/
71
72
boost::shared_ptr<detail::SharedAccessors>
DeviceBackendImpl::getSharedAccessors
() {
73
std::lock_guard<std::mutex> lk(_sharedAccessorsMutex);
74
if
(!_sharedAccessors) {
75
if
(!_sharedAccessors) {
76
_sharedAccessors = boost::make_shared<detail::SharedAccessors>();
77
}
78
}
79
return
_sharedAccessors;
80
}
81
82
/********************************************************************************************************************/
83
84
}
// namespace ChimeraTK
DeviceBackendImpl.h
SharedAccessor.h
ChimeraTK::DeviceBackend::getBackendID
BackendID getBackendID()
Get a unique ID for this backend instance.
Definition
DeviceBackend.h:116
ChimeraTK::DeviceBackendImpl::_asyncDomainsContainer
async::DomainsContainer _asyncDomainsContainer
Container for async::Domains to support wait_for_new_data.
Definition
DeviceBackendImpl.h:71
ChimeraTK::DeviceBackendImpl::setOpenedAndClearException
void setOpenedAndClearException() noexcept
Backends should call this function at the end of a (successful) open() call.
Definition
DeviceBackendImpl.cc:14
ChimeraTK::DeviceBackendImpl::getActiveExceptionMessage
std::string getActiveExceptionMessage() noexcept
Definition
DeviceBackendImpl.cc:53
ChimeraTK::DeviceBackendImpl::getVersionOnOpen
ChimeraTK::VersionNumber getVersionOnOpen() const override
Get the version number which was set during the open process.
Definition
DeviceBackendImpl.cc:66
ChimeraTK::DeviceBackendImpl::setException
void setException(const std::string &message) noexcept final
Set the backend into an exception state.
Definition
DeviceBackendImpl.cc:29
ChimeraTK::DeviceBackendImpl::getInvolvedBackendIDs
std::set< DeviceBackend::BackendID > getInvolvedBackendIDs() override
Get the backend IDs of all involved backends.
Definition
DeviceBackendImpl.cc:60
ChimeraTK::DeviceBackendImpl::_opened
std::atomic< bool > _opened
flag if backend is opened
Definition
DeviceBackendImpl.h:65
ChimeraTK::DeviceBackendImpl::getSharedAccessors
boost::shared_ptr< detail::SharedAccessors > getSharedAccessors() final
Get the SharedAccessors object of this backend instance.
Definition
DeviceBackendImpl.cc:72
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