]> git.saurik.com Git - apt.git/blame - apt-pkg/install-progress.h
test/integration/test-ubuntu-bug-346386-apt-get-update-paywall: use downloadfile()
[apt.git] / apt-pkg / install-progress.h
CommitLineData
31f97d7b 1#ifndef PKGLIB_IPROGRESS_H
e6ad8031 2#define PKGLIB_IPROGRESS_H
31f97d7b 3
76bd63e2
DK
4#include <apt-pkg/macros.h>
5
e6ad8031
MV
6#include <string>
7#include <unistd.h>
e96e4e9c 8#include <signal.h>
23bd0977 9#include <vector>
31f97d7b
MV
10
11namespace APT {
12namespace Progress {
13
bd5f39b3
MV
14 class PackageManager;
15 PackageManager* PackageManagerProgressFactory();
16
31f97d7b
MV
17 class PackageManager
18 {
19 private:
20 /** \brief dpointer placeholder */
21 void *d;
22
6c5ae8ed
MV
23 protected:
24 std::string progress_str;
25 float percentage;
26 int last_reported_progress;
27
31f97d7b 28 public:
d3e8fbb3 29 PackageManager()
65dbd5a1 30 : percentage(0.0), last_reported_progress(-1) {};
31f97d7b
MV
31 virtual ~PackageManager() {};
32
e45c4617 33 /* Global Start/Stop */
65512241 34 virtual void Start(int /*child_pty*/=-1) {};
a22fdebf 35 virtual void Stop() {};
e6ad8031 36
d3e8fbb3
DK
37 /* When dpkg is invoked (may happen multiple times for each
38 * install/remove block
e45c4617
MV
39 */
40 virtual void StartDpkg() {};
41
e6ad8031 42 virtual pid_t fork() {return fork(); };
ca5b2578
MV
43
44 virtual void Pulse() {};
45 virtual long GetPulseInterval() {
46 return 500000;
47 };
48
d3e8fbb3 49 virtual bool StatusChanged(std::string PackageName,
31f97d7b 50 unsigned int StepsDone,
e6ad8031 51 unsigned int TotalSteps,
d3e8fbb3 52 std::string HumanReadableAction);
65512241
DK
53 virtual void Error(std::string /*PackageName*/,
54 unsigned int /*StepsDone*/,
55 unsigned int /*TotalSteps*/,
56 std::string /*ErrorMessage*/) {}
57 virtual void ConffilePrompt(std::string /*PackageName*/,
58 unsigned int /*StepsDone*/,
59 unsigned int /*TotalSteps*/,
60 std::string /*ConfMessage*/) {}
e6ad8031
MV
61 };
62
63 class PackageManagerProgressFd : public PackageManager
64 {
65 protected:
66 int OutStatusFd;
67 int StepsDone;
68 int StepsTotal;
f9935b1c 69 void WriteToStatusFd(std::string msg);
e6ad8031
MV
70
71 public:
72 PackageManagerProgressFd(int progress_fd);
f9935b1c 73
e45c4617 74 virtual void StartDpkg();
a22fdebf 75 virtual void Stop();
e6ad8031 76
d3e8fbb3 77 virtual bool StatusChanged(std::string PackageName,
e6ad8031
MV
78 unsigned int StepsDone,
79 unsigned int TotalSteps,
80 std::string HumanReadableAction);
d3e8fbb3 81 virtual void Error(std::string PackageName,
e6ad8031
MV
82 unsigned int StepsDone,
83 unsigned int TotalSteps,
84 std::string ErrorMessage);
85 virtual void ConffilePrompt(std::string PackageName,
86 unsigned int StepsDone,
87 unsigned int TotalSteps,
88 std::string ConfMessage);
89
31f97d7b
MV
90 };
91
c7ea1eba
MV
92 class PackageManagerProgressDeb822Fd : public PackageManager
93 {
94 protected:
95 int OutStatusFd;
96 int StepsDone;
97 int StepsTotal;
98 void WriteToStatusFd(std::string msg);
99
100 public:
101 PackageManagerProgressDeb822Fd(int progress_fd);
102
790d41f6 103 virtual void StartDpkg();
c7ea1eba
MV
104 virtual void Stop();
105
d3e8fbb3 106 virtual bool StatusChanged(std::string PackageName,
c7ea1eba
MV
107 unsigned int StepsDone,
108 unsigned int TotalSteps,
109 std::string HumanReadableAction);
d3e8fbb3 110 virtual void Error(std::string PackageName,
c7ea1eba
MV
111 unsigned int StepsDone,
112 unsigned int TotalSteps,
113 std::string ErrorMessage);
114 virtual void ConffilePrompt(std::string PackageName,
115 unsigned int StepsDone,
116 unsigned int TotalSteps,
117 std::string ConfMessage);
118 };
119
31f97d7b
MV
120 class PackageManagerFancy : public PackageManager
121 {
5ed88785
MV
122 private:
123 static void staticSIGWINCH(int);
124 static std::vector<PackageManagerFancy*> instances;
76bd63e2 125 APT_HIDDEN bool DrawStatusLine();
5ed88785 126
31f97d7b 127 protected:
5ed88785
MV
128 void SetupTerminalScrollArea(int nr_rows);
129 void HandleSIGWINCH(int);
130
fa211e2d
MV
131 typedef struct {
132 int rows;
133 int columns;
134 } TermSize;
135 TermSize GetTerminalSize();
136
e96e4e9c 137 sighandler_t old_SIGWINCH;
5ed88785 138 int child_pty;
db78c60c 139
31f97d7b
MV
140 public:
141 PackageManagerFancy();
e96e4e9c 142 ~PackageManagerFancy();
4754718a 143 virtual void Start(int child_pty=-1);
a22fdebf 144 virtual void Stop();
d3e8fbb3 145 virtual bool StatusChanged(std::string PackageName,
31f97d7b 146 unsigned int StepsDone,
e6ad8031
MV
147 unsigned int TotalSteps,
148 std::string HumanReadableAction);
fa211e2d
MV
149
150 // return a progress bar of the given size for the given progress
151 // percent between 0.0 and 1.0 in the form "[####...]"
152 static std::string GetTextProgressStr(float percent, int OutputSize);
31f97d7b
MV
153 };
154
155 class PackageManagerText : public PackageManager
156 {
31f97d7b 157 public:
d3e8fbb3 158 virtual bool StatusChanged(std::string PackageName,
31f97d7b 159 unsigned int StepsDone,
e6ad8031
MV
160 unsigned int TotalSteps,
161 std::string HumanReadableAction);
31f97d7b
MV
162 };
163
164
d3e8fbb3
DK
165} // namespace Progress
166} // namespace APT
31f97d7b
MV
167
168#endif