- use schema in repodata to make it extendible
[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 SYSTEM_SYSTEM           20
50 #define ARCH_SRC                21
51 #define ARCH_NOSRC              22
52 #define ARCH_NOARCH             23
53 #define REPODATA_EXTERNAL       24
54 #define REPODATA_KEYS           25
55 #define REPODATA_LOCATION       26
56
57 #define ID_NUM_INTERNAL         27
58
59
60 /* well known solvable */
61 #define SYSTEMSOLVABLE          1
62
63
64 /* how many strings to maintain (round robin) */
65 #define DEP2STRBUF 16
66
67 //-----------------------------------------------
68
69 struct _Repo;
70
71 struct _Pool {
72   struct _Stringpool ss;
73
74   Reldep *rels;               // table of rels: Id -> Reldep
75   int nrels;                  // number of unique rels
76   Hashtable relhashtbl;       // hash table: (name,evr,op ->) Hash -> Id
77   Hashmask relhashmask;
78
79   struct _Repo **repos;
80   int nrepos;
81
82   Solvable *solvables;
83   int nsolvables;
84
85   int promoteepoch;             /* 0/1  */
86
87   Id *id2arch;                  /* map arch ids to scores */
88   Id lastarch;                  /* last valid entry in id2arch */
89   Queue vendormap;              /* map vendor to vendorclasses mask */
90
91   /* providers data, as two-step indirect list
92    * whatprovides[Id] -> Offset into whatprovidesdata for name
93    * whatprovidesdata[Offset] -> ID_NULL-terminated list of solvables providing Id
94    */
95   Offset *whatprovides;         /* Offset to providers of a specific name, Id -> Offset  */
96   Offset *whatprovides_rel;     /* Offset to providers of a specific relation, Id -> Offset  */
97
98   Id *whatprovidesdata;         /* Ids of solvable providing Id */
99   Offset whatprovidesdataoff;   /* next free slot within whatprovidesdata */
100   int whatprovidesdataleft;     /* number of 'free slots' within whatprovidesdata */
101
102   Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr);
103   void *nscallbackdata;
104
105   /* our dep2str string space */
106   char *dep2strbuf[DEP2STRBUF];
107   int   dep2strlen[DEP2STRBUF];
108   int   dep2strn;
109
110   /* debug mask and callback */
111   int  debugmask;
112   void (*debugcallback)(struct _Pool *, void *data, int type, const char *str);
113   void *debugcallbackdata;
114 };
115
116 #define SAT_FATAL                       (1<<0)
117 #define SAT_ERROR                       (1<<1)
118 #define SAT_WARN                        (1<<2)
119 #define SAT_DEBUG_STATS                 (1<<3)
120 #define SAT_DEBUG_RULE_CREATION         (1<<4)
121 #define SAT_DEBUG_PROPAGATE             (1<<5)
122 #define SAT_DEBUG_ANALYZE               (1<<6)
123 #define SAT_DEBUG_UNSOLVABLE            (1<<7)
124 #define SAT_DEBUG_SOLUTIONS             (1<<8)
125 #define SAT_DEBUG_POLICY                (1<<9)
126 #define SAT_DEBUG_RESULT                (1<<10)
127 #define SAT_DEBUG_JOB                   (1<<11)
128 #define SAT_DEBUG_SCHUBI                (1<<12)
129
130 #define TYPE_VOID               0
131 #define TYPE_ID                 1
132 #define TYPE_IDARRAY            2
133 #define TYPE_STR                3
134 #define TYPE_U32                4
135 #define TYPE_REL_IDARRAY        5
136
137 #define TYPE_ATTR_INT           6
138 #define TYPE_ATTR_CHUNK         7
139 #define TYPE_ATTR_STRING        8
140 #define TYPE_ATTR_INTLIST       9
141 #define TYPE_ATTR_LOCALIDS      10
142
143 #define TYPE_COUNT_NAMED        11
144 #define TYPE_COUNTED            12
145 #define TYPE_ATTR_TYPE_MAX      12
146
147 #define TYPE_IDVALUEARRAY       13
148 #define TYPE_IDVALUEVALUEARRAY  14
149
150 //-----------------------------------------------
151
152
153 /* mark dependencies with relation by setting bit31 */
154
155 #define MAKERELDEP(id) ((id) | 0x80000000)
156 #define ISRELDEP(id) (((id) & 0x80000000) != 0)
157 #define GETRELID(id) ((id) ^ 0x80000000)                                /* returns Id */
158 #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000))        /* returns Reldep* */
159
160 #define REL_GT          1
161 #define REL_EQ          2
162 #define REL_LT          4
163
164 #define REL_AND         16
165 #define REL_OR          17
166 #define REL_WITH        18
167 #define REL_NAMESPACE   19
168
169 #if !defined(__GNUC__) && !defined(__attribute__)
170 # define __attribute__(x)
171 #endif
172
173 /**
174  * Creates a new pool
175  */
176 extern Pool *pool_create(void);
177 /**
178  * Delete a pool
179  */
180 extern void pool_free(Pool *pool);
181
182 extern void pool_debug(Pool *pool, int type, const char *format, ...) __attribute__((format(printf, 3, 4)));
183
184 /**
185  * Solvable management
186  */
187 extern Id pool_add_solvable(Pool *pool);
188 extern Id pool_add_solvable_block(Pool *pool, int count);
189
190 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
191 static inline Solvable *pool_id2solvable(Pool *pool, Id p)
192 {
193   return pool->solvables + p;
194 }
195 extern const char *solvable2str(Pool *pool, Solvable *s);
196
197
198 /**
199  * Prepares a pool for solving
200  */
201 extern void pool_createwhatprovides(Pool *pool);
202 extern void pool_freewhatprovides(Pool *pool);
203 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);
204
205 static inline int pool_installable(Pool *pool, Solvable *s)
206 {
207   if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
208     return 0;
209   if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
210     return 0;
211   return 1;
212 }
213
214 extern Id *pool_addrelproviders(Pool *pool, Id d);
215
216 static inline Id *pool_whatprovides(Pool *pool, Id d)
217 {
218   Id v;
219   if (!ISRELDEP(d))
220     return pool->whatprovidesdata + pool->whatprovides[d];
221   v = GETRELID(d);
222   if (pool->whatprovides_rel[v])
223     return pool->whatprovidesdata + pool->whatprovides_rel[v];
224   return pool_addrelproviders(pool, d);
225 }
226
227 extern void pool_setdebuglevel(Pool *pool, int level);
228
229 static inline void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
230 {
231   pool->debugcallback = debugcallback;
232   pool->debugcallbackdata = debugcallbackdata;
233 }
234
235 static inline void pool_setdebugmask(Pool *pool, int mask)
236 {
237   pool->debugmask = mask;
238 }
239
240 /* loop over all providers of d */
241 #define FOR_PROVIDES(v, vp, d)                                          \
242   for (vp = pool_whatprovides(pool, d) ; (v = *vp++) != 0; )
243
244 #define POOL_DEBUG(type, ...) do {if ((pool->debugmask & (type)) != 0) pool_debug(pool, (type), __VA_ARGS__);} while (0)
245 #define IF_POOLDEBUG(type) if ((pool->debugmask & (type)) != 0)
246
247 #ifdef __cplusplus
248 }
249 #endif
250
251
252 #endif /* SATSOLVER_POOL_H */