install-progress.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. int GetNumberTerminalRows();
  106. sighandler_t old_SIGWINCH;
  107. int child_pty;
  108. public:
  109. PackageManagerFancy();
  110. ~PackageManagerFancy();
  111. virtual void Start(int child_pty=-1);
  112. virtual void Stop();
  113. virtual bool StatusChanged(std::string PackageName,
  114. unsigned int StepsDone,
  115. unsigned int TotalSteps,
  116. std::string HumanReadableAction);
  117. };
  118. class PackageManagerText : public PackageManager
  119. {
  120. public:
  121. virtual bool StatusChanged(std::string PackageName,
  122. unsigned int StepsDone,
  123. unsigned int TotalSteps,
  124. std::string HumanReadableAction);
  125. };
  126. } // namespace Progress
  127. } // namespace APT
  128. #endif