Resolver.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* Resolver.h
00003  *
00004  * Copyright (C) 2000-2002 Ximian, Inc.
00005  * Copyright (C) 2005 SUSE Linux Products GmbH
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019  * 02111-1307, USA.
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     //  CLASS NAME : ItemCapKind
00062     //
00064     struct ItemCapKind
00065     {
00066         public:
00067         Capability cap; //Capability which has triggerd this selection
00068         Dep capKind; //Kind of that capability
00069         PoolItem_Ref item; //Item which has triggered this selection
00070         bool initialInstallation; //This item has triggered the installation
00071                                   //Not already fullfilled requierement only.
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 //      CLASS NAME : Resolver
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     // In order reducing solver time we are reducing the branches
00100     // by skipping resolvables which have worse architecture,edition
00101     // than a resolvable which provides the same cababilities.
00102     // BUT if there is no valid solution we will regard the "other"
00103     // resolvables in a second solver run too.
00104     bool _tryAllPossibilities; // Try ALL alternatives
00105 
00106     // list populated by calls to addPoolItemTo*()
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     // pool of valid contexts which are "recycled" in order to fasten the solver
00116     ContextPool contextPool;
00117 
00118     // list of problematic items after doUpgrade()
00119     PoolItemList _update_items;
00120 
00121     // Additional information about the solverrun
00122     ItemCapKindMap _isInstalledBy;
00123     ItemCapKindMap _installs;
00124 
00125     CapSet _extra_caps;
00126     CapSet _extra_conflicts;
00127 
00128     //typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
00129 
00130     // These conflict should be ignored of the concering item
00131     IgnoreMap _ignoreConflicts;
00132     // These requires should be ignored of the concering item
00133     IgnoreMap _ignoreRequires;
00134     // These obsoletes should be ignored of the concering item
00135     IgnoreMap _ignoreObsoletes;
00136     // Ignore architecture of the item
00137     PoolItemList _ignoreArchitecture;
00138     // Ignore the status "installed" of the item
00139     PoolItemList _ignoreInstalledItem;
00140     // Ignore the architecture of the item
00141     PoolItemList _ignoreArchitectureItem;
00142     // Ignore the vendor of the item
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     // Context of the last establishing call ( without any transaction )
00155     ResolverContext_Ptr _establish_context;
00156     bool _timed_out;
00157 
00158     std::set<Repository> _subscribed;
00159 
00160     Arch _architecture;
00161 
00162     bool _forceResolve; // remove items which are conflicts with others or
00163                         // have unfulfilled requirements.
00164                         // This behaviour is favourited by ZMD
00165     bool _upgradeMode;  // Resolver has been called with doUpgrade
00166     bool _preferHighestVersion; // Prefer the result with the newest version
00167                                 //if there are more solver results.
00168 
00169     // helpers
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     // ---------------------------------- I/O
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     // ---------------------------------- accessors
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     // ---------------------------------- methods
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     // returns a string list of ResolverInfo of the LAST not valid solution
00276     std::list<std::string> problemDescription( void ) const;
00277 
00278     // reset all SOLVER transaction in pool
00279     void undo(void);
00280 
00281     // Get more information about the solverrun
00282     // Which item will be installed by another item or triggers an item for
00283     // installation
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     };// namespace detail
00300   };// namespace solver
00303 };// namespace zypp
00305 
00306 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H

Generated on Tue Sep 25 19:23:06 2007 for libzypp by  doxygen 1.5.3