]> git.saurik.com Git - apt.git/blame - apt-pkg/install-progress.h
fixup foldmarkers in acquire-item.cc
[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:
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 {
64 protected:
65 int OutStatusFd;
66 int StepsDone;
67 int StepsTotal;
f9935b1c 68 void WriteToStatusFd(std::string msg);
e6ad8031
MV
69
70 public:
71 PackageManagerProgressFd(int progress_fd);
f9935b1c 72
e45c4617 73 virtual void StartDpkg();
a22fdebf 74 virtual void Stop();
e6ad8031 75
d3e8fbb3 76 virtual bool StatusChanged(std::string PackageName,
e6ad8031
MV
77 unsigned int StepsDone,
78 unsigned int TotalSteps,
79 std::string HumanReadableAction);
d3e8fbb3 80 virtual void Error(std::string PackageName,
e6ad8031
MV
81 unsigned int StepsDone,
82 unsigned int TotalSteps,
83 std::string ErrorMessage);
84 virtual void ConffilePrompt(std::string PackageName,
85 unsigned int StepsDone,
86 unsigned int TotalSteps,
87 std::string ConfMessage);
88
31f97d7b
MV
89 };
90
c7ea1eba
MV
91 class PackageManagerProgressDeb822Fd : public PackageManager
92 {
93 protected:
94 int OutStatusFd;
95 int StepsDone;
96 int StepsTotal;
97 void WriteToStatusFd(std::string msg);
98
99 public:
100 PackageManagerProgressDeb822Fd(int progress_fd);
101
790d41f6 102 virtual void StartDpkg();
c7ea1eba
MV
103 virtual void Stop();
104
d3e8fbb3 105 virtual bool StatusChanged(std::string PackageName,
c7ea1eba
MV
106 unsigned int StepsDone,
107 unsigned int TotalSteps,
108 std::string HumanReadableAction);
d3e8fbb3 109 virtual void Error(std::string PackageName,
c7ea1eba
MV
110 unsigned int StepsDone,
111 unsigned int TotalSteps,
112 std::string ErrorMessage);
113 virtual void ConffilePrompt(std::string PackageName,
114 unsigned int StepsDone,
115 unsigned int TotalSteps,
116 std::string ConfMessage);
117 };
118
31f97d7b
MV
119 class PackageManagerFancy : public PackageManager
120 {
5ed88785
MV
121 private:
122 static void staticSIGWINCH(int);
123 static std::vector<PackageManagerFancy*> instances;
76bd63e2 124 APT_HIDDEN bool DrawStatusLine();
5ed88785 125
31f97d7b 126 protected:
5ed88785
MV
127 void SetupTerminalScrollArea(int nr_rows);
128 void HandleSIGWINCH(int);
129
fa211e2d
MV
130 typedef struct {
131 int rows;
132 int columns;
133 } TermSize;
134 TermSize GetTerminalSize();
135
e96e4e9c 136 sighandler_t old_SIGWINCH;
5ed88785 137 int child_pty;
db78c60c 138
31f97d7b
MV
139 public:
140 PackageManagerFancy();
e96e4e9c 141 ~PackageManagerFancy();
4754718a 142 virtual void Start(int child_pty=-1);
a22fdebf 143 virtual void Stop();
d3e8fbb3 144 virtual bool StatusChanged(std::string PackageName,
31f97d7b 145 unsigned int StepsDone,
e6ad8031
MV
146 unsigned int TotalSteps,
147 std::string HumanReadableAction);
fa211e2d
MV
148
149 // return a progress bar of the given size for the given progress
150 // percent between 0.0 and 1.0 in the form "[####...]"
151 static std::string GetTextProgressStr(float percent, int OutputSize);
31f97d7b
MV
152 };
153
154 class PackageManagerText : public PackageManager
155 {
31f97d7b 156 public:
d3e8fbb3 157 virtual bool StatusChanged(std::string PackageName,
31f97d7b 158 unsigned int StepsDone,
e6ad8031
MV
159 unsigned int TotalSteps,
160 std::string HumanReadableAction);
31f97d7b
MV
161 };
162
163
d3e8fbb3
DK
164} // namespace Progress
165} // namespace APT
31f97d7b
MV
166
167#endif