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 
00035 #include "zypp/solver/detail/Types.h"
00036 #include "zypp/solver/detail/ResolverQueue.h"
00037 #include "zypp/solver/detail/ResolverContext.h"
00038 
00039 #include "zypp/ProblemTypes.h"
00040 #include "zypp/ResolverProblem.h"
00041 #include "zypp/ProblemSolution.h"
00042 #include "zypp/UpgradeStatistics.h"
00043 
00044 #include "zypp/CapSet.h"
00045 
00046 
00048 namespace zypp
00049 { 
00050 
00051   namespace solver
00052   { 
00053 
00054     namespace detail
00055     { 
00056 
00058 //
00059 //      CLASS NAME : Resolver
00060 
00061 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
00062 
00063   private:
00064     ResPool _pool;
00065 
00066     unsigned _timeout_seconds;
00067     unsigned _maxSolverPasses;
00068     bool _verifying;
00069     bool _testing;
00070     
00071     // In order reducing solver time we are reducing the branches
00072     // by skipping resolvables which have worse architecture,edition
00073     // than a resolvable which provides the same cababilities.
00074     // BUT if there is no valid solution we will regard the "other"
00075     // resolvables in a second solver run too.
00076     bool _tryAllPossibilities; // Try ALL alternatives
00077     bool _skippedPossibilities;// Flag that there are other possibilities
00078                                // which we are currently ignore
00079 
00080     // list populated by calls to addPoolItemTo*()
00081     QueueItemList _initial_items;
00082     PoolItemList _items_to_install;
00083     PoolItemList _items_to_establish;
00084     PoolItemList _items_to_remove;
00085     PoolItemList _items_to_verify;
00086 
00087     // list of problematic items after doUpgrade()
00088     PoolItemList _update_items;
00089 
00090 
00091     CapSet _extra_caps;
00092     CapSet _extra_conflicts;
00093 
00094     //typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
00095 
00096     // These conflict should be ignored of the concering item
00097     IgnoreMap _ignoreConflicts;
00098     // These requires should be ignored of the concering item    
00099     IgnoreMap _ignoreRequires;
00100     // These obsoletes should be ignored of the concering item    
00101     IgnoreMap _ignoreObsoletes;    
00102     // Ignore architecture of the item
00103     PoolItemList _ignoreArchitecture;
00104     // Ignore the status "installed" of the item
00105     PoolItemList _ignoreInstalledItem;
00106     // Ignore the architecture of the item
00107     PoolItemList _ignoreArchitectureItem;    
00108     
00109 
00110     ResolverQueueList _pending_queues;
00111     ResolverQueueList _pruned_queues;
00112     ResolverQueueList _complete_queues;
00113     ResolverQueueList _deferred_queues;
00114     ResolverQueueList _invalid_queues;
00115 
00116     int _valid_solution_count;
00117 
00118     ResolverContext_Ptr _best_context;
00119     // Context of the last establishing call ( without any transaction )
00120     ResolverContext_Ptr _establish_context;    
00121     bool _timed_out;
00122 
00123     std::set<Source_Ref> _subscribed;
00124 
00125     Arch _architecture;
00126 
00127     bool _forceResolve; // remove items which are conflicts with others or
00128                         // have unfulfilled requirements.
00129                         // This behaviour is favourited by ZMD
00130     bool _upgradeMode;  // Resolver has been called with doUpgrade
00131     bool _preferHighestVersion; // Prefer the result with the newest version
00132                                 //if there are more solver results. 
00133 
00134     // helpers
00135     bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
00136     bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
00137 
00138   public:
00139 
00140     Resolver (const ResPool & pool);
00141     virtual ~Resolver();
00142 
00143     // ---------------------------------- I/O
00144 
00145     virtual std::ostream & dumpOn( std::ostream & str ) const;
00146     friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
00147     { return obj.dumpOn (str); }
00148 
00149     // ---------------------------------- accessors
00150 
00151     QueueItemList initialItems () const { return _initial_items; }
00152 
00153     ResolverQueueList pendingQueues () const { return _pending_queues; }
00154     ResolverQueueList prunedQueues () const { return _pruned_queues; }
00155     ResolverQueueList completeQueues () const { return _complete_queues; }
00156     ResolverQueueList deferredQueues () const { return _deferred_queues; }
00157     ResolverQueueList invalidQueues () const { return _invalid_queues; }
00158 
00159     ResolverContext_Ptr bestContext (void) const { return _best_context; }
00160 
00163     ResolverContext_Ptr context (void) const;
00164 
00165     // ---------------------------------- methods
00166 
00167     void setTimeout (int seconds) { _timeout_seconds = seconds; }
00168     void setMaxSolverPasses (int count) { _maxSolverPasses = count; }
00169     int timeout () { return _timeout_seconds; }
00170     int maxSolverPasses () { return _maxSolverPasses; }
00171 
00172     ResPool pool (void) const;
00173     void setPool (const ResPool & pool) { _pool = pool; }
00174 
00175     void addSubscribedSource (Source_Ref source);
00176 
00177     void addPoolItemToInstall (PoolItem_Ref item);
00178     void addPoolItemsToInstallFromList (PoolItemList & rl);
00179 
00180     void addPoolItemToRemove (PoolItem_Ref item);
00181     void addPoolItemsToRemoveFromList (PoolItemList & rl);
00182 
00183     void addPoolItemToEstablish (PoolItem_Ref item);
00184     void addPoolItemsToEstablishFromList (PoolItemList & rl);
00185 
00186     void addPoolItemToVerify (PoolItem_Ref item);
00187 
00188     void addExtraCapability (const Capability & capability);
00189     void addExtraConflict (const Capability & capability);
00190 
00191     void addIgnoreConflict (const PoolItem_Ref item,
00192                             const Capability & capability);
00193     void addIgnoreRequires (const PoolItem_Ref item,
00194                             const Capability & capability);
00195     void addIgnoreObsoletes (const PoolItem_Ref item,
00196                              const Capability & capability);
00197     void addIgnoreInstalledItem (const PoolItem_Ref item);
00198     void addIgnoreArchitectureItem (const PoolItem_Ref item);    
00199 
00200     void setForceResolve (const bool force) { _forceResolve = force; }
00201     const bool forceResolve() { return _forceResolve; }
00202     void setPreferHighestVersion (const bool highestVersion) { _preferHighestVersion = highestVersion; }
00203     const bool preferHighestVersion() { return _preferHighestVersion; }  
00204 
00205     bool verifySystem (bool considerNewHardware = false);
00206     void establishState (ResolverContext_Ptr context = NULL);
00207     bool establishPool (void);
00208     void freshenState( ResolverContext_Ptr context = NULL, bool resetAfterSolve = true );
00209     bool freshenPool( bool resetAfterSolve = true );
00210     bool resolveDependencies (const ResolverContext_Ptr context = NULL);
00211     bool resolvePool( bool tryAllPossibilities = false );
00212 
00213     bool transactResObject( ResObject::constPtr robj,
00214                             bool install = true,
00215                             bool recursive = false);
00216     bool transactResKind( Resolvable::Kind kind );
00217     void transactReset( ResStatus::TransactByValue causer );
00218 
00219     void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
00220     PoolItemList problematicUpdateItems( void ) const { return _update_items; }
00221 
00222 
00223     ResolverProblemList problems (const bool ignoreValidSolution = false) const;
00224     void applySolutions (const ProblemSolutionList &solutions);
00225     // returns a string list of ResolverInfo of the LAST not valid solution
00226     std::list<std::string> problemDescription( void ) const;
00227 
00228     // reset all SOLVER transaction in pool
00229     void undo(void);
00230 
00231     // only for testsuite
00232     void reset (void);
00233 
00234     Arch architecture() const { return _architecture; }
00235     void setArchitecture( const Arch & arch) { _architecture = arch; }
00236 
00237     bool testing(void) const { return _testing; }
00238     void setTesting( bool testing ) { _testing = testing; }
00239 };
00240 
00242     };// namespace detail
00245   };// namespace solver
00248 };// namespace zypp
00250 
00251 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H

Generated on Fri Jul 4 16:57:58 2008 for zypp by  doxygen 1.5.0