libzypp  17.38.17
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-core/Globals.h>
34 #include <zypp/solver/Types.h>
35 #include <zypp/base/SerialNumber.h>
36 
38 namespace zypp
39 {
40  namespace sat
41  {
42  class Transaction;
43  }
45  namespace solver
46  {
48  namespace detail
49  {
50  class SATResolver;
51  typedef std::list<PoolItem> PoolItemList;
52  typedef std::set<PoolItem> PoolItemSet;
53 
55 //
56 // CLASS NAME : Resolver
64 class ZYPP_API_DEPTESTOMATIC Resolver : private base::NonCopyable
65 {
66  typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
67  private:
68  ResPool _pool;
69  SATResolver *_satResolver;
70  SerialNumberWatcher _poolchanged;
71 
72  CapabilitySet _extra_requires;
73  CapabilitySet _extra_conflicts;
74  std::set<Repository> _upgradeRepos;
75 
76  // Regard dependencies of the item weak onl
77  PoolItemList _addWeak;
78 
81  bool _upgradeMode:1; // Resolver has been called with doUpgrade
82  bool _updateMode:1; // Resolver has been called with doUpdate
83  bool _verifying:1; // The system will be checked
84  bool _solveSrcPackages:1; // whether to generate solver jobs for selected source packges.
85  bool _ignoreAlreadyRecommended:1; // ignore recommended packages that have already been recommended by the installed packages
87 
93  bool _applyDefault_focus:1;
94  bool _applyDefault_forceResolve:1;
95  bool _applyDefault_cleandepsOnRemove:1;
96  bool _applyDefault_noUpdateProvide:1;
97  bool _applyDefault_onlyRequires:1;
98  bool _applyDefault_allowDowngrade:1;
99  bool _applyDefault_allowNameChange:1;
100  bool _applyDefault_allowArchChange:1;
101  bool _applyDefault_allowVendorChange:1;
102  bool _applyDefault_dupAllowDowngrade:1;
103  bool _applyDefault_dupAllowNameChange:1;
104  bool _applyDefault_dupAllowArchChange:1;
105  bool _applyDefault_dupAllowVendorChange:1;
107 
108  // Additional QueueItems which has to be regarded by the solver
109  // This will be used e.g. by solution actions
110  solver::detail::SolverQueueItemList _removed_queue_items;
111  solver::detail::SolverQueueItemList _added_queue_items;
112 
113  // Additional information about the solverrun
114  ItemCapKindMap _isInstalledBy;
115  ItemCapKindMap _installs;
116  ItemCapKindMap _satifiedByInstalled;
117  ItemCapKindMap _installedSatisfied;
118 
119  // helpers
120  void collectResolverInfo();
121 
122  // Unmaintained packages which does not fit to the updated system
123  // (broken dependencies) will be deleted.
124  // returns true if solving was successful
125  bool checkUnmaintainedItems ();
126 
127  void solverInit();
128 
129  public:
130 
131  Resolver( ResPool pool );
132  virtual ~Resolver();
133 
134  // ---------------------------------- I/O
135 
136  std::ostream & dumpOn( std::ostream & str ) const;
137 
138  friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
139  { return obj.dumpOn (str); }
140 
141  // ---------------------------------- methods
142 
143  ResPool pool() const;
144  void setPool( const ResPool & pool ) { _pool = pool; }
145 
155  void setDefaultSolverFlags( bool all_r );
156 
157  void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
158  bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
159  void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); }
160  void removeUpgradeRepos() { _upgradeRepos.clear(); }
161  const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; }
162 
163  void addExtraRequire( const Capability & capability );
164  void removeExtraRequire( const Capability & capability );
165  void addExtraConflict( const Capability & capability );
166  void removeExtraConflict( const Capability & capability );
167 
168  void removeQueueItem( const SolverQueueItem_Ptr& item );
169  void addQueueItem( const SolverQueueItem_Ptr& item );
170 
171  CapabilitySet extraRequires() const { return _extra_requires; }
172  CapabilitySet extraConflicts() const { return _extra_conflicts; }
173 
174  void addWeak( const PoolItem & item );
175 
176  bool verifySystem();
177  bool resolvePool();
178  bool resolveQueue( SolverQueueItemList & queue );
179  void doUpdate();
180 
181  bool doUpgrade();
182  PoolItemList problematicUpdateItems() const;
183 
186  bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; }
187  void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
188 
189  bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
190  void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; }
191 
192  bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
193  void setUpdateMode( bool yesno_r ) { _updateMode = yesno_r; }
194 
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); }
197 
198  bool solveSrcPackages() const { return _solveSrcPackages; }
199  void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
201 
202  void setRemoveOrphaned( bool yesno_r );
203  bool removeOrphaned() const;
204 
205  void setRemoveUnneeded( bool yesno_r );
206  bool removeUnneeded() const;
207 
208  void setFocus( ResolverFocus focus_r );
209  ResolverFocus focus() const;
210 
211 #define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER ) \
212  void ZSETTER( TriBool state_r ); \
213  bool ZGETTER() const; \
214 
215  ZOLV_FLAG_TRIBOOL( setForceResolve ,forceResolve )
216  ZOLV_FLAG_TRIBOOL( setCleandepsOnRemove ,cleandepsOnRemove )
217  ZOLV_FLAG_TRIBOOL( setNoUpdateProvide ,noUpdateProvide )
218  ZOLV_FLAG_TRIBOOL( setOnlyRequires ,onlyRequires )
219  ZOLV_FLAG_TRIBOOL( setAllowDowngrade ,allowDowngrade )
220  ZOLV_FLAG_TRIBOOL( setAllowNameChange ,allowNameChange )
221  ZOLV_FLAG_TRIBOOL( setAllowArchChange ,allowArchChange )
222  ZOLV_FLAG_TRIBOOL( setAllowVendorChange ,allowVendorChange )
223  ZOLV_FLAG_TRIBOOL( dupSetAllowDowngrade ,dupAllowDowngrade )
224  ZOLV_FLAG_TRIBOOL( dupSetAllowNameChange ,dupAllowNameChange )
225  ZOLV_FLAG_TRIBOOL( dupSetAllowArchChange ,dupAllowArchChange )
226  ZOLV_FLAG_TRIBOOL( dupSetAllowVendorChange ,dupAllowVendorChange )
227 #undef ZOLV_FLAG_TRIBOOL
228 
229  ResolverProblemList problems() const;
230 
231  void applySolutions( const ProblemSolutionList & solutions );
232  bool applySolution( const ProblemSolution & solution );
233 
234  // Return the Transaction computed by the last solver run.
235  sat::Transaction getTransaction();
236 
237  // reset all SOLVER transaction in pool
238  void undo();
239 
240  void reset( bool keepExtras = false );
241 
242  // Get more information about the solverrun
243  // Which item will be installed by another item or triggers an item for
244  // installation
245  ItemCapKindList isInstalledBy( const PoolItem & item );
246  ItemCapKindList installs( const PoolItem & item );
247  ItemCapKindList satifiedByInstalled (const PoolItem & item );
248  ItemCapKindList installedSatisfied( const PoolItem & item );
249 
250 public:
252  sat::detail::CSolver * get() const;
253 };
254 
256  };// namespace detail
259  };// namespace solver
262 };// namespace zypp
264 #endif // ZYPP_USE_RESOLVER_INTERNALS
265 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H
Common types used in the Resolver public API and need to be passed down to the details tree...
::s_Solver CSolver
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolDefines.h:40
ResolverFocus
The resolver&#39;s general attitude.
Definition: ResolverFocus.h:23
_noUpdateProvide _allowvendorchange dupAllowNameChange
Definition: Resolver.cc:178
String related utilities and Regular expression matching.
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:31
_noUpdateProvide allowVendorChange
Definition: Resolver.cc:176
std::list< ItemCapKind > ItemCapKindList
Definition: Types.h:42
#define ZOLV_FLAG_TRIBOOL(ZSETTER, ZDEFAULT, ZGETTER)
Definition: Resolver.cc:131
std::ostream & operator<<(std::ostream &str, const SolutionActionList &actionlist)
_noUpdateProvide _allowvendorchange _dup_allownamechange dupAllowVendorChange
Definition: Resolver.cc:180
Provides API related macros.
#define ZYPP_API_DEPTESTOMATIC
Definition: Globals.h:82
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
relates: Capability Detailed stream output
Definition: Capability.cc:589
std::list< SolverQueueItem_Ptr > SolverQueueItemList
Definition: Types.h:45
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:35
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43