libzypp 17.31.23
Resolver.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2/* Resolver.h
3 *
4 * Copyright (C) 2000-2002 Ximian, Inc.
5 * Copyright (C) 2005 SUSE Linux Products GmbH
6 *
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.
10 *
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.
15 *
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
19 * 02111-1307, USA.
20 */
21
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!
26#else
27
28#include <iosfwd>
29#include <string>
30#include <list>
31#include <map>
32
33#include <zypp/solver/Types.h>
35
37namespace zypp
38{
39 namespace sat
40 {
41 class Transaction;
42 }
44 namespace solver
45 {
47 namespace detail
48 {
49 class SATResolver;
50 typedef std::list<PoolItem> PoolItemList;
51 typedef std::set<PoolItem> PoolItemSet;
52
54//
55// CLASS NAME : Resolver
63class Resolver : private base::NonCopyable
64{
65 typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
66 private:
67 ResPool _pool;
68 SATResolver *_satResolver;
69 SerialNumberWatcher _poolchanged;
70
71 CapabilitySet _extra_requires;
72 CapabilitySet _extra_conflicts;
73 std::set<Repository> _upgradeRepos;
74
75 // Regard dependencies of the item weak onl
76 PoolItemList _addWeak;
77
80 bool _upgradeMode:1; // Resolver has been called with doUpgrade
81 bool _updateMode:1; // Resolver has been called with doUpdate
82 bool _verifying:1; // The system will be checked
83 bool _solveSrcPackages:1; // whether to generate solver jobs for selected source packges.
84 bool _ignoreAlreadyRecommended:1; // ignore recommended packages that have already been recommended by the installed packages
86
92 bool _applyDefault_focus:1;
93 bool _applyDefault_forceResolve:1;
94 bool _applyDefault_cleandepsOnRemove:1;
95 bool _applyDefault_onlyRequires:1;
96 bool _applyDefault_allowDowngrade:1;
97 bool _applyDefault_allowNameChange:1;
98 bool _applyDefault_allowArchChange:1;
99 bool _applyDefault_allowVendorChange:1;
100 bool _applyDefault_dupAllowDowngrade:1;
101 bool _applyDefault_dupAllowNameChange:1;
102 bool _applyDefault_dupAllowArchChange:1;
103 bool _applyDefault_dupAllowVendorChange:1;
105
106 // Additional QueueItems which has to be regarded by the solver
107 // This will be used e.g. by solution actions
108 solver::detail::SolverQueueItemList _removed_queue_items;
109 solver::detail::SolverQueueItemList _added_queue_items;
110
111 // Additional information about the solverrun
112 ItemCapKindMap _isInstalledBy;
113 ItemCapKindMap _installs;
114 ItemCapKindMap _satifiedByInstalled;
115 ItemCapKindMap _installedSatisfied;
116
117 // helpers
118 void collectResolverInfo();
119
120 // Unmaintained packages which does not fit to the updated system
121 // (broken dependencies) will be deleted.
122 // returns true if solving was successful
123 bool checkUnmaintainedItems ();
124
125 void solverInit();
126
127 public:
128
129 Resolver( const ResPool & pool );
130 virtual ~Resolver();
131
132 // ---------------------------------- I/O
133
134 std::ostream & dumpOn( std::ostream & str ) const;
135
136 friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
137 { return obj.dumpOn (str); }
138
139 // ---------------------------------- methods
140
141 ResPool pool() const;
142 void setPool( const ResPool & pool ) { _pool = pool; }
143
153 void setDefaultSolverFlags( bool all_r );
154
155 void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
156 bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
157 void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); }
158 void removeUpgradeRepos() { _upgradeRepos.clear(); }
159 const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; }
160
161 void addExtraRequire( const Capability & capability );
162 void removeExtraRequire( const Capability & capability );
163 void addExtraConflict( const Capability & capability );
164 void removeExtraConflict( const Capability & capability );
165
166 void removeQueueItem( SolverQueueItem_Ptr item );
167 void addQueueItem( SolverQueueItem_Ptr item );
168
169 CapabilitySet extraRequires() const { return _extra_requires; }
170 CapabilitySet extraConflicts() const { return _extra_conflicts; }
171
172 void addWeak( const PoolItem & item );
173
174 bool verifySystem();
175 bool resolvePool();
176 bool resolveQueue( SolverQueueItemList & queue );
177 void doUpdate();
178
179 bool doUpgrade();
180 PoolItemList problematicUpdateItems() const;
181
184 bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; }
185 void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
186
187 bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
188 void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; }
189
190 bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
191 void setUpdateMode( bool yesno_r ) { _updateMode = yesno_r; }
192
193 bool isVerifyingMode() const { return _verifying; } // The system will be checked
194 void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); }
195
196 bool solveSrcPackages() const { return _solveSrcPackages; }
197 void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
199
200 void setFocus( ResolverFocus focus_r );
201 ResolverFocus focus() const;
202
203#define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER ) \
204 void ZSETTER( TriBool state_r ); \
205 bool ZGETTER() const; \
206
207 ZOLV_FLAG_TRIBOOL( setForceResolve ,forceResolve )
208 ZOLV_FLAG_TRIBOOL( setCleandepsOnRemove ,cleandepsOnRemove )
209 ZOLV_FLAG_TRIBOOL( setOnlyRequires ,onlyRequires )
210 ZOLV_FLAG_TRIBOOL( setAllowDowngrade ,allowDowngrade )
211 ZOLV_FLAG_TRIBOOL( setAllowNameChange ,allowNameChange )
212 ZOLV_FLAG_TRIBOOL( setAllowArchChange ,allowArchChange )
213 ZOLV_FLAG_TRIBOOL( setAllowVendorChange ,allowVendorChange )
214 ZOLV_FLAG_TRIBOOL( dupSetAllowDowngrade ,dupAllowDowngrade )
215 ZOLV_FLAG_TRIBOOL( dupSetAllowNameChange ,dupAllowNameChange )
216 ZOLV_FLAG_TRIBOOL( dupSetAllowArchChange ,dupAllowArchChange )
217 ZOLV_FLAG_TRIBOOL( dupSetAllowVendorChange ,dupAllowVendorChange )
218#undef ZOLV_FLAG_TRIBOOL
219
220 ResolverProblemList problems() const;
221
222 void applySolutions( const ProblemSolutionList & solutions );
223 bool applySolution( const ProblemSolution & solution );
224
225 // Return the Transaction computed by the last solver run.
226 sat::Transaction getTransaction();
227
228 // reset all SOLVER transaction in pool
229 void undo();
230
231 void reset( bool keepExtras = false );
233 // Get more information about the solverrun
234 // Which item will be installed by another item or triggers an item for
235 // installation
236 ItemCapKindList isInstalledBy( const PoolItem & item );
237 ItemCapKindList installs( const PoolItem & item );
238 ItemCapKindList satifiedByInstalled (const PoolItem & item );
239 ItemCapKindList installedSatisfied( const PoolItem & item );
240
241public:
243 sat::detail::CSolver * get() const;
245
247 };// namespace detail
250 };// namespace solver
253};// namespace zypp
255#endif // ZYPP_USE_RESOLVER_INTERNALS
256#endif // ZYPP_SOLVER_DETAIL_RESOLVER_H
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
Definition: LookupAttr.cc:807
A sat capability.
Definition: Capability.h:63
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:51
Class representing one possible solution to a problem found during resolving.
bool isSystemRepo() const
Return whether this is the system repository.
Definition: Repository.cc:53
Global ResObject pool.
Definition: ResPool.h:61
Dependency resolver interface.
Definition: Resolver.h:45
Simple serial number watcher.
Definition: SerialNumber.h:123
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
Libsolv transaction wrapper.
Definition: Transaction.h:52
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
::s_Solver CSolver
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:65
std::list< SolverQueueItem_Ptr > SolverQueueItemList
Definition: Types.h:45
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:35
ResolverFocus
The resolver's general attitude.
Definition: ResolverFocus.h:22
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:580
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43
#define ZOLV_FLAG_TRIBOOL(ZSETTER, ZDEFAULT, ZGETTER)
Definition: Resolver.cc:142