compile
[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 "pooltypes.h"
21 #include "poolid.h"
22 #include "solvable.h"
23 #include "queue.h"
24 #include "strpool.h"
25
26 // see initpool_data[] in pool.c
27
28 /* well known ids */
29 #define ID_NULL                 STRID_NULL
30 #define ID_EMPTY                STRID_EMPTY
31 #define SOLVABLE_NAME           2
32 #define SOLVABLE_ARCH           3
33 #define SOLVABLE_EVR            4
34 #define SOLVABLE_VENDOR         5
35 #define SOLVABLE_PROVIDES       6
36 #define SOLVABLE_OBSOLETES      7
37 #define SOLVABLE_CONFLICTS      8
38 #define SOLVABLE_REQUIRES       9
39 #define SOLVABLE_RECOMMENDS     10
40 #define SOLVABLE_SUGGESTS       11
41 #define SOLVABLE_SUPPLEMENTS    12
42 #define SOLVABLE_ENHANCES       13
43 #define SOLVABLE_FRESHENS       14
44 #define RPM_RPMDBID             15
45 #define SOLVABLE_PREREQMARKER   16              // normal requires before this, prereqs after this
46 #define SOLVABLE_FILEMARKER     17              // normal provides before this, generated file provides after this
47 #define NAMESPACE_INSTALLED     18
48 #define NAMESPACE_MODALIAS      19
49 #define NAMESPACE_SPLITPROVIDES 20
50 #define NAMESPACE_LANGUAGE      21
51 #define SYSTEM_SYSTEM           22
52 #define ARCH_SRC                23
53 #define ARCH_NOSRC              24
54 #define ARCH_NOARCH             25
55 #define REPODATA_EXTERNAL       26
56 #define REPODATA_KEYS           27
57 #define REPODATA_LOCATION       28
58
59 #define ID_NUM_INTERNAL         29
60
61
62 /* well known solvable */
63 #define SYSTEMSOLVABLE          1
64
65
66 /* how many strings to maintain (round robin) */
67 #define DEP2STRBUF 16
68
69 //-----------------------------------------------
70
71 struct FILE;
72 struct _Repo;
73 struct _Repodata;
74
75 struct _Pool {
76   struct _Stringpool ss;
77
78   Reldep *rels;               // table of rels: Id -> Reldep
79   int nrels;                  // number of unique rels
80   Hashtable relhashtbl;       // hash table: (name,evr,op ->) Hash -> Id
81   Hashmask relhashmask;
82
83   struct _Repo **repos;
84   int nrepos;
85
86   Solvable *solvables;
87   int nsolvables;
88
89   int promoteepoch;             /* 0/1  */
90
91   Id *id2arch;                  /* map arch ids to scores */
92   Id lastarch;                  /* last valid entry in id2arch */
93   Queue vendormap;              /* map vendor to vendorclasses mask */
94
95   /* providers data, as two-step indirect list
96    * whatprovides[Id] -> Offset into whatprovidesdata for name
97    * whatprovidesdata[Offset] -> ID_NULL-terminated list of solvables providing Id
98    */
99   Offset *whatprovides;         /* Offset to providers of a specific name, Id -> Offset  */
100   Offset *whatprovides_rel;     /* Offset to providers of a specific relation, Id -> Offset  */
101
102   Id *whatprovidesdata;         /* Ids of solvable providing Id */
103   Offset whatprovidesdataoff;   /* next free slot within whatprovidesdata */
104   int whatprovidesdataleft;     /* number of 'free slots' within whatprovidesdata */
105
106   Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr);
107   void *nscallbackdata;
108
109   /* our dep2str string space */
110   char *dep2strbuf[DEP2STRBUF];
111   int   dep2strlen[DEP2STRBUF];
112   int   dep2strn;
113
114   /* debug mask and callback */
115   int  debugmask;
116   void (*debugcallback)(struct _Pool *, void *data, int type, const char *str);
117   void *debugcallbackdata;
118
119   /* load callback */
120   FILE * (*loadcallback)(struct _Pool *, struct _Repodata *, void *);
121   void *loadcallbackdata;
122 };
123
124 #define SAT_FATAL                       (1<<0)
125 #define SAT_ERROR                       (1<<1)
126 #define SAT_WARN                        (1<<2)
127 #define SAT_DEBUG_STATS                 (1<<3)
128 #define SAT_DEBUG_RULE_CREATION         (1<<4)
129 #define SAT_DEBUG_PROPAGATE             (1<<5)
130 #define SAT_DEBUG_ANALYZE               (1<<6)
131 #define SAT_DEBUG_UNSOLVABLE            (1<<7)
132 #define SAT_DEBUG_SOLUTIONS             (1<<8)
133 #define SAT_DEBUG_POLICY                (1<<9)
134 #define SAT_DEBUG_RESULT                (1<<10)
135 #define SAT_DEBUG_JOB                   (1<<11)
136 #define SAT_DEBUG_SCHUBI                (1<<12)
137
138 /* The void type is usable to encode one-valued attributes, they have
139    no associated data.  This is useful to encode values which many solvables
140    have in common, and whose overall set is relatively limited.  A prime
141    example would be the media number.  The actual value is encoded in the
142    SIZE member of the key structure.  Be warned: careless use of this
143    leads to combinatoric explosion of number of schemas.  */
144 #define TYPE_VOID               0
145 #define TYPE_ID                 1
146 #define TYPE_IDARRAY            2
147 #define TYPE_STR                3
148 #define TYPE_U32                4
149 #define TYPE_REL_IDARRAY        5
150
151 #define TYPE_ATTR_INT           6
152 #define TYPE_ATTR_CHUNK         7
153 #define TYPE_ATTR_STRING        8
154 #define TYPE_ATTR_INTLIST       9
155 #define TYPE_ATTR_LOCALIDS      10
156
157 #define TYPE_COUNT_NAMED        11
158 #define TYPE_COUNTED            12
159
160 #define TYPE_IDVALUEARRAY       13
161
162 #define TYPE_DIR                14
163 #define TYPE_DIRNUMNUMARRAY     15
164 #define TYPE_DIRSTRARRAY        16
165
166 #define TYPE_CONSTANT           17
167 #define TYPE_NUM                18
168
169 #define TYPE_ATTR_TYPE_MAX      18
170
171 //-----------------------------------------------
172
173
174 /* mark dependencies with relation by setting bit31 */
175
176 #define MAKERELDEP(id) ((id) | 0x80000000)
177 #define ISRELDEP(id) (((id) & 0x80000000) != 0)
178 #define GETRELID(id) ((id) ^ 0x80000000)                                /* returns Id */
179 #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000))        /* returns Reldep* */
180
181 #define REL_GT          1
182 #define REL_EQ          2
183 #define REL_LT          4
184
185 #define REL_AND         16
186 #define REL_OR          17
187 #define REL_WITH        18
188 #define REL_NAMESPACE   19
189
190 #if !defined(__GNUC__) && !defined(__attribute__)
191 # define __attribute__(x)
192 #endif
193
194 /**
195  * Creates a new pool
196  */
197 extern Pool *pool_create(void);
198 /**
199  * Delete a pool
200  */
201 extern void pool_free(Pool *pool);
202
203 extern void pool_debug(Pool *pool, int type, const char *format, ...) __attribute__((format(printf, 3, 4)));
204
205 /**
206  * Solvable management
207  */
208 extern Id pool_add_solvable(Pool *pool);
209 extern Id pool_add_solvable_block(Pool *pool, int count);
210
211 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
212 static inline Solvable *pool_id2solvable(Pool *pool, Id p)
213 {
214   return pool->solvables + p;
215 }
216 extern const char *solvable2str(Pool *pool, Solvable *s);
217
218
219 /**
220  * Prepares a pool for solving
221  */
222 extern void pool_createwhatprovides(Pool *pool);
223 extern void pool_addfileprovides(Pool *pool, struct _Repo *installed);
224 extern void pool_freewhatprovides(Pool *pool);
225 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);
226
227 static inline int pool_installable(Pool *pool, Solvable *s)
228 {
229   if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
230     return 0;
231   if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
232     return 0;
233   return 1;
234 }
235
236 extern Id *pool_addrelproviders(Pool *pool, Id d);
237
238 static inline Id *pool_whatprovides(Pool *pool, Id d)
239 {
240   Id v;
241   if (!ISRELDEP(d))
242     return pool->whatprovidesdata + pool->whatprovides[d];
243   v = GETRELID(d);
244   if (pool->whatprovides_rel[v])
245     return pool->whatprovidesdata + pool->whatprovides_rel[v];
246   return pool_addrelproviders(pool, d);
247 }
248
249 extern void pool_setdebuglevel(Pool *pool, int level);
250
251 static inline void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
252 {
253   pool->debugcallback = debugcallback;
254   pool->debugcallbackdata = debugcallbackdata;
255 }
256
257 static inline void pool_setdebugmask(Pool *pool, int mask)
258 {
259   pool->debugmask = mask;
260 }
261
262 static inline void pool_setloadcallback(Pool *pool, FILE *(*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
263 {
264   pool->loadcallback = cb;
265   pool->loadcallbackdata = loadcbdata;
266 }
267
268 /* loop over all providers of d */
269 #define FOR_PROVIDES(v, vp, d)                                          \
270   for (vp = pool_whatprovides(pool, d) ; (v = *vp++) != 0; )
271
272 #define POOL_DEBUG(type, ...) do {if ((pool->debugmask & (type)) != 0) pool_debug(pool, (type), __VA_ARGS__);} while (0)
273 #define IF_POOLDEBUG(type) if ((pool->debugmask & (type)) != 0)
274
275 #ifdef __cplusplus
276 }
277 #endif
278
279
280 #endif /* SATSOLVER_POOL_H */