private-progress.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 PackageManagerFancy : public PackageManager
  65. {
  66. protected:
  67. int nr_terminal_rows;
  68. void SetupTerminalScrollArea(int nr_rows);
  69. public:
  70. PackageManagerFancy();
  71. virtual void Start();
  72. virtual void Stop();
  73. virtual bool StatusChanged(std::string PackageName,
  74. unsigned int StepsDone,
  75. unsigned int TotalSteps,
  76. std::string HumanReadableAction);
  77. };
  78. class PackageManagerText : public PackageManager
  79. {
  80. public:
  81. virtual bool StatusChanged(std::string PackageName,
  82. unsigned int StepsDone,
  83. unsigned int TotalSteps,
  84. std::string HumanReadableAction);
  85. };
  86. }; // namespace Progress
  87. }; // namespace APT
  88. #endif