ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
awaitState.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup daq_common_libdaq
4 * @copyright 2022 ESO - European Southern Observatory
5 *
6 * @brief Contains declaration for the AwaitStateAsync operation
7 */
8#ifndef OCM_DAQ_OP_AWAIT_STATE_HPP_
9#define OCM_DAQ_OP_AWAIT_STATE_HPP_
10#include "../config.hpp"
11
12#include <boost/asio/steady_timer.hpp>
13#include <boost/signals2/connection.hpp>
14#include <boost/thread/future.hpp>
15#include <log4cplus/logger.h>
16
17#include "../status.hpp"
18#include "../utility.hpp"
19
20
21namespace daq::op {
22
23
24/**
25 * Async operation to await Data Acquisition state
26 *
27 * Satisfies concept requirements for op::InitiateAbortableOperation and
28 * op::InitiateOperation.
29 *
30 * @ingroup daq_common_libdaq
31 */
33public:
35 /**
36 * Constructs operation with the privided parameters.
37 *
38 * @param io_ctx ASIO context.
39 * @param status DAQ status to monitor/observe changes on.
40 * @param state Target state.
41 * @param timeout Operation timeout.
42 */
43 explicit AwaitStateAsync(boost::asio::io_context& io_ctx,
44 std::shared_ptr<ObservableStatus> status,
45 State state,
46 std::chrono::milliseconds timeout,
47 log4cplus::Logger const& logger);
48
49 /**
50 * Initiates operation that await state.
51 *
52 * @returns future with value being set when condition is satisifed or times out.
53 * Exception DaqOperationAborted is set when operation is aborted.
54 * ResultType::error is true if operation times out with await condition unsatisfied.
55 *
56 * @note Caller is responsible for keeping object alive until
57 * result is set.
58 */
59 [[nodiscard]] boost::future<ResultType> Initiate();
60
61 /**
62 * Aborts the operation and completes the operation with DaqOperationAborted.
63 */
64 void Abort() noexcept;
65
66private:
67 bool IsConditionSatisfied() const;
68 boost::asio::io_context& m_io_ctx;
69 std::shared_ptr<ObservableStatus> m_status;
70 State m_target;
71 std::chrono::milliseconds m_timeout;
72 /**
73 * Indicates whether operation was aborted or not.
74 *
75 * If this is true it means that m_promise has already been fulfilled.
76 */
77 bool m_aborted;
78
79 /**
80 * Promise for future returned from `Initiate()`
81 */
82 boost::promise<ResultType> m_promise;
83
84 boost::asio::steady_timer m_timer;
85 boost::signals2::scoped_connection m_connection;
86 log4cplus::Logger m_logger;
87};
88
89
90} // namespace daq::op
91#endif // #ifndef OCM_DAQ_OP_AWAIT_STATE_HPP_
Stores data acquisition status and allows subscription to status changes.
Definition: status.hpp:224
State
Observable states of the data acquisition process.
Definition: state.hpp:41
Utility class that represents a result and an error.
Definition: utility.hpp:17
Async operation to await Data Acquisition state.
Definition: awaitState.hpp:32
boost::future< ResultType > Initiate()
Initiates operation that await state.
Definition: awaitState.cpp:33
void Abort() noexcept
Aborts the operation and completes the operation with DaqOperationAborted.
Definition: awaitState.cpp:92