]> git.saurik.com Git - apt.git/blame - apt-pkg/install-progress.h
Consider md5sum no longer a usable hash
[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 */
6c55f07a 21 void * const d;
31f97d7b 22
6c5ae8ed
MV
23 protected:
24 std::string progress_str;
25 float percentage;
26 int last_reported_progress;
27
31f97d7b 28 public:
25613a61
DK
29 PackageManager();
30 virtual ~PackageManager();
31f97d7b 31
e45c4617 32 /* Global Start/Stop */
65512241 33 virtual void Start(int /*child_pty*/=-1) {};
a22fdebf 34 virtual void Stop() {};
e6ad8031 35
d3e8fbb3
DK
36 /* When dpkg is invoked (may happen multiple times for each
37 * install/remove block
e45c4617
MV
38 */
39 virtual void StartDpkg() {};
40
e6ad8031 41 virtual pid_t fork() {return fork(); };
ca5b2578
MV
42
43 virtual void Pulse() {};
44 virtual long GetPulseInterval() {
45 return 500000;
46 };
47
d3e8fbb3 48 virtual bool StatusChanged(std::string PackageName,
31f97d7b 49 unsigned int StepsDone,
e6ad8031 50 unsigned int TotalSteps,
d3e8fbb3 51 std::string HumanReadableAction);
65512241
DK
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*/) {}
e6ad8031
MV
60 };
61
62 class PackageManagerProgressFd : public PackageManager
63 {
6c55f07a 64 void * const d;
e6ad8031
MV
65 protected:
66 int OutStatusFd;
67 int StepsDone;
68 int StepsTotal;
f9935b1c 69 void WriteToStatusFd(std::string msg);
e6ad8031
MV
70
71 public:
e8afd168 72 explicit PackageManagerProgressFd(int progress_fd);
c8a4ce6c 73 virtual ~PackageManagerProgressFd();
f9935b1c 74
3b302846
DK
75 virtual void StartDpkg() APT_OVERRIDE;
76 virtual void Stop() APT_OVERRIDE;
e6ad8031 77
d3e8fbb3 78 virtual bool StatusChanged(std::string PackageName,
e6ad8031
MV
79 unsigned int StepsDone,
80 unsigned int TotalSteps,
3b302846 81 std::string HumanReadableAction) APT_OVERRIDE;
d3e8fbb3 82 virtual void Error(std::string PackageName,
e6ad8031
MV
83 unsigned int StepsDone,
84 unsigned int TotalSteps,
3b302846 85 std::string ErrorMessage) APT_OVERRIDE;
e6ad8031
MV
86 virtual void ConffilePrompt(std::string PackageName,
87 unsigned int StepsDone,
88 unsigned int TotalSteps,
3b302846 89 std::string ConfMessage) APT_OVERRIDE;
e6ad8031 90
31f97d7b
MV
91 };
92
c7ea1eba
MV
93 class PackageManagerProgressDeb822Fd : public PackageManager
94 {
6c55f07a 95 void * const d;
c7ea1eba
MV
96 protected:
97 int OutStatusFd;
98 int StepsDone;
99 int StepsTotal;
100 void WriteToStatusFd(std::string msg);
101
102 public:
e8afd168 103 explicit PackageManagerProgressDeb822Fd(int progress_fd);
c8a4ce6c 104 virtual ~PackageManagerProgressDeb822Fd();
c7ea1eba 105
3b302846
DK
106 virtual void StartDpkg() APT_OVERRIDE;
107 virtual void Stop() APT_OVERRIDE;
c7ea1eba 108
d3e8fbb3 109 virtual bool StatusChanged(std::string PackageName,
c7ea1eba
MV
110 unsigned int StepsDone,
111 unsigned int TotalSteps,
3b302846 112 std::string HumanReadableAction) APT_OVERRIDE;
d3e8fbb3 113 virtual void Error(std::string PackageName,
c7ea1eba
MV
114 unsigned int StepsDone,
115 unsigned int TotalSteps,
3b302846 116 std::string ErrorMessage) APT_OVERRIDE;
c7ea1eba
MV
117 virtual void ConffilePrompt(std::string PackageName,
118 unsigned int StepsDone,
119 unsigned int TotalSteps,
3b302846 120 std::string ConfMessage) APT_OVERRIDE;
c7ea1eba
MV
121 };
122
31f97d7b
MV
123 class PackageManagerFancy : public PackageManager
124 {
6c55f07a 125 void * const d;
5ed88785 126 private:
3809194b 127 APT_HIDDEN static void staticSIGWINCH(int);
5ed88785 128 static std::vector<PackageManagerFancy*> instances;
76bd63e2 129 APT_HIDDEN bool DrawStatusLine();
5ed88785 130
31f97d7b 131 protected:
5ed88785
MV
132 void SetupTerminalScrollArea(int nr_rows);
133 void HandleSIGWINCH(int);
134
fa211e2d
MV
135 typedef struct {
136 int rows;
137 int columns;
138 } TermSize;
139 TermSize GetTerminalSize();
140
e96e4e9c 141 sighandler_t old_SIGWINCH;
5ed88785 142 int child_pty;
db78c60c 143
31f97d7b
MV
144 public:
145 PackageManagerFancy();
c8a4ce6c 146 virtual ~PackageManagerFancy();
3b302846
DK
147 virtual void Start(int child_pty=-1) APT_OVERRIDE;
148 virtual void Stop() APT_OVERRIDE;
d3e8fbb3 149 virtual bool StatusChanged(std::string PackageName,
31f97d7b 150 unsigned int StepsDone,
e6ad8031 151 unsigned int TotalSteps,
3b302846 152 std::string HumanReadableAction) APT_OVERRIDE;
fa211e2d
MV
153
154 // return a progress bar of the given size for the given progress
155 // percent between 0.0 and 1.0 in the form "[####...]"
156 static std::string GetTextProgressStr(float percent, int OutputSize);
31f97d7b
MV
157 };
158
159 class PackageManagerText : public PackageManager
160 {
6c55f07a 161 void * const d;
31f97d7b 162 public:
d3e8fbb3 163 virtual bool StatusChanged(std::string PackageName,
31f97d7b 164 unsigned int StepsDone,
e6ad8031 165 unsigned int TotalSteps,
3b302846 166 std::string HumanReadableAction) APT_OVERRIDE;
c8a4ce6c
DK
167
168 PackageManagerText();
169 virtual ~PackageManagerText();
31f97d7b
MV
170 };
171
172
d3e8fbb3
DK
173} // namespace Progress
174} // namespace APT
31f97d7b
MV
175
176#endif