14using metadaqif::DaqReply;
15using metadaqif::DaqStopReply;
16using recif::RecStatus;
18template std::optional<std::shared_ptr<DaqReply>> HandleMetaDaqReply<std::shared_ptr<DaqReply>>(
20 std::optional<State> expected_state,
22 std::optional<State> error_state,
25 boost::future<std::shared_ptr<DaqReply>>&& fut,
26 std::function<void(std::shared_ptr<DaqReply>
const&)>);
28template std::optional<std::shared_ptr<DaqStopReply>>
29HandleMetaDaqReply<std::shared_ptr<DaqStopReply>>(
31 std::optional<State> expected_state,
33 std::optional<State> error_state,
36 boost::future<std::shared_ptr<DaqStopReply>>&& fut,
37 std::function<void(std::shared_ptr<DaqStopReply>
const&)>);
40template std::optional<std::string>
42 std::optional<State> expected_state,
44 std::optional<State> error_state,
47 boost::future<std::string>&& fut);
49template std::optional<std::shared_ptr<RecStatus>>
50HandlePrimDaqReply<std::shared_ptr<RecStatus>>(
char const* request,
51 std::optional<State> expected_state,
53 std::optional<State> error_state,
56 boost::future<std::shared_ptr<RecStatus>>&& fut);
59 LOG4CPLUS_DEBUG(
"daq",
"UnwrapVoidReplies: Entered.");
60 std::vector<boost::future<void>> values = futures.get();
61 auto exceptions = ExtractExceptions<void>(values);
62 if (!exceptions.empty()) {
63 LOG4CPLUS_DEBUG(
"daq",
"UnwrapVoidReplies: Throwing gathered exceptions.");
64 throw boost::enable_current_exception(
DaqSourceErrors(std::move(exceptions)));
66 LOG4CPLUS_DEBUG(
"daq",
"UnwrapVoidReplies: Done.");
69template <
class ReplyType>
71 std::optional<State> expected_state,
73 std::optional<State> error_state,
76 boost::future<ReplyType>&& fut,
77 std::function<
void(ReplyType
const&)> func) {
78 if (source.
GetState() == success_state) {
80 LOG4CPLUS_INFO(params.
logger,
81 fmt::format(
"{}: State of source '{}' is already satisfied. "
88 if (source.
GetState() != *expected_state) {
89 LOG4CPLUS_WARN(params.
logger,
90 fmt::format(
"{}: State of source '{}' is in an unexpected state. "
91 "Expected '{}'. Proceeding normally anyway.",
98 auto set_error_state = [&] {
100 source.
SetState(*error_state,
true);
110 ReplyType r = fut.get();
115 source.
SetState(success_state,
false);
118 }
catch (metadaqif::DaqException
const& e) {
119 auto msg = fmt::format(
120 "{}: Metadata source '{}' replied with ICD exception: "
127 LOG4CPLUS_WARN(params.
logger, msg);
131 throw boost::enable_current_exception(
133 }
catch (std::exception
const& e) {
134 auto msg = fmt::format(
135 "{}: Metadata source '{}' reply contains error for id='{}': {}",
140 LOG4CPLUS_WARN(params.
logger, msg);
144 throw boost::enable_current_exception(
151 "{}: Metadata source '{}' reply contains error:\n{}", params.
status, source, what));
153 fmt::format(
"Metadata source '{}' request '{}' failed: {}",
159 throw boost::enable_current_exception(
164template <
class ReplyType>
166 std::optional<State> expected_state,
168 std::optional<State> error_state,
171 boost::future<ReplyType>&& fut) {
172 if (source.
GetState() == success_state) {
176 LOG4CPLUS_INFO(params.
logger,
177 fmt::format(
"{}: State of source '{}' is already satisfied. "
178 "Will ignore reply.",
184 if (expected_state) {
185 if (source.
GetState() != *expected_state) {
189 LOG4CPLUS_WARN(params.
logger,
190 fmt::format(
"{}: State of source '{}' is in an unexpected state. "
191 "Expected '{}'. Proceeding normally anyway.",
198 auto set_error_state = [&] {
200 source.
SetState(*error_state,
true);
212 source.
SetState(success_state,
false);
215 }
catch (recif::ExceptionErr
const& e) {
216 LOG4CPLUS_WARN(params.
logger,
217 fmt::format(
"{}: Primdata source '{}' replied with "
225 fmt::format(
"Primary source '{}' request '{}' replied "
226 "with error: ({}) {}",
233 throw boost::enable_current_exception(
239 fmt::format(
"{}: Primdata source '{}' failed: {}", params.
status, source, what));
241 fmt::format(
"Primary source '{}' request '{}' failed: {}",
247 throw boost::enable_current_exception(
Represents error in single source.
Exception thrown to carry reply errors.
constexpr std::string_view REQUEST
Request.
void FormatException(std::ostream &os, std::exception_ptr ptr)
Report without nesting.
std::optional< ReplyType > HandlePrimDaqReply(char const *request, std::optional< State > expected_state, State success_state, std::optional< State > error_state, AsyncOpParams params, Source< PrimSource > &source, boost::future< ReplyType > &&fut)
Reply handler that checks for exceptions in reply.
void UnwrapVoidReplies(boost::future< std::vector< boost::future< void > > > futures)
Unwrap futures to extract errors.
std::optional< ReplyType > HandleMetaDaqReply(char const *request, std::optional< State > expected_state, State success_state, std::optional< State > error_state, AsyncOpParams params, Source< MetaSource > &source, boost::future< ReplyType > &&fut, std::function< void(ReplyType const &)> func={})
Reply handler that checks for exceptions in reply.
template std::optional< std::string > HandlePrimDaqReply< std::string >(char const *request, std::optional< State > expected_state, State success_state, std::optional< State > error_state, AsyncOpParams params, Source< PrimSource > &source, boost::future< std::string > &&fut)
AlertId MakeAlertId(std::string_view category, std::string key)
State
Observable states of the data acquisition process.
Alert MakeAlert(std::string_view category, std::string key, std::string description)
Construct alert.
Simple class that holds the source and associated state.
void SetState(State state, std::optional< bool > error_flag={})
Parameters required for each async operation.
AlertState & alerts
Alerts to be merged only after completion of async operation.
ObservableStatus & status
Async operations should not modify state directly DaqController does that.
log4cplus::Logger & logger
Contains declaration for the async op utilities.