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