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