00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ZYPP_SOLVER_DETAIL_RESOLVER_H
00023 #define ZYPP_SOLVER_DETAIL_RESOLVER_H
00024
00025 #include <iosfwd>
00026 #include <list>
00027 #include <map>
00028 #include <string>
00029
00030 #include "zypp/base/ReferenceCounted.h"
00031 #include "zypp/base/PtrTypes.h"
00032
00033 #include "zypp/ResPool.h"
00034 #include "zypp/base/SerialNumber.h"
00035
00036 #include "zypp/solver/detail/Types.h"
00037 #include "zypp/solver/detail/ResolverQueue.h"
00038 #include "zypp/solver/detail/ResolverContext.h"
00039 #include "zypp/solver/detail/ContextPool.h"
00040
00041 #include "zypp/ProblemTypes.h"
00042 #include "zypp/ResolverProblem.h"
00043 #include "zypp/ProblemSolution.h"
00044 #include "zypp/UpgradeStatistics.h"
00045
00046 #include "zypp/CapSet.h"
00047
00048
00050 namespace zypp
00051 {
00052
00053 namespace solver
00054 {
00055
00056 namespace detail
00057 {
00058
00060
00061
00062
00064 struct ItemCapKind
00065 {
00066 public:
00067 Capability cap;
00068 Dep capKind;
00069 PoolItem_Ref item;
00070 bool initialInstallation;
00071
00072
00073 ItemCapKind() : capKind("FRESHENS") {}
00074 ItemCapKind( PoolItem i, Capability c, Dep k, bool initial)
00075 : cap( c )
00076 , capKind( k )
00077 , item( i )
00078 , initialInstallation( initial )
00079 { }
00080 };
00081 typedef std::multimap<PoolItem_Ref,ItemCapKind> ItemCapKindMap;
00082 typedef std::list<ItemCapKind> ItemCapKindList;
00083
00085
00086
00087
00088 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
00089
00090 private:
00091 ResPool _pool;
00092 SerialNumberWatcher _poolchanged;
00093
00094 unsigned _timeout_seconds;
00095 unsigned _maxSolverPasses;
00096 bool _verifying;
00097 bool _testing;
00098
00099
00100
00101
00102
00103
00104 bool _tryAllPossibilities;
00105
00106
00107 QueueItemList _initial_items;
00108 PoolItemList _items_to_install;
00109 PoolItemList _items_to_establish;
00110 PoolItemList _items_to_remove;
00111 PoolItemList _items_to_verify;
00112 PoolItemList _items_to_lockUninstalled;
00113 PoolItemList _items_to_keep;
00114
00115
00116 ContextPool contextPool;
00117
00118
00119 PoolItemList _update_items;
00120
00121
00122 ItemCapKindMap _isInstalledBy;
00123 ItemCapKindMap _installs;
00124
00125 CapSet _extra_caps;
00126 CapSet _extra_conflicts;
00127
00128
00129
00130
00131 IgnoreMap _ignoreConflicts;
00132
00133 IgnoreMap _ignoreRequires;
00134
00135 IgnoreMap _ignoreObsoletes;
00136
00137 PoolItemList _ignoreArchitecture;
00138
00139 PoolItemList _ignoreInstalledItem;
00140
00141 PoolItemList _ignoreArchitectureItem;
00142
00143 PoolItemList _ignoreVendorItem;
00144
00145 ResolverQueueList _pending_queues;
00146 ResolverQueueList _pruned_queues;
00147 ResolverQueueList _complete_queues;
00148 ResolverQueueList _deferred_queues;
00149 ResolverQueueList _invalid_queues;
00150
00151 int _valid_solution_count;
00152
00153 ResolverContext_Ptr _best_context;
00154
00155 ResolverContext_Ptr _establish_context;
00156 bool _timed_out;
00157
00158 std::set<Repository> _subscribed;
00159
00160 Arch _architecture;
00161
00162 bool _forceResolve;
00163
00164
00165 bool _upgradeMode;
00166 bool _preferHighestVersion;
00167
00168
00169
00170 bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
00171 bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
00172
00173 void collectResolverInfo (void);
00174
00175
00176 public:
00177
00178 Resolver (const ResPool & pool);
00179 virtual ~Resolver();
00180
00181
00182
00183 virtual std::ostream & dumpOn( std::ostream & str ) const;
00184 friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
00185 { return obj.dumpOn (str); }
00186 void dumpTaskList(const PoolItemList &install, const PoolItemList &remove );
00187
00188
00189
00190 QueueItemList initialItems () const { return _initial_items; }
00191
00192 ResolverQueueList pendingQueues () const { return _pending_queues; }
00193 ResolverQueueList prunedQueues () const { return _pruned_queues; }
00194 ResolverQueueList completeQueues () const { return _complete_queues; }
00195 ResolverQueueList deferredQueues () const { return _deferred_queues; }
00196 ResolverQueueList invalidQueues () const { return _invalid_queues; }
00197
00198 ResolverContext_Ptr bestContext (void) const { return _best_context; }
00199
00202 ResolverContext_Ptr context (void) const;
00203
00204
00205
00206 void setTimeout (int seconds) { _timeout_seconds = seconds; }
00207 void setMaxSolverPasses (int count) { _maxSolverPasses = count; }
00208 int timeout () const { return _timeout_seconds; }
00209 int maxSolverPasses () const { return _maxSolverPasses; }
00210
00211 ResPool pool (void) const;
00212 void setPool (const ResPool & pool) { _pool = pool; }
00213
00214 void addSubscribedSource (Repository source);
00215
00216 void addPoolItemToInstall (PoolItem_Ref item);
00217 void addPoolItemsToInstallFromList (PoolItemList & rl);
00218
00219 void addPoolItemToLockUninstalled (PoolItem_Ref item);
00220 void addPoolItemToKepp (PoolItem_Ref item);
00221
00222 void addPoolItemToRemove (PoolItem_Ref item);
00223 void addPoolItemsToRemoveFromList (PoolItemList & rl);
00224
00225 void addPoolItemToEstablish (PoolItem_Ref item);
00226 void addPoolItemsToEstablishFromList (PoolItemList & rl);
00227
00228 void addPoolItemToVerify (PoolItem_Ref item);
00229
00230 void addExtraCapability (const Capability & capability);
00231 void removeExtraCapability (const Capability & capability);
00232 void addExtraConflict (const Capability & capability);
00233
00234 const CapSet extraCapability () { return _extra_caps; }
00235 const CapSet extraConflicts () { return _extra_conflicts; }
00236
00237 void addIgnoreConflict (const PoolItem_Ref item,
00238 const Capability & capability);
00239 void addIgnoreRequires (const PoolItem_Ref item,
00240 const Capability & capability);
00241 void addIgnoreObsoletes (const PoolItem_Ref item,
00242 const Capability & capability);
00243 void addIgnoreInstalledItem (const PoolItem_Ref item);
00244 void addIgnoreArchitectureItem (const PoolItem_Ref item);
00245 void addIgnoreVendorItem (const PoolItem_Ref item);
00246
00247 void setForceResolve (const bool force) { _forceResolve = force; }
00248 const bool forceResolve() { return _forceResolve; }
00249 void setPreferHighestVersion (const bool highestVersion) { _preferHighestVersion = highestVersion; }
00250 const bool preferHighestVersion() { return _preferHighestVersion; }
00251
00252 void setTryAllPossibilities (const bool tryAllPossibilities) { _tryAllPossibilities = tryAllPossibilities; }
00253 const bool tryAllPossibilities () const { return _tryAllPossibilities; };
00254
00255 bool verifySystem (bool considerNewHardware = false);
00256 void establishState (ResolverContext_Ptr context = NULL);
00257 bool establishPool (void);
00258 void freshenState( ResolverContext_Ptr context = NULL, bool resetAfterSolve = true );
00259 bool freshenPool( bool resetAfterSolve = true );
00260 bool resolveDependencies (const ResolverContext_Ptr context = NULL);
00261 bool resolvePool( bool tryAllPossibilities = false);
00262
00263 bool transactResObject( ResObject::constPtr robj,
00264 bool install = true,
00265 bool recursive = false);
00266 bool transactResKind( Resolvable::Kind kind );
00267 void transactReset( ResStatus::TransactByValue causer );
00268
00269 void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
00270 PoolItemList problematicUpdateItems( void ) const { return _update_items; }
00271
00272
00273 ResolverProblemList problems (const bool ignoreValidSolution = false) const;
00274 void applySolutions (const ProblemSolutionList &solutions);
00275
00276 std::list<std::string> problemDescription( void ) const;
00277
00278
00279 void undo(void);
00280
00281
00282
00283
00284 const ItemCapKindList isInstalledBy (const PoolItem_Ref item);
00285 const ItemCapKindList installs (const PoolItem_Ref item);
00286
00287 void reset (bool resetValidResults = false, bool keepExtras = false );
00288
00289 Arch architecture() const { return _architecture; }
00290 void setArchitecture( const Arch & arch) { _architecture = arch; }
00291
00292 bool testing(void) const { return _testing; }
00293 void setTesting( bool testing ) { _testing = testing; }
00294 };
00295
00297 };
00300 };
00303 };
00305
00306 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H