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
8namespace ChimeraTK {
9
10 /********************************************************************************************************************/
11
13 // busy-wait until all exceptions have been distributed to the AsyncAccessors
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
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
65 return _versionOnOpen;
66 }
67
68 /********************************************************************************************************************/
69
70} // namespace ChimeraTK
BackendID getBackendID()
Get a unique ID for this backend instance.
async::DomainsContainer _asyncDomainsContainer
Container for async::Domains to support wait_for_new_data.
void setOpenedAndClearException() noexcept
Backends should call this function at the end of a (successful) open() call.
std::string getActiveExceptionMessage() noexcept
ChimeraTK::VersionNumber getVersionOnOpen() const override
Get the version number which was set during the open process.
void setException(const std::string &message) noexcept final
Set the backend into an exception state.
std::set< DeviceBackend::BackendID > getInvolvedBackendIDs() override
Get the backend IDs of all involved backends.
std::atomic< bool > _opened
flag if backend is opened
Class for generating and holding version numbers without exposing a numeric representation.
bool isSendingExceptions()
Check whether an exception distribution is started and not completed yet.