libzypp  13.10.6
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 
25 #include <iosfwd>
26 #include <list>
27 #include <map>
28 #include <string>
29 
31 #include "zypp/base/PtrTypes.h"
32 
33 #include "zypp/ResPool.h"
34 #include "zypp/TriBool.h"
35 #include "zypp/base/SerialNumber.h"
36 
39 
40 #include "zypp/ProblemTypes.h"
41 #include "zypp/ResolverProblem.h"
42 #include "zypp/ProblemSolution.h"
43 #include "zypp/Capabilities.h"
44 #include "zypp/Capability.h"
45 
46 
48 namespace zypp
49 {
50 
51  namespace sat
52  {
53  class Transaction;
54  }
55 
57  namespace solver
58  {
59  namespace detail
61  {
62 
63  class SATResolver;
64 
66  //
67  // CLASS NAME : ItemCapKind
68  //
70  struct ItemCapKind
71  {
72  public:
73  Capability cap; //Capability which has triggerd this selection
74  Dep capKind; //Kind of that capability
75  PoolItem item; //Item which has triggered this selection
76  bool initialInstallation; //This item has triggered the installation
77  //Not already fullfilled requierement only.
78 
79  ItemCapKind() : capKind(Dep::PROVIDES) {}
80  ItemCapKind( PoolItem i, Capability c, Dep k, bool initial)
81  : cap( c )
82  , capKind( k )
83  , item( i )
84  , initialInstallation( initial )
85  { }
86  };
87  typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
88  typedef std::list<ItemCapKind> ItemCapKindList;
89 
90 
92 //
93 // CLASS NAME : Resolver
102 
103  private:
107 
110  std::set<Repository> _upgradeRepos;
111 
112  // Regard dependencies of the item weak onl
114 
117  bool _forceResolve; // remove items which are conflicts with others or
118  // have unfulfilled requirements.
119  // This behaviour is favourited by ZMD
120  bool _upgradeMode; // Resolver has been called with doUpgrade
121  bool _updateMode; // Resolver has been called with doUpdate
122  bool _verifying; // The system will be checked
123  bool _onlyRequires; // do install required resolvables only
124  // no recommended resolvables, language
125  // packages, hardware packages (modalias)
126  bool _allowVendorChange; // whether the solver should allow or disallow vendor changes.
127  bool _solveSrcPackages; // whether to generate solver jobs for selected source packges.
128  bool _cleandepsOnRemove; // whether removing a package should also remove no longer needed requirements
129 
130  bool _ignoreAlreadyRecommended; //ignore recommended packages that have already been recommended by the installed packages
132 
133  // Additional QueueItems which has to be regarded by the solver
134  // This will be used e.g. by solution actions
137 
138  // Additional information about the solverrun
143 
144  // helpers
145  void collectResolverInfo();
146 
147  // Unmaintained packages which does not fit to the updated system
148  // (broken dependencies) will be deleted.
149  // returns true if solving was successful
150  bool checkUnmaintainedItems ();
151 
152  void solverInit();
153 
154  public:
155 
156  Resolver( const ResPool & pool );
157  virtual ~Resolver();
158 
159  // ---------------------------------- I/O
160 
161  virtual std::ostream & dumpOn( std::ostream & str ) const;
162  friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
163  { return obj.dumpOn (str); }
164 
165  // ---------------------------------- methods
166 
167  ResPool pool() const;
168  void setPool( const ResPool & pool ) { _pool = pool; }
169 
170  void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
171  bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
172  void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); }
173  void removeUpgradeRepos() { _upgradeRepos.clear(); }
174  const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; }
175 
176  void addExtraRequire( const Capability & capability );
177  void removeExtraRequire( const Capability & capability );
178  void addExtraConflict( const Capability & capability );
179  void removeExtraConflict( const Capability & capability );
180 
181  void removeQueueItem( SolverQueueItem_Ptr item );
182  void addQueueItem( SolverQueueItem_Ptr item );
183 
186 
187  void addWeak( const PoolItem & item );
188 
189  bool verifySystem();
190  bool resolvePool();
191  bool resolveQueue( SolverQueueItemList & queue );
192  void doUpdate();
193 
194  bool doUpgrade();
196 
200  void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
201 
202  bool onlyRequires () const { return _onlyRequires; }
203  void setOnlyRequires( TriBool state_r );
204 
205  bool forceResolve() const { return _forceResolve; }
206  void setForceResolve( TriBool state_r ) { _forceResolve = indeterminate(state_r) ? false : bool(state_r); }
207 
208  bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
209  void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; }
210 
211  bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
212 
213  bool isVerifyingMode() const { return _verifying; } // The system will be checked
214  void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); }
215 
216  bool allowVendorChange() const { return _allowVendorChange; }
217  void setAllowVendorChange( TriBool state_r );
218 
219  bool solveSrcPackages() const { return _solveSrcPackages; }
220  void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
221 
222  bool cleandepsOnRemove() const { return _cleandepsOnRemove; }
223  void setCleandepsOnRemove( TriBool state_r );
225 
227  void applySolutions( const ProblemSolutionList & solutions );
228 
229  // Return the Transaction computed by the last solver run.
231 
232  // reset all SOLVER transaction in pool
233  void undo();
234 
235  void reset( bool keepExtras = false );
236 
237  // Get more information about the solverrun
238  // Which item will be installed by another item or triggers an item for
239  // installation
240  ItemCapKindList isInstalledBy( const PoolItem & item );
241  ItemCapKindList installs( const PoolItem & item );
244 
245 };
246 
248  };// namespace detail
251  };// namespace solver
254 };// namespace zypp
256 
257 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H
void removeExtraConflict(const Capability &capability)
Definition: Resolver.cc:168
ItemCapKindMap _isInstalledBy
Definition: Resolver.h:139
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:42
void setForceResolve(TriBool state_r)
Definition: Resolver.h:206
const std::set< Repository > & upgradeRepos() const
Definition: Resolver.h:174
Simple serial number watcher.
Definition: SerialNumber.h:122
void addExtraRequire(const Capability &capability)
Definition: Resolver.cc:159
ItemCapKindList isInstalledBy(const PoolItem &item)
Definition: Resolver.cc:535
bool ignoreAlreadyRecommended() const
Definition: Resolver.h:199
void removeQueueItem(SolverQueueItem_Ptr item)
Definition: Resolver.cc:171
void addQueueItem(SolverQueueItem_Ptr item)
Definition: Resolver.cc:188
ResolverProblemList problems() const
Definition: Resolver.cc:371
Enumeration class of dependency types.
Definition: Dep.h:29
bool resolveQueue(SolverQueueItemList &queue)
Definition: Resolver.cc:323
bool solveSrcPackages() const
Definition: Resolver.h:219
void addExtraConflict(const Capability &capability)
Definition: Resolver.cc:165
void setAllowVendorChange(TriBool state_r)
Definition: Resolver.cc:108
CapabilitySet _extra_conflicts
Definition: Resolver.h:109
std::list< PoolItem > PoolItemList
Definition: Types.h:51
Libsolv transaction wrapper.
Definition: Transaction.h:54
SerialNumberWatcher _poolchanged
Definition: Resolver.h:106
std::multimap< PoolItem, ItemCapKind > ItemCapKindMap
Definition: Resolver.h:87
void setUpgradeMode(bool yesno_r)
Definition: Resolver.h:209
std::list< SolverQueueItem_Ptr > SolverQueueItemList
bool isSystemRepo() const
Return whether this is the system repository.
Definition: Repository.cc:51
void reset(bool keepExtras=false)
Definition: Resolver.cc:128
std::tr1::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
void removeUpgradeRepo(Repository repo_r)
Definition: Resolver.h:172
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: TriBool.h:39
void setPool(const ResPool &pool)
Definition: Resolver.h:168
A mid layer class we should remove.
Definition: Resolver.h:101
void setSolveSrcPackages(TriBool state_r)
Definition: Resolver.h:220
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
CapabilitySet extraRequires() const
Definition: Resolver.h:184
solver::detail::SolverQueueItemList _removed_queue_items
Definition: Resolver.h:135
void setCleandepsOnRemove(TriBool state_r)
Definition: Resolver.cc:118
friend std::ostream & operator<<(std::ostream &str, const Resolver &obj)
Definition: Resolver.h:162
solver::detail::SolverQueueItemList _added_queue_items
Definition: Resolver.h:136
sat::Transaction getTransaction()
Definition: Resolver.cc:362
void addWeak(const PoolItem &item)
Definition: Resolver.cc:205
void removeExtraRequire(const Capability &capability)
Definition: Resolver.cc:162
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream &amp; operator&lt;&lt;.
Definition: Resolver.cc:61
void setOnlyRequires(TriBool state_r)
Definition: Resolver.cc:113
void setVerifyingMode(TriBool state_r)
Definition: Resolver.h:214
void setIgnoreAlreadyRecommended(bool yesno_r)
Definition: Resolver.h:200
bool allowVendorChange() const
Definition: Resolver.h:216
bool cleandepsOnRemove() const
Definition: Resolver.h:222
Base class for reference counted objects.
void applySolutions(const ProblemSolutionList &solutions)
Definition: Resolver.cc:377
bool isVerifyingMode() const
Definition: Resolver.h:213
ItemCapKindMap _satifiedByInstalled
Definition: Resolver.h:141
Global ResObject pool.
Definition: ResPool.h:48
std::list< ItemCapKind > ItemCapKindList
Definition: Resolver.h:88
CapabilitySet _extra_requires
Definition: Resolver.h:108
ItemCapKindList installs(const PoolItem &item)
Definition: Resolver.cc:554
ItemCapKindMap _installedSatisfied
Definition: Resolver.h:142
A sat capability.
Definition: Capability.h:59
CapabilitySet extraConflicts() const
Definition: Resolver.h:185
std::set< Repository > _upgradeRepos
Definition: Resolver.h:110
Reference to a PoolItem connecting ResObject and ResStatus.
Definition: PoolItem.h:50
PoolItemList problematicUpdateItems() const
Definition: Resolver.cc:156
ItemCapKindList satifiedByInstalled(const PoolItem &item)
Definition: Resolver.cc:573
void addUpgradeRepo(Repository repo_r)
Definition: Resolver.h:170
ItemCapKindList installedSatisfied(const PoolItem &item)
Definition: Resolver.cc:592
ItemCapKind(PoolItem i, Capability c, Dep k, bool initial)
Definition: Resolver.h:80
Resolver(const ResPool &pool)
Definition: Resolver.cc:81
bool upgradingRepo(Repository repo_r) const
Definition: Resolver.h:171