libzypp  10.5.0
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 sat
00052   {
00053     class Transaction;
00054   }
00055 
00057   namespace solver
00058   { 
00059 
00060     namespace detail
00061     { 
00062 
00063     class SATResolver;
00064 
00066     //
00067     //  CLASS NAME : ItemCapKind
00068     //
00070     struct ItemCapKind
00071     {
00072         public:
00073         Capability cap; //Capability which has triggerd this selection
00074         Dep capKind; //Kind of that capability
00075         PoolItem item; //Item which has triggered this selection
00076         bool initialInstallation; //This item has triggered the installation
00077                                   //Not already fullfilled requierement only.
00078 
00079     ItemCapKind() : capKind(Dep::PROVIDES) {}
00080             ItemCapKind( PoolItem i, Capability c, Dep k, bool initial)
00081                 : cap( c )
00082                 , capKind( k )
00083                 , item( i )
00084                 , initialInstallation( initial )
00085             { }
00086     };
00087     typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
00088     typedef std::list<ItemCapKind> ItemCapKindList;
00089 
00090 
00092 //
00093 //      CLASS NAME : Resolver
00101 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
00102 
00103   private:
00104     ResPool _pool;
00105     SATResolver *_satResolver;
00106     SerialNumberWatcher _poolchanged;
00107 
00108     CapabilitySet _extra_requires;
00109     CapabilitySet _extra_conflicts;
00110     std::set<Repository> _upgradeRepos;
00111 
00112     // Regard dependencies of the item weak onl
00113     PoolItemList _addWeak;
00114 
00117     bool _forceResolve;           // remove items which are conflicts with others or
00118                                   // have unfulfilled requirements.
00119                                   // This behaviour is favourited by ZMD
00120     bool _upgradeMode;            // Resolver has been called with doUpgrade
00121     bool _updateMode;            // Resolver has been called with doUpdate
00122     bool _verifying;              // The system will be checked
00123     bool _onlyRequires;           // do install required resolvables only
00124                                   // no recommended resolvables, language
00125                                   // packages, hardware packages (modalias)
00126     bool _allowVendorChange;    // whether the solver should allow or disallow vendor changes.
00127     bool _solveSrcPackages;     // whether to generate solver jobs for selected source packges.
00128     bool _cleandepsOnRemove;    // whether removing a package should also remove no longer needed requirements
00129 
00130     bool _ignoreAlreadyRecommended;   //ignore recommended packages that have already been recommended by the installed packages
00132 
00133     // Additional QueueItems which has to be regarded by the solver
00134     // This will be used e.g. by solution actions
00135     solver::detail::SolverQueueItemList _removed_queue_items;
00136     solver::detail::SolverQueueItemList _added_queue_items;
00137 
00138     // Additional information about the solverrun
00139     ItemCapKindMap _isInstalledBy;
00140     ItemCapKindMap _installs;
00141     ItemCapKindMap _satifiedByInstalled;
00142     ItemCapKindMap _installedSatisfied;
00143 
00144     // helpers
00145     void collectResolverInfo();
00146 
00147     // Unmaintained packages which does not fit to the updated system
00148     // (broken dependencies) will be deleted.
00149     // returns true if solving was successful
00150     bool checkUnmaintainedItems ();
00151 
00152     void solverInit();
00153 
00154   public:
00155 
00156     Resolver( const ResPool & pool );
00157     virtual ~Resolver();
00158 
00159     // ---------------------------------- I/O
00160 
00161     virtual std::ostream & dumpOn( std::ostream & str ) const;
00162     friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
00163     { return obj.dumpOn (str); }
00164 
00165     // ---------------------------------- methods
00166 
00167     ResPool pool() const;
00168     void setPool( const ResPool & pool ) { _pool = pool; }
00169 
00170     void addUpgradeRepo( Repository repo_r )            { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
00171     bool upgradingRepo( Repository repo_r ) const       { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
00172     void removeUpgradeRepo( Repository repo_r )         { _upgradeRepos.erase( repo_r ); }
00173     void removeUpgradeRepos()                           { _upgradeRepos.clear(); }
00174     const std::set<Repository> & upgradeRepos() const   { return _upgradeRepos; }
00175 
00176     void addExtraRequire( const Capability & capability );
00177     void removeExtraRequire( const Capability & capability );
00178     void addExtraConflict( const Capability & capability );
00179     void removeExtraConflict( const Capability & capability );
00180 
00181     void removeQueueItem( SolverQueueItem_Ptr item );
00182     void addQueueItem( SolverQueueItem_Ptr item );
00183 
00184     CapabilitySet extraRequires() const         { return _extra_requires; }
00185     CapabilitySet extraConflicts() const        { return _extra_conflicts; }
00186 
00187     void addWeak( const PoolItem & item );
00188 
00189     bool verifySystem();
00190     bool resolvePool();
00191     bool resolveQueue( SolverQueueItemList & queue );
00192     void doUpdate();
00193 
00194     bool doUpgrade();
00195     PoolItemList problematicUpdateItems() const;
00196 
00199     bool ignoreAlreadyRecommended() const       { return _ignoreAlreadyRecommended; }
00200     void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
00201 
00202     bool onlyRequires () const                  { return _onlyRequires; }
00203     void setOnlyRequires( TriBool state_r );
00204 
00205     bool forceResolve() const                   { return _forceResolve; }
00206     void setForceResolve( TriBool state_r )     { _forceResolve = indeterminate(state_r) ? false : bool(state_r); }
00207 
00208     bool isUpgradeMode() const                  { return _upgradeMode; }// Resolver has been called with doUpgrade
00209     void setUpgradeMode( bool yesno_r )         { _upgradeMode = yesno_r; }
00210 
00211     bool isUpdateMode() const                   { return _updateMode; } // Resolver has been called with doUpdate
00212 
00213     bool isVerifyingMode() const                { return _verifying; }  // The system will be checked
00214     void setVerifyingMode( TriBool state_r )    { _verifying = indeterminate(state_r) ? false : bool(state_r); }
00215 
00216     bool allowVendorChange() const              { return _allowVendorChange; }
00217     void setAllowVendorChange( TriBool state_r );
00218 
00219     bool solveSrcPackages() const               { return _solveSrcPackages; }
00220     void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
00221 
00222     bool cleandepsOnRemove() const              { return _cleandepsOnRemove; }
00223     void setCleandepsOnRemove( TriBool state_r );
00225 
00226     ResolverProblemList problems() const;
00227     void applySolutions( const ProblemSolutionList & solutions );
00228 
00229     // Return the Transaction computed by the last solver run.
00230     sat::Transaction getTransaction();
00231 
00232     // reset all SOLVER transaction in pool
00233     void undo();
00234 
00235     void reset( bool keepExtras = false );
00236 
00237     // Get more information about the solverrun
00238     // Which item will be installed by another item or triggers an item for
00239     // installation
00240     ItemCapKindList isInstalledBy( const PoolItem & item );
00241     ItemCapKindList installs( const PoolItem & item );
00242     ItemCapKindList satifiedByInstalled (const PoolItem & item );
00243     ItemCapKindList installedSatisfied( const PoolItem & item );
00244 
00245 };
00246 
00248     };// namespace detail
00251   };// namespace solver
00254 };// namespace zypp
00256 
00257 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H