- use schema in repodata to make it extendible
[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 #include "attr_store.h"
19
20 typedef struct _Repodata {
21   /* Keys provided by this attribute store, sorted by name value.
22      The same keys may be provided by multiple attribute stores, but
23      then only for different solvables.  I.e. the relation
24        (solvable,name) -> store
25      has to be injective.  */
26   struct {
27     Id name;
28     unsigned type;
29   } *keys;
30   /* Length of keys array */
31   unsigned nkeys;
32
33   /* The attribute store itself.  */
34   Attrstore *s;
35   /* A filename where to find this attribute store, or where to store
36      it.  May be "", in which case we can't load it on demand or store
37      into it.  It may also be NULL for at most one of the repodata per
38      repo, in which case these are the embedded attributes.  */
39
40   const char *location;
41   /* The SHA1 checksum of the file.  */
42   unsigned char checksum[20];
43 } Repodata;
44
45 typedef struct _Repo {
46   const char *name;
47   struct _Pool *pool;           /* pool containing repo data */
48   int start;                    /* start of this repo solvables within pool->solvables */
49   int end;                      /* last solvable + 1 of this repo */
50   int nsolvables;               /* number of solvables repo is contributing to pool */
51
52   int priority;                 /* priority of this repo */
53
54   Id *idarraydata;              /* array of metadata Ids, solvable dependencies are offsets into this array */
55   int idarraysize;
56   Offset lastoff;
57
58   Id *rpmdbid;
59
60   /* The attribute stores we know about.  */
61   Repodata *repodata;
62   /* Number of attribute stores..  */
63   unsigned nrepodata;
64 } Repo;
65
66 extern Repo *repo_create(Pool *pool, const char *name);
67 extern void repo_free(Repo *repo, int reuseids);
68 extern void repo_freeallrepos(Pool *pool, int reuseids);
69
70 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
71 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, int isreq);
72 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
73 extern Offset repo_fix_legacy(Repo *repo, Offset provides, Offset supplements);
74
75 extern void repo_add_attrstore (Repo *repo, Attrstore *s, const char *location);
76
77 static inline const char *repo_name(const Repo *repo)
78 {
79   return repo->name;
80 }
81
82 static inline Id repo_add_solvable(Repo *repo)
83 {
84   extern Id pool_add_solvable(Pool *pool);
85   Id p = pool_add_solvable(repo->pool);
86   if (!repo->start || repo->start == repo->end)
87     {
88       repo->start = p;
89       repo->end = p + 1;
90     }
91   else
92     {
93       if (p < repo->start)
94         repo->start = p;
95       if (p + 1 > repo->end)
96         repo->end = p + 1;
97     }
98   repo->nsolvables++;
99   repo->pool->solvables[p].repo = repo;
100   return p;
101 }
102
103 static inline Id repo_add_solvable_block(Repo *repo, int count)
104 {
105   extern Id pool_add_solvable_block(Pool *pool, int count);
106   Id p;
107   Solvable *s;
108   if (!count)
109     return 0;
110   p = pool_add_solvable_block(repo->pool, count);
111   if (!repo->start || repo->start == repo->end)
112     {
113       repo->start = p;
114       repo->end = p + count;
115     }
116   else
117     {
118       if (p < repo->start)
119         repo->start = p;
120       if (p + count > repo->end)
121         repo->end = p + count;
122     }
123   repo->nsolvables += count;
124   for (s = repo->pool->solvables + p; count--; s++)
125     s->repo = repo;
126   return p;
127 }
128
129 static inline void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
130 {
131   extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
132   Solvable *s;
133   int i;
134   if (start + count == repo->end)
135     repo->end -= count;
136   repo->nsolvables -= count;
137   for (s = repo->pool->solvables + start, i = count; i--; s++)
138     s->repo = 0;
139   pool_free_solvable_block(repo->pool, start, count, reuseids);
140 }
141
142 #define FOR_REPO_SOLVABLES(r, p, s)                                             \
143   for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s++)    \
144     if (s->repo == (r))
145
146 #endif /* SATSOLVER_REPO_H */