5 #include <fmt/format.h>
10 auto it = find(alerts.begin(), alerts.end(), alert);
11 if (it != alerts.end()) {
13 *it = std::move(alert);
16 alerts.emplace_back(std::move(alert));
21 auto it = std::remove(alerts.begin(), alerts.end(), alert);
22 if (it != alerts.end()) {
23 alerts.erase(it, alerts.end());
29 Alert MakeAlert(std::string_view category, std::string key, std::string description) {
30 return Alert{{std::string(category), std::move(key)},
31 std::move(description),
32 Alert::TimePoint::clock::now()};
36 return Alert{std::move(
id), std::move(description), Alert::TimePoint::clock::now()};
40 return AlertId{std::string(category), std::move(key)};
44 return lhs.key == rhs.key && lhs.category == rhs.category;
52 return lhs.id == rhs.id;
70 , file_id(std::move(file_id))
74 , timestamp(timestamp) {
79 , file_id(std::move(file_id))
80 , state(State::NotStarted)
83 , timestamp(TimePoint::clock::now()) {
87 return id == rhs.id && file_id == rhs.file_id && state == rhs.state &&
error == rhs.error &&
88 alerts == rhs.alerts && result == rhs.result;
92 return !(*
this == rhs);
96 os <<
"Status(id='" << s.
id <<
"', file_id='" << s.
file_id <<
"', state=" << s.
state
97 <<
", error=" << (s.
error ?
"true" :
"false") <<
", result='" << s.
result <<
"')";
108 : m_status(
nullptr) {
109 std::swap(m_status, other.m_status);
117 std::swap(m_status, other.m_status);
130 m_status->EnableSignals();
131 m_status->SignalChanges(
true);
140 : m_status(std::move(
id), std::move(file_id)) {
144 if (m_status == status) {
147 if (m_status.
id != status.
id) {
148 throw std::invalid_argument(fmt::format(
149 "Precondition not met (equality of DAQ IDs): {} != {}", m_status.
id, status.
id));
157 return m_status == rhs.m_status;
161 return !(*
this == rhs);
165 return m_status == rhs;
169 return !(*
this == rhs);
185 return m_status.
state;
189 return m_status.
error;
193 if (s == m_status.state) {
194 if (!
error ||
error.value() == m_status.error) {
199 if (
error.has_value()) {
200 m_status.error = *
error;
206 if (
error == m_status.error) {
209 m_status.error =
error;
214 m_status.
result = std::move(result);
230 m_status.timestamp = Status::TimePoint::clock::now();
232 if (force || m_deferred_signals == 0) {
239 ObservableStatus::operator
Status()
const {
248 assert(m_deferred_signals > 0);
249 --m_deferred_signals;
252 ++m_deferred_signals;
256 os <<
"ObservableStatus(id='" << s.
GetId() <<
"', file_id='" << s.
GetFileId()
257 <<
"', state=" << s.
GetState() <<
", error=" << (s.
GetError() ?
"true" :
"false") <<
")";