Merge branch 'master' of git://git.opensuse.org/projects/zypp/sat-solver
[platform/upstream/libsolv.git] / src / rules.h
1 /*
2  * Copyright (c) 2007-2009, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * rules.h
10  *
11  */
12
13 #ifndef SATSOLVER_RULES_H
14 #define SATSOLVER_RULES_H
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 /* ----------------------------------------------
21  * Rule
22  *
23  *   providerN(B) == Package Id of package providing tag B
24  *   N = 1, 2, 3, in case of multiple providers
25  *
26  * A requires B : !A | provider1(B) | provider2(B)
27  *
28  * A conflicts B : (!A | !provider1(B)) & (!A | !provider2(B)) ...
29  *
30  * 'not' is encoded as a negative Id
31  *
32  * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
33  *
34  * There are a lot of rules, so the struct is kept as small as
35  * possible. Do not add new members unless there is no other way.
36  */
37
38 typedef struct _Rule {
39   Id p;         /* first literal in rule */
40   Id d;         /* Id offset into 'list of providers terminated by 0' as used by whatprovides; pool->whatprovides + d */
41                 /* in case of binary rules, d == 0, w1 == p, w2 == other literal */
42                 /* in case of disabled rules: ~d, aka -d - 1 */
43   Id w1, w2;    /* watches, literals not-yet-decided */
44                 /* if !w2, assertion, not rule */
45   Id n1, n2;    /* next rules in linked list, corresponding to w1, w2 */
46 } Rule;
47
48
49 typedef enum {
50   SOLVER_RULE_UNKNOWN = 0,
51   SOLVER_RULE_RPM = 0x100,
52   SOLVER_RULE_RPM_NOT_INSTALLABLE,
53   SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP,
54   SOLVER_RULE_RPM_PACKAGE_REQUIRES,
55   SOLVER_RULE_RPM_SELF_CONFLICT,
56   SOLVER_RULE_RPM_PACKAGE_CONFLICT,
57   SOLVER_RULE_RPM_SAME_NAME,
58   SOLVER_RULE_RPM_PACKAGE_OBSOLETES,
59   SOLVER_RULE_RPM_IMPLICIT_OBSOLETES,
60   SOLVER_RULE_UPDATE = 0x200,
61   SOLVER_RULE_FEATURE = 0x300,
62   SOLVER_RULE_JOB = 0x400,
63   SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP,
64   SOLVER_RULE_DISTUPGRADE = 0x500,
65   SOLVER_RULE_INFARCH = 0x600,
66   SOLVER_RULE_CHOICE = 0x700,
67   SOLVER_RULE_LEARNT = 0x800
68 } SolverRuleinfo;
69
70 #define SOLVER_RULE_TYPEMASK    0xff00
71
72 struct _Solver;
73
74 /*-------------------------------------------------------------------
75  * disable rule
76  */
77
78 static inline void
79 solver_disablerule(struct _Solver *solv, Rule *r)
80 {
81   if (r->d >= 0)
82     r->d = -r->d - 1;
83 }
84
85 /*-------------------------------------------------------------------
86  * enable rule
87  */
88
89 static inline void
90 solver_enablerule(struct _Solver *solv, Rule *r)
91 {
92   if (r->d < 0)
93     r->d = -r->d - 1;
94 }
95
96 Rule *solver_addrule(struct _Solver *solv, Id p, Id d);
97 void solver_unifyrules(struct _Solver *solv);
98 int solver_samerule(struct _Solver *solv, Rule *r1, Rule *r2);
99
100 /* rpm rules */
101 void solver_addrpmrulesforsolvable(struct _Solver *solv, Solvable *s, Map *m);
102 void solver_addrpmrulesforweak(struct _Solver *solv, Map *m);
103 void solver_addrpmrulesforupdaters(struct _Solver *solv, Solvable *s, Map *m, int allow_all);
104
105 /* update/feature rules */
106 void solver_addupdaterule(struct _Solver *solv, Solvable *s, int allow_all);
107
108 /* infarch rules */
109 void solver_addinfarchrules(struct _Solver *solv, Map *addedmap);
110
111 /* dup rules */
112 void solver_createdupmaps(struct _Solver *solv);
113 void solver_freedupmaps(struct _Solver *solv);
114 void solver_addduprules(struct _Solver *solv, Map *addedmap);
115
116 /* policy rule disabling/reenabling */
117 void solver_disablepolicyrules(struct _Solver *solv);
118 void solver_reenablepolicyrules(struct _Solver *solv, int jobidx);
119
120 /* rule info */
121 int solver_allruleinfos(struct _Solver *solv, Id rid, Queue *rq);
122 SolverRuleinfo solver_ruleinfo(struct _Solver *solv, Id rid, Id *fromp, Id *top, Id *depp);
123
124
125 #ifdef __cplusplus
126 }
127 #endif
128
129 #endif
130