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