12 #include <gsl/gsl_util>
16 using metadaqif::DaqReply;
17 using metadaqif::DaqStopReply;
18 using recif::RecStatus;
20 template std::optional<std::shared_ptr<DaqReply>>
21 HandleMetaDaqReply<std::shared_ptr<DaqReply>>(std::optional<State> expected_state,
23 std::optional<State> error_state,
26 boost::future<std::shared_ptr<DaqReply>>&& fut);
28 template std::optional<std::shared_ptr<DaqStopReply>>
29 HandleMetaDaqReply<std::shared_ptr<DaqStopReply>>(
30 std::optional<State> expected_state,
32 std::optional<State> error_state,
35 boost::future<std::shared_ptr<DaqStopReply>>&& fut);
38 template std::optional<std::string>
39 HandlePrimDaqReply<std::string>(std::optional<State> expected_state,
41 std::optional<State> error_state,
44 boost::future<std::string>&& fut);
46 template std::optional<std::shared_ptr<RecStatus>>
47 HandlePrimDaqReply<std::shared_ptr<RecStatus>>(std::optional<State> expected_state,
49 std::optional<State> error_state,
52 boost::future<std::shared_ptr<RecStatus>>&& fut);
55 LOG4CPLUS_DEBUG(
"daq",
"UnwrapVoidReplies: Entered.");
56 std::vector<boost::future<void>> values = futures.get();
57 auto exceptions = ExtractExceptions<void>(values);
58 if (!exceptions.empty()) {
59 throw boost::enable_current_exception(
DaqSourceErrors(std::move(exceptions)));
61 LOG4CPLUS_DEBUG(
"daq",
"UnwrapVoidReplies: Done.");
64 template <
class ReplyType>
67 std::optional<State> error_state,
70 boost::future<ReplyType>&& fut) {
71 if (source.
GetState() == success_state) {
73 LOG4CPLUS_INFO(params.
logger,
74 fmt::format(
"{}: State of source '{}' is already satisfied. "
81 if (source.
GetState() != *expected_state) {
82 LOG4CPLUS_WARN(params.
logger,
83 fmt::format(
"{}: State of source '{}' is in an unexpected state. "
84 "Expected '{}'. Proceeding normally anyway.",
91 auto _ = gsl::finally([&] {
92 if (!std::uncaught_exceptions()) {
106 source.
SetState(success_state,
false);
108 }
catch (metadaqif::DaqException
const& e) {
109 LOG4CPLUS_WARN(params.
logger,
110 fmt::format(
"{}: Metadata source '{}' replied with "
117 if (e.getId() != params.
id) {
121 throw boost::enable_current_exception(
124 LOG4CPLUS_WARN(params.
logger,
125 fmt::format(
"{}: Metadata source '{}' reply contains unknown exception "
130 throw boost::enable_current_exception(
135 template <
class ReplyType>
138 std::optional<State> error_state,
141 boost::future<ReplyType>&& fut) {
142 if (source.
GetState() == success_state) {
146 LOG4CPLUS_INFO(params.
logger,
147 fmt::format(
"{}: State of source '{}' is already satisfied. "
148 "Will ignore reply.",
154 if (expected_state) {
155 if (source.
GetState() != *expected_state) {
159 LOG4CPLUS_WARN(params.
logger,
160 fmt::format(
"{}: State of source '{}' is in an unexpected state. "
161 "Expected '{}'. Proceeding normally anyway.",
168 auto _ = gsl::finally([&] {
169 if (!std::uncaught_exceptions()) {
174 source.
SetState(*error_state,
true);
183 source.
SetState(success_state,
false);
185 }
catch (metadaqif::DaqException
const& e) {
186 LOG4CPLUS_WARN(params.
logger,
187 fmt::format(
"{}: Primdata source '{}' replied with "
194 if (e.getId() != params.
id) {
198 throw boost::enable_current_exception(
201 LOG4CPLUS_WARN(params.
logger,
202 fmt::format(
"{}: Primdata source '{}' reply contains unknown exception "
207 throw boost::enable_current_exception(