libzypp  10.5.0
SATResolver.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* SATResolver.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_SAT_RESOLVER_H
00023 #define ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
00024 
00025 extern "C"
00026 {
00027 #include <solv/solver.h>
00028 #include <solv/pool.h>
00029 }
00030 
00031 #include <iosfwd>
00032 #include <list>
00033 #include <map>
00034 #include <string>
00035 
00036 #include "zypp/base/ReferenceCounted.h"
00037 #include "zypp/base/PtrTypes.h"
00038 #include "zypp/ResPool.h"
00039 #include "zypp/base/SerialNumber.h"
00040 #include "zypp/ProblemTypes.h"
00041 #include "zypp/ResolverProblem.h"
00042 #include "zypp/ProblemSolution.h"
00043 #include "zypp/Capability.h"
00044 #include "zypp/solver/detail/SolverQueueItem.h"
00045 
00047 namespace zypp
00048 { 
00049 
00050   namespace sat
00051   {
00052     class Transaction;
00053   }
00054 
00056   namespace solver
00057   { 
00058 
00059     namespace detail
00060     { 
00061 
00062 
00064 //
00065 //      CLASS NAME : SATResolver
00071 class SATResolver : public base::ReferenceCounted, private base::NonCopyable {
00072 
00073   private:
00074     ResPool _pool;
00075     Pool *_SATPool;
00076     Solver *_solv;
00077     Queue _jobQueue;
00078 
00079     // list of problematic items (orphaned)
00080     PoolItemList _problem_items;
00081 
00082     // list populated by calls to addPoolItemTo*()
00083     PoolItemList _items_to_install;
00084     PoolItemList _items_to_remove;
00085     PoolItemList _items_to_lock;
00086     PoolItemList _items_to_keep;
00087 
00088     // solve results
00089     PoolItemList _result_items_to_install;
00090     PoolItemList _result_items_to_remove;
00091 
00092     bool _fixsystem;                    // repair errors in rpm dependency graph
00093     bool _allowdowngrade;               // allow to downgrade installed solvable
00094     bool _allowarchchange;              // allow to change architecture of installed solvables
00095     bool _allowvendorchange;            // allow to change vendor of installed solvables
00096     bool _allowuninstall;               // allow removal of installed solvables
00097     bool _updatesystem;                 // update
00098     bool _noupdateprovide;              // true: update packages needs not to provide old package
00099     bool _dosplitprovides;              // true: consider legacy split provides
00100     bool _onlyRequires;                 // true: consider required packages only
00101     bool _ignorealreadyrecommended;     // true: ignore recommended packages that were already recommended by the installed packages
00102     bool _distupgrade;
00103     bool _distupgrade_removeunsupported;
00104     bool _solveSrcPackages;             // false: generate no job rule for source packages selected in the pool
00105     bool _cleandepsOnRemove;            // whether removing a package should also remove no longer needed requirements
00106 
00107     // ---------------------------------- methods
00108     std::string SATprobleminfoString (Id problem, std::string &detail, Id &ignoreId);
00109     void resetItemTransaction (PoolItem item);
00110 
00111     // Create a SAT solver and reset solver selection in the pool (Collecting
00112     void solverInit(const PoolItemList & weakItems);
00113     // common solver run with the _jobQueue; Save results back to pool
00114     bool solving(const CapabilitySet & requires_caps = CapabilitySet(),
00115                  const CapabilitySet & conflict_caps = CapabilitySet());
00116     // cleanup solver
00117     void solverEnd();
00118     // set locks for the solver
00119     void setLocks();
00120     // set requirements for a running system
00121     void setSystemRequirements();
00122 
00123    // Checking if this solvable/item has a buddy which reflect the real
00124    // user visible description of an item
00125    // e.g. The release package has a buddy to the concerning product item.
00126    // This user want's the message "Product foo conflicts with product bar" and
00127    // NOT "package release-foo conflicts with package release-bar"
00128    // So these functions return the concerning buddy (e.g. product item)
00129     sat::Solvable mapSolvable (const Id &id);
00130     PoolItem mapItem (const PoolItem &item);
00131 
00132   public:
00133 
00134     SATResolver (const ResPool & pool, Pool *SATPool);
00135     virtual ~SATResolver();
00136 
00137     // ---------------------------------- I/O
00138 
00139     virtual std::ostream & dumpOn( std::ostream & str ) const;
00140     friend std::ostream& operator<<(std::ostream& str, const SATResolver & obj)
00141     { return obj.dumpOn (str); }
00142 
00143     ResPool pool (void) const;
00144     void setPool (const ResPool & pool) { _pool = pool; }
00145 
00146     // solver run with pool selected items
00147     bool resolvePool(const CapabilitySet & requires_caps,
00148                      const CapabilitySet & conflict_caps,
00149                      const PoolItemList & weakItems,
00150                      const std::set<Repository> & upgradeRepos
00151                      );
00152     // solver run with the given request queue
00153     bool resolveQueue(const SolverQueueItemList &requestQueue,
00154                       const PoolItemList & weakItems
00155                       );
00156     // searching for new packages
00157     void doUpdate();
00158 
00159     ResolverProblemList problems ();
00160     void applySolutions (const ProblemSolutionList &solutions);
00161 
00162     // Return the Transaction computed by the last solver run.
00163     sat::Transaction getTransaction();
00164 
00165     void addPoolItemToInstall (PoolItem item);
00166     void addPoolItemsToInstallFromList (PoolItemList & rl);
00167 
00168     void addPoolItemToLock (PoolItem item);
00169     void addPoolItemToKeep (PoolItem item);
00170 
00171     void addPoolItemToRemove (PoolItem item);
00172     void addPoolItemsToRemoveFromList (PoolItemList & rl);
00173 
00174     bool fixsystem () const {return _fixsystem;}
00175     void setFixsystem ( const bool fixsystem) { _fixsystem = fixsystem;}
00176 
00177     bool ignorealreadyrecommended () const {return _ignorealreadyrecommended;}
00178     void setIgnorealreadyrecommended ( const bool ignorealreadyrecommended) { _ignorealreadyrecommended = ignorealreadyrecommended;}
00179 
00180     bool distupgrade () const {return _distupgrade;}
00181     void setDistupgrade ( const bool distupgrade) { _distupgrade = distupgrade;}
00182 
00183     bool distupgrade_removeunsupported () const {return _distupgrade_removeunsupported;}
00184     void setDistupgrade_removeunsupported ( const bool distupgrade_removeunsupported) { _distupgrade_removeunsupported = distupgrade_removeunsupported;}
00185 
00186     bool allowdowngrade () const {return _allowdowngrade;}
00187     void setAllowdowngrade ( const bool allowdowngrade) { _allowdowngrade = allowdowngrade;}
00188 
00189     bool allowarchchange () const {return _allowarchchange;}
00190     void setAllowarchchange ( const bool allowarchchange) { _allowarchchange = allowarchchange;}
00191 
00192     bool allowvendorchange () const {return _allowvendorchange;}
00193     void setAllowvendorchange ( const bool allowvendorchange) { _allowvendorchange = allowvendorchange;}
00194 
00195     bool allowuninstall () const {return _allowuninstall;}
00196     void setAllowuninstall ( const bool allowuninstall) { _allowuninstall = allowuninstall;}
00197 
00198     bool updatesystem () const {return _updatesystem;}
00199     void setUpdatesystem ( const bool updatesystem) { _updatesystem = updatesystem;}
00200 
00201     bool noupdateprovide () const {return _noupdateprovide;}
00202     void setNoupdateprovide ( const bool noupdateprovide) { _noupdateprovide = noupdateprovide;}
00203 
00204     bool dosplitprovides () const {return _dosplitprovides;}
00205     void setDosplitprovides ( const bool dosplitprovides) { _dosplitprovides = dosplitprovides;}
00206 
00207     bool onlyRequires () const {return _onlyRequires;}
00208     void setOnlyRequires ( const bool onlyRequires) { _onlyRequires = onlyRequires;}
00209 
00210     bool solveSrcPackages() const               { return _solveSrcPackages; }
00211     void setSolveSrcPackages( bool state_r )    { _solveSrcPackages = state_r; }
00212 
00213     bool cleandepsOnRemove() const              { return _cleandepsOnRemove; }
00214     void setCleandepsOnRemove( bool state_r )   { _cleandepsOnRemove = state_r; }
00215 
00216     PoolItemList problematicUpdateItems( void ) const { return _problem_items; }
00217 
00218     PoolItemList resultItemsToInstall () { return _result_items_to_install; }
00219     PoolItemList resultItemsToRemove () { return _result_items_to_remove; }
00220     PoolItemList problematicUpdateItems() { return _problem_items; }
00221 
00222 };
00223 
00225     };// namespace detail
00228   };// namespace solver
00231 };// namespace zypp
00233 
00234 #endif // ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H