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 
00063     typedef std::map<PoolItem_Ref,ResStatus> Context;
00064     Context _context;                           // the set of items touched in this transaction
00065 
00066     ResPool _pool;
00067 
00068     ResolverInfoList _log;                      // report log
00069 
00070     unsigned long long _download_size;
00071     unsigned long long _install_size;
00072     int _total_priority;
00073     int _min_priority;
00074     int _max_priority;
00075     int _other_penalties;
00076 
00077     bool _verifying;                            // running 'verifySystem'
00078     bool _establishing;                         // running 'establishSystem'
00079     bool _invalid;                              // lead to invalid solution
00080     bool _askUser;                              // lead to invalid solution too cause we have to ask the user 
00081 
00082     PoolItem_Ref _last_checked_item;            // cache for {get,set}Status
00083     ResStatus _last_checked_status;
00084 
00085     PoolItemList _last_getMarked;       // status of the last getMarked call
00086                                         // it is sorted
00087     int _last_getMarked_which;          // which kind of getMarked
00088 
00089     Arch _architecture;
00090 
00091     // These conflict should be ignored of the concering item
00092     IgnoreMap _ignoreConflicts;
00093     // These requires should be ignored of the concering item    
00094     IgnoreMap _ignoreRequires;
00095     // These obsoletes should be ignored of the concering item    
00096     IgnoreMap _ignoreObsoletes;    
00097     // Ignore the status "installed" of the item
00098     PoolItemList _ignoreInstalledItem;
00099     // Ignore the architecture of the item
00100     PoolItemList _ignoreArchitectureItem;
00101     
00102 
00103     bool _forceResolve; // remove items which are conflicts with others or
00104                         // have unfulfilled requirements.
00105                         // This behaviour is favourited by ZMD    
00106     bool _upgradeMode;  // Resolver has been called with doUpgrade
00107     
00108   public:
00109     ResolverContext (const ResPool & pool, const Arch & arch, ResolverContext_Ptr parent = NULL);
00110     virtual ~ResolverContext();
00111 
00112     // ---------------------------------- I/O
00113 
00114     friend std::ostream& operator<<(std::ostream&, const ResolverContext & context);
00115 
00116     // ---------------------------------- accessors
00117 
00118     unsigned long long downloadSize(void) const { return _download_size; }
00119     unsigned long long installSize(void) const { return _install_size; }
00120     int totalPriority (void) const { return _total_priority; }
00121     int minPriority (void) const { return _min_priority; }
00122     int maxPriority (void) const { return _max_priority; }
00123     int otherPenalties (void) const { return _other_penalties; }
00124 
00125     bool isValid (void) const { return !_invalid; }
00126     bool askUser (void) const { return _askUser; }
00127     bool isInvalid (void) const { return _invalid; }
00128 
00129     bool verifying (void) const { return _verifying; }
00130     void setVerifying (bool verifying) { _verifying = verifying; }
00131 
00132     bool establishing (void) const { return _establishing; }
00133     void setEstablishing (bool establishing) { _establishing = establishing; }
00134 
00135     inline ResPool pool() const { return _pool; }
00136 
00137     inline Arch architecture() const { return _architecture; }
00138 
00139     // ---------------------------------- ignore capabilities
00140     void setIgnoreCababilities(const IgnoreMap ignoreConflicts,
00141                                const IgnoreMap ignoreRequires,
00142                                const IgnoreMap ignoreObsoletes,
00143                                const PoolItemList ignoreInstalledItem,
00144                                const PoolItemList ignoreArchitectureItem)
00145         {_ignoreConflicts = ignoreConflicts;
00146         _ignoreRequires = ignoreRequires;
00147         _ignoreObsoletes = ignoreObsoletes;
00148         _ignoreInstalledItem = ignoreInstalledItem;
00149         _ignoreArchitectureItem = ignoreArchitectureItem;}
00150 
00151     const IgnoreMap getIgnoreConflicts() const { return _ignoreConflicts; }
00152     const IgnoreMap getIgnoreRequires() const { return _ignoreRequires; }
00153     const IgnoreMap getIgnoreObsoletes() const { return _ignoreObsoletes; }    
00154     const PoolItemList getIgnoreInstalledItem() const { return _ignoreInstalledItem; }
00155     const PoolItemList getIgnoreArchitectureItem() const { return _ignoreArchitectureItem; }
00156 
00157     
00158     void setForceResolve (const bool force) { _forceResolve = force; }
00159     const bool forceResolve() { return _forceResolve; }
00160 
00161     void setUpgradeMode (const bool upgrade) { _upgradeMode = upgrade; }
00162     const bool upgradeMode() { return _upgradeMode; }    
00163     
00164     // ---------------------------------- methods
00165 
00170     ResStatus getStatus (PoolItem_Ref item);
00171 
00179     void setStatus (PoolItem_Ref item, const ResStatus & status);
00180 
00183     bool install (PoolItem_Ref item, bool is_soft, int other_penalty);
00184 
00187     bool satisfy (PoolItem_Ref item, int other_penalty);
00188 
00191     bool unneeded (PoolItem_Ref item, int other_penalty);
00192 
00195     bool incomplete (PoolItem_Ref item, int other_penalty);
00196 
00200     bool upgrade (PoolItem_Ref to, PoolItem_Ref from, bool is_soft, int other_penalty);
00201 
00204     bool uninstall (PoolItem_Ref item, bool part_of_upgrade, bool due_to_obsolete, bool due_to_unlink);
00205 
00206     // rough installed/uninstalled test for 'after transaction'
00207 
00210     bool isPresent (PoolItem_Ref item, bool *unneeded = NULL,
00211                     bool *installed = NULL);
00212 
00215     bool isAbsent (PoolItem_Ref item);
00216 
00217     bool requirementIsMet (const Capability & cap, bool is_child = false, bool *unneeded = NULL,
00218                            bool *installed = NULL);
00219     bool requirementIsPossible (const Capability & cap);
00220     bool itemIsPossible (const PoolItem_Ref item);
00221     bool isParallelInstall (const PoolItem_Ref item) const;
00222     PoolItem_Ref getParallelInstall (const PoolItem_Ref item) const;
00223 
00226     void foreachMarked (MarkedPoolItemFn fn, void *data) const;
00227     PoolItemList getMarked (int which);                                 // <0:uninstalls, 0:all; >0:installs
00228     
00229     int foreachInstall (MarkedPoolItemFn fn, void *data) const;
00230     PoolItemList getInstalls (void) const;
00231     int installCount (void) const;
00232 
00233     int foreachUninstall (MarkedPoolItemFn fn, void *data);
00234     PoolItemList getUninstalls (void);
00235     int uninstallCount (void);
00236 
00237     int foreachUpgrade (MarkedPoolItemPairFn fn, void *data);
00238     PoolItemList getUpgrades (void);
00239     int upgradeCount (void);
00240 
00241     int foreachSatisfy (MarkedPoolItemFn fn, void *data) const;
00242     PoolItemList getSatisfies (void) const;
00243     int satisfyCount (void) const;
00244 
00245     int foreachIncomplete (MarkedPoolItemFn fn, void *data) const;
00246     PoolItemList getIncompletes (void) const;
00247     int incompleteCount (void) const;
00248 
00249     int foreachImpossible (MarkedPoolItemFn fn, void *data);
00250 //    PoolItemList getImpossibles (void);
00251 //    int impossibleCount (void);
00252 
00253     // add to the report log
00254     void addInfo (ResolverInfo_Ptr info, bool askUser = false); // normal progress info
00255     void addError (ResolverInfo_Ptr info, bool askUser = false);// error progress info
00256     
00257     // iterate over report log
00258     void foreachInfo (PoolItem_Ref item, int priority, ResolverInfoFn fn, void *data) const;
00259     ResolverInfoList getInfo (void) const;
00260 
00261     // Context compare to identify equal branches
00262     void collectCompareInfo (int & cmpVersion,    // Version compare of ACCUMULATED items
00263                              int & cmpSource,    // compare of Sources
00264                              ResolverContext_Ptr compareContext);
00265     
00266     int partialCompare (ResolverContext_Ptr context);
00267     int compare (ResolverContext_Ptr context);
00268 
00269     // debug
00270     void spew (void);
00271     void spewInfo (void) const;
00272 
00273     int getSourcePriority (Source_Ref source) const;
00274 };
00275 
00277     };// namespace detail
00280   };// namespace solver
00283 };// namespace zypp
00285 #endif // ZYPP_SOLVER_DETAIL_RESOLVERCONTEXT_H
00286 

Generated on Thu Sep 14 15:38:43 2006 for zypp by  doxygen 1.4.6