dpkgpm.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // input processing
  56. void DoStdin(int master);
  57. void DoTerminalPty(int master);
  58. void DoDpkgStatusFd(int statusfd, int OutStatusFd);
  59. void ProcessDpkgStatusLine(int OutStatusFd, char *line);
  60. // The Actuall installation implementation
  61. virtual bool Install(PkgIterator Pkg,string File);
  62. virtual bool Configure(PkgIterator Pkg);
  63. virtual bool Remove(PkgIterator Pkg,bool Purge = false);
  64. virtual bool Go(int StatusFd=-1);
  65. virtual void Reset();
  66. public:
  67. pkgDPkgPM(pkgDepCache *Cache);
  68. virtual ~pkgDPkgPM();
  69. };
  70. #endif