interface for generating testcases
[platform/upstream/libzypp.git] / zypp / Resolver.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/Resolver.h
10  *
11 */
12 #ifndef ZYPP_RESOLVER_H
13 #define ZYPP_RESOLVER_H
14
15 #include <iosfwd>
16 #include <functional>
17
18 #include "zypp/base/ReferenceCounted.h"
19 #include "zypp/base/PtrTypes.h"
20
21 #include "zypp/ResPool.h"
22 #include "zypp/UpgradeStatistics.h"
23 #include "zypp/solver/detail/Resolver.h"
24 #include "zypp/solver/detail/ResolverContext.h"
25 #include "zypp/ProblemTypes.h"
26
27 ///////////////////////////////////////////////////////////////////
28 namespace zypp
29 { /////////////////////////////////////////////////////////////////
30
31
32
33   ///////////////////////////////////////////////////////////////////
34   //
35   //    CLASS NAME : Resolver
36   //
37   /** Resolver interface.
38   */
39   class Resolver : public base::ReferenceCounted, private base::NonCopyable
40   {
41   public:
42
43     /** Ctor */
44     Resolver( const ResPool & pool );
45     /** Dtor */
46     virtual ~Resolver();
47
48     /**
49      * Resolve package dependencies:
50      *
51      * Verify consistency of system
52      *
53      **/
54     bool verifySystem (void);
55
56     /**
57      * Establish state of 'higher level' Resolvables in Pool
58      *
59      * Must be called when dealing with non-package resolvables,
60      * like Patches, Patterns, and Products
61      *
62      * Must be called with a 'plain' pool, e.g. no additonal
63      * transacts set.
64      *
65      * return true if it was successful
66      * return false if not (this will only happen if other
67      *   transactions are in the pool which will lead to
68      *   no solution)
69      **/
70     bool establishPool (void);
71
72     /**
73      * go through all package 'freshen' dependencies and
74      * schedule matches for installation.
75      *
76      * To be called at begin of installation and upgrade.
77      * Probably also useful after adding a new package
78      * repository.
79      *
80      * return true if it was successful
81      * return false if not (this will only happen if other
82      *   transactions are in the pool which will lead to
83      *   no solution)
84      **/
85     bool freshenPool (void);
86
87     /**
88      * Resolve package dependencies:
89      *
90      * Try to execute all pending transactions (there may be more than
91      * one!).
92      *
93      * Returns "true" on success (i.e., if there were no problems that
94      * need user interaction) and "false" if there were problems.  In
95      * the latter case, use problems() and later applySolutions()
96      * below.
97      **/
98     bool resolvePool (void);
99
100     /*
101      * Undo solver changes done in resolvePool()
102      * Throwing away all ignored dependencies.
103      */
104     void undo( void );
105
106     /*
107      * Get the most recent resolver context
108      *
109      * It will be NULL if resolvePool() or establishPool() was never called.
110      * Depending on the return code of the last resolvePool() call,
111      * it _either_ points to a valid or an invalid solution.
112      */
113     solver::detail::ResolverContext_Ptr context (void) const;
114
115     /**
116      * Do an distribution upgrade
117      *
118      * This will run a full upgrade on the pool, taking all upgrade
119      * dependencies (provide/obsolete for package renames, split-
120      * provides, etc.) into account and actually removing installed
121      * packages if no upgrade exists.
122      *
123      * To be run with great caution. It basically brings your
124      * system 'back to start'.
125      * Quite helpful to get back to a 'sane state'. Quite disastrous
126      * since you'll loose all non-distribution packages
127      **/
128     void doUpgrade( UpgradeStatistics & opt_stats_r );
129
130     /**
131      * Return the list of problematic update items
132      * i.e. locked ones (due to foreign vendor)
133      **/
134     std::list<PoolItem_Ref> problematicUpdateItems( void ) const;
135
136     /**
137      * Return the dependency problems found by the last call to
138      * resolveDependencies(). If there were no problems, the returned
139      * list will be empty.
140      **/
141     ResolverProblemList problems();
142
143     /**
144      * Return more solver information if an error has happened.
145      **/
146       
147     std::list<std::string> problemDescription( void ) const;      
148
149     /**
150      * Apply problem solutions. No more than one solution per problem
151      * can be applied.
152      **/
153     void applySolutions( const ProblemSolutionList & solutions );
154
155     Arch architecture() const;
156     void setArchitecture( const Arch & arch);
157
158     /**      
159      * Remove resolvables which are conflicts with others or
160      * have unfulfilled requirements.
161      * This behaviour is favourited by ZMD.
162      **/
163     void setForceResolve (const bool force);
164     const bool forceResolve();
165
166     /**
167      * transact a single ResObject
168      *
169      * Installs (install == true) or removes (install == false) all required
170      * and recommended packages(!) of \c robj
171      * (More or less a 'single step' resolver call)
172      *
173      * returns false if requirements are not all fulfillable
174      *
175      */
176     bool transactResObject( ResObject::constPtr robj, bool install = true);
177
178     /**
179      * transact all objects of this kind
180      *
181      * Look through the pool and runs transactResObject, first for removes
182      * then for installs
183      * (More or less a 'single step' resolver call)
184      *
185      * returns false if any transactResObject() call returned false.
186      *
187      */
188     bool transactResKind( Resolvable::Kind kind );
189
190     /**
191      * reset any transact states
192      *
193      * Look through the pool and clear transact state.
194      * It will only reset states which have an equal or
195      * lower causer
196      *
197      */
198     void transactReset( ResStatus::TransactByValue causer );
199
200     /**
201      * Setting solver timeout
202      *
203      * Stop solving after a given timeframe (seconds) 
204      * seconds = 0 : No timeout
205      *
206      */
207     void setTimeout( int seconds );
208
209     /**
210      * Getting solver timeout in seconds
211      *
212      */
213     int timeout();      
214
215     /**
216      * Restricting solver passes
217      *
218      * Stop solving after a given amount of passes
219      * count = 0 : No restriction
220      *
221      */
222     void setMaxSolverPasses (int count);
223
224     /**
225      * Count of max solver passes
226      *
227      */
228     int maxSolverPasses ();
229
230     /**
231      * Generates a solver Testcase of the current state
232      *
233      */
234     bool createSolverTestcase (std::string dumpPath = "/var/log/YaST2/solverTestcase");      
235
236   protected:
237
238   private:
239     solver::detail::Resolver_Ptr _pimpl;
240   };
241   ///////////////////////////////////////////////////////////////////
242
243   /////////////////////////////////////////////////////////////////
244 } // namespace zypp
245 ///////////////////////////////////////////////////////////////////
246 #endif // ZYPP_RESOLVER_H