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