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(Dep::PROVIDES) {}
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 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
95 SATResolver *_satResolver;
96 SerialNumberWatcher _poolchanged;
99 CapabilitySet _extra_requires;
100 CapabilitySet _extra_conflicts;
102 // Regard dependencies of the item weak onl
103 PoolItemList _addWeak;
105 /** \name Solver flags */
107 bool _forceResolve; // remove items which are conflicts with others or
108 // have unfulfilled requirements.
109 // This behaviour is favourited by ZMD
110 bool _upgradeMode; // Resolver has been called with doUpgrade
111 bool _updateMode; // Resolver has been called with doUpdate
112 bool _verifying; // The system will be checked
113 bool _onlyRequires; // do install required resolvables only
114 // no recommended resolvables, language
115 // packages, hardware packages (modalias)
116 bool _allowVendorChange; // whether the solver should allow or disallow vendor changes.
117 bool _solveSrcPackages; // whether to generate solver jobs for selected source packges.
119 bool _ignoreAlreadyRecommended; //ignore recommended packages that have already been recommended by the installed packages
122 // Additional QueueItems which has to be regarded by the solver
123 // This will be used e.g. by solution actions
124 solver::detail::SolverQueueItemList _removed_queue_items;
125 solver::detail::SolverQueueItemList _added_queue_items;
127 // Additional information about the solverrun
128 ItemCapKindMap _isInstalledBy;
129 ItemCapKindMap _installs;
130 ItemCapKindMap _satifiedByInstalled;
131 ItemCapKindMap _installedSatisfied;
134 void collectResolverInfo();
136 // Unmaintained packages which does not fit to the updated system
137 // (broken dependencies) will be deleted.
138 // returns true if solving was successful
139 bool checkUnmaintainedItems ();
145 Resolver( const ResPool & pool );
148 // ---------------------------------- I/O
150 virtual std::ostream & dumpOn( std::ostream & str ) const;
151 friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
152 { return obj.dumpOn (str); }
154 // ---------------------------------- methods
156 ResPool pool() const;
157 void setPool( const ResPool & pool ) { _pool = pool; }
159 void addExtraRequire( const Capability & capability );
160 void removeExtraRequire( const Capability & capability );
161 void addExtraConflict( const Capability & capability );
162 void removeExtraConflict( const Capability & capability );
164 void removeQueueItem( SolverQueueItem_Ptr item );
165 void addQueueItem( SolverQueueItem_Ptr item );
167 CapabilitySet extraRequires() { return _extra_requires; }
168 CapabilitySet extraConflicts() { return _extra_conflicts; }
170 void addWeak( const PoolItem & item );
174 bool resolveQueue( SolverQueueItemList & queue );
177 bool doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
178 PoolItemList problematicUpdateItems() const;
180 /** \name Solver flags */
182 bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; }
183 void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
185 bool onlyRequires () const { return _onlyRequires; }
186 void setOnlyRequires( TriBool state_r );
188 bool forceResolve() const { return _forceResolve; }
189 void setForceResolve( TriBool state_r ) { _forceResolve = indeterminate(state_r) ? false : bool(state_r); }
191 bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
193 bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
195 bool isVerifyingMode() const { return _verifying; } // The system will be checked
196 void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); }
198 bool allowVendorChange() const { return _allowVendorChange; }
199 void setAllowVendorChange( TriBool state_r );
201 bool solveSrcPackages() const { return _solveSrcPackages; }
202 void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
205 ResolverProblemList problems() const;
206 void applySolutions( const ProblemSolutionList & solutions );
208 // reset all SOLVER transaction in pool
211 void reset( bool keepExtras = false );
213 // Get more information about the solverrun
214 // Which item will be installed by another item or triggers an item for
216 ItemCapKindList isInstalledBy( const PoolItem & item );
217 ItemCapKindList installs( const PoolItem & item );
218 ItemCapKindList satifiedByInstalled (const PoolItem & item );
219 ItemCapKindList installedSatisfied( const PoolItem & item );
223 ///////////////////////////////////////////////////////////////////
224 };// namespace detail
225 /////////////////////////////////////////////////////////////////////
226 /////////////////////////////////////////////////////////////////////
227 };// namespace solver
228 ///////////////////////////////////////////////////////////////////////
229 ///////////////////////////////////////////////////////////////////////
231 /////////////////////////////////////////////////////////////////////////
233 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H