- add solvable2str function to make things easier and more flexible
[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 POOL_H
14 #define 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   int verbose;          // pool is used everywhere, so put the verbose flag here
67
68   struct _Stringpool ss;
69
70   Reldep *rels;               // table of rels: Id -> Reldep
71   int nrels;                  // number of unique rels
72   Hashtable relhashtbl;       // hash table: (name,evr,op ->) Hash -> Id
73   Hashmask relhashmask;
74
75   struct _Repo **repos;
76   int nrepos;
77
78   Solvable *solvables;
79   int nsolvables;
80
81   int promoteepoch;             /* 0/1  */
82
83   Id *id2arch;                  /* map arch ids to scores */
84   Id lastarch;                  /* last valid entry in id2arch */
85   Queue vendormap;              /* map vendor to vendorclasses mask */
86
87   /* providers data, as two-step indirect list
88    * whatprovides[Id] -> Offset into whatprovidesdata for name
89    * whatprovidesdata[Offset] -> ID_NULL-terminated list of solvables providing Id
90    */
91   Offset *whatprovides;         /* Offset to providers of a specific name, Id -> Offset  */
92   Id *whatprovidesdata;         /* Ids of solvable providing Id */
93   Offset whatprovidesdataoff;   /* next free slot within whatprovidesdata */
94   int whatprovidesdataleft;     /* number of 'free slots' within whatprovidesdata */
95
96   Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr);
97   void *nscallbackdata;
98
99   /* our dep2str string space */
100   char *dep2strbuf[DEP2STRBUF];
101   int   dep2strlen[DEP2STRBUF];
102   int   dep2strn;
103 };
104
105 #define TYPE_ID                 1
106 #define TYPE_IDARRAY            2
107 #define TYPE_STR                3
108 #define TYPE_U32                4
109 #define TYPE_BITMAP             128
110
111
112 //-----------------------------------------------
113
114
115 /* mark dependencies with relation by setting bit31 */
116
117 #define MAKERELDEP(id) ((id) | 0x80000000)
118 #define ISRELDEP(id) (((id) & 0x80000000) != 0)
119 #define GETRELID(pool, id) ((pool)->ss.nstrings + ((id) ^ 0x80000000))     /* returns Id  */
120 #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000))        /* returns Reldep* */
121
122 #define REL_GT          1
123 #define REL_EQ          2
124 #define REL_LT          4
125
126 #define REL_AND         16
127 #define REL_OR          17
128 #define REL_WITH        18
129 #define REL_NAMESPACE   19
130
131 /**
132  * Creates a new pool
133  */
134 extern Pool *pool_create(void);
135 /**
136  * Delete a pool
137  */
138 extern void pool_free(Pool *pool);
139
140 /**
141  * Solvable management
142  */
143 extern Id pool_add_solvable(Pool *pool);
144 extern Id pool_add_solvable_block(Pool *pool, int count);
145
146 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
147 static inline Solvable *pool_id2solvable(Pool *pool, Id p)
148 {
149   return pool->solvables + p;
150 }
151 extern const char *solvable2str(Pool *pool, Solvable *s);
152
153
154 /**
155  * Prepares a pool for solving
156  */
157 extern void pool_createwhatprovides(Pool *pool);
158 extern void pool_freewhatprovides(Pool *pool);
159 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);
160
161 static inline int pool_installable(Pool *pool, Solvable *s)
162 {
163   if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
164     return 0;
165   if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
166     return 0;
167   return 1;
168 }
169
170 extern Id *pool_addrelproviders(Pool *pool, Id d);
171
172 static inline Id *pool_whatprovides(Pool *pool, Id d)
173 {
174   Id v;
175   if (!ISRELDEP(d))
176     return pool->whatprovidesdata + pool->whatprovides[d];
177   v = GETRELID(pool, d);
178   if (pool->whatprovides[v])
179     return pool->whatprovidesdata + pool->whatprovides[v];
180   return pool_addrelproviders(pool, d);
181 }
182
183 /* loop over all providers of d */
184 #define FOR_PROVIDES(v, vp, d)                                          \
185   for (vp = pool_whatprovides(pool, d) ; (v = *vp++) != 0; )
186
187
188 #ifdef __cplusplus
189 }
190 #endif
191
192 #endif /* POOL_H */