- add HEADEREND
[platform/upstream/libsolv.git] / src / pool.h
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * pool.h
10  * 
11  */
12
13 #ifndef SATSOLVER_POOL_H
14 #define SATSOLVER_POOL_H
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <stdio.h>
21
22 #include "pooltypes.h"
23 #include "poolid.h"
24 #include "solvable.h"
25 #include "bitmap.h"
26 #include "queue.h"
27 #include "strpool.h"
28
29 // see initpool_data[] in pool.c
30
31 /* well known ids */
32 #define ID_NULL                 STRID_NULL
33 #define ID_EMPTY                STRID_EMPTY
34 #define SOLVABLE_NAME           2
35 #define SOLVABLE_ARCH           3
36 #define SOLVABLE_EVR            4
37 #define SOLVABLE_VENDOR         5
38 #define SOLVABLE_PROVIDES       6
39 #define SOLVABLE_OBSOLETES      7
40 #define SOLVABLE_CONFLICTS      8
41 #define SOLVABLE_REQUIRES       9
42 #define SOLVABLE_RECOMMENDS     10
43 #define SOLVABLE_SUGGESTS       11
44 #define SOLVABLE_SUPPLEMENTS    12
45 #define SOLVABLE_ENHANCES       13
46 #define SOLVABLE_FRESHENS       14
47 #define RPM_RPMDBID             15
48 #define SOLVABLE_PREREQMARKER   16              // normal requires before this, prereqs after this
49 #define SOLVABLE_FILEMARKER     17              // normal provides before this, generated file provides after this
50 #define NAMESPACE_INSTALLED     18
51 #define NAMESPACE_MODALIAS      19
52 #define NAMESPACE_SPLITPROVIDES 20
53 #define NAMESPACE_LANGUAGE      21
54 #define NAMESPACE_FILESYSTEM    22
55 #define SYSTEM_SYSTEM           23
56 #define ARCH_SRC                24
57 #define ARCH_NOSRC              25
58 #define ARCH_NOARCH             26
59 #define REPODATA_EXTERNAL       27
60 #define REPODATA_KEYS           28
61 #define REPODATA_LOCATION       29
62
63 /* The void type is usable to encode one-valued attributes, they have
64    no associated data.  This is useful to encode values which many solvables
65    have in common, and whose overall set is relatively limited.  A prime
66    example would be the media number.  The actual value is encoded in the
67    SIZE member of the key structure.  Be warned: careless use of this
68    leads to combinatoric explosion of number of schemas.  */
69 #define REPOKEY_TYPE_VOID       30
70 #define REPOKEY_TYPE_CONSTANT   31
71 #define REPOKEY_TYPE_CONSTANTID 32
72 #define REPOKEY_TYPE_ID         33
73 #define REPOKEY_TYPE_NUM        34
74 #define REPOKEY_TYPE_U32        35
75 #define REPOKEY_TYPE_DIR        36
76 #define REPOKEY_TYPE_STR        37
77 #define REPOKEY_TYPE_IDARRAY    38
78 #define REPOKEY_TYPE_REL_IDARRAY        39
79 #define REPOKEY_TYPE_DIRSTRARRAY        40
80 #define REPOKEY_TYPE_DIRNUMNUMARRAY     41
81
82 #define SOLVABLE_SUMMARY        42
83 #define SOLVABLE_DESCRIPTION    43
84 #define SOLVABLE_AUTHORS        44
85 #define SOLVABLE_GROUP          45
86 #define SOLVABLE_KEYWORDS       46
87 #define SOLVABLE_LICENSE        47
88 #define SOLVABLE_BUILDTIME      48
89 #define SOLVABLE_EULA           49
90 #define SOLVABLE_MESSAGEINS     50
91 #define SOLVABLE_MESSAGEDEL     51
92 #define SOLVABLE_INSTALLSIZE    52
93 #define SOLVABLE_DISKUSAGE      53
94 #define SOLVABLE_FILELIST       54
95 #define SOLVABLE_INSTALLTIME    55
96 #define SOLVABLE_MEDIADIR       56
97 #define SOLVABLE_MEDIAFILE      57
98 #define SOLVABLE_MEDIANR        58
99 #define SOLVABLE_DOWNLOADSIZE   59
100 #define SOLVABLE_SOURCEARCH     60
101 #define SOLVABLE_SOURCENAME     61
102 #define SOLVABLE_SOURCEEVR      62
103 #define SOLVABLE_ISVISIBLE      63
104
105 #define SOLVABLE_PATCHCATEGORY  64
106 #define SOLVABLE_HEADEREND      65
107
108 #define ID_NUM_INTERNAL         66
109
110
111 /* well known solvable */
112 #define SYSTEMSOLVABLE          1
113
114
115 /* how many strings to maintain (round robin) */
116 #define POOL_TMPSPACEBUF 16
117
118 //-----------------------------------------------
119
120 struct _Repo;
121 struct _Repodata;
122 struct _Repokey;
123 struct _KeyValue;
124
125 struct _Pool {
126   struct _Stringpool ss;
127
128   Reldep *rels;               // table of rels: Id -> Reldep
129   int nrels;                  // number of unique rels
130   Hashtable relhashtbl;       // hash table: (name,evr,op ->) Hash -> Id
131   Hashmask relhashmask;
132
133   struct _Repo **repos;
134   int nrepos;
135
136   Solvable *solvables;
137   int nsolvables;
138
139   const char **languages;
140   int nlanguages;
141   Id *languagecache;
142   int languagecacheother;
143
144   int promoteepoch;             /* 0/1  */
145
146   Id *id2arch;                  /* map arch ids to scores */
147   Id lastarch;                  /* last valid entry in id2arch */
148   Queue vendormap;              /* map vendor to vendorclasses mask */
149
150   /* providers data, as two-step indirect list
151    * whatprovides[Id] -> Offset into whatprovidesdata for name
152    * whatprovidesdata[Offset] -> ID_NULL-terminated list of solvables providing Id
153    */
154   Offset *whatprovides;         /* Offset to providers of a specific name, Id -> Offset  */
155   Offset *whatprovides_rel;     /* Offset to providers of a specific relation, Id -> Offset  */
156
157   Id *whatprovidesdata;         /* Ids of solvable providing Id */
158   Offset whatprovidesdataoff;   /* next free slot within whatprovidesdata */
159   int whatprovidesdataleft;     /* number of 'free slots' within whatprovidesdata */
160
161   /* If nonzero, then consider only the solvables with Ids set in this
162      bitmap for solving.  If zero, consider all solvables.  */
163   Map *considered;
164
165   Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr);
166   void *nscallbackdata;
167
168   /* our tmp space string space */
169   char *tmpspacebuf[POOL_TMPSPACEBUF];
170   int   tmpspacelen[POOL_TMPSPACEBUF];
171   int   tmpspacen;
172
173   /* debug mask and callback */
174   int  debugmask;
175   void (*debugcallback)(struct _Pool *, void *data, int type, const char *str);
176   void *debugcallbackdata;
177
178   /* load callback */
179   FILE * (*loadcallback)(struct _Pool *, struct _Repodata *, void *);
180   void *loadcallbackdata;
181 };
182
183 #define SAT_FATAL                       (1<<0)
184 #define SAT_ERROR                       (1<<1)
185 #define SAT_WARN                        (1<<2)
186 #define SAT_DEBUG_STATS                 (1<<3)
187 #define SAT_DEBUG_RULE_CREATION         (1<<4)
188 #define SAT_DEBUG_PROPAGATE             (1<<5)
189 #define SAT_DEBUG_ANALYZE               (1<<6)
190 #define SAT_DEBUG_UNSOLVABLE            (1<<7)
191 #define SAT_DEBUG_SOLUTIONS             (1<<8)
192 #define SAT_DEBUG_POLICY                (1<<9)
193 #define SAT_DEBUG_RESULT                (1<<10)
194 #define SAT_DEBUG_JOB                   (1<<11)
195 #define SAT_DEBUG_SCHUBI                (1<<12)
196
197 //-----------------------------------------------
198
199
200 /* mark dependencies with relation by setting bit31 */
201
202 #define MAKERELDEP(id) ((id) | 0x80000000)
203 #define ISRELDEP(id) (((id) & 0x80000000) != 0)
204 #define GETRELID(id) ((id) ^ 0x80000000)                                /* returns Id */
205 #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000))        /* returns Reldep* */
206
207 #define REL_GT          1
208 #define REL_EQ          2
209 #define REL_LT          4
210
211 #define REL_AND         16
212 #define REL_OR          17
213 #define REL_WITH        18
214 #define REL_NAMESPACE   19
215
216 #if !defined(__GNUC__) && !defined(__attribute__)
217 # define __attribute__(x)
218 #endif
219
220 /**
221  * Creates a new pool
222  */
223 extern Pool *pool_create(void);
224 /**
225  * Delete a pool
226  */
227 extern void pool_free(Pool *pool);
228
229 extern void pool_debug(Pool *pool, int type, const char *format, ...) __attribute__((format(printf, 3, 4)));
230
231 extern char *pool_alloctmpspace(Pool *pool, int len);
232
233 /**
234  * Solvable management
235  */
236 extern Id pool_add_solvable(Pool *pool);
237 extern Id pool_add_solvable_block(Pool *pool, int count);
238
239 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
240 static inline Solvable *pool_id2solvable(Pool *pool, Id p)
241 {
242   return pool->solvables + p;
243 }
244 extern const char *solvable2str(Pool *pool, Solvable *s);
245
246 void pool_set_languages(Pool *pool, const char **languages, int nlanguages);
247
248 unsigned int solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound);
249 const char *solvable_lookup_str(Solvable *s, Id keyname);
250 const char *solvable_lookup_str_lang(Solvable *s, Id keyname);
251 int solvable_lookup_bool(Solvable *s, Id keyname);
252 char * solvable_get_location(Solvable *s, unsigned int *medianrp);
253
254
255
256 /**
257  * Prepares a pool for solving
258  */
259 extern void pool_createwhatprovides(Pool *pool);
260 extern void pool_addfileprovides(Pool *pool, struct _Repo *installed);
261 extern void pool_freewhatprovides(Pool *pool);
262 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);
263
264 static inline int pool_installable(Pool *pool, Solvable *s)
265 {
266   if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
267     return 0;
268   if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
269     return 0;
270   if (pool->considered)
271     { 
272       Id id = s - pool->solvables;
273       if (!MAPTST(pool->considered, id))
274         return 0;
275     }
276   return 1;
277 }
278
279 extern Id *pool_addrelproviders(Pool *pool, Id d);
280
281 static inline Id *pool_whatprovides(Pool *pool, Id d)
282 {
283   Id v;
284   if (!ISRELDEP(d))
285     return pool->whatprovidesdata + pool->whatprovides[d];
286   v = GETRELID(d);
287   if (pool->whatprovides_rel[v])
288     return pool->whatprovidesdata + pool->whatprovides_rel[v];
289   return pool_addrelproviders(pool, d);
290 }
291
292 extern void pool_setdebuglevel(Pool *pool, int level);
293
294 static inline void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
295 {
296   pool->debugcallback = debugcallback;
297   pool->debugcallbackdata = debugcallbackdata;
298 }
299
300 static inline void pool_setdebugmask(Pool *pool, int mask)
301 {
302   pool->debugmask = mask;
303 }
304
305 static inline void pool_setloadcallback(Pool *pool, FILE *(*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
306 {
307   pool->loadcallback = cb;
308   pool->loadcallbackdata = loadcbdata;
309 }
310
311 /* search the pool. the following filters are available:
312  *   p     - search just this solvable
313  *   key   - search only this key
314  *   match - key must match this string
315  */
316 void pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, struct _Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata);
317
318 /* loop over all providers of d */
319 #define FOR_PROVIDES(v, vp, d)                                          \
320   for (vp = pool_whatprovides(pool, d) ; (v = *vp++) != 0; )
321
322 #define POOL_DEBUG(type, ...) do {if ((pool->debugmask & (type)) != 0) pool_debug(pool, (type), __VA_ARGS__);} while (0)
323 #define IF_POOLDEBUG(type) if ((pool->debugmask & (type)) != 0)
324
325 #ifdef __cplusplus
326 }
327 #endif
328
329
330 #endif /* SATSOLVER_POOL_H */