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