added conflict in InjectSolutionAction
[platform/upstream/libzypp.git] / zypp / solver / detail / SolutionAction.h
1 /**
2  *
3  * Easy-to use interface to the ZYPP dependency resolver
4  *
5  * Author: Stefan Hundhammer <sh@suse.de>
6  *
7  **/
8
9 #ifndef ZYPP_SOLVER_DETAIL_SOLUTIONACTION_H
10 #define ZYPP_SOLVER_DETAIL_SOLUTIONACTION_H
11
12 #include <list>
13 #include <string>
14
15 #include "zypp/base/ReferenceCounted.h"
16 #include "zypp/base/PtrTypes.h"
17
18 #include "zypp/Capability.h"
19 #include "zypp/solver/detail/Resolver.h"
20 #include "zypp/solver/detail/ProblemSolutionPtr.h"
21 #include "zypp/solver/detail/ResolverProblemPtr.h"
22 #include "zypp/solver/detail/SolutionActionPtr.h"
23
24 /////////////////////////////////////////////////////////////////////////
25 namespace zypp
26 { ///////////////////////////////////////////////////////////////////////
27   ///////////////////////////////////////////////////////////////////////
28   namespace solver
29   { /////////////////////////////////////////////////////////////////////
30     /////////////////////////////////////////////////////////////////////
31     namespace detail
32     { ///////////////////////////////////////////////////////////////////
33
34         /**
35          * Abstract base class for one action of a problem solution.
36          **/
37         class SolutionAction : public base::ReferenceCounted
38         {
39         public:
40           SolutionAction();
41           virtual ~SolutionAction();
42
43           // ---------------------------------- I/O
44
45           static std::string toString (const SolutionAction & action);
46           static std::string toString (const SolutionActionList & actionlist);
47           static std::string toString (const CSolutionActionList & actionlist);
48
49           virtual std::ostream & dumpOn(std::ostream & str ) const = 0;
50
51           friend std::ostream& operator<<(std::ostream&, const SolutionAction & action);
52
53           virtual std::string asString (void) const = 0;
54
55           // ---------------------------------- methods
56             /**
57              * Execute this action.
58              * Returns 'true' on success, 'false' on error.
59              **/
60             virtual bool execute() = 0;
61         };
62
63
64         /**
65          * A problem solution action that performs a transaction
66          * (installs, updates, removes, ...)  one resolvable
67          * (package, patch, pattern, product).
68          **/
69         class TransactionSolutionAction: public SolutionAction
70         {
71         public:
72
73             typedef enum
74             {
75                 // TO DO: use some already existing enum (?)
76                 Keep,
77                 Install,
78                 Update,
79                 Remove
80             } TransactionKind;
81
82
83             TransactionSolutionAction( ResItem_constPtr resolvable,
84                                        TransactionKind action )
85                 : SolutionAction(), _resolvable( resolvable ), _action( action ) {}
86
87           // ---------------------------------- I/O
88
89           static std::string toString (const TransactionSolutionAction & action);
90
91           virtual std::ostream & dumpOn(std::ostream & str ) const;
92
93           friend std::ostream& operator<<(std::ostream&, const TransactionSolutionAction & action);
94
95           std::string asString (void) const;
96
97           // ---------------------------------- accessors
98             ResItem_constPtr resolvable() const { return _resolvable; }
99             TransactionKind action()     const { return _action;     }
100
101           // ---------------------------------- methods
102             virtual bool execute();
103
104
105         protected:
106
107             ResItem_constPtr    _resolvable;
108             TransactionKind     _action;
109         };
110
111
112         /**
113          * A problem solution action that injects an artificial "provides" to
114          * the pool to satisfy open requirements or remove the conflict of
115          * concerning resolvable
116          *
117          * This is typically used by "ignore" (user override) solutions.
118          **/
119         class InjectSolutionAction: public SolutionAction
120         {
121         public:
122             
123             typedef enum
124             {
125                 PROVIDE,
126                 CONFLICT
127             } CapabilityKind;
128             
129             InjectSolutionAction( const Capability & capability, const CapabilityKind & kind )
130                 : SolutionAction(), _capability( capability ), _kind( kind ) {}
131
132           // ---------------------------------- I/O
133
134           static std::string toString (const InjectSolutionAction & action);
135
136           virtual std::ostream & dumpOn(std::ostream & str ) const;
137
138           friend std::ostream& operator<<(std::ostream&, const InjectSolutionAction & action);
139
140           std::string asString (void) const;
141
142           // ---------------------------------- accessors
143             const Capability & capability() const { return _capability; };
144
145           // ---------------------------------- methods
146             virtual bool execute();
147
148         protected:
149
150             const Capability & _capability;
151             const CapabilityKind & _kind;
152         };
153
154
155       ///////////////////////////////////////////////////////////////////
156     };// namespace detail
157     /////////////////////////////////////////////////////////////////////
158     /////////////////////////////////////////////////////////////////////
159   };// namespace solver
160   ///////////////////////////////////////////////////////////////////////
161   ///////////////////////////////////////////////////////////////////////
162 };// namespace zypp
163 /////////////////////////////////////////////////////////////////////////
164
165 #endif // ZYPP_SOLVER_DETAIL_SOLUTIONACTION_H
166