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_REPO_H
14 #define SATSOLVER_REPO_H
18 #include "pooltypes.h"
22 typedef struct _Repokey {
24 Id type; /* REPOKEY_TYPE_xxx */
26 unsigned int storage; /* KEY_STORAGE_xxx */
29 #define KEY_STORAGE_DROPPED 0
30 #define KEY_STORAGE_SOLVABLE 1
31 #define KEY_STORAGE_INCORE 2
32 #define KEY_STORAGE_VERTICAL_OFFSET 3
35 typedef struct _Repo {
37 struct _Pool *pool; /* pool containing repo data */
39 int start; /* start of this repo solvables within pool->solvables */
40 int end; /* last solvable + 1 of this repo */
41 int nsolvables; /* number of solvables repo is contributing to pool */
42 int nextra; /* number of extra objects (non-solvables) */
44 int priority; /* priority of this repo */
46 Id *idarraydata; /* array of metadata Ids, solvable dependencies are offsets into this array */
50 Id *rpmdbid; /* hmm, go to repodata? */
52 Repodata *repodata; /* our stores for non-solvable related data */
53 unsigned nrepodata; /* number of our stores.. */
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);
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);
65 static inline const char *repo_name(const Repo *repo)
70 static inline Id repo_add_solvable(Repo *repo)
72 extern Id pool_add_solvable(Pool *pool);
73 Id p = pool_add_solvable(repo->pool);
74 if (!repo->start || repo->start == repo->end)
83 if (p + 1 > repo->end)
87 repo->pool->solvables[p].repo = repo;
91 static inline Id repo_add_solvable_block(Repo *repo, int count)
93 extern Id pool_add_solvable_block(Pool *pool, int count);
98 p = pool_add_solvable_block(repo->pool, count);
99 if (!repo->start || repo->start == repo->end)
102 repo->end = p + count;
108 if (p + count > repo->end)
109 repo->end = p + count;
111 repo->nsolvables += count;
112 for (s = repo->pool->solvables + p; count--; s++)
117 static inline void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
119 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
122 if (start + count == repo->end)
124 repo->nsolvables -= count;
125 for (s = repo->pool->solvables + start, i = count; i--; s++)
127 pool_free_solvable_block(repo->pool, start, count, reuseids);
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) \
135 /* search callback values */
137 #define SEARCH_NEXT_KEY 1
138 #define SEARCH_NEXT_SOLVABLE 2
139 #define SEARCH_STOP 3
141 typedef struct _KeyValue {
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
156 #define SEARCH_NOCASE (1<<8)
157 #define SEARCH_NO_STORAGE_SOLVABLE (1<<9)
158 #define SEARCH_EXTRA (1<<10)
159 #define SEARCH_ALL_REPOS (1<<11)
160 #define SEARCH_SKIP_KIND (1<<12)
163 #define __SEARCH_ONESOLVABLE (1 << 31)
165 Repodata *repo_add_repodata(Repo *repo, int localpool);
167 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);
169 /* returns the string value of the attribute, or NULL if not found */
170 const char * repo_lookup_str(Solvable *s, Id key);
171 /* returns the integer value of the attribute, or 0 if not found */
172 unsigned int repo_lookup_num(Solvable *s, Id key);
173 /* generic attribute lookup */
174 int repo_lookup(Solvable *s, Id key, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata);
176 typedef struct _Dataiterator
180 unsigned char *nextkeydp;
200 dataiterator_init(&di, repo, 0, 0, "bla", SEARCH_SUBSTRING);
201 while (dataiterator_step(&di))
202 dosomething(di.solvid, di.key, di.kv); */
203 void dataiterator_init(Dataiterator *di, Repo *repo, Id p, Id keyname,
204 const char *match, int flags);
205 int dataiterator_step(Dataiterator *di);
206 int dataiterator_match(Dataiterator *di, int flags, const void *match);
207 void dataiterator_skip_attribute(Dataiterator *di);
208 void dataiterator_skip_solvable(Dataiterator *di);
209 void dataiterator_skip_repo(Dataiterator *di);
210 void dataiterator_jump_to_solvable(Dataiterator *di, Solvable *s);
211 void dataiterator_jump_to_repo(Dataiterator *di, Repo *repo);
213 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
214 void repo_set_num(Repo *repo, Id p, Id keyname, Id num);
215 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
216 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
217 void repo_internalize(Repo *repo);
218 void repo_disable_paging(Repo *repo);
220 #endif /* SATSOLVER_REPO_H */