libzypp 8.13.6
|
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 bool _cleandepsOnRemove; // whether removing a package should also remove no longer needed requirements 00123 00124 bool _ignoreAlreadyRecommended; //ignore recommended packages that have already been recommended by the installed packages 00126 00127 // Additional QueueItems which has to be regarded by the solver 00128 // This will be used e.g. by solution actions 00129 solver::detail::SolverQueueItemList _removed_queue_items; 00130 solver::detail::SolverQueueItemList _added_queue_items; 00131 00132 // Additional information about the solverrun 00133 ItemCapKindMap _isInstalledBy; 00134 ItemCapKindMap _installs; 00135 ItemCapKindMap _satifiedByInstalled; 00136 ItemCapKindMap _installedSatisfied; 00137 00138 // helpers 00139 void collectResolverInfo(); 00140 00141 // Unmaintained packages which does not fit to the updated system 00142 // (broken dependencies) will be deleted. 00143 // returns true if solving was successful 00144 bool checkUnmaintainedItems (); 00145 00146 void solverInit(); 00147 00148 public: 00149 00150 Resolver( const ResPool & pool ); 00151 virtual ~Resolver(); 00152 00153 // ---------------------------------- I/O 00154 00155 virtual std::ostream & dumpOn( std::ostream & str ) const; 00156 friend std::ostream& operator<<( std::ostream& str, const Resolver & obj ) 00157 { return obj.dumpOn (str); } 00158 00159 // ---------------------------------- methods 00160 00161 ResPool pool() const; 00162 void setPool( const ResPool & pool ) { _pool = pool; } 00163 00164 void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); } 00165 bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); } 00166 void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); } 00167 void removeUpgradeRepos() { _upgradeRepos.clear(); } 00168 const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; } 00169 00170 void addExtraRequire( const Capability & capability ); 00171 void removeExtraRequire( const Capability & capability ); 00172 void addExtraConflict( const Capability & capability ); 00173 void removeExtraConflict( const Capability & capability ); 00174 00175 void removeQueueItem( SolverQueueItem_Ptr item ); 00176 void addQueueItem( SolverQueueItem_Ptr item ); 00177 00178 CapabilitySet extraRequires() const { return _extra_requires; } 00179 CapabilitySet extraConflicts() const { return _extra_conflicts; } 00180 00181 void addWeak( const PoolItem & item ); 00182 00183 bool verifySystem(); 00184 bool resolvePool(); 00185 bool resolveQueue( SolverQueueItemList & queue ); 00186 void doUpdate(); 00187 00188 bool doUpgrade(); 00189 PoolItemList problematicUpdateItems() const; 00190 00193 bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; } 00194 void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; } 00195 00196 bool onlyRequires () const { return _onlyRequires; } 00197 void setOnlyRequires( TriBool state_r ); 00198 00199 bool forceResolve() const { return _forceResolve; } 00200 void setForceResolve( TriBool state_r ) { _forceResolve = indeterminate(state_r) ? false : bool(state_r); } 00201 00202 bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade 00203 void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; } 00204 00205 bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate 00206 00207 bool isVerifyingMode() const { return _verifying; } // The system will be checked 00208 void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); } 00209 00210 bool allowVendorChange() const { return _allowVendorChange; } 00211 void setAllowVendorChange( TriBool state_r ); 00212 00213 bool solveSrcPackages() const { return _solveSrcPackages; } 00214 void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); } 00215 00216 bool cleandepsOnRemove() const { return _cleandepsOnRemove; } 00217 void setCleandepsOnRemove( TriBool state_r ); 00219 00220 ResolverProblemList problems() const; 00221 void applySolutions( const ProblemSolutionList & solutions ); 00222 00223 // reset all SOLVER transaction in pool 00224 void undo(); 00225 00226 void reset( bool keepExtras = false ); 00227 00228 // Get more information about the solverrun 00229 // Which item will be installed by another item or triggers an item for 00230 // installation 00231 ItemCapKindList isInstalledBy( const PoolItem & item ); 00232 ItemCapKindList installs( const PoolItem & item ); 00233 ItemCapKindList satifiedByInstalled (const PoolItem & item ); 00234 ItemCapKindList installedSatisfied( const PoolItem & item ); 00235 00236 }; 00237 00239 };// namespace detail 00242 };// namespace solver 00245 };// namespace zypp 00247 00248 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H