packagemanager.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: packagemanager.h,v 1.14 2001/05/07 04:24:08 jgg Exp $
  4. /* ######################################################################
  5. Package Manager - Abstacts the package manager
  6. Three steps are
  7. - Aquiration of archives (stores the list of final file names)
  8. - Sorting of operations
  9. - Invokation of package manager
  10. This is the final stage when the package cache entities get converted
  11. into file names and the state stored in a DepCache is transformed
  12. into a series of operations.
  13. In the final scheme of things this may serve as a director class to
  14. access the actual install methods based on the file type being
  15. installed.
  16. ##################################################################### */
  17. /*}}}*/
  18. #ifndef PKGLIB_PACKAGEMANAGER_H
  19. #define PKGLIB_PACKAGEMANAGER_H
  20. #include <string>
  21. #include <iostream>
  22. #include <apt-pkg/pkgcache.h>
  23. #include <apt-pkg/depcache.h>
  24. using std::string;
  25. class pkgAcquire;
  26. class pkgDepCache;
  27. class pkgSourceList;
  28. class pkgOrderList;
  29. class pkgRecords;
  30. class pkgPackageManager : protected pkgCache::Namespace
  31. {
  32. public:
  33. enum OrderResult {Completed,Failed,Incomplete};
  34. protected:
  35. string *FileNames;
  36. pkgDepCache &Cache;
  37. pkgOrderList *List;
  38. bool Debug;
  39. bool DepAdd(pkgOrderList &Order,PkgIterator P,int Depth = 0);
  40. virtual OrderResult OrderInstall();
  41. bool CheckRConflicts(PkgIterator Pkg,DepIterator Dep,const char *Ver);
  42. bool CreateOrderList();
  43. // Analysis helpers
  44. bool DepAlwaysTrue(DepIterator D);
  45. // Install helpers
  46. bool ConfigureAll();
  47. bool SmartConfigure(PkgIterator Pkg);
  48. bool SmartUnPack(PkgIterator Pkg);
  49. bool SmartRemove(PkgIterator Pkg);
  50. bool EarlyRemove(PkgIterator Pkg);
  51. // The Actual installation implementation
  52. virtual bool Install(PkgIterator /*Pkg*/,string /*File*/) {return false;};
  53. virtual bool Configure(PkgIterator /*Pkg*/) {return false;};
  54. virtual bool Remove(PkgIterator /*Pkg*/,bool /*Purge*/=false) {return false;};
  55. virtual bool Go(int statusFd=-1) {return true;};
  56. virtual void Reset() {};
  57. // the result of the operation
  58. OrderResult Res;
  59. public:
  60. // Main action members
  61. bool GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
  62. pkgRecords *Recs);
  63. // Do the installation
  64. OrderResult DoInstall(int statusFd=-1);
  65. // stuff that needs to be done before the fork() of a library that
  66. // uses apt
  67. OrderResult DoInstallPreFork() {
  68. Res = OrderInstall();
  69. return Res;
  70. };
  71. // stuff that needs to be done after the fork
  72. OrderResult DoInstallPostFork(int statusFd=-1) {
  73. bool goResult = Go(statusFd);
  74. if(goResult == false)
  75. return Failed;
  76. // if all was fine update the state file
  77. if(Res == Completed) {
  78. Cache.writeStateFile(NULL);
  79. }
  80. return Res;
  81. };
  82. bool FixMissing();
  83. pkgPackageManager(pkgDepCache *Cache);
  84. virtual ~pkgPackageManager();
  85. };
  86. #endif