]> git.saurik.com Git - apt.git/blob - apt-pkg/install-progress.h
Set STRIP_FROM_PATH for doxygen
[apt.git] / apt-pkg / 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 <unistd.h>
8 #include <signal.h>
9 #include <vector>
10
11 namespace APT {
12 namespace Progress {
13
14 class PackageManager;
15 PackageManager* PackageManagerProgressFactory();
16
17 class PackageManager
18 {
19 private:
20 /** \brief dpointer placeholder */
21 void *d;
22
23 protected:
24 std::string progress_str;
25 float percentage;
26 int last_reported_progress;
27
28 public:
29 PackageManager()
30 : percentage(0.0), last_reported_progress(-1) {};
31 virtual ~PackageManager() {};
32
33 /* Global Start/Stop */
34 virtual void Start(int /*child_pty*/=-1) {};
35 virtual void Stop() {};
36
37 /* When dpkg is invoked (may happen multiple times for each
38 * install/remove block
39 */
40 virtual void StartDpkg() {};
41
42 virtual pid_t fork() {return fork(); };
43
44 virtual void Pulse() {};
45 virtual long GetPulseInterval() {
46 return 500000;
47 };
48
49 virtual bool StatusChanged(std::string PackageName,
50 unsigned int StepsDone,
51 unsigned int TotalSteps,
52 std::string HumanReadableAction);
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*/) {}
61 };
62
63 class PackageManagerProgressFd : public PackageManager
64 {
65 protected:
66 int OutStatusFd;
67 int StepsDone;
68 int StepsTotal;
69 void WriteToStatusFd(std::string msg);
70
71 public:
72 PackageManagerProgressFd(int progress_fd);
73
74 virtual void StartDpkg();
75 virtual void Stop();
76
77 virtual bool StatusChanged(std::string PackageName,
78 unsigned int StepsDone,
79 unsigned int TotalSteps,
80 std::string HumanReadableAction);
81 virtual void Error(std::string PackageName,
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
90 };
91
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
103 virtual void StartDpkg();
104 virtual void Stop();
105
106 virtual bool StatusChanged(std::string PackageName,
107 unsigned int StepsDone,
108 unsigned int TotalSteps,
109 std::string HumanReadableAction);
110 virtual void Error(std::string PackageName,
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
120 class PackageManagerFancy : public PackageManager
121 {
122 private:
123 static void staticSIGWINCH(int);
124 static std::vector<PackageManagerFancy*> instances;
125 APT_HIDDEN bool DrawStatusLine();
126
127 protected:
128 void SetupTerminalScrollArea(int nr_rows);
129 void HandleSIGWINCH(int);
130
131 typedef struct {
132 int rows;
133 int columns;
134 } TermSize;
135 TermSize GetTerminalSize();
136
137 sighandler_t old_SIGWINCH;
138 int child_pty;
139
140 public:
141 PackageManagerFancy();
142 ~PackageManagerFancy();
143 virtual void Start(int child_pty=-1);
144 virtual void Stop();
145 virtual bool StatusChanged(std::string PackageName,
146 unsigned int StepsDone,
147 unsigned int TotalSteps,
148 std::string HumanReadableAction);
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);
153 };
154
155 class PackageManagerText : public PackageManager
156 {
157 public:
158 virtual bool StatusChanged(std::string PackageName,
159 unsigned int StepsDone,
160 unsigned int TotalSteps,
161 std::string HumanReadableAction);
162 };
163
164
165 } // namespace Progress
166 } // namespace APT
167
168 #endif