00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00056 class ResolverContext : public base::ReferenceCounted, private base::NonCopyable {
00057
00058
00059 private:
00060
00061 ResolverContext_Ptr _parent;
00062
00063 typedef std::map<PoolItem_Ref,ResStatus> Context;
00064 Context _context;
00065
00066 ResPool _pool;
00067
00068 ResolverInfoList _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;
00078 bool _establishing;
00079 bool _invalid;
00080 bool _askUser;
00081
00082 PoolItem_Ref _last_checked_item;
00083 ResStatus _last_checked_status;
00084
00085 PoolItemList _last_getMarked;
00086
00087 int _last_getMarked_which;
00088
00089 Arch _architecture;
00090
00091
00092 IgnoreMap _ignoreConflicts;
00093
00094 IgnoreMap _ignoreRequires;
00095
00096 IgnoreMap _ignoreObsoletes;
00097
00098 PoolItemList _ignoreInstalledItem;
00099
00100 PoolItemList _ignoreArchitectureItem;
00101
00102
00103 bool _forceResolve;
00104
00105
00106 bool _upgradeMode;
00107
00108
00109
00110
00111
00112
00113 bool _tryAllPossibilities;
00114 bool _scippedPossibilities;
00115
00116
00117
00118 public:
00119 ResolverContext (const ResPool & pool, const Arch & arch, ResolverContext_Ptr parent = NULL);
00120 virtual ~ResolverContext();
00121
00122
00123
00124 friend std::ostream& operator<<(std::ostream&, const ResolverContext & context);
00125
00126
00127
00128 unsigned long long downloadSize(void) const { return _download_size; }
00129 unsigned long long installSize(void) const { return _install_size; }
00130 int totalPriority (void) const { return _total_priority; }
00131 int minPriority (void) const { return _min_priority; }
00132 int maxPriority (void) const { return _max_priority; }
00133 int otherPenalties (void) const { return _other_penalties; }
00134
00135 bool isValid (void) const { return !_invalid; }
00136 bool askUser (void) const { return _askUser; }
00137 bool isInvalid (void) const { return _invalid; }
00138
00139 bool verifying (void) const { return _verifying; }
00140 void setVerifying (bool verifying) { _verifying = verifying; }
00141
00142 bool tryAllPossibilities (void) const { return _tryAllPossibilities; }
00143 void setTryAllPossibilities (bool tryAllPossibilities) { _tryAllPossibilities = tryAllPossibilities; }
00144
00145 bool scippedPossibilities (void) const { return _scippedPossibilities; }
00146 void setScippedPossibilities (bool scippedPossibilities) { _scippedPossibilities = scippedPossibilities; }
00147
00148 bool establishing (void) const { return _establishing; }
00149 void setEstablishing (bool establishing) { _establishing = establishing; }
00150
00151 inline ResPool pool() const { return _pool; }
00152
00153 inline Arch architecture() const { return _architecture; }
00154
00155
00156 void setIgnoreCababilities(const IgnoreMap ignoreConflicts,
00157 const IgnoreMap ignoreRequires,
00158 const IgnoreMap ignoreObsoletes,
00159 const PoolItemList ignoreInstalledItem,
00160 const PoolItemList ignoreArchitectureItem)
00161 {_ignoreConflicts = ignoreConflicts;
00162 _ignoreRequires = ignoreRequires;
00163 _ignoreObsoletes = ignoreObsoletes;
00164 _ignoreInstalledItem = ignoreInstalledItem;
00165 _ignoreArchitectureItem = ignoreArchitectureItem;}
00166
00167 const IgnoreMap getIgnoreConflicts() const { return _ignoreConflicts; }
00168 const IgnoreMap getIgnoreRequires() const { return _ignoreRequires; }
00169 const IgnoreMap getIgnoreObsoletes() const { return _ignoreObsoletes; }
00170 const PoolItemList getIgnoreInstalledItem() const { return _ignoreInstalledItem; }
00171 const PoolItemList getIgnoreArchitectureItem() const { return _ignoreArchitectureItem; }
00172
00173
00174 void setForceResolve (const bool force) { _forceResolve = force; }
00175 const bool forceResolve() { return _forceResolve; }
00176
00177 void setUpgradeMode (const bool upgrade) { _upgradeMode = upgrade; }
00178 const bool upgradeMode() { return _upgradeMode; }
00179
00180
00181
00186 ResStatus getStatus (PoolItem_Ref item);
00187
00195 void setStatus (PoolItem_Ref item, const ResStatus & status);
00196
00199 bool install (PoolItem_Ref item, bool is_soft, int other_penalty);
00200
00203 bool satisfy (PoolItem_Ref item, int other_penalty);
00204
00207 bool unneeded (PoolItem_Ref item, int other_penalty);
00208
00211 bool incomplete (PoolItem_Ref item, int other_penalty);
00212
00216 bool upgrade (PoolItem_Ref to, PoolItem_Ref from, bool is_soft, int other_penalty);
00217
00220 bool uninstall (PoolItem_Ref item, bool part_of_upgrade, bool due_to_obsolete, bool due_to_unlink);
00221
00222
00223
00226 bool isPresent (PoolItem_Ref item, bool *unneeded = NULL,
00227 bool *installed = NULL);
00228
00231 bool isAbsent (PoolItem_Ref item);
00232
00233 bool requirementIsMet (const Capability & cap, bool *unneeded = NULL,
00234 bool *installed = NULL);
00241 bool requirementIsInstalledOrUnneeded (const ResObject::Kind & kind,
00242 const Capability & capability);
00243 bool requirementIsPossible (const Capability & cap);
00244 bool itemIsPossible (const PoolItem_Ref item);
00245 bool isParallelInstall (const PoolItem_Ref item) const;
00246 PoolItem_Ref getParallelInstall (const PoolItem_Ref item) const;
00247
00250 void foreachMarked (MarkedPoolItemFn fn, void *data) const;
00251 PoolItemList getMarked (int which);
00252
00253 int foreachInstall (MarkedPoolItemFn fn, void *data) const;
00254 PoolItemList getInstalls (void) const;
00255 int installCount (void) const;
00256
00257 int foreachUninstall (MarkedPoolItemFn fn, void *data);
00258 PoolItemList getUninstalls (void);
00259 int uninstallCount (void);
00260
00261 int foreachUpgrade (MarkedPoolItemPairFn fn, void *data);
00262 PoolItemList getUpgrades (void);
00263 int upgradeCount (void);
00264
00265 int foreachSatisfy (MarkedPoolItemFn fn, void *data) const;
00266 PoolItemList getSatisfies (void) const;
00267 int satisfyCount (void) const;
00268
00269 int foreachIncomplete (MarkedPoolItemFn fn, void *data) const;
00270 PoolItemList getIncompletes (void) const;
00271 int incompleteCount (void) const;
00272
00273 int foreachImpossible (MarkedPoolItemFn fn, void *data);
00274
00275
00276
00277
00278 void addInfo (ResolverInfo_Ptr info, bool askUser = false);
00279 void addError (ResolverInfo_Ptr info, bool askUser = false);
00280
00281
00282 void foreachInfo (PoolItem_Ref item, int priority, ResolverInfoFn fn, void *data) const;
00283 ResolverInfoList getInfo (void) const;
00284
00285
00286 void collectCompareInfo (int & cmpVersion,
00287 int & cmpSource,
00288 ResolverContext_Ptr compareContext);
00289
00290 int partialCompare (ResolverContext_Ptr context);
00291 int compare (ResolverContext_Ptr context);
00292
00293
00294 void spew (void);
00295 void spewInfo (void) const;
00296
00297 int getSourcePriority (Source_Ref source) const;
00298 };
00299
00301 };
00304 };
00307 };
00309 #endif // ZYPP_SOLVER_DETAIL_RESOLVERCONTEXT_H
00310