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