1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * Copyright (C) 2000-2002 Ximian, Inc.
5 * Copyright (C) 2005 SUSE Linux Products GmbH
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.
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.
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
22 #ifndef ZYPP_SOLVER_DETAIL_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_RESOLVER_H
30 #include "zypp/base/ReferenceCounted.h"
31 #include "zypp/base/PtrTypes.h"
33 #include "zypp/ResPool.h"
34 #include "zypp/TriBool.h"
35 #include "zypp/base/SerialNumber.h"
37 #include "zypp/solver/detail/Types.h"
38 #include "zypp/solver/detail/SolverQueueItem.h"
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"
48 /////////////////////////////////////////////////////////////////////////
50 { ///////////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////////
53 { /////////////////////////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////////
56 { ///////////////////////////////////////////////////////////////////
61 ///////////////////////////////////////////////////////////////////
63 // CLASS NAME : ItemCapKind
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.
75 ItemCapKind() : capKind("FRESHENS") {}
76 ItemCapKind( PoolItem i, Capability c, Dep k, bool initial)
80 , initialInstallation( initial )
83 typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
84 typedef std::list<ItemCapKind> ItemCapKindList;
87 ///////////////////////////////////////////////////////////////////
89 // CLASS NAME : Resolver
91 typedef std::set<std::string> ObsoleteStrings;
93 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
97 SATResolver *_satResolver;
98 SerialNumberWatcher _poolchanged;
101 // list of problematic items after doUpgrade()
102 PoolItemList _problem_items;
104 // list of not supported packages
105 PoolItemSet _unmaintained_items;
107 CapabilitySet _extra_requires;
108 CapabilitySet _extra_conflicts;
110 // Regard dependencies of the item weak onl
111 PoolItemList _addWeak;
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)
122 bool _ignorealreadyrecommended; //ignore recommended packages that were already recommended by the installed packages
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;
129 // Additional information about the solverrun
130 ItemCapKindMap _isInstalledBy;
131 ItemCapKindMap _installs;
132 ItemCapKindMap _satifiedByInstalled;
133 ItemCapKindMap _installedSatisfied;
137 CapabilitySet _noObsoletesCapability;
138 PoolItemSet _noObsoletesItem;
139 ObsoleteStrings _noObsoletesString;
142 bool doesObsoleteCapability (PoolItem candidate, const Capability & cap);
143 bool doesObsoleteItem (PoolItem candidate, PoolItem installed);
144 void collectResolverInfo (void);
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 ();
155 Resolver (const ResPool & pool);
158 // ---------------------------------- I/O
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); }
164 // ---------------------------------- methods
166 ResPool pool (void) const;
167 void setPool (const ResPool & pool) { _pool = pool; }
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.
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;}
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; }
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; }
195 void addExtraRequire (const Capability & capability);
196 void removeExtraRequire (const Capability & capability);
197 void addExtraConflict (const Capability & capability);
198 void removeExtraConflict (const Capability & capability);
200 void removeQueueItem (const SolverQueueItem_Ptr item);
201 void addQueueItem (const SolverQueueItem_Ptr item);
203 const CapabilitySet extraRequires () { return _extra_requires; }
204 const CapabilitySet extraConflicts () { return _extra_conflicts; }
206 void addWeak (const PoolItem item);
208 void setForceResolve (const bool force) { _forceResolve = force; }
209 bool forceResolve() { return _forceResolve; }
211 void setIgnorealreadyrecommended (const bool ignorealreadyrecommended)
212 { _ignorealreadyrecommended = ignorealreadyrecommended; }
213 bool ignorealreadyrecommended() { return _ignorealreadyrecommended; }
215 void setOnlyRequires (const TriBool state)
216 { _onlyRequires = state; }
217 TriBool onlyRequires () { return _onlyRequires; }
219 bool verifySystem ();
221 bool resolveQueue(solver::detail::SolverQueueItemList & queue);
224 bool doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
225 PoolItemList problematicUpdateItems( void ) const { return _problem_items; }
227 ResolverProblemList problems () const;
228 void applySolutions (const ProblemSolutionList &solutions);
230 // reset all SOLVER transaction in pool
233 void reset (bool keepExtras = false );
235 bool testing(void) const { return _testing; }
236 void setTesting( bool testing ) { _testing = testing; }
238 // Get more information about the solverrun
239 // Which item will be installed by another item or triggers an item for
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);
248 ///////////////////////////////////////////////////////////////////
249 };// namespace detail
250 /////////////////////////////////////////////////////////////////////
251 /////////////////////////////////////////////////////////////////////
252 };// namespace solver
253 ///////////////////////////////////////////////////////////////////////
254 ///////////////////////////////////////////////////////////////////////
256 /////////////////////////////////////////////////////////////////////////
258 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H