install-progress.h 4.3 KB

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