libzypp  17.36.7
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/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_onlyRequires:1;
97  bool _applyDefault_allowDowngrade:1;
98  bool _applyDefault_allowNameChange:1;
99  bool _applyDefault_allowArchChange:1;
100  bool _applyDefault_allowVendorChange:1;
101  bool _applyDefault_dupAllowDowngrade:1;
102  bool _applyDefault_dupAllowNameChange:1;
103  bool _applyDefault_dupAllowArchChange:1;
104  bool _applyDefault_dupAllowVendorChange:1;
106 
107  // Additional QueueItems which has to be regarded by the solver
108  // This will be used e.g. by solution actions
109  solver::detail::SolverQueueItemList _removed_queue_items;
110  solver::detail::SolverQueueItemList _added_queue_items;
111 
112  // Additional information about the solverrun
113  ItemCapKindMap _isInstalledBy;
114  ItemCapKindMap _installs;
115  ItemCapKindMap _satifiedByInstalled;
116  ItemCapKindMap _installedSatisfied;
117 
118  // helpers
119  void collectResolverInfo();
120 
121  // Unmaintained packages which does not fit to the updated system
122  // (broken dependencies) will be deleted.
123  // returns true if solving was successful
124  bool checkUnmaintainedItems ();
125 
126  void solverInit();
127 
128  public:
129 
130  Resolver( ResPool pool );
131  virtual ~Resolver();
132 
133  // ---------------------------------- I/O
134 
135  std::ostream & dumpOn( std::ostream & str ) const;
136 
137  friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
138  { return obj.dumpOn (str); }
139 
140  // ---------------------------------- methods
141 
142  ResPool pool() const;
143  void setPool( const ResPool & pool ) { _pool = pool; }
144 
154  void setDefaultSolverFlags( bool all_r );
155 
156  void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
157  bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
158  void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); }
159  void removeUpgradeRepos() { _upgradeRepos.clear(); }
160  const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; }
161 
162  void addExtraRequire( const Capability & capability );
163  void removeExtraRequire( const Capability & capability );
164  void addExtraConflict( const Capability & capability );
165  void removeExtraConflict( const Capability & capability );
166 
167  void removeQueueItem( const SolverQueueItem_Ptr& item );
168  void addQueueItem( const SolverQueueItem_Ptr& item );
169 
170  CapabilitySet extraRequires() const { return _extra_requires; }
171  CapabilitySet extraConflicts() const { return _extra_conflicts; }
172 
173  void addWeak( const PoolItem & item );
174 
175  bool verifySystem();
176  bool resolvePool();
177  bool resolveQueue( SolverQueueItemList & queue );
178  void doUpdate();
179 
180  bool doUpgrade();
181  PoolItemList problematicUpdateItems() const;
182 
185  bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; }
186  void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
187 
188  bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
189  void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; }
190 
191  bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
192  void setUpdateMode( bool yesno_r ) { _updateMode = yesno_r; }
193 
194  bool isVerifyingMode() const { return _verifying; } // The system will be checked
195  void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); }
196 
197  bool solveSrcPackages() const { return _solveSrcPackages; }
198  void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
200 
201  void setRemoveOrphaned( bool yesno_r );
202  bool removeOrphaned() const;
203 
204  void setRemoveUnneeded( bool yesno_r );
205  bool removeUnneeded() const;
206 
207  void setFocus( ResolverFocus focus_r );
208  ResolverFocus focus() const;
209 
210 #define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER ) \
211  void ZSETTER( TriBool state_r ); \
212  bool ZGETTER() const; \
213 
214  ZOLV_FLAG_TRIBOOL( setForceResolve ,forceResolve )
215  ZOLV_FLAG_TRIBOOL( setCleandepsOnRemove ,cleandepsOnRemove )
216  ZOLV_FLAG_TRIBOOL( setOnlyRequires ,onlyRequires )
217  ZOLV_FLAG_TRIBOOL( setAllowDowngrade ,allowDowngrade )
218  ZOLV_FLAG_TRIBOOL( setAllowNameChange ,allowNameChange )
219  ZOLV_FLAG_TRIBOOL( setAllowArchChange ,allowArchChange )
220  ZOLV_FLAG_TRIBOOL( setAllowVendorChange ,allowVendorChange )
221  ZOLV_FLAG_TRIBOOL( dupSetAllowDowngrade ,dupAllowDowngrade )
222  ZOLV_FLAG_TRIBOOL( dupSetAllowNameChange ,dupAllowNameChange )
223  ZOLV_FLAG_TRIBOOL( dupSetAllowArchChange ,dupAllowArchChange )
224  ZOLV_FLAG_TRIBOOL( dupSetAllowVendorChange ,dupAllowVendorChange )
225 #undef ZOLV_FLAG_TRIBOOL
226 
227  ResolverProblemList problems() const;
228 
229  void applySolutions( const ProblemSolutionList & solutions );
230  bool applySolution( const ProblemSolution & solution );
231 
232  // Return the Transaction computed by the last solver run.
233  sat::Transaction getTransaction();
234 
235  // reset all SOLVER transaction in pool
236  void undo();
237 
238  void reset( bool keepExtras = false );
239 
240  // Get more information about the solverrun
241  // Which item will be installed by another item or triggers an item for
242  // installation
243  ItemCapKindList isInstalledBy( const PoolItem & item );
244  ItemCapKindList installs( const PoolItem & item );
245  ItemCapKindList satifiedByInstalled (const PoolItem & item );
246  ItemCapKindList installedSatisfied( const PoolItem & item );
247 
248 public:
250  sat::detail::CSolver * get() const;
251 };
252 
254  };// namespace detail
257  };// namespace solver
260 };// namespace zypp
262 #endif // ZYPP_USE_RESOLVER_INTERNALS
263 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
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: PoolMember.h:65
ResolverFocus
The resolver&#39;s general attitude.
Definition: ResolverFocus.h:23
String related utilities and Regular expression matching.
_onlyRequires _dup_allowdowngrade dupAllowArchChange
Definition: Resolver.cc:176
std::list< ItemCapKind > ItemCapKindList
Definition: Types.h:42
#define ZOLV_FLAG_TRIBOOL(ZSETTER, ZDEFAULT, ZGETTER)
Definition: Resolver.cc:127
std::ostream & operator<<(std::ostream &str, const SolutionActionList &actionlist)
#define ZYPP_API_DEPTESTOMATIC
Definition: Globals.h:77
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:580
std::list< SolverQueueItem_Ptr > SolverQueueItemList
Definition: Types.h:45
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:35
_onlyRequires dupAllowDowngrade
Definition: Resolver.cc:174
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43