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/TriBool.h"
00035 #include "zypp/base/SerialNumber.h"
00036 
00037 #include "zypp/solver/detail/Types.h"
00038 #include "zypp/solver/detail/SolverQueueItem.h"
00039 
00040 #include "zypp/ProblemTypes.h"
00041 #include "zypp/ResolverProblem.h"
00042 #include "zypp/ProblemSolution.h"
00043 #include "zypp/Capabilities.h"
00044 #include "zypp/Capability.h"
00045 
00046 
00048 namespace zypp
00049 { 
00050 
00051   namespace solver
00052   { 
00053 
00054     namespace detail
00055     { 
00056 
00057     class SATResolver;
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 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(Dep::PROVIDES) {}
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,ItemCapKind> ItemCapKindMap;
00082     typedef std::list<ItemCapKind> ItemCapKindList;
00083 
00084 
00086 //
00087 //      CLASS NAME : Resolver
00088 
00089 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
00090 
00091   private:
00092     ResPool _pool;
00093     SATResolver *_satResolver;
00094     SerialNumberWatcher _poolchanged;
00095 
00096     CapabilitySet _extra_requires;
00097     CapabilitySet _extra_conflicts;
00098     std::set<Repository> _upgradeRepos;
00099 
00100     // Regard dependencies of the item weak onl
00101     PoolItemList _addWeak;
00102 
00105     bool _forceResolve;           // remove items which are conflicts with others or
00106                                   // have unfulfilled requirements.
00107                                   // This behaviour is favourited by ZMD
00108     bool _upgradeMode;            // Resolver has been called with doUpgrade
00109     bool _updateMode;            // Resolver has been called with doUpdate
00110     bool _verifying;              // The system will be checked
00111     bool _onlyRequires;           // do install required resolvables only
00112                                   // no recommended resolvables, language
00113                                   // packages, hardware packages (modalias)
00114     bool _allowVendorChange;    // whether the solver should allow or disallow vendor changes.
00115     bool _solveSrcPackages;     // whether to generate solver jobs for selected source packges.
00116     bool _cleandepsOnRemove;    // whether removing a package should also remove no longer needed requirements
00117 
00118     bool _ignoreAlreadyRecommended;   //ignore recommended packages that have already been recommended by the installed packages
00120 
00121     // Additional QueueItems which has to be regarded by the solver
00122     // This will be used e.g. by solution actions
00123     solver::detail::SolverQueueItemList _removed_queue_items;
00124     solver::detail::SolverQueueItemList _added_queue_items;
00125 
00126     // Additional information about the solverrun
00127     ItemCapKindMap _isInstalledBy;
00128     ItemCapKindMap _installs;
00129     ItemCapKindMap _satifiedByInstalled;
00130     ItemCapKindMap _installedSatisfied;
00131 
00132     // helpers
00133     void collectResolverInfo();
00134 
00135     // Unmaintained packages which does not fit to the updated system
00136     // (broken dependencies) will be deleted.
00137     // returns true if solving was successful
00138     bool checkUnmaintainedItems ();
00139 
00140     void solverInit();
00141 
00142   public:
00143 
00144     Resolver( const ResPool & pool );
00145     virtual ~Resolver();
00146 
00147     // ---------------------------------- I/O
00148 
00149     virtual std::ostream & dumpOn( std::ostream & str ) const;
00150     friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
00151     { return obj.dumpOn (str); }
00152 
00153     // ---------------------------------- methods
00154 
00155     ResPool pool() const;
00156     void setPool( const ResPool & pool ) { _pool = pool; }
00157 
00158     void addUpgradeRepo( Repository repo_r )            { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
00159     bool upgradingRepo( Repository repo_r ) const       { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
00160     void removeUpgradeRepo( Repository repo_r )         { _upgradeRepos.erase( repo_r ); }
00161     void removeUpgradeRepos()                           { _upgradeRepos.clear(); }
00162     const std::set<Repository> & upgradeRepos() const   { return _upgradeRepos; }
00163 
00164     void addExtraRequire( const Capability & capability );
00165     void removeExtraRequire( const Capability & capability );
00166     void addExtraConflict( const Capability & capability );
00167     void removeExtraConflict( const Capability & capability );
00168 
00169     void removeQueueItem( SolverQueueItem_Ptr item );
00170     void addQueueItem( SolverQueueItem_Ptr item );
00171 
00172     CapabilitySet extraRequires() const         { return _extra_requires; }
00173     CapabilitySet extraConflicts() const        { return _extra_conflicts; }
00174 
00175     void addWeak( const PoolItem & item );
00176 
00177     bool verifySystem();
00178     bool resolvePool();
00179     bool resolveQueue( SolverQueueItemList & queue );
00180     void doUpdate();
00181 
00182     bool doUpgrade();
00183     PoolItemList problematicUpdateItems() const;
00184 
00187     bool ignoreAlreadyRecommended() const       { return _ignoreAlreadyRecommended; }
00188     void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
00189 
00190     bool onlyRequires () const                  { return _onlyRequires; }
00191     void setOnlyRequires( TriBool state_r );
00192 
00193     bool forceResolve() const                   { return _forceResolve; }
00194     void setForceResolve( TriBool state_r )     { _forceResolve = indeterminate(state_r) ? false : bool(state_r); }
00195 
00196     bool isUpgradeMode() const                  { return _upgradeMode; }// Resolver has been called with doUpgrade
00197 
00198     bool isUpdateMode() const                   { return _updateMode; } // Resolver has been called with doUpdate
00199 
00200     bool isVerifyingMode() const                { return _verifying; }  // The system will be checked
00201     void setVerifyingMode( TriBool state_r )    { _verifying = indeterminate(state_r) ? false : bool(state_r); }
00202 
00203     bool allowVendorChange() const              { return _allowVendorChange; }
00204     void setAllowVendorChange( TriBool state_r );
00205 
00206     bool solveSrcPackages() const               { return _solveSrcPackages; }
00207     void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
00208 
00209     bool cleandepsOnRemove() const              { return _cleandepsOnRemove; }
00210     void setCleandepsOnRemove( TriBool state_r );
00212 
00213     ResolverProblemList problems() const;
00214     void applySolutions( const ProblemSolutionList & solutions );
00215 
00216     // reset all SOLVER transaction in pool
00217     void undo();
00218 
00219     void reset( bool keepExtras = false );
00220 
00221     // Get more information about the solverrun
00222     // Which item will be installed by another item or triggers an item for
00223     // installation
00224     ItemCapKindList isInstalledBy( const PoolItem & item );
00225     ItemCapKindList installs( const PoolItem & item );
00226     ItemCapKindList satifiedByInstalled (const PoolItem & item );
00227     ItemCapKindList installedSatisfied( const PoolItem & item );
00228 
00229 };
00230 
00232     };// namespace detail
00235   };// namespace solver
00238 };// namespace zypp
00240 
00241 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H
Generated on Fri Mar 2 09:45:53 2012 for libzypp by  doxygen 1.6.3