2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef SATSOLVER_POOL_H
14 #define SATSOLVER_POOL_H
22 #include "pooltypes.h"
29 // see initpool_data[] in pool.c
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
57 #define ARCH_NOARCH 25
58 #define REPODATA_EXTERNAL 26
59 #define REPODATA_KEYS 27
60 #define REPODATA_LOCATION 28
62 #define ID_NUM_INTERNAL 29
65 /* well known solvable */
66 #define SYSTEMSOLVABLE 1
69 /* how many strings to maintain (round robin) */
72 //-----------------------------------------------
78 struct _Stringpool ss;
80 Reldep *rels; // table of rels: Id -> Reldep
81 int nrels; // number of unique rels
82 Hashtable relhashtbl; // hash table: (name,evr,op ->) Hash -> Id
91 int promoteepoch; /* 0/1 */
93 Id *id2arch; /* map arch ids to scores */
94 Id lastarch; /* last valid entry in id2arch */
95 Queue vendormap; /* map vendor to vendorclasses mask */
97 /* providers data, as two-step indirect list
98 * whatprovides[Id] -> Offset into whatprovidesdata for name
99 * whatprovidesdata[Offset] -> ID_NULL-terminated list of solvables providing Id
101 Offset *whatprovides; /* Offset to providers of a specific name, Id -> Offset */
102 Offset *whatprovides_rel; /* Offset to providers of a specific relation, Id -> Offset */
104 Id *whatprovidesdata; /* Ids of solvable providing Id */
105 Offset whatprovidesdataoff; /* next free slot within whatprovidesdata */
106 int whatprovidesdataleft; /* number of 'free slots' within whatprovidesdata */
108 /* If nonzero, then consider only the solvables with Ids set in this
109 bitmap for solving. If zero, consider all solvables. */
112 Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr);
113 void *nscallbackdata;
115 /* our dep2str string space */
116 char *dep2strbuf[DEP2STRBUF];
117 int dep2strlen[DEP2STRBUF];
120 /* debug mask and callback */
122 void (*debugcallback)(struct _Pool *, void *data, int type, const char *str);
123 void *debugcallbackdata;
126 FILE * (*loadcallback)(struct _Pool *, struct _Repodata *, void *);
127 void *loadcallbackdata;
130 #define SAT_FATAL (1<<0)
131 #define SAT_ERROR (1<<1)
132 #define SAT_WARN (1<<2)
133 #define SAT_DEBUG_STATS (1<<3)
134 #define SAT_DEBUG_RULE_CREATION (1<<4)
135 #define SAT_DEBUG_PROPAGATE (1<<5)
136 #define SAT_DEBUG_ANALYZE (1<<6)
137 #define SAT_DEBUG_UNSOLVABLE (1<<7)
138 #define SAT_DEBUG_SOLUTIONS (1<<8)
139 #define SAT_DEBUG_POLICY (1<<9)
140 #define SAT_DEBUG_RESULT (1<<10)
141 #define SAT_DEBUG_JOB (1<<11)
142 #define SAT_DEBUG_SCHUBI (1<<12)
144 /* The void type is usable to encode one-valued attributes, they have
145 no associated data. This is useful to encode values which many solvables
146 have in common, and whose overall set is relatively limited. A prime
147 example would be the media number. The actual value is encoded in the
148 SIZE member of the key structure. Be warned: careless use of this
149 leads to combinatoric explosion of number of schemas. */
152 #define TYPE_IDARRAY 2
155 #define TYPE_REL_IDARRAY 5
157 #define TYPE_ATTR_INT 6
158 #define TYPE_ATTR_CHUNK 7
159 #define TYPE_ATTR_STRING 8
160 #define TYPE_ATTR_INTLIST 9
161 #define TYPE_ATTR_LOCALIDS 10
163 #define TYPE_COUNT_NAMED 11
164 #define TYPE_COUNTED 12
166 #define TYPE_IDVALUEARRAY 13
169 #define TYPE_DIRNUMNUMARRAY 15
170 #define TYPE_DIRSTRARRAY 16
172 #define TYPE_CONSTANT 17
175 #define TYPE_ATTR_TYPE_MAX 18
177 //-----------------------------------------------
180 /* mark dependencies with relation by setting bit31 */
182 #define MAKERELDEP(id) ((id) | 0x80000000)
183 #define ISRELDEP(id) (((id) & 0x80000000) != 0)
184 #define GETRELID(id) ((id) ^ 0x80000000) /* returns Id */
185 #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000)) /* returns Reldep* */
194 #define REL_NAMESPACE 19
196 #if !defined(__GNUC__) && !defined(__attribute__)
197 # define __attribute__(x)
203 extern Pool *pool_create(void);
207 extern void pool_free(Pool *pool);
209 extern void pool_debug(Pool *pool, int type, const char *format, ...) __attribute__((format(printf, 3, 4)));
212 * Solvable management
214 extern Id pool_add_solvable(Pool *pool);
215 extern Id pool_add_solvable_block(Pool *pool, int count);
217 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
218 static inline Solvable *pool_id2solvable(Pool *pool, Id p)
220 return pool->solvables + p;
222 extern const char *solvable2str(Pool *pool, Solvable *s);
226 * Prepares a pool for solving
228 extern void pool_createwhatprovides(Pool *pool);
229 extern void pool_addfileprovides(Pool *pool, struct _Repo *installed);
230 extern void pool_freewhatprovides(Pool *pool);
231 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);
233 static inline int pool_installable(Pool *pool, Solvable *s)
235 if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
237 if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
239 if (pool->considered)
241 Id id = s - pool->solvables;
242 if (!MAPTST(pool->considered, id))
248 extern Id *pool_addrelproviders(Pool *pool, Id d);
250 static inline Id *pool_whatprovides(Pool *pool, Id d)
254 return pool->whatprovidesdata + pool->whatprovides[d];
256 if (pool->whatprovides_rel[v])
257 return pool->whatprovidesdata + pool->whatprovides_rel[v];
258 return pool_addrelproviders(pool, d);
261 extern void pool_setdebuglevel(Pool *pool, int level);
263 static inline void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
265 pool->debugcallback = debugcallback;
266 pool->debugcallbackdata = debugcallbackdata;
269 static inline void pool_setdebugmask(Pool *pool, int mask)
271 pool->debugmask = mask;
274 static inline void pool_setloadcallback(Pool *pool, FILE *(*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
276 pool->loadcallback = cb;
277 pool->loadcallbackdata = loadcbdata;
280 /* loop over all providers of d */
281 #define FOR_PROVIDES(v, vp, d) \
282 for (vp = pool_whatprovides(pool, d) ; (v = *vp++) != 0; )
284 #define POOL_DEBUG(type, ...) do {if ((pool->debugmask & (type)) != 0) pool_debug(pool, (type), __VA_ARGS__);} while (0)
285 #define IF_POOLDEBUG(type) if ((pool->debugmask & (type)) != 0)
292 #endif /* SATSOLVER_POOL_H */