ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
dpmService.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_dpm
4  * @copyright (c) Copyright ESO 2022
5  * All Rights Reserved
6  * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7  *
8  * @brief daq::dpm::DpmService implements MAL services daqif::DpmControl and daqif::DpmDaqControl.
9  */
10 #ifndef DAQ_DPM_DPMREPLIER_HPP
11 #define DAQ_DPM_DPMREPLIER_HPP
12 #include <daq/config.hpp>
13 
14 #include <boost/asio/executor_work_guard.hpp>
15 #include <boost/asio/signal_set.hpp>
16 #include <log4cplus/logger.h>
17 #include <mal/Mal.hpp>
18 #include <rad/ioExecutor.hpp>
19 
20 #include <Daqif.hpp>
21 
22 #include <daq/dpm/scheduler.hpp>
23 #include <daq/dpm/workspace.hpp>
24 #include <daq/state.hpp>
25 
26 namespace daq::dpm {
27 
28 /**
29  * daqif::DpmControl and DpmDaqControl implementation.
30  *
31  * It is mainly responsible for acting as gateway between CII and rest of application.
32  *
33  * Aspects to consider
34  *
35  * - "Requests" are method calls from foreign thread -> requires synchronization, typically by
36  * posting to main thread via io_context.
37  * - Accept requests and transform CII arguments to application format.
38  */
39 class DpmService : public ::daqif::AsyncDpmControl, public ::daqif::AsyncDpmDaqControl {
40 public:
41  static constexpr char const* LOGGER_NAME = "dpm.replier";
42 
43  /**
44  * Construct replier.
45  *
46  * @param executor Executor to use, including the native asio::io_context.
47  */
48  DpmService(rad::IoExecutor& executor,
49  elt::mal::Mal& mal,
50  Workspace& workspace,
51  Scheduler& scheduler);
52  /**
53  * @name AsyncDpmControl
54  */
55  /// @{
56  boost::future<std::shared_ptr<::daqif::StorageStatus>> QueryStorageStatus() override;
57  /**
58  * Cancels any started merges and terminates application.
59  *
60  * @returns future that is set only after all other active operations are cancelled.
61  */
62  boost::future<std::string> Exit() override;
63 
64  boost::future<std::string> GetVersion() override;
65  /// @}
66  /**
67  * @name AsyncDpmDaqControl
68  */
69  /// @{
70  boost::future<std::shared_ptr<::daqif::DaqReply>>
71  QueueDaq(const std::string& specification) override;
72 
73  boost::future<std::shared_ptr<::daqif::DaqReply>> AbortDaq(const std::string& id) override;
74 
75  boost::future<std::shared_ptr<::daqif::DaqStatus>> GetDaqStatus(const std::string& id) override;
76 
77  boost::future<std::vector<std::shared_ptr<::daqif::DaqStatus>>> GetActiveDaqs() override;
78  /// @}
79 
80 private:
81  void InitiateSignalHandler();
82  void HandleExit();
83  /**
84  * Should only be invoked from main thread.
85  */
86  std::shared_ptr<daqif::DaqStatus> GetDaqStatusSync(std::string const& id);
87 
88  rad::IoExecutor& m_executor;
89  elt::mal::Mal& m_mal;
90  /**
91  * @name Must be accessed from main thread via exectuor
92  */
93  ///@{
94  Workspace& m_workspace;
95  Scheduler& m_scheduler;
96  ///@}
97  boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_work_guard;
98  boost::asio::signal_set m_sigset;
99  log4cplus::Logger m_logger;
100 };
101 
102 } // namespace daq::dpm
103 
104 #endif // #ifndef DAQ_DPM_DPMREPLIER_HPP
daqif::DpmControl and DpmDaqControl implementation.
Definition: dpmService.hpp:39
boost::future< std::shared_ptr<::daqif::DaqReply > > QueueDaq(const std::string &specification) override
Definition: dpmService.cpp:75
DpmService(rad::IoExecutor &executor, elt::mal::Mal &mal, Workspace &workspace, Scheduler &scheduler)
Construct replier.
Definition: dpmService.cpp:26
boost::future< std::string > GetVersion() override
Cancels any started merges and terminates application.
Definition: dpmService.cpp:70
boost::future< std::shared_ptr<::daqif::StorageStatus > > QueryStorageStatus() override
Cancels any started merges and terminates application.
Definition: dpmService.cpp:40
boost::future< std::string > Exit() override
Cancels any started merges and terminates application.
Definition: dpmService.cpp:58
static constexpr char const * LOGGER_NAME
Definition: dpmService.hpp:41
boost::future< std::vector< std::shared_ptr<::daqif::DaqStatus > > > GetActiveDaqs() override
Definition: dpmService.cpp:150
boost::future< std::shared_ptr<::daqif::DaqReply > > AbortDaq(const std::string &id) override
Definition: dpmService.cpp:103
boost::future< std::shared_ptr<::daqif::DaqStatus > > GetDaqStatus(const std::string &id) override
Definition: dpmService.cpp:131
Schedules asynchronous activities that results in merged Data Product and delivery.
Definition: scheduler.hpp:274
Interface to interact with DPM workspace.
Definition: workspace.hpp:98
Adapts boost::asio::io_context into a compatible boost::thread Executor type.
Definition: ioExecutor.hpp:12
daq::dpm::Workspace interface and implementation declaration
Declares daq::State and related functions.
daq::dpm::Scheduler and related class declarations.