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 _scippedPossibilities;// 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     bool _timed_out;
00120 
00121     std::set<Source_Ref> _subscribed;
00122 
00123     Arch _architecture;
00124 
00125     bool _forceResolve; // remove items which are conflicts with others or
00126                         // have unfulfilled requirements.
00127                         // This behaviour is favourited by ZMD
00128     bool _upgradeMode;  // Resolver has been called with doUpgrade    
00129 
00130     // helpers
00131     bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
00132     bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
00133 
00134   public:
00135 
00136     Resolver (const ResPool & pool);
00137     virtual ~Resolver();
00138 
00139     // ---------------------------------- I/O
00140 
00141     virtual std::ostream & dumpOn( std::ostream & str ) const;
00142     friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
00143     { return obj.dumpOn (str); }
00144 
00145     // ---------------------------------- accessors
00146 
00147     QueueItemList initialItems () const { return _initial_items; }
00148 
00149     ResolverQueueList pendingQueues () const { return _pending_queues; }
00150     ResolverQueueList prunedQueues () const { return _pruned_queues; }
00151     ResolverQueueList completeQueues () const { return _complete_queues; }
00152     ResolverQueueList deferredQueues () const { return _deferred_queues; }
00153     ResolverQueueList invalidQueues () const { return _invalid_queues; }
00154 
00155     ResolverContext_Ptr bestContext (void) const { return _best_context; }
00156 
00159     ResolverContext_Ptr context (void) const;
00160 
00161     // ---------------------------------- methods
00162 
00163     void setTimeout (int seconds) { _timeout_seconds = seconds; }
00164     void setMaxSolverPasses (int count) { _maxSolverPasses = count; }
00165     int timeout () { return _timeout_seconds; }
00166     int maxSolverPasses () { return _maxSolverPasses; }
00167 
00168     ResPool pool (void) const;
00169     void setPool (const ResPool & pool) { _pool = pool; }
00170 
00171     void addSubscribedSource (Source_Ref source);
00172 
00173     void addPoolItemToInstall (PoolItem_Ref item);
00174     void addPoolItemsToInstallFromList (PoolItemList & rl);
00175 
00176     void addPoolItemToRemove (PoolItem_Ref item);
00177     void addPoolItemsToRemoveFromList (PoolItemList & rl);
00178 
00179     void addPoolItemToEstablish (PoolItem_Ref item);
00180     void addPoolItemsToEstablishFromList (PoolItemList & rl);
00181 
00182     void addPoolItemToVerify (PoolItem_Ref item);
00183 
00184     void addExtraCapability (const Capability & capability);
00185     void addExtraConflict (const Capability & capability);
00186 
00187     void addIgnoreConflict (const PoolItem_Ref item,
00188                             const Capability & capability);
00189     void addIgnoreRequires (const PoolItem_Ref item,
00190                             const Capability & capability);
00191     void addIgnoreObsoletes (const PoolItem_Ref item,
00192                              const Capability & capability);
00193     void addIgnoreInstalledItem (const PoolItem_Ref item);
00194     void addIgnoreArchitectureItem (const PoolItem_Ref item);    
00195 
00196     void setForceResolve (const bool force) { _forceResolve = force; }
00197     const bool forceResolve() { return _forceResolve; }
00198 
00199     bool verifySystem (void);
00200     void establishState (ResolverContext_Ptr context = NULL);
00201     bool establishPool (void);
00202     void freshenState( ResolverContext_Ptr context = NULL );
00203     bool freshenPool( void );
00204     bool resolveDependencies (const ResolverContext_Ptr context = NULL);
00205     bool resolvePool (void);
00206 
00207     bool transactResObject( ResObject::constPtr robj,
00208                             bool install = true,
00209                             bool recursive = false);
00210     bool transactResKind( Resolvable::Kind kind );
00211     void transactReset( ResStatus::TransactByValue causer );
00212 
00213     void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
00214     PoolItemList problematicUpdateItems( void ) const { return _update_items; }
00215 
00216 
00217     ResolverProblemList problems (void) const;
00218     void applySolutions (const ProblemSolutionList &solutions);
00219     // returns a string list of ResolverInfo of the LAST not valid solution
00220     std::list<std::string> problemDescription( void ) const;
00221 
00222     // reset all SOLVER transaction in pool
00223     void undo(void);
00224 
00225     // only for testsuite
00226     void reset (void);
00227 
00228     Arch architecture() const { return _architecture; }
00229     void setArchitecture( const Arch & arch) { _architecture = arch; }
00230 
00231     bool testing(void) const { return _testing; }
00232     void setTesting( bool testing ) { _testing = testing; }
00233 };
00234 
00236     };// namespace detail
00239   };// namespace solver
00242 };// namespace zypp
00244 
00245 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H

Generated on Tue Nov 28 16:49:30 2006 for zypp by  doxygen 1.5.0