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