00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ 00002 /* Resolver.h 00003 * 00004 * Copyright (C) 2000-2002 Ximian, Inc. 00005 * Copyright (C) 2005 SUSE Linux Products GmbH 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License, 00009 * version 2, as published by the Free Software Foundation. 00010 * 00011 * This program is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00019 * 02111-1307, USA. 00020 */ 00021 00022 #ifndef ZYPP_SOLVER_DETAIL_RESOLVER_H 00023 #define ZYPP_SOLVER_DETAIL_RESOLVER_H 00024 00025 #include <iosfwd> 00026 #include <list> 00027 #include <map> 00028 #include <string> 00029 00030 #include "zypp/base/ReferenceCounted.h" 00031 #include "zypp/base/PtrTypes.h" 00032 00033 #include "zypp/ResPool.h" 00034 #include "zypp/TriBool.h" 00035 #include "zypp/base/SerialNumber.h" 00036 00037 #include "zypp/solver/detail/Types.h" 00038 #include "zypp/solver/detail/SolverQueueItem.h" 00039 00040 #include "zypp/ProblemTypes.h" 00041 #include "zypp/ResolverProblem.h" 00042 #include "zypp/ProblemSolution.h" 00043 #include "zypp/Capabilities.h" 00044 #include "zypp/Capability.h" 00045 00046 00048 namespace zypp 00049 { 00050 00051 namespace solver 00052 { 00053 00054 namespace detail 00055 { 00056 00057 class SATResolver; 00058 00060 // 00061 // CLASS NAME : ItemCapKind 00062 // 00064 struct ItemCapKind 00065 { 00066 public: 00067 Capability cap; //Capability which has triggerd this selection 00068 Dep capKind; //Kind of that capability 00069 PoolItem item; //Item which has triggered this selection 00070 bool initialInstallation; //This item has triggered the installation 00071 //Not already fullfilled requierement only. 00072 00073 ItemCapKind() : capKind(Dep::PROVIDES) {} 00074 ItemCapKind( PoolItem i, Capability c, Dep k, bool initial) 00075 : cap( c ) 00076 , capKind( k ) 00077 , item( i ) 00078 , initialInstallation( initial ) 00079 { } 00080 }; 00081 typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap; 00082 typedef std::list<ItemCapKind> ItemCapKindList; 00083 00084 00086 // 00087 // CLASS NAME : Resolver 00095 class Resolver : public base::ReferenceCounted, private base::NonCopyable { 00096 00097 private: 00098 ResPool _pool; 00099 SATResolver *_satResolver; 00100 SerialNumberWatcher _poolchanged; 00101 00102 CapabilitySet _extra_requires; 00103 CapabilitySet _extra_conflicts; 00104 std::set<Repository> _upgradeRepos; 00105 00106 // Regard dependencies of the item weak onl 00107 PoolItemList _addWeak; 00108 00111 bool _forceResolve; // remove items which are conflicts with others or 00112 // have unfulfilled requirements. 00113 // This behaviour is favourited by ZMD 00114 bool _upgradeMode; // Resolver has been called with doUpgrade 00115 bool _updateMode; // Resolver has been called with doUpdate 00116 bool _verifying; // The system will be checked 00117 bool _onlyRequires; // do install required resolvables only 00118 // no recommended resolvables, language 00119 // packages, hardware packages (modalias) 00120 bool _allowVendorChange; // whether the solver should allow or disallow vendor changes. 00121 bool _solveSrcPackages; // whether to generate solver jobs for selected source packges. 00122 00123 bool _ignoreAlreadyRecommended; //ignore recommended packages that have already been recommended by the installed packages 00125 00126 // Additional QueueItems which has to be regarded by the solver 00127 // This will be used e.g. by solution actions 00128 solver::detail::SolverQueueItemList _removed_queue_items; 00129 solver::detail::SolverQueueItemList _added_queue_items; 00130 00131 // Additional information about the solverrun 00132 ItemCapKindMap _isInstalledBy; 00133 ItemCapKindMap _installs; 00134 ItemCapKindMap _satifiedByInstalled; 00135 ItemCapKindMap _installedSatisfied; 00136 00137 // helpers 00138 void collectResolverInfo(); 00139 00140 // Unmaintained packages which does not fit to the updated system 00141 // (broken dependencies) will be deleted. 00142 // returns true if solving was successful 00143 bool checkUnmaintainedItems (); 00144 00145 void solverInit(); 00146 00147 public: 00148 00149 Resolver( const ResPool & pool ); 00150 virtual ~Resolver(); 00151 00152 // ---------------------------------- I/O 00153 00154 virtual std::ostream & dumpOn( std::ostream & str ) const; 00155 friend std::ostream& operator<<( std::ostream& str, const Resolver & obj ) 00156 { return obj.dumpOn (str); } 00157 00158 // ---------------------------------- methods 00159 00160 ResPool pool() const; 00161 void setPool( const ResPool & pool ) { _pool = pool; } 00162 00163 void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); } 00164 bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); } 00165 void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); } 00166 void removeUpgradeRepos() { _upgradeRepos.clear(); } 00167 const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; } 00168 00169 void addExtraRequire( const Capability & capability ); 00170 void removeExtraRequire( const Capability & capability ); 00171 void addExtraConflict( const Capability & capability ); 00172 void removeExtraConflict( const Capability & capability ); 00173 00174 void removeQueueItem( SolverQueueItem_Ptr item ); 00175 void addQueueItem( SolverQueueItem_Ptr item ); 00176 00177 CapabilitySet extraRequires() { return _extra_requires; } 00178 CapabilitySet extraConflicts() { return _extra_conflicts; } 00179 00180 void addWeak( const PoolItem & item ); 00181 00182 bool verifySystem(); 00183 bool resolvePool(); 00184 bool resolveQueue( SolverQueueItemList & queue ); 00185 void doUpdate(); 00186 00187 bool doUpgrade(); 00188 PoolItemList problematicUpdateItems() const; 00189 00192 bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; } 00193 void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; } 00194 00195 bool onlyRequires () const { return _onlyRequires; } 00196 void setOnlyRequires( TriBool state_r ); 00197 00198 bool forceResolve() const { return _forceResolve; } 00199 void setForceResolve( TriBool state_r ) { _forceResolve = indeterminate(state_r) ? false : bool(state_r); } 00200 00201 bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade 00202 void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; } 00203 00204 bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate 00205 00206 bool isVerifyingMode() const { return _verifying; } // The system will be checked 00207 void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); } 00208 00209 bool allowVendorChange() const { return _allowVendorChange; } 00210 void setAllowVendorChange( TriBool state_r ); 00211 00212 bool solveSrcPackages() const { return _solveSrcPackages; } 00213 void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); } 00215 00216 ResolverProblemList problems() const; 00217 void applySolutions( const ProblemSolutionList & solutions ); 00218 00219 // reset all SOLVER transaction in pool 00220 void undo(); 00221 00222 void reset( bool keepExtras = false ); 00223 00224 // Get more information about the solverrun 00225 // Which item will be installed by another item or triggers an item for 00226 // installation 00227 ItemCapKindList isInstalledBy( const PoolItem & item ); 00228 ItemCapKindList installs( const PoolItem & item ); 00229 ItemCapKindList satifiedByInstalled (const PoolItem & item ); 00230 ItemCapKindList installedSatisfied( const PoolItem & item ); 00231 00232 }; 00233 00235 };// namespace detail 00238 };// namespace solver 00241 };// namespace zypp 00243 00244 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H