Fixed warnings by removing useless const in return types.
[platform/upstream/libzypp.git] / zypp / solver / detail / Resolver.h
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* Resolver.h
3  *
4  * Copyright (C) 2000-2002 Ximian, Inc.
5  * Copyright (C) 2005 SUSE Linux Products GmbH
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21
22 #ifndef ZYPP_SOLVER_DETAIL_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_RESOLVER_H
24
25 #include <iosfwd>
26 #include <list>
27 #include <map>
28 #include <string>
29
30 #include "zypp/base/ReferenceCounted.h"
31 #include "zypp/base/PtrTypes.h"
32
33 #include "zypp/ResPool.h"
34 #include "zypp/base/SerialNumber.h"
35
36 #include "zypp/solver/detail/Types.h"
37 #include "zypp/solver/detail/ResolverQueue.h"
38 #include "zypp/solver/detail/ResolverContext.h"
39 #include "zypp/solver/detail/ContextPool.h"
40
41 #include "zypp/ProblemTypes.h"
42 #include "zypp/ResolverProblem.h"
43 #include "zypp/ProblemSolution.h"
44 #include "zypp/UpgradeStatistics.h"
45
46 #include "zypp/CapSet.h"
47
48
49 /////////////////////////////////////////////////////////////////////////
50 namespace zypp
51 { ///////////////////////////////////////////////////////////////////////
52   ///////////////////////////////////////////////////////////////////////
53   namespace solver
54   { /////////////////////////////////////////////////////////////////////
55     /////////////////////////////////////////////////////////////////////
56     namespace detail
57     { ///////////////////////////////////////////////////////////////////
58
59     ///////////////////////////////////////////////////////////////////
60     //
61     //  CLASS NAME : ItemCapKind
62     //
63     /** */
64     struct ItemCapKind
65     {
66         public:
67         Capability cap; //Capability which has triggerd this selection
68         Dep capKind; //Kind of that capability
69         PoolItem_Ref item; //Item which has triggered this selection
70         bool initialInstallation; //This item has triggered the installation
71                                   //Not already fullfilled requierement only.
72
73     ItemCapKind() : capKind("FRESHENS") {}
74             ItemCapKind( PoolItem i, Capability c, Dep k, bool initial)
75                 : cap( c )
76                 , capKind( k )
77                 , item( i )
78                 , initialInstallation( initial )
79             { }
80     };
81     typedef std::multimap<PoolItem_Ref,ItemCapKind> ItemCapKindMap;
82     typedef std::list<ItemCapKind> ItemCapKindList;
83
84 ///////////////////////////////////////////////////////////////////
85 //
86 //      CLASS NAME : Resolver
87
88 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
89
90   private:
91     ResPool _pool;
92     SerialNumberWatcher _poolchanged;
93
94     unsigned _timeout_seconds;
95     unsigned _maxSolverPasses;
96     bool _verifying;
97     bool _testing;
98
99     // In order reducing solver time we are reducing the branches
100     // by skipping resolvables which have worse architecture,edition
101     // than a resolvable which provides the same cababilities.
102     // BUT if there is no valid solution we will regard the "other"
103     // resolvables in a second solver run too.
104     bool _tryAllPossibilities; // Try ALL alternatives
105
106     // list populated by calls to addPoolItemTo*()
107     QueueItemList _initial_items;
108     PoolItemList _items_to_install;
109     PoolItemList _items_to_establish;
110     PoolItemList _items_to_remove;
111     PoolItemList _items_to_verify;
112     PoolItemList _items_to_lockUninstalled;
113     PoolItemList _items_to_keep;    
114
115     // pool of valid contexts which are "recycled" in order to fasten the solver
116     ContextPool contextPool;
117
118     // list of problematic items after doUpgrade()
119     PoolItemList _update_items;
120
121     // Additional information about the solverrun
122     ItemCapKindMap _isInstalledBy;
123     ItemCapKindMap _installs;
124
125     CapSet _extra_caps;
126     CapSet _extra_conflicts;
127
128     //typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
129
130     // These conflict should be ignored of the concering item
131     IgnoreMap _ignoreConflicts;
132     // These requires should be ignored of the concering item
133     IgnoreMap _ignoreRequires;
134     // These obsoletes should be ignored of the concering item
135     IgnoreMap _ignoreObsoletes;
136     // Ignore architecture of the item
137     PoolItemList _ignoreArchitecture;
138     // Ignore the status "installed" of the item
139     PoolItemList _ignoreInstalledItem;
140     // Ignore the architecture of the item
141     PoolItemList _ignoreArchitectureItem;
142     // Ignore the vendor of the item
143     PoolItemList _ignoreVendorItem;
144
145     ResolverQueueList _pending_queues;
146     ResolverQueueList _pruned_queues;
147     ResolverQueueList _complete_queues;
148     ResolverQueueList _deferred_queues;
149     ResolverQueueList _invalid_queues;
150
151     int _valid_solution_count;
152
153     ResolverContext_Ptr _best_context;
154     // Context of the last establishing call ( without any transaction )
155     ResolverContext_Ptr _establish_context;
156     bool _timed_out;
157
158     std::set<Repository> _subscribed;
159
160     Arch _architecture;
161
162     bool _forceResolve; // remove items which are conflicts with others or
163                         // have unfulfilled requirements.
164                         // This behaviour is favourited by ZMD
165     bool _upgradeMode;  // Resolver has been called with doUpgrade
166     bool _preferHighestVersion; // Prefer the result with the newest version
167                                 //if there are more solver results.
168
169     // helpers
170     bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
171     bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
172
173     void collectResolverInfo (void);
174
175
176   public:
177
178     Resolver (const ResPool & pool);
179     virtual ~Resolver();
180
181     // ---------------------------------- I/O
182
183     virtual std::ostream & dumpOn( std::ostream & str ) const;
184     friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
185     { return obj.dumpOn (str); }
186     void dumpTaskList(const PoolItemList &install, const PoolItemList &remove );
187
188     // ---------------------------------- accessors
189
190     QueueItemList initialItems () const { return _initial_items; }
191
192     ResolverQueueList pendingQueues () const { return _pending_queues; }
193     ResolverQueueList prunedQueues () const { return _pruned_queues; }
194     ResolverQueueList completeQueues () const { return _complete_queues; }
195     ResolverQueueList deferredQueues () const { return _deferred_queues; }
196     ResolverQueueList invalidQueues () const { return _invalid_queues; }
197
198     ResolverContext_Ptr bestContext (void) const { return _best_context; }
199
200     /** depending on the last solver result, either return bestContext()
201         of the first invalid context */
202     ResolverContext_Ptr context (void) const;
203
204     // ---------------------------------- methods
205
206     void setTimeout (int seconds) { _timeout_seconds = seconds; }
207     void setMaxSolverPasses (int count) { _maxSolverPasses = count; }
208     int timeout () const { return _timeout_seconds; }
209     int maxSolverPasses () const { return _maxSolverPasses; }
210
211     ResPool pool (void) const;
212     void setPool (const ResPool & pool) { _pool = pool; }
213
214     void addSubscribedSource (Repository source);
215
216     void addPoolItemToInstall (PoolItem_Ref item);
217     void addPoolItemsToInstallFromList (PoolItemList & rl);
218
219     void addPoolItemToLockUninstalled (PoolItem_Ref item);
220     void addPoolItemToKepp (PoolItem_Ref item);
221
222     void addPoolItemToRemove (PoolItem_Ref item);
223     void addPoolItemsToRemoveFromList (PoolItemList & rl);
224
225     void addPoolItemToEstablish (PoolItem_Ref item);
226     void addPoolItemsToEstablishFromList (PoolItemList & rl);
227
228     void addPoolItemToVerify (PoolItem_Ref item);
229
230     void addExtraCapability (const Capability & capability);
231     void removeExtraCapability (const Capability & capability);
232     void addExtraConflict (const Capability & capability);
233
234     const CapSet extraCapability () { return _extra_caps; }
235     const CapSet extraConflicts () { return _extra_conflicts; }
236
237     void addIgnoreConflict (const PoolItem_Ref item,
238                             const Capability & capability);
239     void addIgnoreRequires (const PoolItem_Ref item,
240                             const Capability & capability);
241     void addIgnoreObsoletes (const PoolItem_Ref item,
242                              const Capability & capability);
243     void addIgnoreInstalledItem (const PoolItem_Ref item);
244     void addIgnoreArchitectureItem (const PoolItem_Ref item);
245     void addIgnoreVendorItem (const PoolItem_Ref item);    
246
247     void setForceResolve (const bool force) { _forceResolve = force; }
248     bool forceResolve() { return _forceResolve; }
249     void setPreferHighestVersion (const bool highestVersion) { _preferHighestVersion = highestVersion; }
250     bool preferHighestVersion() { return _preferHighestVersion; }
251
252     void setTryAllPossibilities (const bool tryAllPossibilities) { _tryAllPossibilities = tryAllPossibilities; }
253     bool tryAllPossibilities () const { return _tryAllPossibilities; };
254
255     bool verifySystem (bool considerNewHardware = false);
256     void establishState (ResolverContext_Ptr context = NULL);
257     bool establishPool (void);
258     void freshenState( ResolverContext_Ptr context = NULL, bool resetAfterSolve = true );
259     bool freshenPool( bool resetAfterSolve = true );
260     bool resolveDependencies (const ResolverContext_Ptr context = NULL);
261     bool resolvePool( bool tryAllPossibilities = false);
262
263     bool transactResObject( ResObject::constPtr robj,
264                             bool install = true,
265                             bool recursive = false);
266     bool transactResKind( Resolvable::Kind kind );
267     void transactReset( ResStatus::TransactByValue causer );
268
269     void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
270     PoolItemList problematicUpdateItems( void ) const { return _update_items; }
271
272
273     ResolverProblemList problems (const bool ignoreValidSolution = false) const;
274     void applySolutions (const ProblemSolutionList &solutions);
275     // returns a string list of ResolverInfo of the LAST not valid solution
276     std::list<std::string> problemDescription( void ) const;
277
278     // reset all SOLVER transaction in pool
279     void undo(void);
280
281     // Get more information about the solverrun
282     // Which item will be installed by another item or triggers an item for
283     // installation
284     const ItemCapKindList isInstalledBy (const PoolItem_Ref item);
285     const ItemCapKindList installs (const PoolItem_Ref item);
286
287     void reset (bool resetValidResults = false, bool keepExtras = false );
288
289     Arch architecture() const { return _architecture; }
290     void setArchitecture( const Arch & arch) { _architecture = arch; }
291
292     bool testing(void) const { return _testing; }
293     void setTesting( bool testing ) { _testing = testing; }
294 };
295
296 ///////////////////////////////////////////////////////////////////
297     };// namespace detail
298     /////////////////////////////////////////////////////////////////////
299     /////////////////////////////////////////////////////////////////////
300   };// namespace solver
301   ///////////////////////////////////////////////////////////////////////
302   ///////////////////////////////////////////////////////////////////////
303 };// namespace zypp
304 /////////////////////////////////////////////////////////////////////////
305
306 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H