- provide testing flag in Resolver
[platform/upstream/libzypp.git] / zypp / solver / detail / Resolver.h
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
30 #include "zypp/base/ReferenceCounted.h"
31 #include "zypp/base/PtrTypes.h"
32
33 #include "zypp/ResPool.h"
34
35 #include "zypp/solver/detail/Types.h"
36 #include "zypp/solver/detail/ResolverQueue.h"
37 #include "zypp/solver/detail/ResolverContext.h"
38
39 #include "zypp/ProblemTypes.h"
40 #include "zypp/ResolverProblem.h"
41 #include "zypp/ProblemSolution.h"
42 #include "zypp/UpgradeStatistics.h"
43
44 #include "zypp/CapSet.h"
45
46
47 /////////////////////////////////////////////////////////////////////////
48 namespace zypp
49 { ///////////////////////////////////////////////////////////////////////
50   ///////////////////////////////////////////////////////////////////////
51   namespace solver
52   { /////////////////////////////////////////////////////////////////////
53     /////////////////////////////////////////////////////////////////////
54     namespace detail
55     { ///////////////////////////////////////////////////////////////////
56
57 ///////////////////////////////////////////////////////////////////
58 //
59 //      CLASS NAME : Resolver
60
61 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
62
63   private:
64     ResPool _pool;
65
66     int _timeout_seconds;
67     bool _verifying;
68     bool _testing;
69
70     QueueItemList _initial_items;
71     PoolItemList _items_to_install;
72     PoolItemList _items_to_establish;
73     PoolItemList _items_to_remove;
74     PoolItemList _items_to_verify;
75
76     CapSet _extra_caps;
77     CapSet _extra_conflicts;
78
79     //typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
80
81     // These conflict should be ignored of the concering item
82     IgnoreMap _ignoreConflicts;
83     // These conflict should be ignored of the concering item    
84     IgnoreMap _ignoreRequires;
85     // Ignore architecture of the item
86     PoolItemList _ignoreArchitecture;
87     // Ignore the status "installed" of the item
88     PoolItemList _ignoreInstalledItem;    
89
90     ResolverQueueList _pending_queues;
91     ResolverQueueList _pruned_queues;
92     ResolverQueueList _complete_queues;
93     ResolverQueueList _deferred_queues;
94     ResolverQueueList _invalid_queues;
95
96     int _valid_solution_count;
97
98     ResolverContext_Ptr _best_context;
99     bool _timed_out;
100
101     std::set<Source_Ref> _subscribed;
102
103     Arch _architecture;
104
105     bool _forceResolve; // remove items which are conflicts with others or
106                         // have unfulfilled requirements.
107                         // This behaviour is favourited by ZMD
108
109     // helpers
110     bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
111     bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
112
113   public:
114
115     Resolver (const ResPool & pool);
116     virtual ~Resolver();
117
118     // ---------------------------------- I/O
119
120     virtual std::ostream & dumpOn( std::ostream & str ) const;
121     friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
122     { return obj.dumpOn (str); }
123
124     // ---------------------------------- accessors
125
126     QueueItemList initialItems () const { return _initial_items; }
127
128     ResolverQueueList pendingQueues () const { return _pending_queues; }
129     ResolverQueueList prunedQueues () const { return _pruned_queues; }
130     ResolverQueueList completeQueues () const { return _complete_queues; }
131     ResolverQueueList deferredQueues () const { return _deferred_queues; }
132     ResolverQueueList invalidQueues () const { return _invalid_queues; }
133
134     ResolverContext_Ptr bestContext (void) const { return _best_context; }
135
136     /** depending on the last solver result, either return bestContext()
137         of the first invalid context */
138     ResolverContext_Ptr context (void) const;
139
140     // ---------------------------------- methods
141
142     void setTimeout (int seconds) { _timeout_seconds = seconds; }
143
144     ResPool pool (void) const;
145     void setPool (const ResPool & pool) { _pool = pool; }
146
147     void addSubscribedSource (Source_Ref source);
148
149     void addPoolItemToInstall (PoolItem_Ref item);
150     void addPoolItemsToInstallFromList (PoolItemList & rl);
151
152     void addPoolItemToRemove (PoolItem_Ref item);
153     void addPoolItemsToRemoveFromList (PoolItemList & rl);
154
155     void addPoolItemToEstablish (PoolItem_Ref item);
156     void addPoolItemsToEstablishFromList (PoolItemList & rl);
157
158     void addPoolItemToVerify (PoolItem_Ref item);
159
160     void addExtraCapability (const Capability & capability);
161     void addExtraConflict (const Capability & capability);
162
163     void addIgnoreConflict (const PoolItem_Ref item,
164                             const Capability & capability);
165     void addIgnoreRequires (const PoolItem_Ref item,
166                             const Capability & capability);
167     void addIgnoreArchitecture (const PoolItem_Ref item);
168     void addIgnoreInstalledItem (const PoolItem_Ref item);
169
170     void setForceResolve (const bool force) { _forceResolve = force; }
171     const bool forceResolve() { return _forceResolve; }
172
173     bool verifySystem (void);
174     void establishState (const ResolverContext_Ptr context = NULL);
175     void establishPool (void);
176     bool resolveDependencies (const ResolverContext_Ptr context = NULL);
177     bool resolvePool (void);
178
179     bool transactResObject( ResObject::constPtr robj, bool install = true);
180
181     void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
182
183     ResolverProblemList problems (void) const;
184     void applySolutions (const ProblemSolutionList &solutions);
185
186     // reset all SOLVER transaction in pool
187     void undo(void);
188
189     // only for testsuite
190     void reset (void);
191
192     Arch architecture() const { return _architecture; }
193     void setArchitecture( const Arch & arch) { _architecture = arch; }
194
195     bool testing(void) const { return _testing; }
196     void setTesting( bool testing ) { _testing = testing; }
197 };
198
199 ///////////////////////////////////////////////////////////////////
200     };// namespace detail
201     /////////////////////////////////////////////////////////////////////
202     /////////////////////////////////////////////////////////////////////
203   };// namespace solver
204   ///////////////////////////////////////////////////////////////////////
205   ///////////////////////////////////////////////////////////////////////
206 };// namespace zypp
207 /////////////////////////////////////////////////////////////////////////
208
209 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H