* Gives information about WHICH items require an already installed
[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/TriBool.h"
35 #include "zypp/base/SerialNumber.h"
36
37 #include "zypp/solver/detail/Types.h"
38 #include "zypp/solver/detail/SolverQueueItem.h"
39
40 #include "zypp/ProblemTypes.h"
41 #include "zypp/ResolverProblem.h"
42 #include "zypp/ProblemSolution.h"
43 #include "zypp/UpgradeStatistics.h"
44 #include "zypp/Capabilities.h"
45 #include "zypp/Capability.h"
46
47
48 /////////////////////////////////////////////////////////////////////////
49 namespace zypp
50 { ///////////////////////////////////////////////////////////////////////
51   ///////////////////////////////////////////////////////////////////////
52   namespace solver
53   { /////////////////////////////////////////////////////////////////////
54     /////////////////////////////////////////////////////////////////////
55     namespace detail
56     { ///////////////////////////////////////////////////////////////////
57
58     class SATResolver;
59
60
61     ///////////////////////////////////////////////////////////////////
62     //
63     //  CLASS NAME : ItemCapKind
64     //
65     /** */
66     struct ItemCapKind
67     {
68         public:
69         Capability cap; //Capability which has triggerd this selection
70         Dep capKind; //Kind of that capability
71         PoolItem item; //Item which has triggered this selection
72         bool initialInstallation; //This item has triggered the installation
73                                   //Not already fullfilled requierement only.
74
75     ItemCapKind() : capKind("FRESHENS") {}
76             ItemCapKind( PoolItem i, Capability c, Dep k, bool initial)
77                 : cap( c )
78                 , capKind( k )
79                 , item( i )
80                 , initialInstallation( initial )
81             { }
82     };
83     typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
84     typedef std::list<ItemCapKind> ItemCapKindList;
85         
86
87 ///////////////////////////////////////////////////////////////////
88 //
89 //      CLASS NAME : Resolver
90
91 typedef std::set<std::string> ObsoleteStrings;  
92
93 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
94
95   private:
96     ResPool _pool;
97     SATResolver *_satResolver;
98     SerialNumberWatcher _poolchanged;
99     bool _testing;
100
101     // list of problematic items after doUpgrade()
102     PoolItemList _problem_items;
103
104     // list of not supported packages
105     PoolItemSet _unmaintained_items;    
106
107     CapabilitySet _extra_requires;
108     CapabilitySet _extra_conflicts;
109     
110     // Regard dependencies of the item weak onl
111     PoolItemList _addWeak;
112
113     bool _forceResolve;           // remove items which are conflicts with others or
114                                   // have unfulfilled requirements.
115                                   // This behaviour is favourited by ZMD
116     bool _upgradeMode;            // Resolver has been called with doUpgrade
117     bool _verifying;              // The system will be checked
118     TriBool _onlyRequires;        // do install required resolvables only
119                                   // no recommended resolvables, language
120                                   // packages, hardware packages (modalias)
121
122     bool _ignorealreadyrecommended;   //ignore recommended packages that were already recommended by the installed packages
123
124     // Additional QueueItems which has to be regarded by the solver
125     // This will be used e.g. by solution actions
126     solver::detail::SolverQueueItemList _removed_queue_items;
127     solver::detail::SolverQueueItemList _added_queue_items;
128
129     // Additional information about the solverrun
130     ItemCapKindMap _isInstalledBy;
131     ItemCapKindMap _installs;
132     ItemCapKindMap _satifiedByInstalled;
133     ItemCapKindMap _installedSatisfied;
134
135
136     // Ignore Obsoletes
137     CapabilitySet _noObsoletesCapability;
138     PoolItemSet _noObsoletesItem;
139     ObsoleteStrings _noObsoletesString;   
140     
141     // helpers
142     bool doesObsoleteCapability (PoolItem candidate, const Capability & cap);
143     bool doesObsoleteItem (PoolItem candidate, PoolItem installed);
144     void collectResolverInfo (void);    
145
146     // Unmaintained packages which does not fit to the updated system
147     // (broken dependencies) will be deleted.
148     // returns true if solving was successful
149     bool checkUnmaintainedItems ();
150
151     void solverInit();
152
153   public:
154
155     Resolver (const ResPool & pool);
156     virtual ~Resolver();
157
158     // ---------------------------------- I/O
159
160     virtual std::ostream & dumpOn( std::ostream & str ) const;
161     friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
162     { return obj.dumpOn (str); }
163
164     // ---------------------------------- methods
165
166     ResPool pool (void) const;
167     void setPool (const ResPool & pool) { _pool = pool; }
168
169
170     // Ignore Obsoletes. This is used for installing more than
171     // one pacakges with the same name but different versions.
172     // Often needed by kernels.
173
174     // via capability who provides it
175     void addNoObsoletesCapability (const Capability & capability)
176         { _noObsoletesCapability.insert (capability); }    
177     void removeNoObsoletesCapability (const Capability & capability)
178         { _noObsoletesCapability.erase (capability); }
179     CapabilitySet noObsoletesCapability() { return _noObsoletesCapability;}
180
181     // via poolItem
182     void addNoObsoletesItem (const PoolItem & item)
183         { _noObsoletesItem.insert (item); }
184     void removeNoObsoletesItem (const PoolItem & item)
185         { _noObsoletesItem.erase (item); }
186     PoolItemSet noObsoletesItem() { return _noObsoletesItem; }
187
188     // via package name
189     void addNoObsoletesName (const std::string & name)
190         { _noObsoletesString.insert (name); }
191     void removeNoObsoletesName (const std::string & name)
192         { _noObsoletesString.erase (name); }    
193     ObsoleteStrings noObsoletesString () { return _noObsoletesString; }
194
195     void addExtraRequire (const Capability & capability);
196     void removeExtraRequire (const Capability & capability);
197     void addExtraConflict (const Capability & capability);
198     void removeExtraConflict (const Capability & capability);
199
200     void removeQueueItem (const SolverQueueItem_Ptr item);
201     void addQueueItem (const SolverQueueItem_Ptr item);    
202
203     const CapabilitySet extraRequires () { return _extra_requires; }
204     const CapabilitySet extraConflicts () { return _extra_conflicts; }
205
206     void addWeak (const PoolItem item);
207
208     void setForceResolve (const bool force) { _forceResolve = force; }
209     bool forceResolve() { return _forceResolve; }
210
211     void setIgnorealreadyrecommended (const bool ignorealreadyrecommended)
212         { _ignorealreadyrecommended = ignorealreadyrecommended; }
213     bool ignorealreadyrecommended() { return _ignorealreadyrecommended; }    
214
215     void setOnlyRequires (const TriBool state)
216         { _onlyRequires = state; }
217     TriBool onlyRequires () { return _onlyRequires; }
218
219     bool verifySystem ();
220     bool resolvePool();
221     bool resolveQueue(solver::detail::SolverQueueItemList & queue);    
222     void doUpdate();
223
224     bool doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
225     PoolItemList problematicUpdateItems( void ) const { return _problem_items; }
226
227     ResolverProblemList problems () const;
228     void applySolutions (const ProblemSolutionList &solutions);
229
230     // reset all SOLVER transaction in pool
231     void undo(void);
232
233     void reset (bool keepExtras = false );
234
235     bool testing(void) const { return _testing; }
236     void setTesting( bool testing ) { _testing = testing; }
237
238     // Get more information about the solverrun
239     // Which item will be installed by another item or triggers an item for
240     // installation
241     const ItemCapKindList isInstalledBy (const PoolItem item);
242     const ItemCapKindList installs (const PoolItem item);
243     const ItemCapKindList satifiedByInstalled (const PoolItem item);    
244     const ItemCapKindList installedSatisfied (const PoolItem item);
245     
246 };
247
248 ///////////////////////////////////////////////////////////////////
249     };// namespace detail
250     /////////////////////////////////////////////////////////////////////
251     /////////////////////////////////////////////////////////////////////
252   };// namespace solver
253   ///////////////////////////////////////////////////////////////////////
254   ///////////////////////////////////////////////////////////////////////
255 };// namespace zypp
256 /////////////////////////////////////////////////////////////////////////
257
258 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H