apt: apt-pkg/contrib/progress.h Source File

apt 3.1.16 commandline package manager

progress.h
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
5 OpProgress - Operation Progress
6
7 This class allows lengthy operations to communicate their progress
8 to the GUI. The progress model is simple and is not designed to handle
9 the complex case of the multi-activity acquire class.
10
11 The model is based on the concept of an overall operation consisting
12 of a series of small sub operations. Each sub operation has it's own
13 completion status and the overall operation has it's completion status.
14 The units of the two are not mixed and are completely independent.
15
16 The UI is expected to subclass this to provide the visuals to the user.
17
18 ##################################################################### */
19 /*}}}*/
20#ifndef PKGLIB_PROGRESS_H
21#define PKGLIB_PROGRESS_H
22
23#include <apt-pkg/macros.h>
24#include <string>
25#include <sys/time.h>
26
27
28class Configuration;
29 class APT_PUBLIC OpProgress
30{
31 friend class OpTextProgress;
32 unsigned long long Current;
33 unsigned long long Total;
34 unsigned long long Size;
35 unsigned long long SubTotal;
36 float LastPercent;
37
38 // Change reduction code
39 struct timeval LastTime;
40 std::string LastOp;
41 std::string LastSubOp;
42
43 protected:
44
45 std::string Op;
46 std::string SubOp;
47 float Percent;
48
49 bool MajorChange;
50
51 bool CheckChange(float Interval = 0.7);
52 virtual void Update() {};
53
54 public:
55
56 void Progress(unsigned long long Current);
57 void SubProgress(unsigned long long SubTotal, const std::string &Op = "", float const Percent = -1);
58 void OverallProgress(unsigned long long Current,unsigned long long Total,
59 unsigned long long Size,const std::string &Op);
60 virtual void Done() {};
61
62 OpProgress();
63 virtual ~OpProgress() {};
64};
65
66 class APT_PUBLIC OpTextProgress : public OpProgress
67{
68 protected:
69
70 std::string OldOp;
71 bool NoUpdate;
72 bool NoDisplay;
73 unsigned long LastLen;
74 void Update() override;
75 void Write(const char *S);
76
77 public:
78
79 void Done() override;
80
81 explicit OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate),
82 NoDisplay(false), LastLen(0) {};
83 explicit OpTextProgress(Configuration &Config);
84 virtual ~OpTextProgress() {Done();};
85};
86
87#endif
Configuration
Definition configuration.h:41
OpTextProgress::Done
void Done() override
Definition progress.cc:152