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

apt 3.3.2 commandline package manager

install-progress.h
1#ifndef PKGLIB_IPROGRESS_H
2#define PKGLIB_IPROGRESS_H
3
4#include <apt-pkg/macros.h>
5
6#include <csignal>
7#include <string>
8#include <vector>
9#include <unistd.h>
10
11namespace APT {
12namespace Progress {
13
14 class PackageManager;
15 APT_PUBLIC PackageManager* PackageManagerProgressFactory();
16
17 class APT_PUBLIC PackageManager
18 {
19 private:
21 void * const d;
22
23 protected:
24 std::string progress_str;
25 float percentage;
26 int last_reported_progress;
27
28 public:
29 PackageManager();
30 virtual ~PackageManager();
31
32 /* Global Start/Stop */
33 virtual void Start(int /*child_pty*/=-1) {};
34 virtual void Stop() {};
35
36 /* When dpkg is invoked (may happen multiple times for each
37 * install/remove block
38 */
39 virtual void StartDpkg() {};
40
41 virtual pid_t fork() {return ::fork(); };
42
43 virtual void Pulse() {};
44 virtual long GetPulseInterval() {
45 return 50000000;
46 };
47
48 virtual bool StatusChanged(std::string PackageName,
49 unsigned int StepsDone,
50 unsigned int TotalSteps,
51 std::string HumanReadableAction);
52 virtual void Error(std::string /*PackageName*/,
53 unsigned int /*StepsDone*/,
54 unsigned int /*TotalSteps*/,
55 std::string /*ErrorMessage*/) {}
56 virtual void ConffilePrompt(std::string /*PackageName*/,
57 unsigned int /*StepsDone*/,
58 unsigned int /*TotalSteps*/,
59 std::string /*ConfMessage*/) {}
60 };
61
62 class APT_PUBLIC PackageManagerProgressFd : public PackageManager
63 {
64 void * const d;
65 protected:
66 int OutStatusFd;
67 int StepsDone;
68 int StepsTotal;
69 void WriteToStatusFd(std::string msg);
70
71 public:
72 explicit PackageManagerProgressFd(int progress_fd);
73 ~PackageManagerProgressFd() override;
74
75 void StartDpkg() override;
76 void Stop() override;
77
78 bool StatusChanged(std::string PackageName,
79 unsigned int StepsDone,
80 unsigned int TotalSteps,
81 std::string HumanReadableAction) override;
82 void Error(std::string PackageName,
83 unsigned int StepsDone,
84 unsigned int TotalSteps,
85 std::string ErrorMessage) override;
86 void ConffilePrompt(std::string PackageName,
87 unsigned int StepsDone,
88 unsigned int TotalSteps,
89 std::string ConfMessage) override;
90 };
91
92 class APT_PUBLIC PackageManagerProgressDeb822Fd : public PackageManager
93 {
94 void * const d;
95 protected:
96 int OutStatusFd;
97 int StepsDone;
98 int StepsTotal;
99 void WriteToStatusFd(std::string msg);
100
101 public:
102 explicit PackageManagerProgressDeb822Fd(int progress_fd);
103 ~PackageManagerProgressDeb822Fd() override;
104
105 void StartDpkg() override;
106 void Stop() override;
107
108 bool StatusChanged(std::string PackageName,
109 unsigned int StepsDone,
110 unsigned int TotalSteps,
111 std::string HumanReadableAction) override;
112 void Error(std::string PackageName,
113 unsigned int StepsDone,
114 unsigned int TotalSteps,
115 std::string ErrorMessage) override;
116 void ConffilePrompt(std::string PackageName,
117 unsigned int StepsDone,
118 unsigned int TotalSteps,
119 std::string ConfMessage) override;
120 };
121
122 class APT_PUBLIC PackageManagerFancy : public PackageManager
123 {
124 void * const d;
125 private:
126 APT_HIDDEN static void staticSIGWINCH(int);
127 static std::vector<PackageManagerFancy*> instances;
128 static sighandler_t SIGWINCH_orig;
129 static volatile sig_atomic_t SIGWINCH_flag;
130 APT_HIDDEN void CheckSIGWINCH();
131 APT_HIDDEN bool DrawStatusLine();
132
133 protected:
134 void SetupTerminalScrollArea(int nr_rows);
135 void HandleSIGWINCH(int); // for abi compatibility, do not use
136
137 typedef struct {
138 int rows;
139 int columns;
140 } TermSize;
141 TermSize GetTerminalSize();
142
143 sighandler_t old_SIGWINCH; // for abi compatibility, do not use
144 int child_pty;
145
146 public:
147 PackageManagerFancy();
148 ~PackageManagerFancy() override;
149 void Pulse() override;
150 void Start(int child_pty = -1) override;
151 void Stop() override;
152 bool StatusChanged(std::string PackageName,
153 unsigned int StepsDone,
154 unsigned int TotalSteps,
155 std::string HumanReadableAction) override;
156
157 // return a progress bar of the given size for the given progress
158 // percent between 0.0 and 1.0 in the form "[####...]"
159 static std::string GetTextProgressStr(float percent, int OutputSize);
160 };
161
162 class APT_PUBLIC PackageManagerText : public PackageManager
163 {
164 void * const d;
165 public:
166 bool StatusChanged(std::string PackageName,
167 unsigned int StepsDone,
168 unsigned int TotalSteps,
169 std::string HumanReadableAction) override;
170
171 PackageManagerText();
172 ~PackageManagerText() override;
173 };
174
175
176} // namespace Progress
177} // namespace APT
178
179#endif
APT::Progress::PackageManagerFancy::GetTerminalSize
TermSize GetTerminalSize()
Definition install-progress.cc:267
APT::Progress::PackageManagerProgressDeb822Fd::StartDpkg
void StartDpkg() override
Definition install-progress.cc:180
APT::Progress::PackageManagerProgressFd::StartDpkg
void StartDpkg() override
Definition install-progress.cc:94
APT::Progress::PackageManager
Definition install-progress.h:18
APT::Progress::PackageManagerFancy::TermSize
Definition install-progress.h:137