libzypp  17.36.3
OptionalDownloadProgressReport.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
11 
12 namespace internal {
13 
14  using namespace zypp;
15 
18  , _isOptional { isOptional }
19  { connect(); }
20 
22  if (_oldRec)
24  else
26  }
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
64  _lastProgressSent = now;
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 
81  { return _isOptional; }
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 }
virtual bool progress(int, const Url &, double dbps_avg=-1, double dbps_current=-1)
Download progress.
virtual Action problem(const Url &, Error, const std::string &)
void setReceiver(Receiver &rec_r)
Definition: Callback.h:213
std::chrono::steady_clock::time_point TimePoint
virtual void finish(const Url &, Error, const std::string &)
bool progress(int value_r, const zypp::Url &file_r, double dbps_avg_r=-1, double dbps_current_r=-1) override
Download progress.
virtual void report(const UserData &userData_r=UserData())
The most generic way of sending/receiving data.
Definition: Callback.h:155
virtual void start(const Url &, Pathname)
static DistributeReport & instance()
Definition: Callback.h:204
Action problem(const zypp::Url &file_r, Error error_r, const std::string &description_r) override
virtual void reportend()
Definition: Callback.h:191
Receiver * _oldRec
Receiver * getReceiver() const
Definition: Callback.h:210
Typesafe passing of user data via callbacks.
Definition: UserData.h:39
void start(const zypp::Url &file_r, zypp::Pathname localfile_r) override
void report(const UserData &userData_r=UserData()) override
The most generic way of sending/receiving data.
virtual void reportbegin()
Definition: Callback.h:189
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
void finish(const zypp::Url &file_r, Error error_r, const std::string &reason_r) override
Url manipulation class.
Definition: Url.h:92