dpkgpm.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: dpkgpm.h,v 1.8 2001/05/07 05:05:13 jgg Exp $
  4. /* ######################################################################
  5. DPKG Package Manager - Provide an interface to dpkg
  6. ##################################################################### */
  7. /*}}}*/
  8. #ifndef PKGLIB_DPKGPM_H
  9. #define PKGLIB_DPKGPM_H
  10. #include <apt-pkg/packagemanager.h>
  11. #include <vector>
  12. #include <map>
  13. #include <stdio.h>
  14. using std::vector;
  15. using std::map;
  16. class pkgDPkgPM : public pkgPackageManager
  17. {
  18. private:
  19. // the buffer we use for the dpkg status-fd reading
  20. char dpkgbuf[1024];
  21. int dpkgbuf_pos;
  22. FILE *term_out;
  23. protected:
  24. // progress reporting
  25. struct DpkgState
  26. {
  27. const char *state; // the dpkg state (e.g. "unpack")
  28. const char *str; // the human readable translation of the state
  29. };
  30. // the dpkg states that the pkg will run through, the string is
  31. // the package, the vector contains the dpkg states that the package
  32. // will go through
  33. map<string,vector<struct DpkgState> > PackageOps;
  34. // the dpkg states that are already done; the string is the package
  35. // the int is the state that is already done (e.g. a package that is
  36. // going to be install is already in state "half-installed")
  37. map<string,unsigned int> PackageOpsDone;
  38. // progress reporting
  39. unsigned int PackagesDone;
  40. unsigned int PackagesTotal;
  41. struct Item
  42. {
  43. enum Ops {Install, Configure, Remove, Purge} Op;
  44. string File;
  45. PkgIterator Pkg;
  46. Item(Ops Op,PkgIterator Pkg,string File = "") : Op(Op),
  47. File(File), Pkg(Pkg) {};
  48. Item() {};
  49. };
  50. vector<Item> List;
  51. // Helpers
  52. bool RunScripts(const char *Cnf);
  53. bool RunScriptsWithPkgs(const char *Cnf);
  54. bool SendV2Pkgs(FILE *F);
  55. // dpkg log
  56. bool OpenLog();
  57. bool CloseLog();
  58. // input processing
  59. void DoStdin(int master);
  60. void DoTerminalPty(int master);
  61. void DoDpkgStatusFd(int statusfd, int OutStatusFd);
  62. void ProcessDpkgStatusLine(int OutStatusFd, char *line);
  63. // The Actuall installation implementation
  64. virtual bool Install(PkgIterator Pkg,string File);
  65. virtual bool Configure(PkgIterator Pkg);
  66. virtual bool Remove(PkgIterator Pkg,bool Purge = false);
  67. virtual bool Go(int StatusFd=-1);
  68. virtual void Reset();
  69. public:
  70. pkgDPkgPM(pkgDepCache *Cache);
  71. virtual ~pkgDPkgPM();
  72. };
  73. #endif