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

apt 2.3.15 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 <string>
7#include <vector>
8#include <signal.h>
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 virtual ~PackageManagerProgressFd();
74
75 virtual void StartDpkg() APT_OVERRIDE;
76 virtual void Stop() APT_OVERRIDE;
77
78 virtual bool StatusChanged(std::string PackageName,
79 unsigned int StepsDone,
80 unsigned int TotalSteps,
81 std::string HumanReadableAction) APT_OVERRIDE;
82 virtual void Error(std::string PackageName,
83 unsigned int StepsDone,
84 unsigned int TotalSteps,
85 std::string ErrorMessage) APT_OVERRIDE;
86 virtual void ConffilePrompt(std::string PackageName,
87 unsigned int StepsDone,
88 unsigned int TotalSteps,
89 std::string ConfMessage) APT_OVERRIDE;
90
91 };
92
93 class APT_PUBLIC PackageManagerProgressDeb822Fd : public PackageManager
94 {
95 void * const d;
96 protected:
97 int OutStatusFd;
98 int StepsDone;
99 int StepsTotal;
100 void WriteToStatusFd(std::string msg);
101
102 public:
103 explicit PackageManagerProgressDeb822Fd(int progress_fd);
104 virtual ~PackageManagerProgressDeb822Fd();
105
106 virtual void StartDpkg() APT_OVERRIDE;
107 virtual void Stop() APT_OVERRIDE;
108
109 virtual bool StatusChanged(std::string PackageName,
110 unsigned int StepsDone,
111 unsigned int TotalSteps,
112 std::string HumanReadableAction) APT_OVERRIDE;
113 virtual void Error(std::string PackageName,
114 unsigned int StepsDone,
115 unsigned int TotalSteps,
116 std::string ErrorMessage) APT_OVERRIDE;
117 virtual void ConffilePrompt(std::string PackageName,
118 unsigned int StepsDone,
119 unsigned int TotalSteps,
120 std::string ConfMessage) APT_OVERRIDE;
121 };
122
123 class APT_PUBLIC PackageManagerFancy : public PackageManager
124 {
125 void * const d;
126 private:
127 APT_HIDDEN static void staticSIGWINCH(int);
128 static std::vector<PackageManagerFancy*> instances;
129 static sighandler_t SIGWINCH_orig;
130 static volatile sig_atomic_t SIGWINCH_flag;
131 APT_HIDDEN void CheckSIGWINCH();
132 APT_HIDDEN bool DrawStatusLine();
133
134 protected:
135 void SetupTerminalScrollArea(int nr_rows);
136 void HandleSIGWINCH(int); // for abi compatibility, do not use
137
138 typedef struct {
139 int rows;
140 int columns;
141 } TermSize;
142 TermSize GetTerminalSize();
143
144 sighandler_t old_SIGWINCH; // for abi compatibility, do not use
145 int child_pty;
146
147 public:
148 PackageManagerFancy();
149 virtual ~PackageManagerFancy();
150 virtual void Pulse() APT_OVERRIDE;
151 virtual void Start(int child_pty=-1) APT_OVERRIDE;
152 virtual void Stop() APT_OVERRIDE;
153 virtual bool StatusChanged(std::string PackageName,
154 unsigned int StepsDone,
155 unsigned int TotalSteps,
156 std::string HumanReadableAction) APT_OVERRIDE;
157
158 // return a progress bar of the given size for the given progress
159 // percent between 0.0 and 1.0 in the form "[####...]"
160 static std::string GetTextProgressStr(float percent, int OutputSize);
161 };
162
163 class APT_PUBLIC PackageManagerText : public PackageManager
164 {
165 void * const d;
166 public:
167 virtual bool StatusChanged(std::string PackageName,
168 unsigned int StepsDone,
169 unsigned int TotalSteps,
170 std::string HumanReadableAction) APT_OVERRIDE;
171
172 PackageManagerText();
173 virtual ~PackageManagerText();
174 };
175
176
177} // namespace Progress
178} // namespace APT
179
180#endif
APT::Progress::PackageManagerFancy
Definition: install-progress.h:124
APT::Progress::PackageManagerProgressDeb822Fd
Definition: install-progress.h:94
APT::Progress::PackageManagerProgressFd
Definition: install-progress.h:63
APT::Progress::PackageManagerText
Definition: install-progress.h:164
APT::Progress::PackageManager
Definition: install-progress.h:18
APT::Progress::PackageManagerFancy::TermSize
Definition: install-progress.h:138