]>
Commit | Line | Data |
---|---|---|
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 | 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 500000; | |
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 | protected: | |
65 | int OutStatusFd; | |
66 | int StepsDone; | |
67 | int StepsTotal; | |
68 | void WriteToStatusFd(std::string msg); | |
69 | ||
70 | public: | |
71 | PackageManagerProgressFd(int progress_fd); | |
72 | ||
73 | virtual void StartDpkg(); | |
74 | virtual void Stop(); | |
75 | ||
76 | virtual bool StatusChanged(std::string PackageName, | |
77 | unsigned int StepsDone, | |
78 | unsigned int TotalSteps, | |
79 | std::string HumanReadableAction); | |
80 | virtual void Error(std::string PackageName, | |
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 | ||
89 | }; | |
90 | ||
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 | ||
102 | virtual void StartDpkg(); | |
103 | virtual void Stop(); | |
104 | ||
105 | virtual bool StatusChanged(std::string PackageName, | |
106 | unsigned int StepsDone, | |
107 | unsigned int TotalSteps, | |
108 | std::string HumanReadableAction); | |
109 | virtual void Error(std::string PackageName, | |
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 | ||
119 | class PackageManagerFancy : public PackageManager | |
120 | { | |
121 | private: | |
122 | APT_HIDDEN static void staticSIGWINCH(int); | |
123 | static std::vector<PackageManagerFancy*> instances; | |
124 | APT_HIDDEN bool DrawStatusLine(); | |
125 | ||
126 | protected: | |
127 | void SetupTerminalScrollArea(int nr_rows); | |
128 | void HandleSIGWINCH(int); | |
129 | ||
130 | typedef struct { | |
131 | int rows; | |
132 | int columns; | |
133 | } TermSize; | |
134 | TermSize GetTerminalSize(); | |
135 | ||
136 | sighandler_t old_SIGWINCH; | |
137 | int child_pty; | |
138 | ||
139 | public: | |
140 | PackageManagerFancy(); | |
141 | ~PackageManagerFancy(); | |
142 | virtual void Start(int child_pty=-1); | |
143 | virtual void Stop(); | |
144 | virtual bool StatusChanged(std::string PackageName, | |
145 | unsigned int StepsDone, | |
146 | unsigned int TotalSteps, | |
147 | std::string HumanReadableAction); | |
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); | |
152 | }; | |
153 | ||
154 | class PackageManagerText : public PackageManager | |
155 | { | |
156 | public: | |
157 | virtual bool StatusChanged(std::string PackageName, | |
158 | unsigned int StepsDone, | |
159 | unsigned int TotalSteps, | |
160 | std::string HumanReadableAction); | |
161 | }; | |
162 | ||
163 | ||
164 | } // namespace Progress | |
165 | } // namespace APT | |
166 | ||
167 | #endif |