apt
@VERSION@
|
00001 // -*- mode: cpp; mode: fold -*- 00002 // Description /*{{{*/ 00003 // $Id: orderlist.h,v 1.9 2001/02/20 07:03:17 jgg Exp $ 00004 /* ###################################################################### 00005 00006 Order List - Represents and Manipulates an ordered list of packages. 00007 00008 A list of packages can be ordered by a number of conflicting criteria 00009 each given a specific priority. Each package also has a set of flags 00010 indicating some useful things about it that are derived in the 00011 course of sorting. The pkgPackageManager class uses this class for 00012 all of it's installation ordering needs. 00013 00014 ##################################################################### */ 00015 /*}}}*/ 00016 #ifndef PKGLIB_ORDERLIST_H 00017 #define PKGLIB_ORDERLIST_H 00018 00019 00020 #include <apt-pkg/pkgcache.h> 00021 #include <apt-pkg/macros.h> 00022 00023 class pkgDepCache; 00024 class pkgOrderList : protected pkgCache::Namespace 00025 { 00026 protected: 00027 00028 pkgDepCache &Cache; 00029 typedef bool (pkgOrderList::*DepFunc)(DepIterator D); 00030 00031 // These are the currently selected ordering functions 00032 DepFunc Primary; 00033 DepFunc Secondary; 00034 DepFunc RevDepends; 00035 DepFunc Remove; 00036 00037 // State 00038 Package **End; 00039 Package **List; 00040 Package **AfterEnd; 00041 std::string *FileList; 00042 DepIterator Loops[20]; 00043 int LoopCount; 00044 int Depth; 00045 unsigned short *Flags; 00046 bool Debug; 00047 00048 // Main visit function 00049 __deprecated bool VisitNode(PkgIterator Pkg) { return VisitNode(Pkg, "UNKNOWN"); }; 00050 bool VisitNode(PkgIterator Pkg, char const* from); 00051 bool VisitDeps(DepFunc F,PkgIterator Pkg); 00052 bool VisitRDeps(DepFunc F,PkgIterator Pkg); 00053 bool VisitRProvides(DepFunc F,VerIterator Ver); 00054 bool VisitProvides(DepIterator Pkg,bool Critical); 00055 00056 // Dependency checking functions. 00057 bool DepUnPackCrit(DepIterator D); 00058 bool DepUnPackPreD(DepIterator D); 00059 bool DepUnPackPre(DepIterator D); 00060 bool DepUnPackDep(DepIterator D); 00061 bool DepConfigure(DepIterator D); 00062 bool DepRemove(DepIterator D); 00063 00064 // Analysis helpers 00065 bool AddLoop(DepIterator D); 00066 bool CheckDep(DepIterator D); 00067 bool DoRun(); 00068 00069 // For pre sorting 00070 static pkgOrderList *Me; 00071 static int OrderCompareA(const void *a, const void *b); 00072 static int OrderCompareB(const void *a, const void *b); 00073 int FileCmp(PkgIterator A,PkgIterator B); 00074 00075 public: 00076 00077 typedef Package **iterator; 00078 00079 /* State flags 00080 The Loop flag can be set on a package that is currently being processed by either SmartConfigure or 00081 SmartUnPack. This allows the package manager to tell when a loop has been formed as it will try to 00082 SmartUnPack or SmartConfigure a package with the Loop flag set. It will then either stop (as it knows 00083 that the operation is unnecessary as its already in process), or in the case of the conflicts resolution 00084 in SmartUnPack, use EarlyRemove to resolve the situation. */ 00085 enum Flags {Added = (1 << 0), AddPending = (1 << 1), 00086 Immediate = (1 << 2), Loop = (1 << 3), 00087 UnPacked = (1 << 4), Configured = (1 << 5), 00088 Removed = (1 << 6), // Early Remove 00089 InList = (1 << 7), 00090 After = (1 << 8), 00091 States = (UnPacked | Configured | Removed)}; 00092 00093 // Flag manipulators 00094 inline bool IsFlag(PkgIterator Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;}; 00095 inline bool IsFlag(Package *Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;}; 00096 void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;}; 00097 inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;}; 00098 inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;}; 00099 // RmFlag removes a flag from a package 00100 inline void RmFlag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] &= ~F;}; 00101 // IsNow will return true if the Pkg has been not been either configured or unpacked 00102 inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & (States & (~Removed))) == 0;}; 00103 bool IsMissing(PkgIterator Pkg); 00104 void WipeFlags(unsigned long F); 00105 void SetFileList(std::string *FileList) {this->FileList = FileList;}; 00106 00107 // Accessors 00108 inline iterator begin() {return List;}; 00109 inline iterator end() {return End;}; 00110 inline void push_back(Package *Pkg) {*(End++) = Pkg;}; 00111 inline void push_back(PkgIterator Pkg) {*(End++) = Pkg;}; 00112 inline void pop_back() {End--;}; 00113 inline bool empty() {return End == List;}; 00114 inline unsigned int size() {return End - List;}; 00115 00116 // Ordering modes 00117 bool OrderCritical(); 00118 bool OrderUnpack(std::string *FileList = 0); 00119 bool OrderConfigure(); 00120 00121 int Score(PkgIterator Pkg); 00122 00123 pkgOrderList(pkgDepCache *Cache); 00124 ~pkgOrderList(); 00125 }; 00126 00127 #endif