ResolverContext.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* ResolverContext.h
00003  *
00004  *Keep a set of 'active' PoolItems, these are part of the current
00005  *transaction. It thereby provides a to-be status for these items
00006  *
00007  *
00008  *Copyright (C) 2000-2002 Ximian, Inc.
00009  *Copyright (C) 2005 SUSE Linux Products GmbH
00010  *
00011  *This program is free software; you can redistribute it and/or
00012  *modify it under the terms of the GNU General Public License,
00013  *version 2, as published by the Free Software Foundation.
00014  *
00015  *This program is distributed in the hope that it will be useful, but
00016  *WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *General Public License for more details.
00019  *
00020  *You should have received a copy of the GNU General Public License
00021  *along with this program; if not, write to the Free Software
00022  *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00023  *02111-1307, USA.
00024  */
00025 
00026 #ifndef ZYPP_SOLVER_DETAIL_RESOLVERCONTEXT_H
00027 #define ZYPP_SOLVER_DETAIL_RESOLVERCONTEXT_H
00028 
00029 #include "zypp/ResPool.h"
00030 #include "zypp/PoolItem.h"
00031 #include "zypp/Capability.h"
00032 #include "zypp/Source.h"
00033 
00034 #include "zypp/solver/detail/Types.h"
00035 #include "zypp/solver/detail/ResolverInfo.h"
00036 
00038 namespace zypp
00039 { 
00040 
00041   namespace solver
00042   { 
00043 
00044     namespace detail
00045     { 
00046 
00047 typedef void (*ResolverContextFn) (ResolverContext_Ptr ctx, void *data);
00048 typedef void (*MarkedPoolItemFn) (PoolItem_Ref item, const ResStatus & status, void *data);
00049 typedef void (*MarkedPoolItemPairFn) (PoolItem_Ref item1, const ResStatus & status1, PoolItem_Ref item2, const ResStatus & status2, void *data);
00050 typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
00051 typedef std::map<Source_Ref ,int> SourceCounter;        
00052 
00054 //
00055 //      CLASS NAME : ResolverContext
00056 class ResolverContext : public base::ReferenceCounted, private base::NonCopyable {
00057     
00058 
00059   private:
00060 
00061     ResolverContext_Ptr _parent;                // branches share a common parent
00062     ResolverContext_Ptr _establish_context;   // Context of the last Resolver-Establish call
00063 
00064     typedef std::map<PoolItem_Ref,ResStatus> Context;
00065     Context _context;                           // the set of items touched in this transaction
00066 
00067     ResPool _pool;
00068 
00069     ResolverInfoList _log;                      // report log
00070 
00071     unsigned long long _download_size;
00072     unsigned long long _install_size;
00073     int _total_priority;
00074     int _min_priority;
00075     int _max_priority;
00076     int _other_penalties;
00077 
00078     bool _verifying;                            // running 'verifySystem'
00079     bool _establishing;                         // running 'establishSystem'
00080     bool _invalid;                              // lead to invalid solution
00081     bool _askUser;                              // lead to invalid solution too cause we have to ask the user 
00082 
00083     PoolItem_Ref _last_checked_item;            // cache for {get,set}Status
00084     ResStatus _last_checked_status;
00085 
00086     PoolItemList _last_getMarked;       // status of the last getMarked call
00087                                         // it is sorted
00088     int _last_getMarked_which;          // which kind of getMarked
00089 
00090     Arch _architecture;
00091 
00092     // These conflict should be ignored of the concering item
00093     IgnoreMap _ignoreConflicts;
00094     // These requires should be ignored of the concering item    
00095     IgnoreMap _ignoreRequires;
00096     // These obsoletes should be ignored of the concering item    
00097     IgnoreMap _ignoreObsoletes;    
00098     // Ignore the status "installed" of the item
00099     PoolItemList _ignoreInstalledItem;
00100     // Ignore the architecture of the item
00101     PoolItemList _ignoreArchitectureItem;
00102     
00103 
00104     bool _forceResolve; // remove items which are conflicts with others or
00105                         // have unfulfilled requirements.
00106                         // This behaviour is favourited by ZMD    
00107     bool _upgradeMode;  // Resolver has been called with doUpgrade
00108 
00109     bool _preferHighestVersion; // Prefer the result with the newest version
00110                                //if there are more solver results. 
00111     
00112     // In order reducing solver time we are reducing the branches
00113     // by skipping resolvables which have worse architecture,edition
00114     // than a resolvable which provides the same cababilities.
00115     // BUT if there is no valid solution we will regard the "other"
00116     // resolvables in a second solver run too.
00117     bool _tryAllPossibilities; // Try ALL alternatives
00118     bool _skippedPossibilities;// Flag that there are other possibilities
00119                                // which we are currently ignore
00120     
00121   public:
00122     ResolverContext (const ResPool & pool, const Arch & arch, ResolverContext_Ptr parent = NULL);
00123     virtual ~ResolverContext();
00124 
00125     // ---------------------------------- I/O
00126 
00127     friend std::ostream& operator<<(std::ostream&, const ResolverContext & context);
00128 
00129     // ---------------------------------- accessors
00130 
00131     unsigned long long downloadSize(void) const { return _download_size; }
00132     unsigned long long installSize(void) const { return _install_size; }
00133     int totalPriority (void) const { return _total_priority; }
00134     int minPriority (void) const { return _min_priority; }
00135     int maxPriority (void) const { return _max_priority; }
00136     int otherPenalties (void) const { return _other_penalties; }
00137 
00138     bool isValid (void) const { return !_invalid; }
00139     bool askUser (void) const { return _askUser; }
00140     bool isInvalid (void) const { return _invalid; }
00141 
00142     bool verifying (void) const { return _verifying; }
00143     void setVerifying (bool verifying) { _verifying = verifying; }
00144 
00145     bool tryAllPossibilities (void) const { return _tryAllPossibilities; }
00146     void setTryAllPossibilities (bool tryAllPossibilities) { _tryAllPossibilities = tryAllPossibilities; }
00147     
00148     bool skippedPossibilities (void) const { return _skippedPossibilities; }
00149     void setScippedPossibilities (bool skippedPossibilities) { _skippedPossibilities = skippedPossibilities; }
00150 
00151     bool establishing (void) const { return _establishing; }
00152     void setEstablishing (bool establishing) { _establishing = establishing; }
00153 
00154     inline ResPool pool() const { return _pool; }
00155 
00156     inline Arch architecture() const { return _architecture; }
00157 
00158     // ---------------------------------- ignore capabilities
00159     void setIgnoreCababilities(const IgnoreMap ignoreConflicts,
00160                                const IgnoreMap ignoreRequires,
00161                                const IgnoreMap ignoreObsoletes,
00162                                const PoolItemList ignoreInstalledItem,
00163                                const PoolItemList ignoreArchitectureItem)
00164         {_ignoreConflicts = ignoreConflicts;
00165         _ignoreRequires = ignoreRequires;
00166         _ignoreObsoletes = ignoreObsoletes;
00167         _ignoreInstalledItem = ignoreInstalledItem;
00168         _ignoreArchitectureItem = ignoreArchitectureItem;}
00169 
00170     const IgnoreMap getIgnoreConflicts() const { return _ignoreConflicts; }
00171     const IgnoreMap getIgnoreRequires() const { return _ignoreRequires; }
00172     const IgnoreMap getIgnoreObsoletes() const { return _ignoreObsoletes; }    
00173     const PoolItemList getIgnoreInstalledItem() const { return _ignoreInstalledItem; }
00174     const PoolItemList getIgnoreArchitectureItem() const { return _ignoreArchitectureItem; }
00175 
00176     
00177     void setForceResolve (const bool force) { _forceResolve = force; }
00178     const bool forceResolve() { return _forceResolve; }
00179 
00180     void setEstablishContext (const ResolverContext_Ptr establish_context) { _establish_context = establish_context; }
00181 
00182     void setPreferHighestVersion (const bool highestVersion) { _preferHighestVersion = highestVersion; }
00183     const bool preferHighestVersion() { return _preferHighestVersion; }  
00184 
00185     void setUpgradeMode (const bool upgrade) { _upgradeMode = upgrade; }
00186     const bool upgradeMode() { return _upgradeMode; }    
00187     
00188     // ---------------------------------- methods
00189 
00194     ResStatus getStatus (PoolItem_Ref item);
00195 
00203     void setStatus (PoolItem_Ref item, const ResStatus & status);
00204 
00207     bool install (PoolItem_Ref item, bool is_soft, int other_penalty);
00208 
00211     bool satisfy (PoolItem_Ref item, int other_penalty);
00212 
00215     bool unneeded (PoolItem_Ref item, int other_penalty);
00216 
00219     bool incomplete (PoolItem_Ref item, int other_penalty);
00220 
00224     bool upgrade (PoolItem_Ref to, PoolItem_Ref from, bool is_soft, int other_penalty);
00225 
00228     bool uninstall (PoolItem_Ref item, bool part_of_upgrade, bool due_to_obsolete, bool due_to_unlink);
00229 
00230     // rough installed/uninstalled test for 'after transaction'
00231 
00234     bool isPresent (PoolItem_Ref item, bool *unneeded = NULL,
00235                     bool *installed = NULL);
00236 
00239     bool isAbsent (PoolItem_Ref item);
00240 
00241     bool requirementIsMet (const Capability & cap, bool *unneeded = NULL,
00242                            bool *installed = NULL);
00249     bool requirementIsInstalledOrUnneeded (const ResObject::Kind & kind,
00250                                            const Capability & capability);
00251     bool requirementIsPossible (const Capability & cap);
00252     bool itemIsPossible (const PoolItem_Ref item);
00253     bool isParallelInstall (const PoolItem_Ref item) const;
00254     PoolItem_Ref getParallelInstall (const PoolItem_Ref item) const;
00255 
00258     void foreachMarked (MarkedPoolItemFn fn, void *data) const;
00259     PoolItemList getMarked (int which);                                 // <0:uninstalls, 0:all; >0:installs
00260     
00261     int foreachInstall (MarkedPoolItemFn fn, void *data) const;
00262     PoolItemList getInstalls (void) const;
00263     int installCount (void) const;
00264 
00265     int foreachUninstall (MarkedPoolItemFn fn, void *data);
00266     PoolItemList getUninstalls (void);
00267     int uninstallCount (void);
00268 
00269     int foreachUpgrade (MarkedPoolItemPairFn fn, void *data);
00270     PoolItemList getUpgrades (void);
00271     int upgradeCount (void);
00272 
00273     int foreachSatisfy (MarkedPoolItemFn fn, void *data) const;
00274     PoolItemList getSatisfies (void) const;
00275     int satisfyCount (void) const;
00276 
00277     int foreachIncomplete (MarkedPoolItemFn fn, void *data) const;
00278     PoolItemList getIncompletes (void) const;
00279     int incompleteCount (void) const;
00280 
00281     int foreachImpossible (MarkedPoolItemFn fn, void *data);
00282 //    PoolItemList getImpossibles (void);
00283 //    int impossibleCount (void);
00284 
00285     // add to the report log
00286     void addInfo (ResolverInfo_Ptr info, bool askUser = false); // normal progress info
00287     void addError (ResolverInfo_Ptr info, bool askUser = false);// error progress info
00288     
00289     // iterate over report log
00290     void foreachInfo (PoolItem_Ref item, int priority, ResolverInfoFn fn, void *data) const;
00291     ResolverInfoList getInfo (void) const;
00292 
00293     // Context compare to identify equal branches
00294     void collectCompareInfo (int & cmpVersion,    // Version compare of ACCUMULATED items
00295                              int & cmpSource,    // compare of Sources
00296                              ResolverContext_Ptr compareContext);
00297     
00298     int partialCompare (ResolverContext_Ptr context);
00299     int compare (ResolverContext_Ptr context);
00300 
00301     // debug
00302     void spew (void);
00303     void spewInfo (void) const;
00304 
00305     int getSourcePriority (Source_Ref source) const;
00306 };
00307 
00309     };// namespace detail
00312   };// namespace solver
00315 };// namespace zypp
00317 #endif // ZYPP_SOLVER_DETAIL_RESOLVERCONTEXT_H
00318 

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