New API calls added:
authorStefan Schubert <schubi@suse.de>
Fri, 22 Jun 2007 13:27:34 +0000 (13:27 +0000)
committerStefan Schubert <schubi@suse.de>
Fri, 22 Jun 2007 13:27:34 +0000 (13:27 +0000)
const solver::detail::ItemCapKindList isSelectedBy (const PoolItem_Ref
item);
const solver::detail::ItemCapKindList selects (const PoolItem_Ref
item);

zypp/ProblemSolution.h
zypp/Resolver.cc
zypp/Resolver.h
zypp/ResolverProblem.h
zypp/solver/detail/Resolver.cc
zypp/solver/detail/Resolver.h
zypp/solver/detail/ResolverInfoNeededBy.h

index 85a9a8d..fe357f0 100644 (file)
@@ -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"
index 39ce462..bb71680 100644 (file)
@@ -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
index 21f6f38..811eced 100644 (file)
@@ -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:
 
index 06f1411..6780b96 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "zypp/base/ReferenceCounted.h"
 #include "zypp/base/PtrTypes.h"
-#include "zypp/Resolver.h"
 #include "zypp/ProblemSolution.h"
 
 /////////////////////////////////////////////////////////////////////////
index 458497e..ab606ee 100644 (file)
@@ -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<const ResolverInfoNeededBy>(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
 {
index b06ddda..09c651f 100644 (file)
@@ -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<PoolItem_Ref,ItemCapKind> ItemCapKindMap;
+    typedef std::list<ItemCapKind> 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);
 
index 29df4af..d8656e6 100644 (file)
@@ -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;};
 };
 
  ///////////////////////////////////////////////////////////////////