pool.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007, Novell Inc.
00003  *
00004  * This program is licensed under the BSD license, read LICENSE.BSD
00005  * for further information
00006  */
00007 
00008 /*
00009  * pool.h
00010  * 
00011  */
00012 
00013 #ifndef SATSOLVER_POOL_H
00014 #define SATSOLVER_POOL_H
00015 
00016 #ifdef __cplusplus
00017 extern "C" {
00018 #endif
00019 
00020 #include <stdio.h>
00021 
00022 #include "satversion.h"
00023 #include "pooltypes.h"
00024 #include "poolid.h"
00025 #include "solvable.h"
00026 #include "bitmap.h"
00027 #include "queue.h"
00028 #include "strpool.h"
00029 
00030 /* well known ids */
00031 #include "knownid.h"
00032 
00033 /* well known solvable */
00034 #define SYSTEMSOLVABLE          1
00035 
00036 
00037 /* how many strings to maintain (round robin) */
00038 #define POOL_TMPSPACEBUF 16
00039 
00040 //-----------------------------------------------
00041 
00042 struct _Repo;
00043 struct _Repodata;
00044 struct _Repokey;
00045 struct _KeyValue;
00046 
00047 typedef struct _Repopos {
00048   struct _Repo *repo;
00049   Id solvid;
00050   Id repodataid;
00051   Id schema;
00052   Id dp; 
00053 } Repopos;
00054 
00055 struct _Pool {
00056   void *appdata;                /* application private pointer */
00057 
00058   struct _Stringpool ss;
00059 
00060   Reldep *rels;                 /* table of rels: Id -> Reldep */
00061   int nrels;                    /* number of unique rels */
00062   Hashtable relhashtbl;         /* hashtable: (name,evr,op)Hash -> Id */
00063   Hashmask relhashmask;
00064 
00065   struct _Repo **repos;
00066   int nrepos;
00067 
00068   struct _Repo *installed;      /* packages considered installed */
00069 
00070   Solvable *solvables;
00071   int nsolvables;
00072 
00073   const char **languages;
00074   int nlanguages;
00075   Id *languagecache;
00076   int languagecacheother;
00077 
00078   /* flags to tell the library how the installed rpm works */
00079   int promoteepoch;             /* true: missing epoch is replaced by epoch of dependency   */
00080   int obsoleteusesprovides;     /* true: obsoletes are matched against provides, not names */
00081   int implicitobsoleteusesprovides;     /* true: implicit obsoletes due to same name are matched against provides, not names */
00082   int obsoleteusescolors;       /* true: obsoletes check arch color */
00083   int novirtualconflicts;       /* true: conflicts on names, not on provides */
00084   int allowselfconflicts;       /* true: packages which conflict with itself are installable */
00085 #ifdef MULTI_SEMANTICS
00086   int disttype;
00087 #endif
00088 
00089   Id *id2arch;                  /* map arch ids to scores */
00090   unsigned char *id2color;      /* map arch ids to colors */
00091   Id lastarch;                  /* last valid entry in id2arch/id2color */
00092 
00093   Queue vendormap;              /* map vendor to vendorclasses mask */
00094 
00095   /* providers data, as two-step indirect list
00096    * whatprovides[Id] -> Offset into whatprovidesdata for name
00097    * whatprovidesdata[Offset] -> ID_NULL-terminated list of solvables providing Id
00098    */
00099   Offset *whatprovides;         /* Offset to providers of a specific name, Id -> Offset  */
00100   Offset *whatprovides_rel;     /* Offset to providers of a specific relation, Id -> Offset  */
00101 
00102   Id *whatprovidesdata;         /* Ids of solvable providing Id */
00103   Offset whatprovidesdataoff;   /* next free slot within whatprovidesdata */
00104   int whatprovidesdataleft;     /* number of 'free slots' within whatprovidesdata */
00105 
00106   /* If nonzero, then consider only the solvables with Ids set in this
00107      bitmap for solving.  If zero, consider all solvables.  */
00108   Map *considered;
00109 
00110   Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr);
00111   void *nscallbackdata;
00112 
00113   /* our tmp space string space */
00114   char *tmpspacebuf[POOL_TMPSPACEBUF];
00115   int   tmpspacelen[POOL_TMPSPACEBUF];
00116   int   tmpspacen;
00117 
00118   /* debug mask and callback */
00119   int  debugmask;
00120   void (*debugcallback)(struct _Pool *, void *data, int type, const char *str);
00121   void *debugcallbackdata;
00122 
00123   /* load callback */
00124   int (*loadcallback)(struct _Pool *, struct _Repodata *, void *);
00125   void *loadcallbackdata;
00126 
00127   /* search position */
00128   Repopos pos;
00129 };
00130 
00131 #ifdef MULTI_SEMANTICS
00132 # define DISTTYPE_RPM   0
00133 # define DISTTYPE_DEB   1
00134 #endif
00135 
00136 #define SAT_FATAL                       (1<<0)
00137 #define SAT_ERROR                       (1<<1)
00138 #define SAT_WARN                        (1<<2)
00139 #define SAT_DEBUG_STATS                 (1<<3)
00140 #define SAT_DEBUG_RULE_CREATION         (1<<4)
00141 #define SAT_DEBUG_PROPAGATE             (1<<5)
00142 #define SAT_DEBUG_ANALYZE               (1<<6)
00143 #define SAT_DEBUG_UNSOLVABLE            (1<<7)
00144 #define SAT_DEBUG_SOLUTIONS             (1<<8)
00145 #define SAT_DEBUG_POLICY                (1<<9)
00146 #define SAT_DEBUG_RESULT                (1<<10)
00147 #define SAT_DEBUG_JOB                   (1<<11)
00148 #define SAT_DEBUG_SCHUBI                (1<<12)
00149 #define SAT_DEBUG_SOLVER                (1<<13)
00150 #define SAT_DEBUG_TRANSACTION           (1<<14)
00151 
00152 #define SAT_DEBUG_TO_STDERR             (1<<30)
00153 
00154 //-----------------------------------------------
00155 
00156 
00157 /* mark dependencies with relation by setting bit31 */
00158 
00159 #define MAKERELDEP(id) ((id) | 0x80000000)
00160 #define ISRELDEP(id) (((id) & 0x80000000) != 0)
00161 #define GETRELID(id) ((id) ^ 0x80000000)                                /* returns Id */
00162 #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000))        /* returns Reldep* */
00163 
00164 #define REL_GT          1
00165 #define REL_EQ          2
00166 #define REL_LT          4
00167 
00168 #define REL_AND         16
00169 #define REL_OR          17
00170 #define REL_WITH        18
00171 #define REL_NAMESPACE   19
00172 #define REL_ARCH        20
00173 #define REL_FILECONFLICT        21
00174 
00175 #if !defined(__GNUC__) && !defined(__attribute__)
00176 # define __attribute__(x)
00177 #endif
00178 
00182 extern Pool *pool_create(void);
00186 extern void pool_free(Pool *pool);
00187 
00188 extern void pool_setdebuglevel(Pool *pool, int level);
00189 #ifdef MULTI_SEMANTICS
00190 extern void pool_setdisttype(Pool *pool, int disttype);
00191 #endif
00192 
00193 extern void pool_debug(Pool *pool, int type, const char *format, ...) __attribute__((format(printf, 3, 4)));
00194 
00195 extern char *pool_alloctmpspace(Pool *pool, int len);
00196 extern char *pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3);
00197 
00198 extern void pool_set_installed(Pool *pool, struct _Repo *repo);
00199 
00203 extern Id pool_add_solvable(Pool *pool);
00204 extern Id pool_add_solvable_block(Pool *pool, int count);
00205 
00206 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
00207 static inline Solvable *pool_id2solvable(const Pool *pool, Id p)
00208 {
00209   return pool->solvables + p;
00210 }
00211 
00212 extern const char *solvable2str(Pool *pool, Solvable *s);
00213 static inline const char *solvid2str(Pool *pool, Id p)
00214 {
00215   return solvable2str(pool, pool->solvables + p);
00216 }
00217 
00218 void pool_set_languages(Pool *pool, const char **languages, int nlanguages);
00219 Id pool_id2langid(Pool *pool, Id id, const char *lang, int create);
00220 
00221 Id solvable_lookup_id(Solvable *s, Id keyname);
00222 unsigned int solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound);
00223 const char *solvable_lookup_str(Solvable *s, Id keyname);
00224 const char *solvable_lookup_str_poollang(Solvable *s, Id keyname);
00225 const char *solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang, int usebase);
00226 int solvable_lookup_bool(Solvable *s, Id keyname);
00227 int solvable_lookup_void(Solvable *s, Id keyname);
00228 char * solvable_get_location(Solvable *s, unsigned int *medianrp);
00229 const unsigned char *solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep);
00230 const char *solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep);
00231 int solvable_lookup_idarray(Solvable *s, Id keyname, Queue *q);
00232 int solvable_identical(Solvable *s1, Solvable *s2);
00233 Id solvable_selfprovidedep(Solvable *s);
00234 
00235 int solvable_trivial_installable_map(Solvable *s, Map *installedmap, Map *conflictsmap);
00236 int solvable_trivial_installable_repo(Solvable *s, struct _Repo *installed);
00237 int solvable_trivial_installable_queue(Solvable *s, Queue *installed);
00238 
00239 void pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap);
00240 
00241 int pool_match_nevr_rel(Pool *pool, Solvable *s, Id d);
00242 int pool_match_dep(Pool *pool, Id d1, Id d2);
00243 
00244 static inline int pool_match_nevr(Pool *pool, Solvable *s, Id d)
00245 {
00246   if (!ISRELDEP(d))
00247     return d == s->name;
00248   else
00249     return pool_match_nevr_rel(pool, s, d);
00250 }
00251 
00252 
00256 extern void pool_createwhatprovides(Pool *pool);
00257 extern void pool_addfileprovides(Pool *pool);
00258 extern void pool_addfileprovides_ids(Pool *pool, struct _Repo *installed, Id **idp);
00259 extern void pool_freewhatprovides(Pool *pool);
00260 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);
00261 
00262 extern Id pool_addrelproviders(Pool *pool, Id d);
00263 
00264 static inline Id pool_whatprovides(Pool *pool, Id d)
00265 {
00266   Id v;
00267   if (!ISRELDEP(d))
00268     return pool->whatprovides[d];
00269   v = GETRELID(d);
00270   if (pool->whatprovides_rel[v])
00271     return pool->whatprovides_rel[v];
00272   return pool_addrelproviders(pool, d);
00273 }
00274 
00275 static inline Id *pool_whatprovides_ptr(Pool *pool, Id d)
00276 {
00277   Id off = pool_whatprovides(pool, d);
00278   return pool->whatprovidesdata + off;
00279 }
00280 
00281 static inline void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
00282 {
00283   pool->debugcallback = debugcallback;
00284   pool->debugcallbackdata = debugcallbackdata;
00285 }
00286 
00287 static inline void pool_setdebugmask(Pool *pool, int mask)
00288 {
00289   pool->debugmask = mask;
00290 }
00291 
00292 static inline void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
00293 {
00294   pool->loadcallback = cb;
00295   pool->loadcallbackdata = loadcbdata;
00296 }
00297 
00298 /* search the pool. the following filters are available:
00299  *   p     - search just this solvable
00300  *   key   - search only this key
00301  *   match - key must match this string
00302  */
00303 void pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, struct _Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata);
00304 
00305 void pool_clear_pos(Pool *pool);
00306 
00307 
00308 typedef struct _DUChanges {
00309   const char *path;
00310   int kbytes;
00311   int files;
00312 } DUChanges;
00313 
00314 void pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps);
00315 int pool_calc_installsizechange(Pool *pool, Map *installedmap);
00316 void pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res);
00317 void pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap);
00318 
00319 const char *pool_lookup_str(Pool *pool, Id entry, Id keyname);
00320 Id pool_lookup_id(Pool *pool, Id entry, Id keyname);
00321 unsigned int pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound);
00322 int pool_lookup_void(Pool *pool, Id entry, Id keyname);
00323 const unsigned char *pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep);
00324 const char *pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep);
00325 
00326 void pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts);
00327 
00328 
00329 
00330 /* loop over all providers of d */
00331 #define FOR_PROVIDES(v, vp, d)                                          \
00332   for (vp = pool_whatprovides(pool, d) ; (v = pool->whatprovidesdata[vp++]) != 0; )
00333 
00334 /* loop over all repositories */
00335 /* note that idx is not the repoid */
00336 #define FOR_REPOS(idx, r)                                               \
00337   for (idx = 0; idx < pool->nrepos; idx++)                              \
00338     if ((r = pool->repos[idx]) != 0)
00339     
00340 
00341 #define POOL_DEBUG(type, ...) do {if ((pool->debugmask & (type)) != 0) pool_debug(pool, (type), __VA_ARGS__);} while (0)
00342 #define IF_POOLDEBUG(type) if ((pool->debugmask & (type)) != 0)
00343 
00344 #ifdef __cplusplus
00345 }
00346 #endif
00347 
00348 
00349 #endif /* SATSOLVER_POOL_H */

doxygen