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/Capabilities.h"
44 #include "zypp/Capability.h"
47 /////////////////////////////////////////////////////////////////////////
49 { ///////////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////////
58 { /////////////////////////////////////////////////////////////////////
59 /////////////////////////////////////////////////////////////////////
61 { ///////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////
67 // CLASS NAME : ItemCapKind
73 Capability cap; //Capability which has triggerd this selection
74 Dep capKind; //Kind of that capability
75 PoolItem item; //Item which has triggered this selection
76 bool initialInstallation; //This item has triggered the installation
77 //Not already fullfilled requierement only.
79 ItemCapKind() : capKind(Dep::PROVIDES) {}
80 ItemCapKind( PoolItem i, Capability c, Dep k, bool initial)
84 , initialInstallation( initial )
87 typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
88 typedef std::list<ItemCapKind> ItemCapKindList;
91 ///////////////////////////////////////////////////////////////////
93 // CLASS NAME : Resolver
94 /** A mid layer class we should remove
95 * \todo Merge this and class SATResolver. Logic and date are horribly
96 * distributed between this and SATResolver. Either SATResolver becomes
97 * a pure wrapper adapting the libsolv C interface to fit our needs, and
98 * all the solver logic and problem handling goes here; or completely merge
101 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
105 SATResolver *_satResolver;
106 SerialNumberWatcher _poolchanged;
108 CapabilitySet _extra_requires;
109 CapabilitySet _extra_conflicts;
110 std::set<Repository> _upgradeRepos;
112 // Regard dependencies of the item weak onl
113 PoolItemList _addWeak;
115 /** \name Solver flags */
117 bool _forceResolve; // remove items which are conflicts with others or
118 // have unfulfilled requirements.
119 // This behaviour is favourited by ZMD
120 bool _upgradeMode; // Resolver has been called with doUpgrade
121 bool _updateMode; // Resolver has been called with doUpdate
122 bool _verifying; // The system will be checked
123 bool _onlyRequires; // do install required resolvables only
124 // no recommended resolvables, language
125 // packages, hardware packages (modalias)
126 bool _allowVendorChange; // whether the solver should allow or disallow vendor changes.
127 bool _solveSrcPackages; // whether to generate solver jobs for selected source packges.
128 bool _cleandepsOnRemove; // whether removing a package should also remove no longer needed requirements
130 bool _ignoreAlreadyRecommended; //ignore recommended packages that have already been recommended by the installed packages
133 // Additional QueueItems which has to be regarded by the solver
134 // This will be used e.g. by solution actions
135 solver::detail::SolverQueueItemList _removed_queue_items;
136 solver::detail::SolverQueueItemList _added_queue_items;
138 // Additional information about the solverrun
139 ItemCapKindMap _isInstalledBy;
140 ItemCapKindMap _installs;
141 ItemCapKindMap _satifiedByInstalled;
142 ItemCapKindMap _installedSatisfied;
145 void collectResolverInfo();
147 // Unmaintained packages which does not fit to the updated system
148 // (broken dependencies) will be deleted.
149 // returns true if solving was successful
150 bool checkUnmaintainedItems ();
156 Resolver( const ResPool & pool );
159 // ---------------------------------- I/O
161 virtual std::ostream & dumpOn( std::ostream & str ) const;
162 friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
163 { return obj.dumpOn (str); }
165 // ---------------------------------- methods
167 ResPool pool() const;
168 void setPool( const ResPool & pool ) { _pool = pool; }
170 void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
171 bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
172 void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); }
173 void removeUpgradeRepos() { _upgradeRepos.clear(); }
174 const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; }
176 void addExtraRequire( const Capability & capability );
177 void removeExtraRequire( const Capability & capability );
178 void addExtraConflict( const Capability & capability );
179 void removeExtraConflict( const Capability & capability );
181 void removeQueueItem( SolverQueueItem_Ptr item );
182 void addQueueItem( SolverQueueItem_Ptr item );
184 CapabilitySet extraRequires() const { return _extra_requires; }
185 CapabilitySet extraConflicts() const { return _extra_conflicts; }
187 void addWeak( const PoolItem & item );
191 bool resolveQueue( SolverQueueItemList & queue );
195 PoolItemList problematicUpdateItems() const;
197 /** \name Solver flags */
199 bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; }
200 void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
202 bool onlyRequires () const { return _onlyRequires; }
203 void setOnlyRequires( TriBool state_r );
205 bool forceResolve() const { return _forceResolve; }
206 void setForceResolve( TriBool state_r ) { _forceResolve = indeterminate(state_r) ? false : bool(state_r); }
208 bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
209 void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; }
211 bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
213 bool isVerifyingMode() const { return _verifying; } // The system will be checked
214 void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); }
216 bool allowVendorChange() const { return _allowVendorChange; }
217 void setAllowVendorChange( TriBool state_r );
219 bool solveSrcPackages() const { return _solveSrcPackages; }
220 void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
222 bool cleandepsOnRemove() const { return _cleandepsOnRemove; }
223 void setCleandepsOnRemove( TriBool state_r );
226 ResolverProblemList problems() const;
227 void applySolutions( const ProblemSolutionList & solutions );
229 // Return the Transaction computed by the last solver run.
230 sat::Transaction getTransaction();
232 // reset all SOLVER transaction in pool
235 void reset( bool keepExtras = false );
237 // Get more information about the solverrun
238 // Which item will be installed by another item or triggers an item for
240 ItemCapKindList isInstalledBy( const PoolItem & item );
241 ItemCapKindList installs( const PoolItem & item );
242 ItemCapKindList satifiedByInstalled (const PoolItem & item );
243 ItemCapKindList installedSatisfied( const PoolItem & item );
247 ///////////////////////////////////////////////////////////////////
248 };// namespace detail
249 /////////////////////////////////////////////////////////////////////
250 /////////////////////////////////////////////////////////////////////
251 };// namespace solver
252 ///////////////////////////////////////////////////////////////////////
253 ///////////////////////////////////////////////////////////////////////
255 /////////////////////////////////////////////////////////////////////////
257 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H