dpkgpm.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. FILE *history_out;
  25. string dpkg_error;
  26. protected:
  27. // progress reporting
  28. struct DpkgState
  29. {
  30. const char *state; // the dpkg state (e.g. "unpack")
  31. const char *str; // the human readable translation of the state
  32. };
  33. // the dpkg states that the pkg will run through, the string is
  34. // the package, the vector contains the dpkg states that the package
  35. // will go through
  36. map<string,vector<struct DpkgState> > PackageOps;
  37. // the dpkg states that are already done; the string is the package
  38. // the int is the state that is already done (e.g. a package that is
  39. // going to be install is already in state "half-installed")
  40. map<string,unsigned int> PackageOpsDone;
  41. // progress reporting
  42. unsigned int PackagesDone;
  43. unsigned int PackagesTotal;
  44. struct Item
  45. {
  46. enum Ops {Install, Configure, Remove, Purge, ConfigurePending, TriggersPending} Op;
  47. string File;
  48. PkgIterator Pkg;
  49. Item(Ops Op,PkgIterator Pkg,string File = "") : Op(Op),
  50. File(File), Pkg(Pkg) {};
  51. Item() {};
  52. };
  53. vector<Item> List;
  54. // Helpers
  55. bool RunScriptsWithPkgs(const char *Cnf);
  56. bool SendV2Pkgs(FILE *F);
  57. void WriteHistoryTag(string tag, string value);
  58. // dpkg log
  59. bool OpenLog();
  60. bool CloseLog();
  61. // input processing
  62. void DoStdin(int master);
  63. void DoTerminalPty(int master);
  64. void DoDpkgStatusFd(int statusfd, int OutStatusFd);
  65. void ProcessDpkgStatusLine(int OutStatusFd, char *line);
  66. // The Actuall installation implementation
  67. virtual bool Install(PkgIterator Pkg,string File);
  68. virtual bool Configure(PkgIterator Pkg);
  69. virtual bool Remove(PkgIterator Pkg,bool Purge = false);
  70. virtual bool Go(int StatusFd=-1);
  71. virtual void Reset();
  72. public:
  73. pkgDPkgPM(pkgDepCache *Cache);
  74. virtual ~pkgDPkgPM();
  75. };
  76. #endif