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.
 
 
 
 
 
 

166 lines
4.8 KiB

  1. #ifndef PKGLIB_IPROGRESS_H
  2. #define PKGLIB_IPROGRESS_H
  3. #include <string>
  4. #include <unistd.h>
  5. #include <signal.h>
  6. #include <vector>
  7. namespace APT {
  8. namespace Progress {
  9. class PackageManager;
  10. PackageManager* PackageManagerProgressFactory();
  11. class PackageManager
  12. {
  13. private:
  14. /** \brief dpointer placeholder */
  15. void *d;
  16. protected:
  17. std::string progress_str;
  18. float percentage;
  19. int last_reported_progress;
  20. public:
  21. PackageManager()
  22. : percentage(0.0), last_reported_progress(-1) {};
  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. protected:
  103. void SetupTerminalScrollArea(int nr_rows);
  104. void HandleSIGWINCH(int);
  105. typedef struct {
  106. int rows;
  107. int columns;
  108. } TermSize;
  109. TermSize GetTerminalSize();
  110. sighandler_t old_SIGWINCH;
  111. int child_pty;
  112. public:
  113. PackageManagerFancy();
  114. ~PackageManagerFancy();
  115. virtual void Start(int child_pty=-1);
  116. virtual void Stop();
  117. virtual bool StatusChanged(std::string PackageName,
  118. unsigned int StepsDone,
  119. unsigned int TotalSteps,
  120. std::string HumanReadableAction);
  121. // return a progress bar of the given size for the given progress
  122. // percent between 0.0 and 1.0 in the form "[####...]"
  123. static std::string GetTextProgressStr(float percent, int OutputSize);
  124. };
  125. class PackageManagerText : public PackageManager
  126. {
  127. public:
  128. virtual bool StatusChanged(std::string PackageName,
  129. unsigned int StepsDone,
  130. unsigned int TotalSteps,
  131. std::string HumanReadableAction);
  132. };
  133. } // namespace Progress
  134. } // namespace APT
  135. #endif