ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
rsyncAsyncProcess.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup daq_common_libdaq
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::RsyncAsyncProcess and related class declarations.
9 */
10#ifndef DAQ_PROCESS_RSYNC_ASYNC_PROCESS_HPP
11#define DAQ_PROCESS_RSYNC_ASYNC_PROCESS_HPP
12#include <daq/config.hpp>
13
14#include <chrono>
15#include <optional>
16#include <string>
17#include <filesystem>
18
19#include <boost/signals2/signal.hpp>
20
22
23namespace daq {
24
25/**
26 * Options controlling rsync invocation.
27 */
29 /**
30 * Binary to use.
31 */
32 std::optional<std::string> rsync;
33 /**
34 * Enables rate-limiting in kb/s.
35 */
36 std::optional<unsigned> bw_limit;
37 /**
38 * Transfer with/without delta xfer algorithm.
39 */
40 std::optional<bool> whole_file;
41
42 /**
43 * --inplace/--no-inplace
44 */
45 std::optional<bool> inplace;
46 /**
47 * I/O timeout
48 */
49 std::optional<std::chrono::seconds> timeout;
50 /**
51 * Log file
52 */
53 std::optional<std::filesystem::path> logfile;
54};
55
56/**
57 * Describes file transfer progress,
58 */
60 /**
61 * Number of transferred bytes.
62 */
63 uint64_t transferred;
64 /**
65 * Progress as fraction of 1 (complete == 1.0)
66 */
67 float progress;
68 /**
69 * Transfer speed in bytes/sec.
70 */
71 float speed;
72 /**
73 * Estimated remaining time.
74 */
75 std::chrono::seconds remaining;
76};
77
78/**
79 * More specialized version for `rsync` which also monitors transfer progress.
80 */
81class RsyncAsyncProcessIf : public virtual AsyncProcessIf {
82public:
83 enum class DryRun { Disabled = 0, Enabled };
85 }
86
87 /**
88 * Progress update signal.
89 */
90 using SigProgress = boost::signals2::signal<void(pid_t, RsyncProgress const&)>;
91
92 /**
93 * Connect to progress signal.
94 */
95 virtual boost::signals2::connection ConnectProgress(SigProgress::slot_type const& slot) = 0;
96};
97
98/**
99 * Parse progress update from rsync.
100 *
101 * @param line a single line in the format rsync outputs with option `--info=progress2`.
102 * @returns optional with value if parsing suceeds, empty optional otherwise.
103 */
104std::optional<RsyncProgress> ParseRsyncProgress(std::string const& line) noexcept;
105
106/**
107 * Represents an rsync process as an asynchronous operation.
108 *
109 * Once constructed the operation is initiated (only once) with `Initiate()` which starts the
110 * process and returns a boost::future object that will receive exit code when process terminates
111 * *and* all output has been read.
112 *
113 * @note No signals will be emitted after future has received the value or exception.
114 *
115 * Operation can be aborted with `Abort()` which will terminate process and set future with
116 * exceptional result.
117 *
118 * @ingroup daq_common_libdaq
119 */
120class RsyncAsyncProcess : public virtual RsyncAsyncProcessIf, public AsyncProcess {
121public:
122 virtual ~RsyncAsyncProcess();
123
124 /**
125 * Construct async operation.
126 *
127 * @note Does not start the process or any other asynchronous operations. This is done in
128 * AsyncProcess::Initiate().
129 *
130 * @param ctx io_context instance to use.
131 * @param source rsync file source.
132 * @param dest rsync file dest.
133 * @param opts rsync options.
134 * @param flag Control whether rsync should do a dry-run (useful to test if connection is
135 * possible).
136 */
137 RsyncAsyncProcess(boost::asio::io_context& ctx,
138 std::string source,
139 std::string dest,
140 RsyncOptions const& opts = {},
141 DryRun flag = DryRun::Disabled);
142
143 /**
144 * @name Signals
145 */
146 /// @{
147 /**
148 * Progress update signal.
149 */
151
152 [[nodiscard]] boost::future<int> Initiate() override;
153
154 /**
155 * Connect to progress signal.
156 */
157 boost::signals2::connection ConnectProgress(SigProgress::slot_type const& slot) override;
158 /// @}
159private:
160 SigProgress m_progress;
161};
162
163} // namespace daq
164
165#endif // #ifndef DAQ_PROCESS_RSYNC_ASYNC_PROCESS_HPP
daq::AsyncProcess class definition
Interface to asynchronous process.
Represents a subprocess as an asynchronous operation.
More specialized version for rsync which also monitors transfer progress.
virtual boost::signals2::connection ConnectProgress(SigProgress::slot_type const &slot)=0
Connect to progress signal.
boost::signals2::signal< void(pid_t, RsyncProgress const &)> SigProgress
Progress update signal.
Represents an rsync process as an asynchronous operation.
boost::future< int > Initiate() override
Progress update signal.
RsyncAsyncProcessIf::SigProgress SigProgress
Progress update signal.
boost::signals2::connection ConnectProgress(SigProgress::slot_type const &slot) override
Connect to progress signal.
std::optional< std::string > rsync
Binary to use.
std::optional< std::chrono::seconds > timeout
I/O timeout.
std::optional< bool > inplace
–inplace/–no-inplace
std::optional< bool > whole_file
Transfer with/without delta xfer algorithm.
std::chrono::seconds remaining
Estimated remaining time.
std::optional< RsyncProgress > ParseRsyncProgress(std::string const &line) noexcept
Parse progress update from rsync.
float progress
Progress as fraction of 1 (complete == 1.0)
uint64_t transferred
Number of transferred bytes.
float speed
Transfer speed in bytes/sec.
std::optional< std::filesystem::path > logfile
Log file.
std::optional< unsigned > bw_limit
Enables rate-limiting in kb/s.
Options controlling rsync invocation.
Describes file transfer progress,.