packagemanager.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #ifdef __GNUG__
  21. #pragma interface "apt-pkg/packagemanager.h"
  22. #endif
  23. #include <string>
  24. #include <iostream>
  25. #include <apt-pkg/pkgcache.h>
  26. #include <apt-pkg/depcache.h>
  27. using std::string;
  28. class pkgAcquire;
  29. class pkgDepCache;
  30. class pkgSourceList;
  31. class pkgOrderList;
  32. class pkgRecords;
  33. class pkgPackageManager : protected pkgCache::Namespace
  34. {
  35. public:
  36. enum OrderResult {Completed,Failed,Incomplete};
  37. protected:
  38. string *FileNames;
  39. pkgDepCache &Cache;
  40. pkgOrderList *List;
  41. bool Debug;
  42. bool DepAdd(pkgOrderList &Order,PkgIterator P,int Depth = 0);
  43. virtual OrderResult OrderInstall();
  44. bool CheckRConflicts(PkgIterator Pkg,DepIterator Dep,const char *Ver);
  45. bool CreateOrderList();
  46. // Analysis helpers
  47. bool DepAlwaysTrue(DepIterator D);
  48. // Install helpers
  49. bool ConfigureAll();
  50. bool SmartConfigure(PkgIterator Pkg);
  51. bool SmartUnPack(PkgIterator Pkg);
  52. bool SmartRemove(PkgIterator Pkg);
  53. bool EarlyRemove(PkgIterator Pkg);
  54. // The Actual installation implementation
  55. virtual bool Install(PkgIterator /*Pkg*/,string /*File*/) {return false;};
  56. virtual bool Configure(PkgIterator /*Pkg*/) {return false;};
  57. virtual bool Remove(PkgIterator /*Pkg*/,bool /*Purge*/=false) {return false;};
  58. virtual bool Go(int statusFd=-1) {return true;};
  59. virtual void Reset() {};
  60. // the result of the operation
  61. OrderResult Res;
  62. public:
  63. // Main action members
  64. bool GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
  65. pkgRecords *Recs);
  66. // Do the installation
  67. OrderResult DoInstall() {
  68. if(DoInstallPreFork() == Failed)
  69. return Failed;
  70. return DoInstallPostFork();
  71. }
  72. // stuff that needs to be done before the fork() of a library that
  73. // uses apt
  74. OrderResult DoInstallPreFork() {
  75. Res = OrderInstall();
  76. return Res;
  77. };
  78. // stuff that needs to be done after the fork
  79. OrderResult DoInstallPostFork(int statusFd=-1) {
  80. bool goResult = Go(statusFd);
  81. if(goResult == false)
  82. return Failed;
  83. // if all was fine update the state file
  84. if(Res == Completed) {
  85. Cache.writeStateFile(NULL);
  86. }
  87. return Res;
  88. };
  89. bool FixMissing();
  90. pkgPackageManager(pkgDepCache *Cache);
  91. virtual ~pkgPackageManager();
  92. };
  93. #endif