ChimeraTK-DeviceAccess 03.25.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 _opened = true;
19 _hasActiveException = false;
20 std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
21 _activeExceptionMessage = "(exception cleared)";
22 }
23
24 /********************************************************************************************************************/
25
26 void DeviceBackendImpl::setException(const std::string& message) noexcept {
27 // set exception flag and atomically get the previous state
28 bool hadExceptionBefore = _hasActiveException.exchange(true);
29
30 // if previously backend was already in exception state, don't continue here
31 if(hadExceptionBefore) {
32 return;
33 }
34
35 // set exception message
36 {
37 std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
38 _activeExceptionMessage = message;
39 }
40
41 // execute backend-specific code
42 setExceptionImpl();
43
44 // finally turn off all async accessors and distribute the exception to them
45 _asyncDomainsContainer.sendExceptions(message);
46 }
47
48 /********************************************************************************************************************/
49
51 std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
52 return _activeExceptionMessage;
53 }
54
55 /********************************************************************************************************************/
56
57 std::set<DeviceBackend::BackendID> DeviceBackendImpl::getInvolvedBackendIDs() {
58 return {getBackendID()};
59 }
60 /********************************************************************************************************************/
61
62} // 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
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
bool isSendingExceptions()
Check whether an exception distribution is started and not completed yet.