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