Add Resolver::setSolveSrcPackages to per default disable solving of source package...
[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 #include "zypp/TriBool.h"
35 #include "zypp/base/SerialNumber.h"
36
37 #include "zypp/solver/detail/Types.h"
38 #include "zypp/solver/detail/SolverQueueItem.h"
39
40 #include "zypp/ProblemTypes.h"
41 #include "zypp/ResolverProblem.h"
42 #include "zypp/ProblemSolution.h"
43 #include "zypp/UpgradeStatistics.h"
44 #include "zypp/Capabilities.h"
45 #include "zypp/Capability.h"
46
47
48 /////////////////////////////////////////////////////////////////////////
49 namespace zypp
50 { ///////////////////////////////////////////////////////////////////////
51   ///////////////////////////////////////////////////////////////////////
52   namespace solver
53   { /////////////////////////////////////////////////////////////////////
54     /////////////////////////////////////////////////////////////////////
55     namespace detail
56     { ///////////////////////////////////////////////////////////////////
57
58     class SATResolver;
59
60
61     ///////////////////////////////////////////////////////////////////
62     //
63     //  CLASS NAME : ItemCapKind
64     //
65     /** */
66     struct ItemCapKind
67     {
68         public:
69         Capability cap; //Capability which has triggerd this selection
70         Dep capKind; //Kind of that capability
71         PoolItem item; //Item which has triggered this selection
72         bool initialInstallation; //This item has triggered the installation
73                                   //Not already fullfilled requierement only.
74
75     ItemCapKind() : capKind(Dep::PROVIDES) {}
76             ItemCapKind( PoolItem i, Capability c, Dep k, bool initial)
77                 : cap( c )
78                 , capKind( k )
79                 , item( i )
80                 , initialInstallation( initial )
81             { }
82     };
83     typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
84     typedef std::list<ItemCapKind> ItemCapKindList;
85
86
87 ///////////////////////////////////////////////////////////////////
88 //
89 //      CLASS NAME : Resolver
90
91 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
92
93   private:
94     ResPool _pool;
95     SATResolver *_satResolver;
96     SerialNumberWatcher _poolchanged;
97     bool _testing;
98
99     CapabilitySet _extra_requires;
100     CapabilitySet _extra_conflicts;
101
102     // Regard dependencies of the item weak onl
103     PoolItemList _addWeak;
104
105     bool _forceResolve;           // remove items which are conflicts with others or
106                                   // have unfulfilled requirements.
107                                   // This behaviour is favourited by ZMD
108     bool _upgradeMode;            // Resolver has been called with doUpgrade
109     bool _updateMode;            // Resolver has been called with doUpdate
110     bool _verifying;              // The system will be checked
111     TriBool _onlyRequires;        // do install required resolvables only
112                                   // no recommended resolvables, language
113                                   // packages, hardware packages (modalias)
114     bool _solveSrcPackages;     // whether to generate solver jobs for selected source packges.
115
116     bool _ignorealreadyrecommended;   //ignore recommended packages that have already been recommended by the installed packages
117
118     // Additional QueueItems which has to be regarded by the solver
119     // This will be used e.g. by solution actions
120     solver::detail::SolverQueueItemList _removed_queue_items;
121     solver::detail::SolverQueueItemList _added_queue_items;
122
123     // Additional information about the solverrun
124     ItemCapKindMap _isInstalledBy;
125     ItemCapKindMap _installs;
126     ItemCapKindMap _satifiedByInstalled;
127     ItemCapKindMap _installedSatisfied;
128
129     // helpers
130     void collectResolverInfo (void);
131
132     // Unmaintained packages which does not fit to the updated system
133     // (broken dependencies) will be deleted.
134     // returns true if solving was successful
135     bool checkUnmaintainedItems ();
136
137     void solverInit();
138
139   public:
140
141     Resolver (const ResPool & pool);
142     virtual ~Resolver();
143
144     // ---------------------------------- I/O
145
146     virtual std::ostream & dumpOn( std::ostream & str ) const;
147     friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
148     { return obj.dumpOn (str); }
149
150     // ---------------------------------- methods
151
152     ResPool pool (void) const;
153     void setPool (const ResPool & pool) { _pool = pool; }
154
155     void addExtraRequire (const Capability & capability);
156     void removeExtraRequire (const Capability & capability);
157     void addExtraConflict (const Capability & capability);
158     void removeExtraConflict (const Capability & capability);
159
160     void removeQueueItem (const SolverQueueItem_Ptr item);
161     void addQueueItem (const SolverQueueItem_Ptr item);
162
163     const CapabilitySet extraRequires () { return _extra_requires; }
164     const CapabilitySet extraConflicts () { return _extra_conflicts; }
165
166     void addWeak (const PoolItem item);
167
168     void setForceResolve (const bool force) { _forceResolve = force; }
169     bool forceResolve() { return _forceResolve; }
170
171     void setIgnorealreadyrecommended (const bool ignorealreadyrecommended)
172         { _ignorealreadyrecommended = ignorealreadyrecommended; }
173     bool ignorealreadyrecommended() { return _ignorealreadyrecommended; }
174
175     void setOnlyRequires (const TriBool state)
176         { _onlyRequires = state; }
177     TriBool onlyRequires () { return _onlyRequires; }
178
179     bool verifySystem ();
180     bool resolvePool();
181     bool resolveQueue(solver::detail::SolverQueueItemList & queue);
182     void doUpdate();
183
184     bool doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
185     PoolItemList problematicUpdateItems( void ) const;
186
187     bool isUpgradeMode() const                  { return _upgradeMode;};// Resolver has been called with doUpgrade
188     bool isUpdateMode() const                   { return _updateMode;}; // Resolver has been called with doUpdate
189     bool isVerifyingMode() const                { return _verifying;};  // The system will be checked
190     void setVerifyingMode( TriBool state_r )    { _verifying = ( state_r == indeterminate ) ? false : bool(state_r); }
191
192     bool solveSrcPackages() const               { return _solveSrcPackages; }
193     void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = ( state_r == indeterminate ) ? false : bool(state_r); }
194
195     ResolverProblemList problems () const;
196     void applySolutions (const ProblemSolutionList &solutions);
197
198     // reset all SOLVER transaction in pool
199     void undo(void);
200
201     void reset (bool keepExtras = false );
202
203     bool testing(void) const { return _testing; }
204     void setTesting( bool testing ) { _testing = testing; }
205
206     // Get more information about the solverrun
207     // Which item will be installed by another item or triggers an item for
208     // installation
209     const ItemCapKindList isInstalledBy (const PoolItem item);
210     const ItemCapKindList installs (const PoolItem item);
211     const ItemCapKindList satifiedByInstalled (const PoolItem item);
212     const ItemCapKindList installedSatisfied (const PoolItem item);
213
214 };
215
216 ///////////////////////////////////////////////////////////////////
217     };// namespace detail
218     /////////////////////////////////////////////////////////////////////
219     /////////////////////////////////////////////////////////////////////
220   };// namespace solver
221   ///////////////////////////////////////////////////////////////////////
222   ///////////////////////////////////////////////////////////////////////
223 };// namespace zypp
224 /////////////////////////////////////////////////////////////////////////
225
226 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H