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
24 #ifndef ZYPP_USE_RESOLVER_INTERNALS
25 #error Do not directly include this file!
33 #include "zypp/ResPool.h"
34 #include "zypp/TriBool.h"
35 #include "zypp/base/SerialNumber.h"
36 #include "zypp/base/NonCopyable.h"
38 #include "zypp/ProblemTypes.h"
39 #include "zypp/ResolverProblem.h"
40 #include "zypp/ProblemSolution.h"
41 #include "zypp/Capabilities.h"
42 #include "zypp/Capability.h"
44 /////////////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////////
58 typedef std::list<PoolItem> PoolItemList;
59 typedef std::set<PoolItem> PoolItemSet;
61 ///////////////////////////////////////////////////////////////////
63 // CLASS NAME : Resolver
64 /** A mid layer class we should remove
65 * \todo Merge this and class SATResolver. Logic and date are horribly
66 * distributed between this and SATResolver. Either SATResolver becomes
67 * a pure wrapper adapting the libsolv C interface to fit our needs, and
68 * all the solver logic and problem handling goes here; or completely merge
71 class Resolver : private base::NonCopyable
73 typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
76 SATResolver *_satResolver;
77 SerialNumberWatcher _poolchanged;
79 CapabilitySet _extra_requires;
80 CapabilitySet _extra_conflicts;
81 std::set<Repository> _upgradeRepos;
83 // Regard dependencies of the item weak onl
84 PoolItemList _addWeak;
86 /** \name Solver flags */
88 bool _forceResolve; // remove items which are conflicts with others or
89 // have unfulfilled requirements.
90 // This behaviour is favourited by ZMD
91 bool _upgradeMode; // Resolver has been called with doUpgrade
92 bool _updateMode; // Resolver has been called with doUpdate
93 bool _verifying; // The system will be checked
94 bool _onlyRequires; // do install required resolvables only
95 // no recommended resolvables, language
96 // packages, hardware packages (modalias)
97 bool _allowVendorChange; // whether the solver should allow or disallow vendor changes.
98 bool _solveSrcPackages; // whether to generate solver jobs for selected source packges.
99 bool _cleandepsOnRemove; // whether removing a package should also remove no longer needed requirements
101 bool _ignoreAlreadyRecommended; //ignore recommended packages that have already been recommended by the installed packages
104 // Additional QueueItems which has to be regarded by the solver
105 // This will be used e.g. by solution actions
106 solver::detail::SolverQueueItemList _removed_queue_items;
107 solver::detail::SolverQueueItemList _added_queue_items;
109 // Additional information about the solverrun
110 ItemCapKindMap _isInstalledBy;
111 ItemCapKindMap _installs;
112 ItemCapKindMap _satifiedByInstalled;
113 ItemCapKindMap _installedSatisfied;
116 void collectResolverInfo();
118 // Unmaintained packages which does not fit to the updated system
119 // (broken dependencies) will be deleted.
120 // returns true if solving was successful
121 bool checkUnmaintainedItems ();
127 Resolver( const ResPool & pool );
130 // ---------------------------------- I/O
132 std::ostream & dumpOn( std::ostream & str ) const;
134 friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
135 { return obj.dumpOn (str); }
137 // ---------------------------------- methods
139 ResPool pool() const;
140 void setPool( const ResPool & pool ) { _pool = pool; }
142 void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
143 bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
144 void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); }
145 void removeUpgradeRepos() { _upgradeRepos.clear(); }
146 const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; }
148 void addExtraRequire( const Capability & capability );
149 void removeExtraRequire( const Capability & capability );
150 void addExtraConflict( const Capability & capability );
151 void removeExtraConflict( const Capability & capability );
153 void removeQueueItem( SolverQueueItem_Ptr item );
154 void addQueueItem( SolverQueueItem_Ptr item );
156 CapabilitySet extraRequires() const { return _extra_requires; }
157 CapabilitySet extraConflicts() const { return _extra_conflicts; }
159 void addWeak( const PoolItem & item );
163 bool resolveQueue( SolverQueueItemList & queue );
167 PoolItemList problematicUpdateItems() const;
169 /** \name Solver flags */
171 bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; }
172 void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
174 bool onlyRequires () const { return _onlyRequires; }
175 void setOnlyRequires( TriBool state_r );
177 bool forceResolve() const { return _forceResolve; }
178 void setForceResolve( TriBool state_r ) { _forceResolve = indeterminate(state_r) ? false : bool(state_r); }
180 bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
181 void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; }
183 bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
185 bool isVerifyingMode() const { return _verifying; } // The system will be checked
186 void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); }
188 bool allowVendorChange() const { return _allowVendorChange; }
189 void setAllowVendorChange( TriBool state_r );
191 bool solveSrcPackages() const { return _solveSrcPackages; }
192 void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
194 bool cleandepsOnRemove() const { return _cleandepsOnRemove; }
195 void setCleandepsOnRemove( TriBool state_r );
198 #define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER ) \
199 void ZSETTER( TriBool state_r ); \
200 bool ZGETTER() const; \
202 ZOLV_FLAG_TRIBOOL( dupSetAllowDowngrade, dupAllowDowngrade )
203 ZOLV_FLAG_TRIBOOL( dupSetAllowNameChange, dupAllowNameChange )
204 ZOLV_FLAG_TRIBOOL( dupSetAllowArchChange, dupAllowArchChange )
205 ZOLV_FLAG_TRIBOOL( dupSetAllowVendorChange, dupAllowVendorChange )
207 #undef ZOLV_FLAG_TRIBOOL
209 ResolverProblemList problems() const;
211 void applySolutions( const ProblemSolutionList & solutions );
212 bool applySolution( const ProblemSolution & solution );
214 // Return the Transaction computed by the last solver run.
215 sat::Transaction getTransaction();
217 // reset all SOLVER transaction in pool
220 void reset( bool keepExtras = false );
222 // Get more information about the solverrun
223 // Which item will be installed by another item or triggers an item for
225 ItemCapKindList isInstalledBy( const PoolItem & item );
226 ItemCapKindList installs( const PoolItem & item );
227 ItemCapKindList satifiedByInstalled (const PoolItem & item );
228 ItemCapKindList installedSatisfied( const PoolItem & item );
232 ///////////////////////////////////////////////////////////////////
233 };// namespace detail
234 /////////////////////////////////////////////////////////////////////
235 /////////////////////////////////////////////////////////////////////
236 };// namespace solver
237 ///////////////////////////////////////////////////////////////////////
238 ///////////////////////////////////////////////////////////////////////
240 /////////////////////////////////////////////////////////////////////////
241 #endif // ZYPP_USE_RESOLVER_INTERNALS
242 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H