libzypp: zypp/ng/progressobserveradaptor.cc Source File

libzypp 17.38.9

progressobserveradaptor.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#include "progressobserveradaptor.h"
11
12namespace zyppng {
13
14 void ProgressObserverAdaptor::init()
15 {
16 _observer = ProgressObserver::create();
17 _observer->connectFunc(
18 &ProgressObserver::sigStarted,
19 [this](auto &obs) { update(); }, *_observer);
20 _observer->connectFunc(
21 &ProgressObserver::sigLabelChanged,
22 [this](auto &obs, const auto &) { if(!_first) update(); }, *_observer);
23 _observer->connectFunc(
24 &ProgressObserver::sigProgressChanged,
25 [this](auto &obs, const auto &p) { update(); }, *_observer);
26 _observer->connectFunc(
27 &ProgressObserver::sigFinished,
28 [this](auto &obs, const auto &) { update(true); }, *_observer);
29 }
30
31 ProgressObserverAdaptor::ProgressObserverAdaptor(
32 zypp::callback::SendReport<zypp::ProgressReport> &report)
33 : _report(report)
34 {
35 init();
36 }
37 ProgressObserverAdaptor::ProgressObserverAdaptor(
38 const zypp::ProgressData::ReceiverFnc &fnc,
39 zypp::callback::SendReport<zypp::ProgressReport> &report)
40 : _fnc(fnc), _report(report)
41 {
42 init();
43 }
44 ProgressObserverRef ProgressObserverAdaptor::observer() { return _observer; }
45 bool ProgressObserverAdaptor::update(bool fin) {
46 zypp::ProgressData progress(0, 100, _observer->progress());
47 progress.name(_observer->label());
48
49 if (_first) {
50 _report->start(progress);
51 _first = false;
52 }
53
54 bool value = _report->progress(progress);
55 if (_fnc)
56 value &= _fnc(progress);
57
58 if (fin) {
59 _report->finish(progress);
60 }
61 return value;
62 }
63} // namespace zyppng
zypp::ProgressData
Maintain [min,max] and counter (value) for progress counting.
Definition progressdata.h:132
zypp::ProgressData::name
void name(const std::string &name_r)
Set counter name.
Definition progressdata.h:225
zypp::ProgressData::ReceiverFnc
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition progressdata.h:140
zyppng::ProgressObserver::sigStarted
SignalProxy< void(ProgressObserver &sender)> sigStarted()
Definition progressobserver.cc:206
zyppng::ProgressObserver::sigFinished
SignalProxy< void(ProgressObserver &sender, FinishResult result)> sigFinished()
Definition progressobserver.cc:231
zyppng::ProgressObserver::sigProgressChanged
SignalProxy< void(ProgressObserver &sender, double progress)> sigProgressChanged()
Definition progressobserver.cc:226
zyppng::ProgressObserver::sigLabelChanged
SignalProxy< void(ProgressObserver &sender, const std::string &str)> sigLabelChanged()
Definition progressobserver.cc:211
zyppng
Definition MediaNetworkRequestExecutor.h:16
progressobserveradaptor.h
zypp::callback::SendReport
Definition Callback.h:237
zyppng::ProgressObserverAdaptor::_report
zypp::callback::SendReport< zypp::ProgressReport > & _report
Definition progressobserveradaptor.h:31
zyppng::ProgressObserverAdaptor::_fnc
zypp::ProgressData::ReceiverFnc _fnc
Definition progressobserveradaptor.h:30
zyppng::ProgressObserverAdaptor::_first
bool _first
Definition progressobserveradaptor.h:32
zyppng::ProgressObserverAdaptor::update
bool update(bool fin=false)
Definition progressobserveradaptor.cc:45
zyppng::ProgressObserverAdaptor::_observer
ProgressObserverRef _observer
Definition progressobserveradaptor.h:29
zyppng::ProgressObserverAdaptor::ProgressObserverAdaptor
ProgressObserverAdaptor(zypp::callback::SendReport< zypp::ProgressReport > &report)
Definition progressobserveradaptor.cc:31
zyppng::ProgressObserverAdaptor::observer
ProgressObserverRef observer()
Definition progressobserveradaptor.cc:44
zyppng::ProgressObserverAdaptor::init
void init()
Definition progressobserveradaptor.cc:14