ifw-daq  2.1.0-pre1
IFW Data Acquisition modules
dpmClient.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm_libdaq_test
4  * @copyright 2022 ESO - European Southern Observatory
5  *
6  * @brief `daq::DpmClient`
7  */
8 #ifndef DAQ_DPMCLIENT_HPP
9 #define DAQ_DPMCLIENT_HPP
10 #include "config.hpp"
11 
12 #include <filesystem>
13 
14 #include <boost/asio/io_context.hpp>
15 #include <boost/signals2/signal.hpp>
16 #include <boost/thread/future.hpp>
17 #include <rad/ioExecutor.hpp>
18 
19 #include <daq/status.hpp>
20 
21 namespace daqif {
22  class DpmDaqControlAsync;
23 }
24 
25 namespace elt::mal {
26  class Mal;
27 }
28 namespace mal = ::elt::mal;
29 
30 namespace daq {
31 
32 /**
33  * Interface to DPM server.
34  *
35  * Any implementation is expected to also provide a subscriber for DPM status and storage change
36  * signals.
37  */
38 class DpmClient {
39 public:
40  using StorageSignal = boost::signals2::signal<void(std::filesystem::space_info)>;
41  using StatusSignal = boost::signals2::signal<void(Status)>;
42 
43  /**
44  * Schedule merging.
45  */
46  virtual auto ScheduleAsync(std::string const& spec) -> boost::future<State> = 0;
47 
48  /**
49  * Abort merging.
50  */
51  virtual auto
52  AbortAsync(std::string const& id) -> boost::future<State> = 0;
53 
54  /**
55  * Connect slot to status change signal.
56  *
57  * DpmClient ensures that signals are only emitted from main thread.
58  */
59  virtual auto
60  ConnectStatusSignal(StatusSignal::slot_type const& slot) -> boost::signals2::connection = 0;
61 
62  /**
63  * Connect slot to storage change signal.
64  *
65  * DpmClient ensures that signals are only emitted from main thread.
66  */
67  virtual auto
68  ConnectStorageSignal(StorageSignal::slot_type const& slot) -> boost::signals2::connection = 0;
69 };
70 
71 /**
72  * Connection parameters for DPM
73  */
75  std::string rr_uri;
76  std::string ps_uri;
77  std::chrono::seconds timeout = std::chrono::seconds(5);
78 };
79 
80 class DpmClientImpl : public DpmClient {
81 public:
84 
85  DpmClientImpl(boost::asio::io_context& io_ctx,
86  mal::Mal& mal,
87  DpmClientParams params);
88 
90  /**
91  * Schedule merging.
92  */
93  virtual auto ScheduleAsync(std::string const& spec) -> boost::future<State> override;
94 
95  /**
96  * Abort merging.
97  */
98  virtual auto
99  AbortAsync(std::string const& id) -> boost::future<State> override;
100 
101  /**
102  * Connect slot to status change signal.
103  *
104  * DpmClient ensures that signals are only emitted from main thread.
105  */
106  virtual auto ConnectStatusSignal(StatusSignal::slot_type const& slot)
107  -> boost::signals2::connection override;
108 
109  /**
110  * Connect slot to storage change signal.
111  *
112  * DpmClient ensures that signals are only emitted from main thread.
113  */
114  virtual auto ConnectStorageSignal(StorageSignal::slot_type const& slot)
115  -> boost::signals2::connection override;
116 private:
117  struct Subscriptions;
118 
119  boost::asio::io_context& m_io_ctx;
120  rad::IoExecutor m_executor;
121 
122  mal::Mal& m_mal;
123  DpmClientParams m_params;
124 
125  StatusSignal m_status_signal;
126  StorageSignal m_storage_signal;
127 
128  std::shared_ptr<daqif::DpmDaqControlAsync> m_dpmif;
129  std::unique_ptr<Subscriptions> m_subs;
130 };
131 
132 } // namespace daq
133 #endif
daq::DpmClient::ScheduleAsync
virtual auto ScheduleAsync(std::string const &spec) -> boost::future< State >=0
Schedule merging.
daq::DpmClient::StatusSignal
boost::signals2::signal< void(Status)> StatusSignal
Definition: dpmClient.hpp:41
ioExecutor.hpp
daq::DpmClientImpl::AbortAsync
virtual auto AbortAsync(std::string const &id) -> boost::future< State > override
Abort merging.
Definition: dpmClient.cpp:97
daq::DpmClientImpl::ConnectStatusSignal
virtual auto ConnectStatusSignal(StatusSignal::slot_type const &slot) -> boost::signals2::connection override
Connect slot to status change signal.
Definition: dpmClient.cpp:106
rad::IoExecutor
Adapts boost::asio::io_context into a compatible boost::thread Executor type.
Definition: ioExecutor.hpp:12
daq::DpmClient
Interface to DPM server.
Definition: dpmClient.hpp:38
daq
Definition: asyncProcess.cpp:15
daq::DpmClient::ConnectStatusSignal
virtual auto ConnectStatusSignal(StatusSignal::slot_type const &slot) -> boost::signals2::connection=0
Connect slot to status change signal.
daq::DpmClientParams::timeout
std::chrono::seconds timeout
Definition: dpmClient.hpp:77
daq::DpmClientImpl::~DpmClientImpl
~DpmClientImpl()
daqif
Definition: parsing.hpp:14
config.hpp
Config class header file.
daq::DpmClientImpl::Subscriptions
Definition: dpmClient.cpp:21
daq::DpmClientParams::ps_uri
std::string ps_uri
Definition: dpmClient.hpp:76
status.hpp
Contains declaration for Status and ObservableStatus.
daq::DpmClientImpl
Definition: dpmClient.hpp:80
daq::DpmClient::StorageSignal
boost::signals2::signal< void(std::filesystem::space_info)> StorageSignal
Definition: dpmClient.hpp:40
daq::DpmClient::ConnectStorageSignal
virtual auto ConnectStorageSignal(StorageSignal::slot_type const &slot) -> boost::signals2::connection=0
Connect slot to storage change signal.
daq::Status
Non observable status object that keeps stores status of data acquisition.
Definition: status.hpp:120
daq::DpmClient::AbortAsync
virtual auto AbortAsync(std::string const &id) -> boost::future< State >=0
Abort merging.
daq::DpmClientImpl::ConnectStorageSignal
virtual auto ConnectStorageSignal(StorageSignal::slot_type const &slot) -> boost::signals2::connection override
Connect slot to storage change signal.
Definition: dpmClient.cpp:111
daq::DpmClientParams
Connection parameters for DPM.
Definition: dpmClient.hpp:74
elt::mal
Definition: dpmClient.hpp:25
daq::DpmClientImpl::ScheduleAsync
virtual auto ScheduleAsync(std::string const &spec) -> boost::future< State > override
Schedule merging.
Definition: dpmClient.cpp:88
daq::DpmClientParams::rr_uri
std::string rr_uri
Definition: dpmClient.hpp:75
daq::DpmClientImpl::DpmClientImpl
DpmClientImpl(boost::asio::io_context &io_ctx, mal::Mal &mal, DpmClientParams params)
Definition: dpmClient.cpp:27