orderlist.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Order List - Represents and Manipulates an ordered list of packages.
  5. A list of packages can be ordered by a number of conflicting criteria
  6. each given a specific priority. Each package also has a set of flags
  7. indicating some useful things about it that are derived in the
  8. course of sorting. The pkgPackageManager class uses this class for
  9. all of it's installation ordering needs.
  10. ##################################################################### */
  11. /*}}}*/
  12. #ifndef PKGLIB_ORDERLIST_H
  13. #define PKGLIB_ORDERLIST_H
  14. #include <apt-pkg/pkgcache.h>
  15. #include <apt-pkg/cacheiterators.h>
  16. #include <apt-pkg/macros.h>
  17. #include <string>
  18. class pkgDepCache;
  19. class pkgOrderList : protected pkgCache::Namespace
  20. {
  21. void * const d;
  22. protected:
  23. pkgDepCache &Cache;
  24. typedef bool (pkgOrderList::*DepFunc)(DepIterator D);
  25. // These are the currently selected ordering functions
  26. DepFunc Primary;
  27. DepFunc Secondary;
  28. DepFunc RevDepends;
  29. DepFunc Remove;
  30. // State
  31. Package **End;
  32. Package **List;
  33. Package **AfterEnd;
  34. std::string *FileList;
  35. DepIterator Loops[20];
  36. int LoopCount;
  37. int Depth;
  38. unsigned short *Flags;
  39. bool Debug;
  40. // Main visit function
  41. APT_DEPRECATED_MSG("Add a unique calling identifier as parameter for debugging output") bool VisitNode(PkgIterator Pkg) { return VisitNode(Pkg, "UNKNOWN"); };
  42. bool VisitNode(PkgIterator Pkg, char const* from);
  43. bool VisitDeps(DepFunc F,PkgIterator Pkg);
  44. bool VisitRDeps(DepFunc F,PkgIterator Pkg);
  45. bool VisitRProvides(DepFunc F,VerIterator Ver);
  46. bool VisitProvides(DepIterator Pkg,bool Critical);
  47. // Dependency checking functions.
  48. bool DepUnPackCrit(DepIterator D);
  49. bool DepUnPackPreD(DepIterator D);
  50. bool DepUnPackPre(DepIterator D);
  51. bool DepUnPackDep(DepIterator D);
  52. bool DepConfigure(DepIterator D);
  53. bool DepRemove(DepIterator D);
  54. // Analysis helpers
  55. bool AddLoop(DepIterator D);
  56. bool CheckDep(DepIterator D);
  57. bool DoRun();
  58. // For pre sorting
  59. int OrderCompareA(Package *a, Package *b) APT_PURE;
  60. int OrderCompareB(Package *a, Package *b) APT_PURE;
  61. int FileCmp(PkgIterator A,PkgIterator B) APT_PURE;
  62. public:
  63. typedef Package **iterator;
  64. /* State flags
  65. The Loop flag can be set on a package that is currently being processed by either SmartConfigure or
  66. SmartUnPack. This allows the package manager to tell when a loop has been formed as it will try to
  67. SmartUnPack or SmartConfigure a package with the Loop flag set. It will then either stop (as it knows
  68. that the operation is unnecessary as its already in process), or in the case of the conflicts resolution
  69. in SmartUnPack, use EarlyRemove to resolve the situation. */
  70. enum Flags {Added = (1 << 0), AddPending = (1 << 1),
  71. Immediate = (1 << 2), Loop = (1 << 3),
  72. UnPacked = (1 << 4), Configured = (1 << 5),
  73. Removed = (1 << 6), // Early Remove
  74. InList = (1 << 7),
  75. After = (1 << 8),
  76. States = (UnPacked | Configured | Removed)};
  77. // Flag manipulators
  78. inline bool IsFlag(PkgIterator Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
  79. inline bool IsFlag(Package *Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
  80. void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;};
  81. inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
  82. inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
  83. // RmFlag removes a flag from a package
  84. inline void RmFlag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] &= ~F;};
  85. // IsNow will return true if the Pkg has been not been either configured or unpacked
  86. inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & (States & (~Removed))) == 0;};
  87. bool IsMissing(PkgIterator Pkg) APT_PURE;
  88. void WipeFlags(unsigned long F);
  89. void SetFileList(std::string *FileList) {this->FileList = FileList;};
  90. // Accessors
  91. inline iterator begin() {return List;};
  92. inline iterator end() {return End;};
  93. inline void push_back(Package *Pkg) {*(End++) = Pkg;};
  94. inline void push_back(PkgIterator Pkg) {*(End++) = Pkg;};
  95. inline void pop_back() {End--;};
  96. inline bool empty() {return End == List;};
  97. inline unsigned int size() {return End - List;};
  98. // Ordering modes
  99. bool OrderCritical();
  100. bool OrderUnpack(std::string *FileList = 0);
  101. bool OrderConfigure();
  102. int Score(PkgIterator Pkg);
  103. explicit pkgOrderList(pkgDepCache *Cache);
  104. virtual ~pkgOrderList();
  105. };
  106. #endif