dpkgpm.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. bool stdin_is_dev_null;
  20. // the buffer we use for the dpkg status-fd reading
  21. char dpkgbuf[1024];
  22. int dpkgbuf_pos;
  23. FILE *term_out;
  24. protected:
  25. // progress reporting
  26. struct DpkgState
  27. {
  28. const char *state; // the dpkg state (e.g. "unpack")
  29. const char *str; // the human readable translation of the state
  30. };
  31. // the dpkg states that the pkg will run through, the string is
  32. // the package, the vector contains the dpkg states that the package
  33. // will go through
  34. map<string,vector<struct DpkgState> > PackageOps;
  35. // the dpkg states that are already done; the string is the package
  36. // the int is the state that is already done (e.g. a package that is
  37. // going to be install is already in state "half-installed")
  38. map<string,unsigned int> PackageOpsDone;
  39. // progress reporting
  40. unsigned int PackagesDone;
  41. unsigned int PackagesTotal;
  42. struct Item
  43. {
  44. enum Ops {Install, Configure, Remove, Purge} Op;
  45. string File;
  46. PkgIterator Pkg;
  47. Item(Ops Op,PkgIterator Pkg,string File = "") : Op(Op),
  48. File(File), Pkg(Pkg) {};
  49. Item() {};
  50. };
  51. vector<Item> List;
  52. // Helpers
  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