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(