From 1da3ec962072e55bd247b8613085c18c0da01c1a Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Fri, 22 Jun 2007 13:27:34 +0000 Subject: [PATCH] New API calls added: const solver::detail::ItemCapKindList isSelectedBy (const PoolItem_Ref item); const solver::detail::ItemCapKindList selects (const PoolItem_Ref item); --- zypp/ProblemSolution.h | 1 - zypp/Resolver.cc | 9 +++- zypp/Resolver.h | 35 +++++++++++- zypp/ResolverProblem.h | 1 - zypp/solver/detail/Resolver.cc | 88 +++++++++++++++++++++++++++++++ zypp/solver/detail/Resolver.h | 35 +++++++++++- zypp/solver/detail/ResolverInfoNeededBy.h | 3 +- 7 files changed, 165 insertions(+), 7 deletions(-) diff --git a/zypp/ProblemSolution.h b/zypp/ProblemSolution.h index 85a9a8d..fe357f0 100644 --- a/zypp/ProblemSolution.h +++ b/zypp/ProblemSolution.h @@ -14,7 +14,6 @@ #include "zypp/base/ReferenceCounted.h" #include "zypp/base/PtrTypes.h" -#include "zypp/Resolver.h" #include "zypp/solver/detail/Resolver.h" #include "zypp/ResolverProblem.h" #include "zypp/solver/detail/SolutionAction.h" diff --git a/zypp/Resolver.cc b/zypp/Resolver.cc index 39ce462..bb71680 100644 --- a/zypp/Resolver.cc +++ b/zypp/Resolver.cc @@ -110,7 +110,14 @@ namespace zypp { return _pimpl->maxSolverPasses(); } bool Resolver::createSolverTestcase (const std::string & dumpPath) { solver::detail::Testcase testcase (dumpPath); - return testcase.createTestcase(*_pimpl);} + return testcase.createTestcase(*_pimpl);} +#if 1 + const solver::detail::ItemCapKindList Resolver::isSelectedBy (const PoolItem_Ref item) + { return _pimpl->isSelectedBy (item); } + const solver::detail::ItemCapKindList Resolver::selects (const PoolItem_Ref item) + { return _pimpl->selects (item); } +#endif + ///////////////////////////////////////////////////////////////// } // namespace zypp diff --git a/zypp/Resolver.h b/zypp/Resolver.h index 21f6f38..811eced 100644 --- a/zypp/Resolver.h +++ b/zypp/Resolver.h @@ -270,9 +270,40 @@ namespace zypp /** * Generates a solver Testcase of the current state * - * return true if it was successful + * \parame dumpPath destination directory of the created directory + * \return true if it was successful */ - bool createSolverTestcase (const std::string & dumpPath = "/var/log/YaST2/solverTestcase"); + bool createSolverTestcase (const std::string & dumpPath = "/var/log/YaST2/solverTestcase"); + + + /** + * Gives information about WHO has selected an item for installation. + * + * \param item Evaluate additional information for this resolvable. + * \return A list of structures which contains: + * item Item which has triggered the selection of the given param item. + * cap Capability which has triggerd this selection + * capKind Kind of that capability (e.g. Dep::REQUIRES,Dep::RECOMMENDS,... ) + * + * Note: Start a solver run before in order to have a result. Not matter if it is valid or invalid. + * + */ + const solver::detail::ItemCapKindList isSelectedBy (const PoolItem_Ref item); + + /** + * Gives information about WHICH additional items have been selected by the given item. + * + * \param item Evaluate additional information for this resolvable. + * \return A list of structures which contains: + * item Item which has BEEN triggered by the selection of the given param item. + * cap Capability which has BEEN triggerd by this selection + * capKind Kind of that capability (e.g. Dep::REQUIRES,Dep::RECOMMENDS,... ) + * + * Note: Start a solver run before in order to have a result. Not matter if it is valid or invalid. + * + */ + const solver::detail::ItemCapKindList selects (const PoolItem_Ref item); + protected: diff --git a/zypp/ResolverProblem.h b/zypp/ResolverProblem.h index 06f1411..6780b96 100644 --- a/zypp/ResolverProblem.h +++ b/zypp/ResolverProblem.h @@ -14,7 +14,6 @@ #include "zypp/base/ReferenceCounted.h" #include "zypp/base/PtrTypes.h" -#include "zypp/Resolver.h" #include "zypp/ProblemSolution.h" ///////////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/Resolver.cc b/zypp/solver/detail/Resolver.cc index 458497e..ab606ee 100644 --- a/zypp/solver/detail/Resolver.cc +++ b/zypp/solver/detail/Resolver.cc @@ -33,6 +33,7 @@ #include "zypp/CapFilters.h" #include "zypp/ZYppFactory.h" #include "zypp/SystemResObject.h" +#include "zypp/solver/detail/ResolverInfoNeededBy.h" ///////////////////////////////////////////////////////////////////////// @@ -161,12 +162,99 @@ Resolver::reset (const bool resetValidResults) _best_context = NULL; _timed_out = false; + _isSelectedBy.clear(); + _selects.clear(); + if (resetValidResults) contextPool.reset(); } +//-------------------------------------------------------------------------------------------------- +// Get more information about the solverrun +// Which item will be triggerd by another item or triggers an item for installation +typedef struct { + ItemCapKindMap isSelectedBy; + ItemCapKindMap selects; +} Collector; + + +static void +collector_cb_needed (ResolverInfo_Ptr info, void *data) +{ + Collector *collector = (Collector *)data; + if (info->type() == RESOLVER_INFO_TYPE_NEEDED_BY) { + ResolverInfoNeededBy_constPtr needed_by = dynamic_pointer_cast(info); + if (needed_by->items().size() >= 1) { + PoolItem_Ref item = info->affected(); + PoolItemList itemList = needed_by->items(); + + for (PoolItemList::const_iterator iter = itemList.begin(); + iter != itemList.end(); iter++) { + ItemCapKind capKind( *iter, needed_by->capability(), needed_by->capKind() ); + collector->isSelectedBy.insert (make_pair( item, capKind)); + + ItemCapKind capKindReverse( item, needed_by->capability(), needed_by->capKind() ); + collector->selects.insert (make_pair( *iter, capKindReverse)); + } + + } + } +} + +void +Resolver::collectResolverInfo(void) +{ + ResolverContext_Ptr collectContext = context(); // best context or failed context + if ( collectContext != NULL + && _isSelectedBy.empty() + && _selects.empty()) { + Collector collector; + collectContext->foreachInfo (PoolItem(), RESOLVER_INFO_PRIORITY_VERBOSE, collector_cb_needed, &collector); + _isSelectedBy = collector.isSelectedBy; + _selects = collector.selects; + } +} + + +const ItemCapKindList Resolver::isSelectedBy (const PoolItem_Ref item) { + ItemCapKindList ret; + collectResolverInfo(); + + for (ItemCapKindMap::const_iterator iter = _isSelectedBy.find(item); iter != _isSelectedBy.end();) { + ItemCapKind info = iter->second; + PoolItem_Ref iterItem = iter->first; + if (iterItem == item) { + ret.push_back(info); + iter++; + } else { + // exit + iter = _isSelectedBy.end(); + } + } + return ret; +} + +const ItemCapKindList Resolver::selects (const PoolItem_Ref item) { + ItemCapKindList ret; + collectResolverInfo(); + + for (ItemCapKindMap::const_iterator iter = _selects.find(item); iter != _selects.end();) { + ItemCapKind info = iter->second; + PoolItem_Ref iterItem = iter->first; + if (iterItem == item) { + ret.push_back(info); + iter++; + } else { + // exit + iter = _selects.end(); + } + } + return ret; +} + +//---------------------------------------------------------------------------------------------------- ResolverContext_Ptr Resolver::context (void) const { diff --git a/zypp/solver/detail/Resolver.h b/zypp/solver/detail/Resolver.h index b06ddda..09c651f 100644 --- a/zypp/solver/detail/Resolver.h +++ b/zypp/solver/detail/Resolver.h @@ -54,6 +54,27 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : ItemCapKind + // + /** */ + struct ItemCapKind + { + public: + Capability cap; //Capability which has triggerd this selection + Dep capKind; //Kind of that capability + PoolItem_Ref item; //Item which has triggered this selection + + ItemCapKind( PoolItem i, Capability c, Dep k) + : cap( c ) + , capKind( k ) + , item( i ) + { } + }; + typedef std::multimap ItemCapKindMap; + typedef std::list ItemCapKindList; /////////////////////////////////////////////////////////////////// // @@ -90,7 +111,10 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable { // list of problematic items after doUpgrade() PoolItemList _update_items; - + // Additional information about the solverrun + ItemCapKindMap _isSelectedBy; + ItemCapKindMap _selects; + CapSet _extra_caps; CapSet _extra_conflicts; @@ -138,6 +162,9 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable { bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap); bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed); + void collectResolverInfo (void); + + public: Resolver (const ResPool & pool); @@ -237,6 +264,12 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable { // reset all SOLVER transaction in pool void undo(void); + // Get more information about the solverrun + // Which item will be triggerd by another item or triggers an item for + // installation + const ItemCapKindList isSelectedBy (const PoolItem_Ref item); + const ItemCapKindList selects (const PoolItem_Ref item); + // only for testsuite void reset (const bool resetValidResults = false); diff --git a/zypp/solver/detail/ResolverInfoNeededBy.h b/zypp/solver/detail/ResolverInfoNeededBy.h index 29df4af..d8656e6 100644 --- a/zypp/solver/detail/ResolverInfoNeededBy.h +++ b/zypp/solver/detail/ResolverInfoNeededBy.h @@ -65,7 +65,8 @@ class ResolverInfoNeededBy : public ResolverInfoContainer { virtual std::string message (void) const; virtual ResolverInfo_Ptr copy (void) const; void setCapability (const Capability & cap, const Dep & capKind) { _cap = cap; _capKind = capKind; } -; + Dep capKind() const {return _capKind;} + Capability capability() const {return _cap;}; }; /////////////////////////////////////////////////////////////////// -- 2.7.4