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