libzypp 17.37.17
OptionalDownloadProgressReport.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
11
12namespace internal {
13
14 using namespace zypp;
15
17 : _oldRec { Distributor::instance().getReceiver() }
18 , _isOptional { isOptional }
19 { connect(); }
20
27
29 { if ( _oldRec ) _oldRec->reportbegin(); }
30
32 { if ( _oldRec ) _oldRec->reportend(); }
33
35 { if ( _oldRec ) _oldRec->report( userData_r ); }
36
37 void OptionalDownloadProgressReport::start(const Url &file_r, Pathname localfile_r)
38 {
39 if ( not _oldRec ) return;
40 if ( _isOptional ) {
41 // delay start until first data are received.
42 _startFile = file_r;
43 _startLocalfile = std::move(localfile_r);
44 return;
45 }
46 _oldRec->start( file_r, localfile_r );
47 }
48
49 bool OptionalDownloadProgressReport::progress(int value_r, const Url &file_r, double dbps_avg_r, double dbps_current_r)
50 {
51 if ( not _oldRec ) return true;
52 if ( notStarted() ) {
53 if ( not ( value_r || dbps_avg_r || dbps_current_r ) )
54 return true;
55 sendStart();
56 }
57
58 //static constexpr std::chrono::milliseconds minfequency { 1000 }; only needed if we'd avoid sending reports without change
59 static constexpr std::chrono::milliseconds maxfequency { 100 };
60 TimePoint now { TimePoint::clock::now() };
61 TimePoint::duration elapsed { now - _lastProgressSent };
62 if ( elapsed < maxfequency )
63 return true; // continue
65 return _oldRec->progress( value_r, file_r, dbps_avg_r, dbps_current_r );
66 }
67
68 media::DownloadProgressReport::Action OptionalDownloadProgressReport::problem(const Url &file_r, Error error_r, const std::string &description_r)
69 {
70 if ( not _oldRec || notStarted() ) return ABORT;
71 return _oldRec->problem( file_r, error_r, description_r );
72 }
73
74 void OptionalDownloadProgressReport::finish(const Url &file_r, Error error_r, const std::string &reason_r)
75 {
76 if ( not _oldRec || notStarted() ) return;
77 _oldRec->finish( file_r, error_r, reason_r );
78 }
79
82
84 {
85 if ( _isOptional ) {
86 // we know _oldRec is valid...
87 _oldRec->start( _startFile, std::move(_startLocalfile) );
88 _isOptional = false;
89 }
90 }
91
92}
Url manipulation class.
Definition Url.h:93
Easy-to use interface to the ZYPP dependency resolver.
void report(const UserData &userData_r=UserData()) override
The most generic way of sending/receiving data.
void start(const zypp::Url &file_r, zypp::Pathname localfile_r) override
void finish(const zypp::Url &file_r, Error error_r, const std::string &reason_r) override
Action problem(const zypp::Url &file_r, Error error_r, const std::string &description_r) override
std::chrono::steady_clock::time_point TimePoint
bool progress(int value_r, const zypp::Url &file_r, double dbps_avg_r=-1, double dbps_current_r=-1) override
Download progress.
static DistributeReport & instance()
Definition Callback.h:204
void setReceiver(Receiver &rec_r)
Definition Callback.h:213
DistributeReport< zypp::media::DownloadProgressReport > Distributor
Definition Callback.h:172
callback::UserData UserData
Definition Callback.h:151