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
30 #include "zypp/base/ReferenceCounted.h"
31 #include "zypp/base/PtrTypes.h"
33 #include "zypp/ResPool.h"
35 #include "zypp/solver/detail/Types.h"
36 #include "zypp/solver/detail/ResolverQueue.h"
37 #include "zypp/solver/detail/ResolverContext.h"
39 #include "zypp/ProblemTypes.h"
40 #include "zypp/ResolverProblem.h"
41 #include "zypp/ProblemSolution.h"
42 #include "zypp/UpgradeStatistics.h"
44 #include "zypp/CapSet.h"
47 /////////////////////////////////////////////////////////////////////////
49 { ///////////////////////////////////////////////////////////////////////
50 ///////////////////////////////////////////////////////////////////////
52 { /////////////////////////////////////////////////////////////////////
53 /////////////////////////////////////////////////////////////////////
55 { ///////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////
59 // CLASS NAME : Resolver
61 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
70 // list populated by calls to addPoolItemTo*()
71 QueueItemList _initial_items;
72 PoolItemList _items_to_install;
73 PoolItemList _items_to_establish;
74 PoolItemList _items_to_remove;
75 PoolItemList _items_to_verify;
77 // list of problematic items after doUpgrade()
78 PoolItemList _update_items;
82 CapSet _extra_conflicts;
84 //typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
86 // These conflict should be ignored of the concering item
87 IgnoreMap _ignoreConflicts;
88 // These requires should be ignored of the concering item
89 IgnoreMap _ignoreRequires;
90 // These obsoletes should be ignored of the concering item
91 IgnoreMap _ignoreObsoletes;
92 // Ignore architecture of the item
93 PoolItemList _ignoreArchitecture;
94 // Ignore the status "installed" of the item
95 PoolItemList _ignoreInstalledItem;
97 ResolverQueueList _pending_queues;
98 ResolverQueueList _pruned_queues;
99 ResolverQueueList _complete_queues;
100 ResolverQueueList _deferred_queues;
101 ResolverQueueList _invalid_queues;
103 int _valid_solution_count;
105 ResolverContext_Ptr _best_context;
108 std::set<Source_Ref> _subscribed;
112 bool _forceResolve; // remove items which are conflicts with others or
113 // have unfulfilled requirements.
114 // This behaviour is favourited by ZMD
115 bool _upgradeMode; // Resolver has been called with doUpgrade
118 bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
119 bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
123 Resolver (const ResPool & pool);
126 // ---------------------------------- I/O
128 virtual std::ostream & dumpOn( std::ostream & str ) const;
129 friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
130 { return obj.dumpOn (str); }
132 // ---------------------------------- accessors
134 QueueItemList initialItems () const { return _initial_items; }
136 ResolverQueueList pendingQueues () const { return _pending_queues; }
137 ResolverQueueList prunedQueues () const { return _pruned_queues; }
138 ResolverQueueList completeQueues () const { return _complete_queues; }
139 ResolverQueueList deferredQueues () const { return _deferred_queues; }
140 ResolverQueueList invalidQueues () const { return _invalid_queues; }
142 ResolverContext_Ptr bestContext (void) const { return _best_context; }
144 /** depending on the last solver result, either return bestContext()
145 of the first invalid context */
146 ResolverContext_Ptr context (void) const;
148 // ---------------------------------- methods
150 void setTimeout (int seconds) { _timeout_seconds = seconds; }
152 ResPool pool (void) const;
153 void setPool (const ResPool & pool) { _pool = pool; }
155 void addSubscribedSource (Source_Ref source);
157 void addPoolItemToInstall (PoolItem_Ref item);
158 void addPoolItemsToInstallFromList (PoolItemList & rl);
160 void addPoolItemToRemove (PoolItem_Ref item);
161 void addPoolItemsToRemoveFromList (PoolItemList & rl);
163 void addPoolItemToEstablish (PoolItem_Ref item);
164 void addPoolItemsToEstablishFromList (PoolItemList & rl);
166 void addPoolItemToVerify (PoolItem_Ref item);
168 void addExtraCapability (const Capability & capability);
169 void addExtraConflict (const Capability & capability);
171 void addIgnoreConflict (const PoolItem_Ref item,
172 const Capability & capability);
173 void addIgnoreRequires (const PoolItem_Ref item,
174 const Capability & capability);
175 void addIgnoreObsoletes (const PoolItem_Ref item,
176 const Capability & capability);
177 void addIgnoreInstalledItem (const PoolItem_Ref item);
179 void setForceResolve (const bool force) { _forceResolve = force; }
180 const bool forceResolve() { return _forceResolve; }
182 bool verifySystem (void);
183 void establishState (const ResolverContext_Ptr context = NULL);
184 bool establishPool (void);
185 bool resolveDependencies (const ResolverContext_Ptr context = NULL);
186 bool resolvePool (void);
188 bool transactResObject( ResObject::constPtr robj, bool install = true);
189 bool transactResKind( Resolvable::Kind kind );
191 void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
193 ResolverProblemList problems (void) const;
194 void applySolutions (const ProblemSolutionList &solutions);
196 // reset all SOLVER transaction in pool
199 // only for testsuite
202 Arch architecture() const { return _architecture; }
203 void setArchitecture( const Arch & arch) { _architecture = arch; }
205 bool testing(void) const { return _testing; }
206 void setTesting( bool testing ) { _testing = testing; }
209 ///////////////////////////////////////////////////////////////////
210 };// namespace detail
211 /////////////////////////////////////////////////////////////////////
212 /////////////////////////////////////////////////////////////////////
213 };// namespace solver
214 ///////////////////////////////////////////////////////////////////////
215 ///////////////////////////////////////////////////////////////////////
217 /////////////////////////////////////////////////////////////////////////
219 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H