You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

168 lines
4.8 KiB

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