- make ResolverInfoMisc *much* more detailed.
[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.
115          *
116          * This is typically used by "ignore" (user override) solutions.
117          **/
118         class InjectSolutionAction: public SolutionAction
119         {
120         public:
121             
122             InjectSolutionAction( const Capability & provides )
123                 : SolutionAction(), _capability( provides ) {}
124
125           // ---------------------------------- I/O
126
127           static std::string toString (const InjectSolutionAction & action);
128
129           virtual std::ostream & dumpOn(std::ostream & str ) const;
130
131           friend std::ostream& operator<<(std::ostream&, const InjectSolutionAction & action);
132
133           std::string asString (void) const;
134
135           // ---------------------------------- accessors
136             const Capability & capability() const { return _capability; };
137
138           // ---------------------------------- methods
139             virtual bool execute();
140
141         protected:
142
143             const Capability & _capability;
144         };
145
146
147       ///////////////////////////////////////////////////////////////////
148     };// namespace detail
149     /////////////////////////////////////////////////////////////////////
150     /////////////////////////////////////////////////////////////////////
151   };// namespace solver
152   ///////////////////////////////////////////////////////////////////////
153   ///////////////////////////////////////////////////////////////////////
154 };// namespace zypp
155 /////////////////////////////////////////////////////////////////////////
156
157 #endif // ZYPP_SOLVER_DETAIL_SOLUTIONACTION_H
158