Make solver reset public
[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/SolverQueueItem.h"
25 #include "zypp/ProblemTypes.h"
26
27 ///////////////////////////////////////////////////////////////////
28 namespace zypp
29 { /////////////////////////////////////////////////////////////////
30
31
32   ///////////////////////////////////////////////////////////////////
33   //
34   //    CLASS NAME : Resolver
35   //
36   /**
37    * Dependency resolver interface.
38    *
39    * To resolve dependencies after making changes to the \ref ResPool (using
40    * \ref addRequire(), \ref addConflict(), \ref applySolutions(), or by making
41    * the changes directly on the \ref PoolItem status objects,
42    * call the \ref resolvePool() method.
43    * Do not use this method after \ref verifySystem(), \ref doUpdate(), or
44    * \ref doUpgrade().
45    */
46   class Resolver : public base::ReferenceCounted, private base::NonCopyable
47   {
48   public:
49
50     /** Ctor */
51     Resolver( const ResPool & pool );
52     /** Dtor */
53     virtual ~Resolver();
54
55     /**
56      * Resolve package dependencies:
57      *
58      * Verify consistency of system
59      *
60      **/
61     bool verifySystem ();
62
63
64     /**
65      * Resolve package dependencies:
66      *
67      * Try to execute all pending transactions (there may be more than
68      * one!).
69      * The solver collects all transactions (install/delete resolvables)
70      * from the pool, generates task, solving it and writes the 
71      * results back to pool
72      *
73      * Returns "true" on success (i.e., if there were no problems that
74      * need user interaction) and "false" if there were problems.  In
75      * the latter case, use problems() and later applySolutions()
76      * below.
77      **/
78     bool resolvePool (void);
79
80
81     /**
82      * Resolve package dependencies:
83      *
84      * The solver works off the given queue and writes back the solution
85      * to pool.
86      *
87      * Returns "true" on success (i.e., if there were no problems that
88      * need user interaction) and "false" if there were problems.  In
89      * the latter case, use problems() and later applySolutions()
90      * below.
91      * The solution could be that the solver remove/add some entries
92      * in the task queue. So make a new call of resolveQueue after you
93      * have applied any solution AND check the parameter "queue" if
94      * there has been any changes by the solver and adapt these changes
95      * to e.g. the selectables.
96      * 
97      **/
98     bool resolveQueue (solver::detail::SolverQueueItemList & queue);      
99
100     /*
101      * Undo solver changes done in resolvePool()
102      * Throwing away all ignored dependencies.
103      */
104     void undo( void );
105
106     /*
107      * Resets solver information and verify option.
108      */
109     void reset( void );
110       
111
112     /**
113      * Do an distribution upgrade
114      *
115      * This will run a full upgrade on the pool, taking all upgrade
116      * dependencies (provide/obsolete for package renames, split-
117      * provides, etc.) into account and actually removing installed
118      * packages if no upgrade exists AND the package dependency is
119      * broken
120      *
121      * To be run with great caution. It basically brings your
122      * system 'back to start'.
123      * Quite helpful to get back to a 'sane state'. Quite disastrous
124      * since you'll loose all non-distribution packages
125      **/
126     bool doUpgrade( UpgradeStatistics & opt_stats_r );
127
128     /**
129      * Update to newest package
130      *
131      * Install the newest version of your installed packages as
132      * far as possible. This means a newer package will NOT be
133      * installed if it generates dependency problems.
134      * So the user will not get an error message.
135      *
136      **/
137     void doUpdate( );
138       
139
140     /**
141      * Unmaintained packages which does not fit to 
142      * the updated system (broken dependencies) will be
143      * deleted.       
144      * Return the list of deleted items.
145      * Note : This list is valid after the call doUpgrade() only.
146      **/
147     std::list<PoolItem> problematicUpdateItems( void ) const;
148
149     /**
150      * Return the dependency problems found by the last call to
151      * resolveDependencies(). If there were no problems, the returned
152      * list will be empty.
153      **/
154     ResolverProblemList problems();
155
156       
157     /**
158      * Apply problem solutions. No more than one solution per problem
159      * can be applied.
160      **/
161     void applySolutions( const ProblemSolutionList & solutions );
162
163
164     /**      
165      * Remove resolvables which are conflicts with others or
166      * have unfulfilled requirements.
167      * This behaviour is favourited by ZMD.
168      **/
169     void setForceResolve (const bool force);
170     bool forceResolve();
171
172     /**      
173      * Ignore recommended packages that were already recommended by
174      * the installed packages
175      **/
176     void setIgnoreAlreadyRecommended (const bool ignoreAlreadyRecommended);
177     bool ignoreAlreadyRecommended();
178
179     /**
180      * Setting whether required packages are installed ONLY
181      * So recommended packages, language packages and packages which depend 
182      * on hardware (modalias) will not be regarded.
183      **/
184     void setOnlyRequires (const bool onlyRequires);
185     void resetOnlyRequires(); // set back to default (described in zypp.conf)  
186     bool onlyRequires();
187
188     /**
189      * Adding additional requirement
190      *
191      */
192     void addRequire (const Capability & capability);
193
194     /**
195      * Adding additional conflict
196      *
197      */
198     void addConflict (const Capability & capability);
199
200     /**
201      * Remove the additional requirement set by \ref addRequire(Capability).
202      *
203      */
204     void removeRequire (const Capability & capability);
205
206     /**
207      * Remove the additional conflict set by \ref addConflict(Capability).
208      *
209      */
210     void removeConflict (const Capability & capability);
211
212     /**
213      * Get all the additional requirements set by \ref addRequire(Capability).
214      *
215      */      
216     const CapabilitySet getRequire ();
217       
218     /**
219      * Get all the additional conflicts set by \ref addConflict(Capability).
220      *
221      */            
222     const CapabilitySet getConflict();
223
224     /**
225      * Generates a solver Testcase of the current state
226      *
227      * \parame dumpPath destination directory of the created directory
228      * \return true if it was successful     
229      */
230     bool createSolverTestcase (const std::string & dumpPath = "/var/log/YaST2/solverTestcase");
231
232     /**
233      * Gives information about WHO has pused an installation of an given item.
234      *
235      * \param item    Evaluate additional information for this resolvable.
236      * \return A list of structures which contains:
237      *          item     Item which has triggered the installation of the given param item.
238      *          cap      Capability which has triggerd this installation
239      *          capKind  Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
240      *
241      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
242      *
243      */
244     const solver::detail::ItemCapKindList isInstalledBy (const PoolItem item);
245
246     /**
247      * Gives information about WHICH additional items will be installed due the installation of an item.
248      *
249      * \param item     Evaluate additional information for this resolvable.
250      * \return A list of structures which contains:
251      *          item     Item which will be installed due to the installation of the given param item too.
252      *          cap      Capability which causes the installation
253      *          capKind  Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
254      *
255      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
256      *
257      */      
258     const solver::detail::ItemCapKindList installs (const PoolItem item);
259
260     /**
261      * Gives information about WHICH installed items are requested by the installation of an item.
262      *
263      * \param item     Evaluate additional information for this resolvable.
264      * \return A list of structures which contains:
265      *          item     installed Item which provide the requested capability.
266      *          cap      Capability which is needed
267      *          capKind  Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
268      *
269      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
270      *
271      */      
272     const solver::detail::ItemCapKindList satifiedByInstalled(const PoolItem item);
273       
274
275     /**
276      * Gives information about WHICH items require an already installed item.
277      *
278      * \param item     Evaluate additional information for this resolvable.
279      * \return A list of structures which contains:
280      *          item     Item which requires this capability.
281      *          cap      Capability which is needed
282      *          capKind  Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
283      *
284      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
285      *
286      */      
287     const solver::detail::ItemCapKindList installedSatisfied(const PoolItem item);
288       
289
290       
291   private:
292     solver::detail::Resolver_Ptr _pimpl;
293   };
294   ///////////////////////////////////////////////////////////////////
295
296   /////////////////////////////////////////////////////////////////
297 } // namespace zypp
298 ///////////////////////////////////////////////////////////////////
299 #endif // ZYPP_RESOLVER_H