- beautify a bit
[platform/upstream/libsolv.git] / src / repo.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  * repo.h
10  * 
11  */
12
13 #ifndef SATSOLVER_REPO_H
14 #define SATSOLVER_REPO_H
15
16 #include "pooltypes.h"
17 #include "pool.h"
18 #if 0
19 #include "attr_store.h"
20 #endif
21 #include "repodata.h"
22
23 typedef struct _Repokey {
24   Id name;
25   Id type;               /* REPOKEY_TYPE_xxx */
26   unsigned int size;
27   unsigned int storage; /* KEY_STORAGE_xxx */
28 } Repokey;
29
30 #define KEY_STORAGE_DROPPED             0
31 #define KEY_STORAGE_SOLVABLE            1
32 #define KEY_STORAGE_INCORE              2
33 #define KEY_STORAGE_VERTICAL_OFFSET     3
34
35
36 typedef struct _Repo {
37   const char *name;
38   struct _Pool *pool;           /* pool containing repo data */
39
40   int start;                    /* start of this repo solvables within pool->solvables */
41   int end;                      /* last solvable + 1 of this repo */
42   int nsolvables;               /* number of solvables repo is contributing to pool */
43
44   int priority;                 /* priority of this repo */
45
46   Id *idarraydata;              /* array of metadata Ids, solvable dependencies are offsets into this array */
47   int idarraysize;
48   Offset lastoff;
49
50   Id *rpmdbid;                  /* hmm, go to repodata? */
51
52   Repodata *repodata;           /* our stores for non-solvable related data */
53   unsigned nrepodata;           /* number of our stores..  */
54 } Repo;
55
56 extern Repo *repo_create(Pool *pool, const char *name);
57 extern void repo_free(Repo *repo, int reuseids);
58 extern void repo_freeallrepos(Pool *pool, int reuseids);
59
60 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
61 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
62 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
63 extern Offset repo_fix_legacy(Repo *repo, Offset provides, Offset supplements);
64
65 static inline const char *repo_name(const Repo *repo)
66 {
67   return repo->name;
68 }
69
70 static inline Id repo_add_solvable(Repo *repo)
71 {
72   extern Id pool_add_solvable(Pool *pool);
73   Id p = pool_add_solvable(repo->pool);
74   if (!repo->start || repo->start == repo->end)
75     {
76       repo->start = p;
77       repo->end = p + 1;
78     }
79   else
80     {
81       if (p < repo->start)
82         repo->start = p;
83       if (p + 1 > repo->end)
84         repo->end = p + 1;
85     }
86   repo->nsolvables++;
87   repo->pool->solvables[p].repo = repo;
88   return p;
89 }
90
91 static inline Id repo_add_solvable_block(Repo *repo, int count)
92 {
93   extern Id pool_add_solvable_block(Pool *pool, int count);
94   Id p;
95   Solvable *s;
96   if (!count)
97     return 0;
98   p = pool_add_solvable_block(repo->pool, count);
99   if (!repo->start || repo->start == repo->end)
100     {
101       repo->start = p;
102       repo->end = p + count;
103     }
104   else
105     {
106       if (p < repo->start)
107         repo->start = p;
108       if (p + count > repo->end)
109         repo->end = p + count;
110     }
111   repo->nsolvables += count;
112   for (s = repo->pool->solvables + p; count--; s++)
113     s->repo = repo;
114   return p;
115 }
116
117 static inline void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
118 {
119   extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
120   Solvable *s;
121   int i;
122   if (start + count == repo->end)
123     repo->end -= count;
124   repo->nsolvables -= count;
125   for (s = repo->pool->solvables + start, i = count; i--; s++)
126     s->repo = 0;
127   pool_free_solvable_block(repo->pool, start, count, reuseids);
128 }
129
130 #define FOR_REPO_SOLVABLES(r, p, s)                                             \
131   for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p)   \
132     if (s->repo == (r))
133
134
135 /* search callback values */
136
137 #define SEARCH_NEXT_KEY         1
138 #define SEARCH_NEXT_SOLVABLE    2
139 #define SEARCH_STOP             3
140
141 typedef struct _KeyValue {
142   Id id;
143   const char *str;
144   int num;
145   int num2;
146   int eof;
147 } KeyValue;
148
149 /* search flags */
150 #define SEARCH_STRINGMASK       15
151 #define SEARCH_STRING           1
152 #define SEARCH_SUBSTRING        2
153 #define SEARCH_GLOB             3
154 #define SEARCH_REGEX            4
155
156 #define SEARCH_NOCASE                   (1<<8)
157 #define SEARCH_NO_STORAGE_SOLVABLE      (1<<9)
158
159 /* Internal */
160 #define __SEARCH_ONESOLVABLE            (1 << 31)
161
162 Repodata *repo_add_repodata(Repo *repo, int localpool);
163
164 void repo_search(Repo *repo, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata);
165
166 /* returns the string value of the attribute, or NULL if not found */
167 const char * repo_lookup_str(Solvable *s, Id key);
168 /* returns the integer value of the attribute, or 0 if not found */
169 int repo_lookup_num(Solvable *s, Id key);
170 /* generic attribute lookup */
171 int repo_lookup(Solvable *s, Id key, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata);
172
173 typedef struct _Dataiterator
174 {
175   Repodata *data;
176   Id *keyp;
177   unsigned char *nextkeydp;
178   unsigned char *dp;
179   Repokey *key;
180   Repo *repo;
181   Id *idp;
182   const char *match;
183   Id solvid;
184   Id keyname;
185   unsigned flags;
186   unsigned state;
187   KeyValue kv;
188 } Dataiterator;
189
190 /* Use these like:
191      Dataiterator di;
192      dataiterator_init(&di, repo, 0, 0, "bla", SEARCH_SUBSTRING);
193      while (dataiterator_step(&di))
194        dosomething(di.solvid, di.key, di.kv);  */
195 void dataiterator_init(Dataiterator *di, Repo *repo, Id p, Id keyname,
196                        const char *match, int flags);
197 int dataiterator_step(Dataiterator *di);
198
199 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
200 void repo_set_num(Repo *repo, Id p, Id keyname, Id num);
201 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
202 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
203 void repo_internalize(Repo *repo);
204
205 #endif /* SATSOLVER_REPO_H */