12 #include <gsl/gsl_util>
18 using metadaqif::DaqReply;
19 using metadaqif::DaqStopReply;
20 using recif::RecStatus;
22 template std::optional<std::shared_ptr<DaqReply>>
23 HandleMetaDaqReply<std::shared_ptr<DaqReply>>(
char const* request,
24 std::optional<State> expected_state,
26 std::optional<State> error_state,
29 boost::future<std::shared_ptr<DaqReply>>&& fut);
31 template std::optional<std::shared_ptr<DaqStopReply>>
32 HandleMetaDaqReply<std::shared_ptr<DaqStopReply>>(
34 std::optional<State> expected_state,
36 std::optional<State> error_state,
39 boost::future<std::shared_ptr<DaqStopReply>>&& fut);
42 template std::optional<std::string>
43 HandlePrimDaqReply<std::string>(
char const* request,
44 std::optional<State> expected_state,
46 std::optional<State> error_state,
49 boost::future<std::string>&& fut);
51 template std::optional<std::shared_ptr<RecStatus>>
52 HandlePrimDaqReply<std::shared_ptr<RecStatus>>(
char const* request,
53 std::optional<State> expected_state,
55 std::optional<State> error_state,
58 boost::future<std::shared_ptr<RecStatus>>&& fut);
61 LOG4CPLUS_DEBUG(
"daq",
"UnwrapVoidReplies: Entered.");
62 std::vector<boost::future<void>> values = futures.get();
63 auto exceptions = ExtractExceptions<void>(values);
64 if (!exceptions.empty()) {
65 LOG4CPLUS_DEBUG(
"daq",
"UnwrapVoidReplies: Throwing gathered exceptions.");
66 throw boost::enable_current_exception(
DaqSourceErrors(std::move(exceptions)));
68 LOG4CPLUS_DEBUG(
"daq",
"UnwrapVoidReplies: Done.");
71 template <
class ReplyType>
73 std::optional<State> expected_state,
75 std::optional<State> error_state,
78 boost::future<ReplyType>&& fut) {
79 if (source.
GetState() == success_state) {
81 LOG4CPLUS_INFO(params.
logger,
82 fmt::format(
"{}: State of source '{}' is already satisfied. "
89 if (source.
GetState() != *expected_state) {
90 LOG4CPLUS_WARN(params.
logger,
91 fmt::format(
"{}: State of source '{}' is in an unexpected state. "
92 "Expected '{}'. Proceeding normally anyway.",
99 auto _ = gsl::finally([&] {
100 if (!std::uncaught_exceptions()) {
105 source.
SetState(*error_state,
true);
117 source.
SetState(success_state,
false);
120 }
catch (metadaqif::DaqException
const& e) {
121 LOG4CPLUS_WARN(params.
logger,
122 fmt::format(
"{}: Metadata source '{}' replied with "
131 fmt::format(
"Metadata source '{}' request '{}' replied "
132 "with ICD error: {}",
137 if (e.getId() != params.
id) {
141 throw boost::enable_current_exception(
148 "{}: Metadata source '{}' reply contains error:\n{}", params.
status, source, what));
151 fmt::format(
"Metadata source '{}' request '{}' failed: {}",
156 throw boost::enable_current_exception(
161 template <
class ReplyType>
163 std::optional<State> expected_state,
165 std::optional<State> error_state,
168 boost::future<ReplyType>&& fut) {
169 if (source.
GetState() == success_state) {
173 LOG4CPLUS_INFO(params.
logger,
174 fmt::format(
"{}: State of source '{}' is already satisfied. "
175 "Will ignore reply.",
181 if (expected_state) {
182 if (source.
GetState() != *expected_state) {
186 LOG4CPLUS_WARN(params.
logger,
187 fmt::format(
"{}: State of source '{}' is in an unexpected state. "
188 "Expected '{}'. Proceeding normally anyway.",
195 auto _ = gsl::finally([&] {
196 if (!std::uncaught_exceptions()) {
201 source.
SetState(*error_state,
true);
213 source.
SetState(success_state,
false);
216 }
catch (recif::ExceptionErr
const& e) {
217 LOG4CPLUS_WARN(params.
logger,
218 fmt::format(
"{}: Primdata source '{}' replied with "
227 fmt::format(
"Primary source '{}' request '{}' replied "
228 "with error: ({}) {}",
234 throw boost::enable_current_exception(
240 fmt::format(
"{}: Primdata source '{}' failed: {}", params.
status, source, what));
243 fmt::format(
"Primary source '{}' request '{}' failed: {}",
248 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 > 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)
Reply handler that checks for exceptions in reply.
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.
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.