- better comments
[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      * The solver pays attention to the BEST packages only in order to
103      * come to a solution. 
104      * If there has not been found a valid results all other branches
105      * (e.G. packages with older version numbers, worse architecture)
106      *  will be regarded.
107      *
108      * Returns "true" on success (i.e., if there were no problems that
109      * need user interaction) and "false" if there were problems.  In
110      * the latter case, use problems() and later applySolutions()
111      * below.
112      **/
113     bool resolvePool (void);      
114
115     /**
116      * Resolve package dependencies:
117      *
118      * Try to execute all pending transactions (there may be more than
119      * one!).
120      * If tryAllPossibilities is false, restrict searches for matching
121      *  requirements to best architecture, highest version.
122      * If tryAllPossibilities is true, evaluate all possible matches
123      *  for a requirement.
124      *
125      * Returns "true" on success (i.e., if there were no problems that
126      * need user interaction) and "false" if there were problems.  In
127      * the latter case, use problems() and later applySolutions()
128      * below.
129      **/
130     bool resolvePool (bool tryAllPossibilities);
131       
132     bool resolveDependencies( void );
133
134     /*
135      * Undo solver changes done in resolvePool()
136      * Throwing away all ignored dependencies.
137      */
138     void undo( void );
139
140     /*
141      * Get the most recent resolver context
142      *
143      * It will be NULL if resolvePool() or establishPool() was never called.
144      * Depending on the return code of the last resolvePool() call,
145      * it _either_ points to a valid or an invalid solution.
146      */
147     solver::detail::ResolverContext_Ptr context (void) const;
148
149     /**
150      * Do an distribution upgrade
151      *
152      * This will run a full upgrade on the pool, taking all upgrade
153      * dependencies (provide/obsolete for package renames, split-
154      * provides, etc.) into account and actually removing installed
155      * packages if no upgrade exists.
156      *
157      * To be run with great caution. It basically brings your
158      * system 'back to start'.
159      * Quite helpful to get back to a 'sane state'. Quite disastrous
160      * since you'll loose all non-distribution packages
161      **/
162     void doUpgrade( UpgradeStatistics & opt_stats_r );
163
164     /**
165      * Return the list of problematic update items
166      * i.e. locked ones (due to foreign vendor)
167      **/
168     std::list<PoolItem_Ref> problematicUpdateItems( void ) const;
169
170     /**
171      * Return the dependency problems found by the last call to
172      * resolveDependencies(). If there were no problems, the returned
173      * list will be empty.
174      **/
175     ResolverProblemList problems();
176
177     /**
178      * Return more solver information if an error has happened.
179      **/
180       
181     std::list<std::string> problemDescription( void ) const;      
182
183     /**
184      * Apply problem solutions. No more than one solution per problem
185      * can be applied.
186      **/
187     void applySolutions( const ProblemSolutionList & solutions );
188
189     Arch architecture() const;
190     void setArchitecture( const Arch & arch);
191
192     /**      
193      * Remove resolvables which are conflicts with others or
194      * have unfulfilled requirements.
195      * This behaviour is favourited by ZMD.
196      **/
197     void setForceResolve (const bool force);
198     bool forceResolve();
199
200     /**      
201      * Prefer the result with the newest version if there are more solver
202      * results. 
203      **/
204     void setPreferHighestVersion (const bool highestVersion);
205     bool preferHighestVersion();      
206
207     /**
208      * transact a single ResObject
209      *
210      * Installs (install == true) or removes (install == false) all required
211      * and recommended packages(!) of \c robj
212      * (More or less a 'single step' resolver call)
213      *
214      * returns false if requirements are not all fulfillable
215      * 
216      * Is obsolete; use resolvePool() instead
217      */
218     bool transactResObject( ResObject::constPtr robj, bool install = true);
219
220     /**
221      * transact all objects of this kind
222      *
223      * Look through the pool and runs transactResObject, first for removes
224      * then for installs
225      * (More or less a 'single step' resolver call)
226      *
227      * returns false if any transactResObject() call returned false.
228      *
229      * Is obsolete; use resolvePool() instead     
230      */
231     bool transactResKind( Resolvable::Kind kind );
232
233     /**
234      * reset any transact states
235      *
236      * Look through the pool and clear transact state.
237      * It will only reset states which have an equal or
238      * lower causer
239      *
240      * Is obsolete; use resolvePool() instead     
241      */
242     void transactReset( ResStatus::TransactByValue causer );
243
244     /**
245      * Adding additional requirement
246      *
247      */
248     void addRequire (const Capability & capability);
249
250     /**
251      * Adding additional conflict
252      *
253      */
254     void addConflict (const Capability & capability);
255
256     /**
257      * Remove the additional requirement set by \ref addRequire(Capability).
258      *
259      */
260     void removeRequire (const Capability & capability);
261
262     /**
263      * Remove the additional conflict set by \ref addConflict(Capability).
264      *
265      */
266     void removeConflict (const Capability & capability);
267
268     /**
269      * Get all the additional requirements set by \ref addRequire(Capability).
270      *
271      */      
272     const CapSet getRequire ();
273       
274     /**
275      * Get all the additional conflicts set by \ref addConflict(Capability).
276      *
277      */            
278     const CapSet getConflict();
279
280     /**
281      * Setting solver timeout
282      *
283      * Stop solving after a given timeframe (seconds) 
284      * seconds = 0 : No timeout
285      *
286      */
287     void setTimeout( int seconds );
288
289     /**
290      * Getting solver timeout in seconds
291      *
292      */
293     int timeout();      
294
295     /**
296      * Restricting solver passes
297      *
298      * Stop solving after a given amount of passes
299      * count = 0 : No restriction
300      *
301      */
302     void setMaxSolverPasses (int count);
303
304     /**
305      * Count of max solver passes
306      *
307      */
308     int maxSolverPasses ();
309
310     /**
311      * Generates a solver Testcase of the current state
312      *
313      * \parame dumpPath destination directory of the created directory
314      * \return true if it was successful     
315      */
316     bool createSolverTestcase (const std::string & dumpPath = "/var/log/YaST2/solverTestcase");
317
318
319     /**
320      * Gives information about WHO has pused an installation of an given item.
321      *
322      * \param item    Evaluate additional information for this resolvable.
323      * \return A list of structures which contains:
324      *          item     Item which has triggered the installation of the given param item.
325      *          cap      Capability which has triggerd this installation
326      *          capKind  Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
327      *
328      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
329      *
330      */
331     const solver::detail::ItemCapKindList isInstalledBy (const PoolItem_Ref item);
332
333     /**
334      * Gives information about WHICH additional items will be installed due the installation of an item.
335      *
336      * \param item     Evaluate additional information for this resolvable.
337      * \return A list of structures which contains:
338      *          item     Item which will be installed due to the installation of the given param item too.
339      *          cap      Capability which causes the installation
340      *          capKind  Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
341      *
342      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
343      *
344      */      
345     const solver::detail::ItemCapKindList installs (const PoolItem_Ref item);
346       
347
348   protected:
349
350   private:
351     solver::detail::Resolver_Ptr _pimpl;
352   };
353   ///////////////////////////////////////////////////////////////////
354
355   /////////////////////////////////////////////////////////////////
356 } // namespace zypp
357 ///////////////////////////////////////////////////////////////////
358 #endif // ZYPP_RESOLVER_H