install-progress.h 4.4 KB

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