Commit | Line | Data |
---|---|---|
578bfd0a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
0149949b | 3 | // $Id: pkgcache.h,v 1.3 1998/07/04 22:32:12 jgg Exp $ |
578bfd0a AL |
4 | /* ###################################################################### |
5 | ||
6 | Cache - Structure definitions for the cache file | |
7 | ||
8 | Please see doc/pkglib/cache.sgml for a more detailed description of | |
9 | this format. Also be sure to keep that file up-to-date!! | |
10 | ||
11 | Clients should always use the CacheIterators classes for access to the | |
12 | cache. They provide a simple STL-like method for traversing the links | |
13 | of the datastructure. | |
14 | ||
15 | See pkgcachegen.h for information about generating cache structures. | |
16 | ||
17 | ##################################################################### */ | |
18 | /*}}}*/ | |
19 | // Header section: pkglib | |
20 | #ifndef PKGLIB_PKGCACHE_H | |
21 | #define PKGLIB_PKGCACHE_H | |
22 | ||
23 | #include <string> | |
24 | #include <time.h> | |
25 | #include <pkglib/mmap.h> | |
26 | ||
578bfd0a AL |
27 | class pkgCache |
28 | { | |
29 | public: | |
30 | // Cache element predeclarations | |
31 | struct Header; | |
32 | struct Package; | |
33 | struct PackageFile; | |
34 | struct Version; | |
35 | struct Provides; | |
36 | struct Dependency; | |
37 | struct StringItem; | |
38 | ||
39 | // Iterators | |
40 | class PkgIterator; | |
41 | class VerIterator; | |
42 | class DepIterator; | |
43 | class PrvIterator; | |
44 | class PkgFileIterator; | |
45 | friend PkgIterator; | |
46 | friend VerIterator; | |
47 | friend DepIterator; | |
48 | friend PrvIterator; | |
49 | friend PkgFileIterator; | |
f55a958f AL |
50 | |
51 | // These are all the constants used in the cache structures | |
52 | enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4, | |
53 | Conflicts=5,Replaces=6}; | |
54 | enum VerPriority {Important=1,Required=2,Standard=3,Optional=5,Extra=5}; | |
55 | enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4}; | |
56 | enum PkgFlags {Auto=(1<<0),New=(1<<1),Obsolete=(1<<2),Essential=(1<<3), | |
57 | ImmediateConf=(1<<4)}; | |
58 | enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3}; | |
59 | enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2, | |
60 | UnInstalled=3,HalfInstalled=4,ConfigFiles=5, | |
61 | Installed=6}; | |
62 | enum PkgFFlags {NotSource=(1<<0)}; | |
63 | enum DepCompareOp {Or=0x10,LessEq=0x1,GreaterEq=0x2,Less=0x3, | |
64 | Greater=0x4,Equals=0x5,NotEquals=0x6}; | |
578bfd0a AL |
65 | |
66 | protected: | |
67 | ||
68 | // Memory mapped cache file | |
69 | string CacheFile; | |
70 | MMap ⤅ | |
71 | ||
72 | bool Public; | |
73 | bool ReadOnly; | |
74 | ||
75 | static unsigned long sHash(string S); | |
76 | static unsigned long sHash(const char *S); | |
77 | ||
78 | public: | |
79 | ||
80 | // Pointers to the arrays of items | |
81 | Header *HeaderP; | |
82 | Package *PkgP; | |
83 | PackageFile *PkgFileP; | |
84 | Version *VerP; | |
85 | Provides *ProvideP; | |
86 | Dependency *DepP; | |
87 | StringItem *StringItemP; | |
88 | char *StrP; | |
89 | ||
90 | virtual bool ReMap(); | |
91 | inline bool Sync() {return Map.Sync();}; | |
92 | ||
93 | // String hashing function (512 range) | |
94 | inline unsigned long Hash(string S) const {return sHash(S);}; | |
95 | inline unsigned long Hash(const char *S) const {return sHash(S);}; | |
96 | ||
0149949b AL |
97 | // Usefull transformation things |
98 | const char *Priority(unsigned char Priority); | |
99 | ||
578bfd0a AL |
100 | // Accessors |
101 | PkgIterator FindPkg(string Name); | |
102 | Header &Head() {return *HeaderP;}; | |
103 | inline PkgIterator PkgBegin(); | |
104 | inline PkgIterator PkgEnd(); | |
105 | ||
106 | pkgCache(MMap &Map); | |
107 | virtual ~pkgCache() {}; | |
108 | }; | |
109 | ||
110 | // Header structure | |
111 | struct pkgCache::Header | |
112 | { | |
113 | // Signature information | |
114 | unsigned long Signature; | |
115 | short MajorVersion; | |
116 | short MinorVersion; | |
117 | bool Dirty; | |
118 | ||
119 | // Size of structure values | |
120 | unsigned short HeaderSz; | |
121 | unsigned short PackageSz; | |
122 | unsigned short PackageFileSz; | |
123 | unsigned short VersionSz; | |
124 | unsigned short DependencySz; | |
125 | unsigned short ProvidesSz; | |
126 | ||
127 | // Structure counts | |
128 | unsigned long PackageCount; | |
129 | unsigned long VersionCount; | |
130 | unsigned long DependsCount; | |
131 | unsigned long PackageFileCount; | |
132 | ||
133 | // Offsets | |
134 | unsigned long FileList; // struct PackageFile | |
135 | unsigned long StringList; // struct StringItem | |
136 | ||
137 | /* Allocation pools, there should be one of these for each structure | |
138 | excluding the header */ | |
139 | DynamicMMap::Pool Pools[6]; | |
140 | ||
141 | // Rapid package name lookup | |
142 | unsigned long HashTable[512]; | |
143 | ||
144 | bool CheckSizes(Header &Against) const; | |
145 | Header(); | |
146 | }; | |
147 | ||
148 | struct pkgCache::Package | |
149 | { | |
150 | // Pointers | |
151 | unsigned long Name; // Stringtable | |
152 | unsigned long VersionList; // Version | |
153 | unsigned long TargetVer; // Version | |
154 | unsigned long CurrentVer; // Version | |
155 | unsigned long TargetDist; // StringTable (StringItem) | |
156 | unsigned long Section; // StringTable (StringItem) | |
157 | ||
158 | // Linked list | |
159 | unsigned long NextPackage; // Package | |
160 | unsigned long RevDepends; // Dependency | |
161 | unsigned long ProvidesList; // Provides | |
162 | ||
163 | // Install/Remove/Purge etc | |
164 | unsigned char SelectedState; // What | |
165 | unsigned char InstState; // Flags | |
166 | unsigned char CurrentState; // State | |
167 | ||
168 | unsigned short ID; | |
f55a958f | 169 | unsigned long Flags; |
578bfd0a AL |
170 | }; |
171 | ||
172 | struct pkgCache::PackageFile | |
173 | { | |
174 | // Names | |
175 | unsigned long FileName; // Stringtable | |
176 | unsigned long Version; // Stringtable | |
177 | unsigned long Distribution; // Stringtable | |
178 | unsigned long Size; | |
179 | ||
180 | // Linked list | |
181 | unsigned long NextFile; // PackageFile | |
182 | unsigned short ID; | |
f55a958f | 183 | unsigned long Flags; |
578bfd0a AL |
184 | time_t mtime; // Modification time for the file |
185 | }; | |
186 | ||
187 | struct pkgCache::Version | |
188 | { | |
189 | unsigned long VerStr; // Stringtable | |
190 | unsigned long File; // PackageFile | |
191 | unsigned long Section; // StringTable (StringItem) | |
192 | ||
193 | // Lists | |
194 | unsigned long NextVer; // Version | |
195 | unsigned long DependsList; // Dependency | |
196 | unsigned long ParentPkg; // Package | |
197 | unsigned long ProvidesList; // Provides | |
198 | ||
199 | unsigned long Offset; | |
200 | unsigned long Size; | |
201 | unsigned long InstalledSize; | |
202 | unsigned short ID; | |
203 | unsigned char Priority; | |
204 | }; | |
205 | ||
206 | struct pkgCache::Dependency | |
207 | { | |
208 | unsigned long Version; // Stringtable | |
209 | unsigned long Package; // Package | |
210 | unsigned long NextDepends; // Dependency | |
211 | unsigned long NextRevDepends; // Dependency | |
212 | unsigned long ParentVer; // Version | |
213 | ||
214 | // Specific types of depends | |
215 | unsigned char Type; | |
216 | unsigned char CompareOp; | |
217 | unsigned short ID; | |
218 | }; | |
219 | ||
220 | struct pkgCache::Provides | |
221 | { | |
222 | unsigned long ParentPkg; // Pacakge | |
223 | unsigned long Version; // Version | |
224 | unsigned long ProvideVersion; // Stringtable | |
225 | unsigned long NextProvides; // Provides | |
226 | unsigned long NextPkgProv; // Provides | |
227 | }; | |
228 | ||
229 | struct pkgCache::StringItem | |
230 | { | |
231 | unsigned long String; // Stringtable | |
232 | unsigned long NextItem; // StringItem | |
233 | }; | |
234 | ||
235 | #include <pkglib/cacheiterators.h> | |
236 | ||
237 | inline pkgCache::PkgIterator pkgCache::PkgBegin() | |
238 | {return PkgIterator(*this);}; | |
239 | inline pkgCache::PkgIterator pkgCache::PkgEnd() | |
240 | {return PkgIterator(*this,PkgP);}; | |
241 | ||
242 | #endif |