-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaq_state.cpp
More file actions
58 lines (51 loc) · 1.57 KB
/
Copy pathdaq_state.cpp
File metadata and controls
58 lines (51 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "daq_state.h"
#include <atomic>
#include <mutex>
namespace
{
std::atomic<DaqStatus> gStatus{DaqStatus::Uninitialized};
std::mutex gDetailsMutex;
int gLastErrno = 0;
std::string gDevicePath;
std::string gReason{"DAQ device has not been initialized"};
} // namespace
bool DaqReady() noexcept
{
return gStatus.load(std::memory_order_acquire) == DaqStatus::Ready;
}
DaqStateSnapshot GetDaqStateSnapshot()
{
std::lock_guard<std::mutex> lock(gDetailsMutex);
return DaqStateSnapshot{gStatus.load(std::memory_order_acquire),
gLastErrno, gDevicePath, gReason};
}
const char *DaqStatusName(DaqStatus status) noexcept
{
switch (status)
{
case DaqStatus::Uninitialized: return "Uninitialized";
case DaqStatus::Ready: return "Ready";
case DaqStatus::DeviceDirectoryMissing: return "DeviceDirectoryMissing";
case DaqStatus::NoDeviceFound: return "NoDeviceFound";
case DaqStatus::OpenFailed: return "OpenFailed";
}
return "Unknown";
}
void SetDaqReady(const std::string &devicePath)
{
std::lock_guard<std::mutex> lock(gDetailsMutex);
gLastErrno = 0;
gDevicePath = devicePath;
gReason.clear();
gStatus.store(DaqStatus::Ready, std::memory_order_release);
}
void SetDaqUnavailable(DaqStatus status, int errorNumber,
const std::string &devicePath,
const std::string &reason)
{
std::lock_guard<std::mutex> lock(gDetailsMutex);
gLastErrno = errorNumber;
gDevicePath = devicePath;
gReason = reason;
gStatus.store(status, std::memory_order_release);
}