install-progress.h 4.0 KB

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