Author: kkaempf
Date: Tue Feb 12 18:28:00 2008
New Revision: 8638
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8638&view=rev
Log:
Introduce 'application layer' below sat-solver/applayer.
Primarily for the SWIG bindings, this layer makes using sat-solver a
bit easier by abstracting from sat-solver internals to more
application specific objects.
Added:
trunk/sat-solver/applayer/
trunk/sat-solver/applayer/CMakeLists.txt
trunk/sat-solver/applayer/README
trunk/sat-solver/applayer/action.c
trunk/sat-solver/applayer/action.h
trunk/sat-solver/applayer/applayer.c
trunk/sat-solver/applayer/applayer.h
trunk/sat-solver/applayer/covenant.c
trunk/sat-solver/applayer/covenant.h
trunk/sat-solver/applayer/decision.c
trunk/sat-solver/applayer/decision.h
trunk/sat-solver/applayer/dependency.c
trunk/sat-solver/applayer/dependency.h
trunk/sat-solver/applayer/problem.c
trunk/sat-solver/applayer/problem.h
trunk/sat-solver/applayer/relation.c
trunk/sat-solver/applayer/relation.h
trunk/sat-solver/applayer/solution.c
trunk/sat-solver/applayer/solution.h
trunk/sat-solver/applayer/transaction.c
trunk/sat-solver/applayer/transaction.h
trunk/sat-solver/applayer/xsolvable.c
trunk/sat-solver/applayer/xsolvable.h
trunk/sat-solver/bindings/ruby/tests/Makefile
Modified:
trunk/sat-solver/CMakeLists.txt
trunk/sat-solver/bindings/perl/CMakeLists.txt
trunk/sat-solver/bindings/python/CMakeLists.txt
trunk/sat-solver/bindings/ruby/CMakeLists.txt
trunk/sat-solver/bindings/ruby/tests/covenants.rb
trunk/sat-solver/bindings/ruby/tests/decisions.rb
trunk/sat-solver/bindings/ruby/tests/setup.sh
trunk/sat-solver/bindings/ruby/tests/transaction.rb
trunk/sat-solver/bindings/satsolver.i
Modified: trunk/sat-solver/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/CMakeLists.txt?rev=8638&r1=8637&r2=8638&view=diff
==============================================================================
--- trunk/sat-solver/CMakeLists.txt (original)
+++ trunk/sat-solver/CMakeLists.txt Tue Feb 12 18:28:00 2008
@@ -105,6 +105,7 @@
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tools)
+ADD_SUBDIRECTORY(applayer)
IF( EXISTS "${CMAKE_SOURCE_DIR}/testsuite" )
ADD_SUBDIRECTORY(testsuite)
Added: trunk/sat-solver/applayer/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/CMakeLists.txt?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/CMakeLists.txt (added)
+++ trunk/sat-solver/applayer/CMakeLists.txt Tue Feb 12 18:28:00 2008
@@ -0,0 +1,13 @@
+
+SET(libappsatsolver_SRCS action.c applayer.c covenant.c decision.c dependency.c
+ problem.c relation.c solution.c transaction.c xsolvable.c)
+
+ADD_LIBRARY(appsatsolver STATIC ${libappsatsolver_SRCS})
+
+SET(libappsatsolver_HEADERS action.h applayer.h covenant.h decision.h dependency.h
+ problem.h relation.h solution.h transaction.h xsolvable.h)
+
+SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" )
+
+INSTALL( FILES ${libappsatsolver_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/satsolver" )
+INSTALL(TARGETS appsatsolver LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
Added: trunk/sat-solver/applayer/README
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/README?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/README (added)
+++ trunk/sat-solver/applayer/README Tue Feb 12 18:28:00 2008
@@ -0,0 +1,5 @@
+README for sat-solver/applayer
+
+applayer provides an 'application layer' to ease access to sat-solver.
+Primary consumer are the SWIG bindings below sat-solver/bindings,
+hence the application layer is written in 'C'.
Added: trunk/sat-solver/applayer/action.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/action.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/action.c (added)
+++ trunk/sat-solver/applayer/action.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/*
+ * Action
+ *
+ * A single 'job' item of a Transaction
+ *
+ */
+
+#include
+#include "action.h"
+#include "applayer.h"
+
+Action *
+action_new( Pool *pool, SolverCmd cmd, Id id )
+{
+ Action *action = (Action *)malloc( sizeof( Action ));
+ action->pool = pool;
+ action->cmd = cmd;
+ action->id = id;
+ return action;
+}
+
+
+void
+action_free( Action *a )
+{
+ free( a );
+}
+
+
+XSolvable *
+action_xsolvable( Action *a )
+{
+ if (a->cmd == SOLVER_INSTALL_SOLVABLE
+ || a->cmd == SOLVER_ERASE_SOLVABLE)
+ {
+ return xsolvable_new( a->pool, a->id );
+ }
+ return NULL;
+}
+
+
+const char *
+action_name( Action *a )
+{
+ if (a->cmd == SOLVER_INSTALL_SOLVABLE_NAME
+ || a->cmd == SOLVER_ERASE_SOLVABLE_NAME)
+ {
+ return my_id2str( a->pool, a->id );
+ }
+ return NULL;
+}
+
+
+Relation *
+action_relation( Action *a )
+{
+ if (a->cmd == SOLVER_INSTALL_SOLVABLE_PROVIDES
+ || a->cmd == SOLVER_ERASE_SOLVABLE_PROVIDES)
+ {
+ return relation_new( a->pool, a->id );
+ }
+ return NULL;
+}
Added: trunk/sat-solver/applayer/action.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/action.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/action.h (added)
+++ trunk/sat-solver/applayer/action.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/*
+ * Action
+ *
+ * A single 'job' item of a Transaction
+ *
+ */
+
+
+#ifndef SATSOLVER_ACTION_H
+#define SATSOLVER_ACTION_H
+
+#include "pool.h"
+#include "solver.h"
+
+#include "xsolvable.h"
+#include "relation.h"
+
+typedef struct _Action {
+ Pool *pool;
+ SolverCmd cmd;
+ Id id;
+} Action;
+
+
+Action *action_new( Pool *pool, SolverCmd cmd, Id id );
+void action_free( Action *a );
+
+XSolvable *action_xsolvable( Action *a );
+const char *action_name( Action *a );
+Relation *action_relation( Action *a );
+
+#endif /* SATSOLVER_ACTION_H */
Added: trunk/sat-solver/applayer/applayer.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/applayer.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/applayer.c (added)
+++ trunk/sat-solver/applayer/applayer.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/*
+ * Sat solver application layer
+ *
+ * Helper functions
+ *
+ */
+
+#include "applayer.h"
+
+const char *
+my_id2str( Pool *pool, Id id )
+{
+ if (id == STRID_NULL)
+ return NULL;
+ if (id == STRID_EMPTY)
+ return "";
+ return id2str( pool, id );
+}
Added: trunk/sat-solver/applayer/applayer.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/applayer.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/applayer.h (added)
+++ trunk/sat-solver/applayer/applayer.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/*
+ * Sat solver application layer
+ *
+ * Helper functions
+ *
+ */
+
+
+#ifndef SATSOLVER_APPLAYER_H
+#define SATSOLVER_APPLAYER_H
+
+#include "pool.h"
+
+/************************************************
+ * Id
+ *
+ */
+
+const char *my_id2str( Pool *pool, Id id );
+
+
+#endif /* SATSOLVER_APPLAYER_H */
Added: trunk/sat-solver/applayer/covenant.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/covenant.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/covenant.c (added)
+++ trunk/sat-solver/applayer/covenant.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * Covenant
+ *
+ * Covenants ensure specific dependencies in the (installed) system.
+ * They are usually used to implement locks.
+ *
+ */
+
+#include
+#include "covenant.h"
+#include "applayer.h"
+
+Covenant *
+covenant_new( Pool *pool, SolverCmd cmd, Id id )
+{
+ Covenant *covenant = (Covenant *)malloc( sizeof( Covenant ));
+ covenant->pool = pool;
+ covenant->cmd = cmd;
+ covenant->id = id;
+ return covenant;
+}
+
+void
+covenant_free( Covenant *c )
+{
+ free( c );
+}
+
+XSolvable *
+covenant_xsolvable( const Covenant *c )
+{
+ if (c->cmd == SOLVER_INSTALL_SOLVABLE
+ || c->cmd == SOLVER_ERASE_SOLVABLE)
+ {
+ return xsolvable_new( c->pool, c->id );
+ }
+ return NULL;
+}
+
+
+const char *
+covenant_name( const Covenant *c )
+{
+ if (c->cmd == SOLVER_INSTALL_SOLVABLE_NAME
+ || c->cmd == SOLVER_ERASE_SOLVABLE_NAME)
+ {
+ return my_id2str( c->pool, c->id );
+ }
+ return NULL;
+}
+
+
+Relation *
+covenant_relation( const Covenant *c )
+{
+ if (c->cmd == SOLVER_INSTALL_SOLVABLE_PROVIDES
+ || c->cmd == SOLVER_ERASE_SOLVABLE_PROVIDES)
+ {
+ return relation_new( c->pool, c->id );
+ }
+ return NULL;
+}
+
+void
+covenant_include_xsolvable( Solver *s, const XSolvable *xs )
+{
+ queue_push( &(s->covenantq), SOLVER_INSTALL_SOLVABLE );
+ /* FIXME: check: xs->repo->pool == s->pool */
+ queue_push( &(s->covenantq), xs->id );
+}
+
+
+void
+covenant_exclude_xsolvable( Solver *s, const XSolvable *xs )
+{
+ queue_push( &(s->covenantq), SOLVER_ERASE_SOLVABLE );
+ /* FIXME: check: s->repo->pool == $self->pool */
+ queue_push( &(s->covenantq), xs->id );
+}
+
+
+void
+covenant_include_name( Solver *s, const char *name )
+{
+ queue_push( &(s->covenantq), SOLVER_INSTALL_SOLVABLE_NAME );
+ queue_push( &(s->covenantq), str2id( s->pool, name, 1 ));
+}
+
+
+void
+covenant_exclude_name( Solver *s, const char *name )
+{
+ queue_push( &(s->covenantq), SOLVER_ERASE_SOLVABLE_NAME );
+ queue_push( &(s->covenantq), str2id( s->pool, name, 1 ));
+}
+
+
+void
+covenant_include_relation( Solver *s, const Relation *rel )
+{
+ queue_push( &(s->covenantq), SOLVER_INSTALL_SOLVABLE_PROVIDES );
+ /* FIXME: check: rel->pool == s->pool */
+ queue_push( &(s->covenantq), rel->id );
+}
+
+
+void
+covenant_exclude_relation( Solver *s, const Relation *rel )
+{
+ queue_push( &(s->covenantq), SOLVER_ERASE_SOLVABLE_PROVIDES );
+ /* FIXME: check: rel->pool == $self->pool */
+ queue_push( &(s->covenantq), rel->id );
+}
+
+
+Covenant *covenant_get( const Solver *s, int i )
+{
+ int size, cmd;
+ Id id;
+ i <<= 1;
+ size = s->covenantq.count;
+ if (i-1 >= size)
+ return NULL;
+ cmd = s->covenantq.elements[i];
+ id = s->covenantq.elements[i+1];
+ return covenant_new( s->pool, cmd, id );
+}
Added: trunk/sat-solver/applayer/covenant.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/covenant.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/covenant.h (added)
+++ trunk/sat-solver/applayer/covenant.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#ifndef SATSOLVER_COVENANT_H
+#define SATSOLVER_COVENANT_H
+
+/************************************************
+ * Covenant
+ *
+ * Covenants ensure specific dependencies in the (installed) system.
+ * They are usually used to implement locks.
+ *
+ */
+
+#include "solver.h"
+#include "xsolvable.h"
+#include "relation.h"
+
+typedef struct _Covenant {
+ Pool *pool;
+ SolverCmd cmd;
+ Id id;
+} Covenant;
+
+Covenant *covenant_new( Pool *pool, SolverCmd cmd, Id id );
+void covenant_free( Covenant *c );
+
+XSolvable *covenant_xsolvable( const Covenant *c );
+const char *covenant_name( const Covenant *c );
+Relation *covenant_relation( const Covenant *c );
+
+void covenant_include_xsolvable( Solver *s, const XSolvable *xs );
+void covenant_exclude_xsolvable( Solver *s, const XSolvable *xs );
+void covenant_include_name( Solver *s, const char *name );
+void covenant_exclude_name( Solver *s, const char *name );
+void covenant_include_relation( Solver *s, const Relation *rel );
+void covenant_exclude_relation( Solver *s, const Relation *rel );
+Covenant *covenant_get( const Solver *s, int i );
+
+#endif /* SATSOLVER_COVENANT_H */
+
Added: trunk/sat-solver/applayer/decision.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/decision.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/decision.c (added)
+++ trunk/sat-solver/applayer/decision.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * Decision
+ *
+ * A successful solver result.
+ *
+ * Set of 'job items' needed to solve the Transaction.
+ *
+ */
+
+#include
+#include "decision.h"
+
+Decision *
+decision_new( Pool *pool, int op, Id solvable, Id reason )
+{
+ Decision *d = (Decision *)malloc( sizeof( Decision ));
+ d->pool = pool;
+ d->op = op;
+ d->solvable = solvable;
+ d->reason = reason;
+ return d;
+}
+
+void
+decision_free( Decision *d )
+{
+ free( d );
+}
+
+void
+solver_decisions_iterate( Solver *solver, int (*callback)( const Decision *d ) )
+{
+ Pool *pool = solver->pool;
+ Repo *installed = solver->installed;
+ Id p, *obsoletesmap = create_decisions_obsoletesmap( solver );
+ Id s, r;
+ int op;
+ Decision *d;
+ int i;
+
+ if (!callback)
+ return; /* no use to iterate without callback */
+
+#if 0
+ if (installed)
+ {
+ FOR_REPO_SOLVABLES(installed, p, s)
+ {
+ if (solver->decisionmap[p] >= 0)
+ continue;
+ if (obsoletesmap[p])
+ {
+ d = decision_new( pool, DECISION_OBSOLETE, s, pool_id2solvable( pool, obsoletesmap[p] ) );
+ }
+ else
+ {
+ d = decision_new( pool, DECISION_REMOVE, s, NULL );
+ }
+ callback( d );
+ }
+ }
+#endif
+ for ( i = 0; i < solver->decisionq.count; i++)
+ {
+ p = solver->decisionq.elements[i];
+ r = 0;
+
+ if (p < 0) /* remove */
+ {
+ p = -p;
+ s = p;
+ if (obsoletesmap[p])
+ {
+ op = DECISION_OBSOLETE;
+ r = obsoletesmap[p];
+ }
+ else
+ {
+ op = DECISION_REMOVE;
+ }
+ }
+ else if (p == SYSTEMSOLVABLE)
+ {
+ continue;
+ }
+ else
+ {
+ s = p;
+ if (installed)
+ {
+ Solvable *solv = pool_id2solvable( pool, p );
+ if (solv->repo == installed)
+ continue;
+ }
+ if (!obsoletesmap[p])
+ {
+ op = DECISION_INSTALL;
+ }
+ else
+ {
+ int j;
+ op = DECISION_UPDATE;
+ for (j = installed->start; j < installed->end; j++)
+ {
+ if (obsoletesmap[j] == p)
+ {
+ r = j;
+ break;
+ }
+ }
+ }
+ }
+ d = decision_new( pool, op, s, r );
+ if (callback( d ))
+ break;
+ }
+}
Added: trunk/sat-solver/applayer/decision.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/decision.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/decision.h (added)
+++ trunk/sat-solver/applayer/decision.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#ifndef SATSOLVER_DECISION_H
+#define SATSOLVER_DECISION_H
+
+/************************************************
+ * Decision
+ *
+ * A successful solver result.
+ *
+ * Set of 'job items' needed to solve the Transaction.
+ *
+ */
+
+#include "pool.h"
+#include "solver.h"
+
+enum decisions {
+ DECISION_INSTALL = 1,
+ DECISION_REMOVE,
+ DECISION_UPDATE,
+ DECISION_OBSOLETE
+};
+
+typedef struct _Decision {
+ enum decisions op;
+ Pool *pool;
+ Id solvable;
+ Id reason;
+} Decision;
+
+Decision *decision_new( Pool *pool, int op, Id solvable, Id reason );
+void decision_free( Decision *d );
+
+void solver_decisions_iterate( Solver *solver, int (*callback)( const Decision *d ) );
+
+#endif /* SATSOLVER_DECISION_H */
Added: trunk/sat-solver/applayer/dependency.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/dependency.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/dependency.c (added)
+++ trunk/sat-solver/applayer/dependency.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * Dependency
+ *
+ * Collection of Relations -> Dependency
+ */
+
+#include
+#include "dependency.h"
+
+
+Dependency *
+dependency_new( XSolvable *xsolvable, int dep )
+{
+ Dependency *dependency = (Dependency *)malloc( sizeof( Dependency ));
+ dependency->dep = dep;
+ dependency->xsolvable = xsolvable;
+ return dependency;
+}
+
+
+void
+dependency_free( Dependency *d )
+{
+ free( d );
+}
+
+
+/* get pointer to offset for dependency */
+Offset *
+dependency_relations( const Dependency *dep )
+{
+ Solvable *s;
+ if (!dep) return NULL;
+
+ s = xsolvable_solvable( dep->xsolvable );
+ switch (dep->dep) {
+ case DEP_PRV: return &(s->provides); break;
+ case DEP_REQ: return &(s->requires); break;
+ case DEP_CON: return &(s->conflicts); break;
+ case DEP_OBS: return &(s->obsoletes); break;
+ case DEP_REC: return &(s->recommends); break;
+ case DEP_SUG: return &(s->suggests); break;
+ case DEP_SUP: return &(s->supplements); break;
+ case DEP_ENH: return &(s->enhances); break;
+ case DEP_FRE: return &(s->freshens); break;
+ }
+ return NULL;
+}
+
+
+int
+dependency_size( const Dependency *dep )
+{
+ int i = 0;
+ Solvable *s;
+ Id *ids;
+ Offset *relations = dependency_relations( dep );
+ if (relations) {
+ s = xsolvable_solvable( dep->xsolvable );
+ ids = s->repo->idarraydata + *relations;
+ while (*ids++)
+ ++i;
+ }
+ return i;
+}
+
+
+void
+dependency_relation_add( Dependency *dep, Relation *rel, int pre )
+{
+ Solvable *s = xsolvable_solvable( dep->xsolvable );
+ Offset *relations = dependency_relations( dep );
+ *relations = repo_addid_dep( s->repo, *relations, rel->id, pre ? SOLVABLE_PREREQMARKER : 0 );
+ return;
+}
+
+
+Relation *
+dependency_relation_get( Dependency *dep, int i )
+{
+ Solvable *s = xsolvable_solvable( dep->xsolvable );
+ Offset *relations = dependency_relations( dep );
+ /* loop over it to detect end */
+ Id *ids = s->repo->idarraydata + *relations;
+ while ( i-- >= 0 ) {
+ if ( !*ids )
+ break;
+ if ( i == 0 ) {
+ return relation_new( s->repo->pool, *ids );
+ }
+ ++ids;
+ }
+ return NULL;
+}
+
Added: trunk/sat-solver/applayer/dependency.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/dependency.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/dependency.h (added)
+++ trunk/sat-solver/applayer/dependency.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#ifndef SATSOLVER_DEPENDENCY_H
+#define SATSOLVER_DEPENDENCY_H
+
+#include "xsolvable.h"
+#include "relation.h"
+
+/************************************************
+ * Dependency
+ *
+ * Collection of Relations -> Dependency
+ */
+
+enum dependencies {
+ DEP_PRV = 1,
+ DEP_REQ,
+ DEP_CON,
+ DEP_OBS,
+ DEP_REC,
+ DEP_SUG,
+ DEP_SUP,
+ DEP_ENH,
+ DEP_FRE
+};
+
+typedef struct _Dependency {
+ enum dependencies dep; /* type of dep, any of DEP_xxx */
+ XSolvable *xsolvable; /* xsolvable this dep belongs to */
+} Dependency;
+
+Dependency *dependency_new( XSolvable *xsolvable, int dep );
+
+/* get pointer to offset for dependency */
+Offset *dependency_relations( const Dependency *dep );
+
+int dependency_size( const Dependency *dep );
+
+void dependency_relation_add( Dependency *dep, Relation *rel, int pre );
+Relation *dependency_relation_get( Dependency *dep, int i );
+
+#endif /* SATSOLVER_DEPENDENCY_H */
Added: trunk/sat-solver/applayer/problem.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/problem.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/problem.c (added)
+++ trunk/sat-solver/applayer/problem.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * Problem
+ *
+ * An unsuccessful solver result
+ *
+ * If a transaction is not solvable, one or more
+ * Problems will be reported by the Solver.
+ *
+ */
+
+#include
+#include "problem.h"
+#include "evr.h"
+
+
+Problem *
+problem_new( Solver *s, Transaction *t, Id id )
+{
+ Id prule;
+
+ Problem *p = (Problem *)malloc( sizeof( Problem ));
+ p->solver = s;
+ p->transaction = t;
+ p->id = id;
+ prule = solver_findproblemrule( s, id );
+ p->reason = solver_problemruleinfo( s, &(t->queue), prule, &(p->relation), &(p->source), &(p->target) );
+ return p;
+}
+
+void
+problem_free( Problem *p )
+{
+ free( p );
+}
+
+
+void
+solver_problems_iterate( Solver *solver, Transaction *t, int (*callback)( const Problem *p) )
+{
+ Id problem = 0;
+ if (!callback)
+ return; /* no use to iterate without callback */
+
+ while ((problem = solver_next_problem( solver, problem )) != 0)
+ {
+ Problem *p = problem_new( solver, t, problem );
+ if (callback( p ) )
+ break;
+ }
+}
+
+
+void
+problem_solutions_iterate( Problem *problem, int (*callback)( const Solution *s ) )
+{
+ if (!callback) /* no use to iterate without callback */
+ return;
+
+ Id solution = 0;
+ while ((solution = solver_next_solution( problem->solver, problem->id, solution )) != 0)
+ {
+ Id p, rp, element, what;
+
+ Id s1, s2, n1, n2;
+ int code = SOLUTION_UNKNOWN;
+
+ Solver *solver = problem->solver;
+ Pool *pool = solver->pool;
+ element = 0;
+ s1 = s2 = n1 = n2 = 0;
+
+ while ((element = solver_next_solutionelement( solver, problem->id, solution, element, &p, &rp)) != 0)
+ {
+ if (p == 0)
+ {
+
+ /* job, rp is index into job queue */
+ what = problem->transaction->queue.elements[rp];
+
+ switch (problem->transaction->queue.elements[rp - 1])
+ {
+ case SOLVER_INSTALL_SOLVABLE:
+ s1 = what;
+ if (solver->installed
+ && (pool->solvables + s1)->repo == solver->installed)
+ {
+ code = SOLUTION_NOKEEP_INSTALLED; /* s1 */
+ }
+ else
+ {
+ code = SOLUTION_NOINSTALL_SOLV; /* s1 */
+ }
+ break;
+ case SOLVER_ERASE_SOLVABLE:
+ s1 = what;
+ if (solver->installed
+ && (pool->solvables + s1)->repo == solver->installed)
+ {
+ code = SOLUTION_NOREMOVE_SOLV; /* s1 */
+ }
+ else
+ {
+ code = SOLUTION_NOFORBID_INSTALL; /* s1 */
+ }
+ break;
+ case SOLVER_INSTALL_SOLVABLE_NAME:
+ n1 = what;
+ code = SOLUTION_NOINSTALL_NAME; /* n1 */
+ break;
+ case SOLVER_ERASE_SOLVABLE_NAME:
+ n1 = what;
+ code = SOLUTION_NOREMOVE_NAME; /* n1 */
+ break;
+ case SOLVER_INSTALL_SOLVABLE_PROVIDES:
+ n1 = what;
+ code = SOLUTION_NOINSTALL_REL; /* r1 */
+ break;
+ case SOLVER_ERASE_SOLVABLE_PROVIDES:
+ n1 = what;
+ code = SOLUTION_NOREMOVE_REL; /* r1 */
+ break;
+ case SOLVER_INSTALL_SOLVABLE_UPDATE:
+ s1 = what;
+ code = SOLUTION_NOUPDATE;
+ break;
+ default:
+ code = SOLUTION_UNKNOWN;
+ break;
+ }
+ }
+ else
+ {
+ s1 = p;
+ s2 = rp;
+ /* policy, replace p with rp */
+ Solvable *sp = pool->solvables + p;
+ Solvable *sr = rp ? pool->solvables + rp : 0;
+ if (sr)
+ {
+ if (!solver->allowdowngrade
+ && evrcmp( pool, sp->evr, sr->evr, EVRCMP_MATCH_RELEASE ) > 0)
+ {
+ code = SOLUTION_ALLOW_DOWNGRADE;
+ }
+ else if (!solver->allowarchchange
+ && sp->name == sr->name
+ && sp->arch != sr->arch
+ && policy_illegal_archchange(solver, sp, sr ) )
+ {
+ code = SOLUTION_ALLOW_ARCHCHANGE; /* s1, s2 */
+ }
+ else if (!solver->allowvendorchange
+ && sp->name == sr->name
+ && sp->vendor != sr->vendor
+ && policy_illegal_vendorchange( solver, sp, sr ) )
+ {
+ n1 = sp->vendor;
+ n2 = sr->vendor;
+ code = SOLUTION_ALLOW_VENDORCHANGE;
+ }
+ else
+ {
+ code = SOLUTION_ALLOW_REPLACEMENT;
+ }
+ }
+ else
+ {
+ code = SOLUTION_ALLOW_REMOVE; /* s1 */
+ }
+ }
+ }
+ Solution *s = solution_new( problem->solver->pool, code, s1, n1, s2, n2 );
+ if (callback( s ))
+ break;
+ }
+}
+
+
Added: trunk/sat-solver/applayer/problem.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/problem.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/problem.h (added)
+++ trunk/sat-solver/applayer/problem.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#ifndef SATSOLVER_PROBLEM_H
+#define SATSOLVER_PROBLEM_H
+
+/************************************************
+ * Problem
+ *
+ * An unsuccessful solver result
+ *
+ * If a transaction is not solvable, one or more
+ * Problems will be reported by the Solver.
+ *
+ */
+
+#include "solver.h"
+#include "transaction.h"
+#include "solution.h"
+
+typedef struct _Problem {
+ Solver *solver;
+ Transaction *transaction;
+ Id id; /* [PRIVATE] problem id */
+ SolverProbleminfo reason;
+ Id source; /* solvable id */
+ Id relation; /* relation id */
+ Id target; /* solvable id */
+} Problem;
+
+Problem *problem_new( Solver *s, Transaction *t, Id id );
+void problem_free( Problem *p );
+
+void solver_problems_iterate( Solver *solver, Transaction *t, int (*callback)( const Problem *p) );
+void problem_solutions_iterate( Problem *p, int (*callback)( const Solution *s ) );
+
+#endif /* SATSOLVER_PROBLEM_H */
Added: trunk/sat-solver/applayer/relation.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/relation.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/relation.c (added)
+++ trunk/sat-solver/applayer/relation.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * Relation
+ *
+ */
+
+#include
+#include "relation.h"
+
+
+Relation *
+relation_new( Pool *pool, Id id )
+{
+ Relation *relation;
+ if (!id) return NULL;
+ relation = (Relation *)malloc( sizeof( Relation ));
+ relation->id = id;
+ relation->pool = pool;
+ return relation;
+}
+
+
+void
+relation_free( Relation *r )
+{
+ free( r );
+}
+
+
+Relation *
+relation_create( Pool *pool, const char *name, int op, const char *evr )
+{
+ Id name_id = str2id( pool, name, 1 );
+ Id evr_id;
+ Id rel;
+ if (op == REL_NONE)
+ return relation_new( pool, name_id );
+ evr_id = str2id( pool, evr, 1 );
+ rel = rel2id( pool, name_id, evr_id, op, 1 );
+ return relation_new( pool, rel );
+}
+
+
+Id
+relation_evrid( const Relation *r )
+{
+ if (ISRELDEP( r->id )) {
+ Reldep *rd = GETRELDEP( r->pool, r->id );
+ return rd->evr;
+ }
+ return ID_NULL;
+}
Added: trunk/sat-solver/applayer/relation.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/relation.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/relation.h (added)
+++ trunk/sat-solver/applayer/relation.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#ifndef SATSOLVER_RELATION_H
+#define SATSOLVER_RELATION_H
+
+#include "pool.h"
+
+/************************************************
+ * Relation
+ *
+ */
+
+#define REL_NONE 0
+
+typedef struct _Relation {
+ Offset id;
+ Pool *pool;
+} Relation;
+
+Relation *relation_new( Pool *pool, Id id );
+Relation *relation_create( Pool *pool, const char *name, int op, const char *evr );
+Id relation_evrid( const Relation *r );
+
+#endif /* SATSOLVER_RELATION_H */
Added: trunk/sat-solver/applayer/solution.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/solution.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/solution.c (added)
+++ trunk/sat-solver/applayer/solution.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * Solution
+ *
+ * A possible solution to a Problem.
+ *
+ * For each reported Problem, the Solver might generate
+ * one or more Solutions to make the Transaction solvable.
+ *
+ */
+
+#include
+#include "solution.h"
+
+
+Solution *
+solution_new( Pool *pool, int solution, Id s1, Id n1, Id s2, Id n2 )
+{
+ Solution *s = (Solution *)malloc( sizeof( Solution ));
+ s->pool = pool;
+ s->solution = solution;
+ s->s1 = s1;
+ s->n1 = n1;
+ s->s2 = s2;
+ s->n2 = n2;
+ return s;
+}
+
+void
+solution_free( Solution *s )
+{
+ free( s );
+}
Added: trunk/sat-solver/applayer/solution.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/solution.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/solution.h (added)
+++ trunk/sat-solver/applayer/solution.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#ifndef SATSOLVER_SOLUTION_H
+#define SATSOLVER_SOLUTION_H
+
+/************************************************
+ * Solution
+ *
+ * A possible solution to a Problem.
+ *
+ * For each reported Problem, the Solver might generate
+ * one or more Solutions to make the Transaction solvable.
+ *
+ */
+
+#include "pool.h"
+
+enum solutions {
+ SOLUTION_UNKNOWN = 0,
+ SOLUTION_NOKEEP_INSTALLED,
+ SOLUTION_NOINSTALL_SOLV,
+ SOLUTION_NOREMOVE_SOLV,
+ SOLUTION_NOFORBID_INSTALL,
+ SOLUTION_NOINSTALL_NAME,
+ SOLUTION_NOREMOVE_NAME,
+ SOLUTION_NOINSTALL_REL,
+ SOLUTION_NOREMOVE_REL,
+ SOLUTION_NOUPDATE,
+ SOLUTION_ALLOW_DOWNGRADE,
+ SOLUTION_ALLOW_ARCHCHANGE,
+ SOLUTION_ALLOW_VENDORCHANGE,
+ SOLUTION_ALLOW_REPLACEMENT,
+ SOLUTION_ALLOW_REMOVE
+};
+
+typedef struct _Solution {
+ Pool *pool;
+ enum solutions solution;
+ Id s1;
+ Id n1;
+ Id s2;
+ Id n2;
+} Solution;
+
+Solution *solution_new( Pool *pool, int solution, Id s1, Id n1, Id s2, Id n2 );
+void solution_free( Solution *s );
+
+#endif /* SATSOLVER_SOLUTION_H */
Added: trunk/sat-solver/applayer/transaction.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/transaction.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/transaction.c (added)
+++ trunk/sat-solver/applayer/transaction.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * Transaction
+ *
+ * A set of Actions to be solved by the Solver
+ *
+ */
+
+#include
+#include "transaction.h"
+
+
+Transaction *
+transaction_new( Pool *pool )
+{
+ Transaction *t = (Transaction *)malloc( sizeof( Transaction ));
+ t->pool = pool;
+ queue_init( &(t->queue) );
+ return t;
+}
+
+void
+transaction_free( Transaction *t )
+{
+ queue_free( &(t->queue) );
+ free( t );
+}
+
+
+void
+transaction_install_xsolvable( Transaction *t, XSolvable *xs )
+{
+ queue_push( &(t->queue), SOLVER_INSTALL_SOLVABLE );
+ /* FIXME: check: s->repo->pool == $self->pool */
+ queue_push( &(t->queue), xs->id );
+}
+
+
+void
+transaction_remove_xsolvable( Transaction *t, XSolvable *xs )
+{
+ queue_push( &(t->queue), SOLVER_ERASE_SOLVABLE );
+ /* FIXME: check: s->repo->pool == $self->pool */
+ queue_push( &(t->queue), xs->id );
+}
+
+
+void
+transaction_install_name( Transaction *t, const char *name )
+{
+ queue_push( &(t->queue), SOLVER_INSTALL_SOLVABLE_NAME );
+ queue_push( &(t->queue), str2id( t->pool, name, 1 ));
+}
+
+
+void
+transaction_remove_name( Transaction *t, const char *name )
+{
+ queue_push( &(t->queue), SOLVER_ERASE_SOLVABLE_NAME );
+ queue_push( &(t->queue), str2id( t->pool, name, 1 ));
+}
+
+
+void
+transaction_install_relation( Transaction *t, const Relation *rel )
+{
+ queue_push( &(t->queue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
+ /* FIXME: check: rel->pool == $self->pool */
+ queue_push( &(t->queue), rel->id );
+}
+
+
+void
+transaction_remove_relation( Transaction *t, const Relation *rel )
+{
+ queue_push( &(t->queue), SOLVER_ERASE_SOLVABLE_PROVIDES );
+ /* FIXME: check: rel->pool == $self->pool */
+ queue_push( &(t->queue), rel->id );
+}
+
+
+Action *
+transaction_action_get( Transaction *t, int i )
+{
+ int size, cmd;
+ Id id;
+ i <<= 1;
+ size = t->queue.count;
+ if (i-1 >= size)
+ return NULL;
+ cmd = t->queue.elements[i];
+ id = t->queue.elements[i+1];
+ return action_new( t->pool, cmd, id );
+}
Added: trunk/sat-solver/applayer/transaction.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/transaction.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/transaction.h (added)
+++ trunk/sat-solver/applayer/transaction.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * Transaction
+ *
+ * A set of Actions to be solved by the Solver
+ *
+ */
+
+#ifndef SATSOLVER_TRANSACTION_H
+#define SATSOLVER_TRANSACTION_H
+
+#include "action.h"
+
+
+typedef struct _Transaction {
+ Pool *pool;
+ Queue queue;
+} Transaction;
+
+
+Transaction *transaction_new( Pool *pool );
+void transaction_free( Transaction *t );
+
+void transaction_install_xsolvable( Transaction *t, XSolvable *xs );
+void transaction_remove_xsolvable( Transaction *t, XSolvable *xs );
+void transaction_install_name( Transaction *t, const char *name );
+void transaction_remove_name( Transaction *t, const char *name );
+void transaction_install_relation( Transaction *t, const Relation *rel );
+void transaction_remove_relation( Transaction *t, const Relation *rel );
+Action *transaction_action_get( Transaction *t, int i );
+
+#endif /* SATSOLVER_TRANSACTION_H */
Added: trunk/sat-solver/applayer/xsolvable.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/xsolvable.c?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/xsolvable.c (added)
+++ trunk/sat-solver/applayer/xsolvable.c Tue Feb 12 18:28:00 2008
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * XSolvable - eXternally visible Solvable
+ *
+ * we cannot use a Solvable pointer since the Pool might realloc them
+ * so we use a combination of Solvable Id and Pool the Solvable belongs
+ * to. pool_id2solvable() gives us the pointer.
+ *
+ * And we cannot use Solvable because its already defined in solvable.h
+ * Later, when defining the bindings, a %rename is used to make
+ * 'Solvable' available in the target language. Swig tightrope walk.
+ */
+
+#include
+#include "xsolvable.h"
+
+
+XSolvable *
+xsolvable_new( Pool *pool, Id id )
+{
+ XSolvable *xsolvable = (XSolvable *)malloc( sizeof( XSolvable ));
+ xsolvable->pool = pool;
+ xsolvable->id = id;
+
+ return xsolvable;
+}
+
+
+XSolvable *
+xsolvable_create( Repo *repo, const char *name, const char *evr, const char *arch )
+{
+ Id sid = repo_add_solvable( repo );
+ Pool *pool = repo->pool;
+ XSolvable *xsolvable = xsolvable_new( pool, sid );
+ Solvable *s = pool_id2solvable( pool, sid );
+ Id nameid = str2id( pool, name, 1 );
+ Id evrid = str2id( pool, evr, 1 );
+ Id archid, rel;
+ if (arch == NULL) arch = "noarch";
+ archid = str2id( pool, arch, 1 );
+ s->name = nameid;
+ s->evr = evrid;
+ s->arch = archid;
+
+ /* add self-provides */
+ rel = rel2id( pool, nameid, evrid, REL_EQ, 1 );
+ s->provides = repo_addid_dep( repo, s->provides, rel, 0 );
+
+ return xsolvable;
+}
+
+
+void
+xsolvable_free( XSolvable *xs )
+{
+ free( xs );
+}
+
+
+Solvable *
+xsolvable_solvable( const XSolvable *xs )
+{
+ return pool_id2solvable( xs->pool, xs->id );
+}
+
+
+/************************************************
+ * Pool/Repo
+ *
+ */
+
+XSolvable *
+xsolvable_find( Pool *pool, char *name, const Repo *repo )
+{
+ Id id;
+ Queue plist;
+ int i, end;
+ Solvable *s;
+
+ id = str2id( pool, name, 1 );
+ queue_init( &plist);
+ i = repo ? repo->start : 1;
+ end = repo ? repo->start + repo->nsolvables : pool->nsolvables;
+ for (; i < end; i++) {
+ s = pool->solvables + i;
+ if (!pool_installable(pool, s))
+ continue;
+ if (s->name == id)
+ queue_push(&plist, i);
+ }
+
+ prune_best_arch_name_version(NULL, pool, &plist);
+ if (plist.count == 0) {
+ return NULL;
+ }
+
+ id = plist.elements[0];
+ queue_free(&plist);
+
+ return xsolvable_new( pool, id );
+}
+
+
+/*
+ * get solvable by index (0..size-1)
+ * If repo == NULL, index is relative to pool
+ * If repo != NULL, index is relative to repo
+ *
+ * index is _not_ the internal id, but used as an array index
+ */
+
+XSolvable *
+xsolvable_get( Pool *pool, int i, const Repo *repo )
+{
+ if (repo == NULL)
+ i += 2; /* adapt to internal Id, see size() above */
+ if (i < 0)
+ return NULL;
+ if (i >= (repo ? repo->nsolvables : pool->nsolvables))
+ return NULL;
+ return xsolvable_new( repo ? repo->pool : pool, repo ? repo->start + i : i );
+}
+
+
+void
+solver_installs_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) )
+{
+ Id p;
+ Solvable *s;
+ int i;
+
+ if (!callback)
+ return;
+
+ for ( i = 0; i < solver->decisionq.count; i++)
+ {
+ p = solver->decisionq.elements[i];
+ if (p <= 0)
+ continue; /* conflicting package, ignore */
+ if (p == SYSTEMSOLVABLE)
+ continue; /* system resolvable, always installed */
+
+ // getting repo
+ s = solver->pool->solvables + p;
+ Repo *repo = s->repo;
+ if (!repo || repo == solver->installed)
+ continue; /* already installed resolvable */
+
+ if (callback( xsolvable_new( solver->pool, p ) ) )
+ break;
+ }
+}
+
+
+void
+solver_removals_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) )
+{
+ Id p;
+ Solvable *s;
+
+ if (!callback)
+ return;
+
+ if (!solver->installed)
+ return;
+
+ /* solvables to be removed */
+ FOR_REPO_SOLVABLES(solver->installed, p, s)
+ {
+ if (solver->decisionmap[p] >= 0)
+ continue; /* we keep this package */
+ if (callback( xsolvable_new( solver->pool, p ) ) )
+ break;
+ }
+}
+
+void
+solver_suggestions_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) )
+{
+ int i;
+
+ if (!callback)
+ return;
+
+ for (i = 0; i < solver->suggestions.count; i++)
+ {
+ if (callback( xsolvable_new( solver->pool, solver->suggestions.elements[i] ) ) )
+ break;
+ }
+}
Added: trunk/sat-solver/applayer/xsolvable.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/xsolvable.h?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/applayer/xsolvable.h (added)
+++ trunk/sat-solver/applayer/xsolvable.h Tue Feb 12 18:28:00 2008
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#ifndef SATSOLVER_XSOLVABLE_H
+#define SATSOLVER_XSOLVABLE_H
+
+#include "pool.h"
+#include "repo.h"
+#include "solvable.h"
+#include "solver.h"
+
+/************************************************
+ * XSolvable - eXternally visible Solvable
+ *
+ * we cannot use a Solvable pointer since the Pool might realloc them
+ * so we use a combination of Solvable Id and Pool the Solvable belongs
+ * to. pool_id2solvable() gives us the pointer.
+ *
+ * And we cannot use Solvable because its already defined in solvable.h
+ * Later, when defining the bindings, a %rename is used to make
+ * 'Solvable' available in the target language. Swig tightrope walk.
+ */
+
+typedef struct _xsolvable {
+ Pool *pool;
+ Id id;
+} XSolvable;
+
+XSolvable *xsolvable_new( Pool *pool, Id id );
+XSolvable *xsolvable_create( Repo *repo, const char *name, const char *evr, const char *arch );
+void xsolvable_free( XSolvable *xs );
+Solvable *xsolvable_solvable( const XSolvable *xs );
+XSolvable *xsolvable_find( Pool *pool, char *name, const Repo *repo );
+XSolvable *xsolvable_get( Pool *pool, int i, const Repo *repo );
+
+void solver_installs_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) );
+void solver_removals_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) );
+void solver_suggestions_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) );
+
+#endif /* SATSOLVER_XSOLVABLE_H */
Modified: trunk/sat-solver/bindings/perl/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/perl/CMakeLists.txt?rev=8638&r1=8637&r2=8638&view=diff
==============================================================================
--- trunk/sat-solver/bindings/perl/CMakeLists.txt (original)
+++ trunk/sat-solver/bindings/perl/CMakeLists.txt Tue Feb 12 18:28:00 2008
@@ -29,7 +29,7 @@
ADD_CUSTOM_COMMAND (
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c
COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for Perl ..."
- COMMAND ${SWIG_EXECUTABLE} -perl -features autodoc -o ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c -I${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/../satsolver.i
+ COMMAND ${SWIG_EXECUTABLE} -perl -features autodoc -o ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c ${CMAKE_CURRENT_SOURCE_DIR}/../satsolver.i
COMMAND ${CMAKE_COMMAND} -E echo "Done."
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i
@@ -44,9 +44,10 @@
SET_TARGET_PROPERTIES( satsolverx PROPERTIES PREFIX "" )
ADD_DEPENDENCIES( satsolverx glue )
-INCLUDE_DIRECTORIES( ${PERL_CORE_DIR} ${CMAKE_SOURCE_DIR}/tools )
+INCLUDE_DIRECTORIES( ${PERL_CORE_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/applayer ${CMAKE_SOURCE_DIR}/tools )
TARGET_LINK_LIBRARIES( satsolverx satsolver )
+TARGET_LINK_LIBRARIES( satsolverx appsatsolver )
TARGET_LINK_LIBRARIES( satsolverx perl )
TARGET_LINK_LIBRARIES( satsolverx ${DB43_LIBRARY} )
Modified: trunk/sat-solver/bindings/python/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/python/CMakeLists.txt?rev=8638&r1=8637&r2=8638&view=diff
==============================================================================
--- trunk/sat-solver/bindings/python/CMakeLists.txt (original)
+++ trunk/sat-solver/bindings/python/CMakeLists.txt Tue Feb 12 18:28:00 2008
@@ -21,7 +21,7 @@
ADD_CUSTOM_COMMAND (
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c
COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for Python ..."
- COMMAND ${SWIG_EXECUTABLE} -python -features autodoc -o ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c -I${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/../satsolver.i
+ COMMAND ${SWIG_EXECUTABLE} -python -features autodoc -o ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c ${CMAKE_CURRENT_SOURCE_DIR}/../satsolver.i
COMMAND ${CMAKE_COMMAND} -E echo "Done."
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i
@@ -36,9 +36,10 @@
SET_TARGET_PROPERTIES( _satsolverx PROPERTIES PREFIX "" )
ADD_DEPENDENCIES( _satsolverx glue )
-INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/tools )
+INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/applayer ${CMAKE_SOURCE_DIR}/tools )
TARGET_LINK_LIBRARIES( _satsolverx satsolver )
+TARGET_LINK_LIBRARIES( _satsolverx appsatsolver )
TARGET_LINK_LIBRARIES( _satsolverx ${PYTHON_LIBRARIES} )
TARGET_LINK_LIBRARIES( _satsolverx ${DB43_LIBRARY} )
Modified: trunk/sat-solver/bindings/ruby/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/CMakeLists.txt?rev=8638&r1=8637&r2=8638&view=diff
==============================================================================
--- trunk/sat-solver/bindings/ruby/CMakeLists.txt (original)
+++ trunk/sat-solver/bindings/ruby/CMakeLists.txt Tue Feb 12 18:28:00 2008
@@ -12,7 +12,7 @@
ADD_CUSTOM_COMMAND (
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c
COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for Ruby..."
- COMMAND ${SWIG_EXECUTABLE} -ruby -features autodoc -autorename -o ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c -I${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/../satsolver.i
+ COMMAND ${SWIG_EXECUTABLE} -ruby -features autodoc -autorename -o ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c ${CMAKE_CURRENT_SOURCE_DIR}/../satsolver.i
COMMAND ${CMAKE_COMMAND} -E echo "Done."
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i
@@ -27,9 +27,10 @@
SET_TARGET_PROPERTIES( satsolverx PROPERTIES PREFIX "" )
ADD_DEPENDENCIES( satsolverx glue )
-INCLUDE_DIRECTORIES( ${RUBY_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/tools )
+INCLUDE_DIRECTORIES( ${RUBY_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/applayer ${CMAKE_SOURCE_DIR}/tools )
TARGET_LINK_LIBRARIES( satsolverx satsolver )
+TARGET_LINK_LIBRARIES( satsolverx appsatsolver )
TARGET_LINK_LIBRARIES( satsolverx ${RUBY_LIBRARY} )
TARGET_LINK_LIBRARIES( satsolverx ${DB43_LIBRARY} )
Added: trunk/sat-solver/bindings/ruby/tests/Makefile
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/Makefile?rev=8638&view=auto
==============================================================================
--- trunk/sat-solver/bindings/ruby/tests/Makefile (added)
+++ trunk/sat-solver/bindings/ruby/tests/Makefile Tue Feb 12 18:28:00 2008
@@ -0,0 +1,21 @@
+#
+# Makefile for sat-solver/bindings/ruby/tests
+#
+
+all:
+ ruby loading.rb
+
+ ruby pool.rb
+ ruby repo.rb
+ ruby rpmdb.rb
+
+ ruby solvable.rb
+ ruby relation.rb
+
+ ruby transaction.rb
+ ruby covenants.rb
+
+ ruby solver.rb
+ ruby decisions.rb
+ ruby problems.rb
+ ruby solutions.rb
Modified: trunk/sat-solver/bindings/ruby/tests/covenants.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/covenants.rb?rev=8638&r1=8637&r2=8638&view=diff
==============================================================================
--- trunk/sat-solver/bindings/ruby/tests/covenants.rb (original)
+++ trunk/sat-solver/bindings/ruby/tests/covenants.rb Tue Feb 12 18:28:00 2008
@@ -15,6 +15,9 @@
solver = pool.create_solver
solver.include( "foo" )
+ puts "Hi"
+ puts "#{repo[0]}"
+ puts "Ho"
solver.include( repo[0] )
solver.include( SatSolver::Relation.new( pool, "foo", SatSolver::REL_EQ, "42-7" ) )
solver.exclude( "bar" )
Modified: trunk/sat-solver/bindings/ruby/tests/decisions.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/decisions.rb?rev=8638&r1=8637&r2=8638&view=diff
==============================================================================
--- trunk/sat-solver/bindings/ruby/tests/decisions.rb (original)
+++ trunk/sat-solver/bindings/ruby/tests/decisions.rb Tue Feb 12 18:28:00 2008
@@ -48,12 +48,11 @@
solv2 = repo.create_solvable( 'B', '2.0-0' )
assert solv2
-
+
solv3 = repo.create_solvable( 'CC', '3.3-0' )
solv3.requires << SatSolver::Relation.new( pool, "A", SatSolver::REL_GT, "0.0-0" )
repo.create_solvable( 'DD', '4.4-0' )
-
transaction = pool.create_transaction
transaction.install( solv3 )
transaction.remove( "D" )
Modified: trunk/sat-solver/bindings/ruby/tests/setup.sh
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/setup.sh?rev=8638&r1=8637&r2=8638&view=diff
==============================================================================
--- trunk/sat-solver/bindings/ruby/tests/setup.sh (original)
+++ trunk/sat-solver/bindings/ruby/tests/setup.sh Tue Feb 12 18:28:00 2008
@@ -1 +1 @@
-export RUBYPATH="../../../build/bindings/ruby"
\ No newline at end of file
+export RUBYPATH="../../../build/bindings/ruby"
Modified: trunk/sat-solver/bindings/ruby/tests/transaction.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/transaction.rb?rev=8638&r1=8637&r2=8638&view=diff
==============================================================================
--- trunk/sat-solver/bindings/ruby/tests/transaction.rb (original)
+++ trunk/sat-solver/bindings/ruby/tests/transaction.rb Tue Feb 12 18:28:00 2008
@@ -11,7 +11,7 @@
assert pool
pool.arch = "i686"
repo = pool.add_solv( "../../../testsuite/data.libzypp/basic-exercises/exercise-1-packages.solv" )
- repo.name = "test"
+ repo.name = "test1"
transaction = SatSolver::Transaction.new( pool )
assert transaction
Modified: trunk/sat-solver/bindings/satsolver.i
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=8638&r1=8637&r2=8638&view=diff
==============================================================================
--- trunk/sat-solver/bindings/satsolver.i (original)
+++ trunk/sat-solver/bindings/satsolver.i Tue Feb 12 18:28:00 2008
@@ -23,12 +23,12 @@
/*=============================================================*/
-extern void SWIG_exception( int code, const char *msg );
-
#if defined(SWIGRUBY)
#include
#include
#endif
+
+/* satsolver core includes */
#include "policy.h"
#include "bitmap.h"
#include "evr.h"
@@ -45,424 +45,66 @@
#include "repo_solv.h"
#include "repo_rpmdb.h"
-/************************************************
- * XSolvable
- *
- * we cannot use a Solvable pointer since the Pool might realloc them
- * so we use a combination of Solvable Id and Pool the Solvable belongs
- * to. pool_id2solvable() gives us the pointer.
- *
- * And we cannot use Solvable because its already defined in solvable.h
- * Later, when defining the bindings, a %rename is used to make
- * 'Solvable' available in the target language. Swig tightrope walk.
- */
-
-typedef struct _xsolvable {
- Pool *pool;
- Id id;
-} XSolvable;
-
-XSolvable *xsolvable_new( Pool *pool, Id id )
-{
- XSolvable *xsolvable = (XSolvable *)malloc( sizeof( XSolvable ));
- xsolvable->pool = pool;
- xsolvable->id = id;
-
- return xsolvable;
-}
-
-XSolvable *xsolvable_create( Repo *repo, const char *name, const char *evr, const char *arch )
-{
- Id sid = repo_add_solvable( repo );
- Pool *pool = repo->pool;
- XSolvable *xsolvable = xsolvable_new( pool, sid );
- Solvable *s = pool_id2solvable( pool, sid );
- Id nameid = str2id( pool, name, 1 );
- Id evrid = str2id( pool, evr, 1 );
- Id archid, rel;
- if (arch == NULL) arch = "noarch";
- archid = str2id( pool, arch, 1 );
- s->name = nameid;
- s->evr = evrid;
- s->arch = archid;
-
- /* add self-provides */
- rel = rel2id( pool, nameid, evrid, REL_EQ, 1 );
- s->provides = repo_addid_dep( repo, s->provides, rel, 0 );
-
- return xsolvable;
-}
-
-
-Solvable *xsolvable_solvable( XSolvable *xs )
-{
- return pool_id2solvable( xs->pool, xs->id );
-}
-
+/* satsolver application layer includes */
+#include "applayer.h"
+#include "xsolvable.h"
+#include "relation.h"
+#include "dependency.h"
+#include "action.h"
+#include "transaction.h"
+#include "decision.h"
+#include "problem.h"
+#include "solution.h"
+#include "covenant.h"
-/************************************************
- * Id
- *
- */
-static const char *
-my_id2str( Pool *pool, Id id )
+static int
+problem_solutions_iterate_callback( const Solution *s )
{
- if (id == STRID_NULL)
- return NULL;
- if (id == STRID_EMPTY)
- return "";
- return id2str( pool, id );
-}
-
-
-/************************************************
- * Relation
- *
- */
-
-#define REL_NONE 0
-
-typedef struct _Relation {
- Offset id;
- Pool *pool;
-} Relation;
-
-static Relation *relation_new( Pool *pool, Id id )
-{
- Relation *relation;
- if (!id) return NULL;
- relation = (Relation *)malloc( sizeof( Relation ));
- relation->id = id;
- relation->pool = pool;
- return relation;
-}
-
-static Relation *relation_create( Pool *pool, const char *name, int op, const char *evr )
-{
- Id name_id = str2id( pool, name, 1 );
- Id evr_id;
- Id rel;
- if (op == REL_NONE)
- return relation_new( pool, name_id );
- if (!evr)
- SWIG_exception( SWIG_NullReferenceError, "REL_NONE operator with NULL evr" );
- evr_id = str2id( pool, evr, 1 );
- rel = rel2id( pool, name_id, evr_id, op, 1 );
- return relation_new( pool, rel );
-}
-
-static Id relation_evrid( const Relation *r )
-{
- if (ISRELDEP( r->id )) {
- Reldep *rd = GETRELDEP( r->pool, r->id );
- return rd->evr;
- }
- return ID_NULL;
-}
-
-/************************************************
- * Dependency
- *
- * Collection of Relations -> Dependency
- */
-
-typedef struct _Dependency {
- int dep; /* type of dep, any of DEP_xxx */
- XSolvable *xsolvable; /* xsolvable this dep belongs to */
-} Dependency;
-
-#define DEP_PRV 1
-#define DEP_REQ 2
-#define DEP_CON 3
-#define DEP_OBS 4
-#define DEP_REC 5
-#define DEP_SUG 6
-#define DEP_SUP 7
-#define DEP_ENH 8
-#define DEP_FRE 9
-
-static Dependency *dependency_new( XSolvable *xsolvable, int dep )
-{
- Dependency *dependency = (Dependency *)malloc( sizeof( Dependency ));
- dependency->dep = dep;
- dependency->xsolvable = xsolvable;
- return dependency;
-}
-
-/* get pointer to offset for dependency */
-static Offset *dependency_relations( const Dependency *dep )
-{
- Solvable *s;
- if (!dep) return NULL;
-
- s = xsolvable_solvable( dep->xsolvable );
- switch (dep->dep) {
- case DEP_PRV: return &(s->provides); break;
- case DEP_REQ: return &(s->requires); break;
- case DEP_CON: return &(s->conflicts); break;
- case DEP_OBS: return &(s->obsoletes); break;
- case DEP_REC: return &(s->recommends); break;
- case DEP_SUG: return &(s->suggests); break;
- case DEP_SUP: return &(s->supplements); break;
- case DEP_ENH: return &(s->enhances); break;
- case DEP_FRE: return &(s->freshens); break;
- }
- return NULL;
-}
-
-
-static int dependency_size( const Dependency *dep )
-{
- int i = 0;
- Solvable *s;
- Id *ids;
- Offset *relations = dependency_relations( dep );
- if (relations) {
- s = xsolvable_solvable( dep->xsolvable );
- ids = s->repo->idarraydata + *relations;
- while (*ids++)
- ++i;
- }
- return i;
-}
-
-
-/************************************************
- * Action
- *
- * A single 'job' item of a Transaction
- *
- */
-
-typedef struct _Action {
- Pool *pool;
- SolverCmd cmd;
- Id id;
-} Action;
-
-static Action *action_new( Pool *pool, SolverCmd cmd, Id id )
-{
- Action *action = (Action *)malloc( sizeof( Action ));
- action->pool = pool;
- action->cmd = cmd;
- action->id = id;
- return action;
-}
-
-
-/************************************************
- * Transaction
- *
- * A set of Actions to be solved by the Solver
- *
- */
-
-typedef struct _Transaction {
- Pool *pool;
- Queue queue;
-} Transaction;
-
-static Transaction *transaction_new( Pool *pool )
-{
- Transaction *t = (Transaction *)malloc( sizeof( Transaction ));
- t->pool = pool;
- queue_init( &(t->queue) );
- return t;
+#if defined(SWIGRUBY)
+ /* FIXME: how to pass 'break' back to the caller ? */
+ rb_yield( SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solution, 0) );
+#endif
+ return 0;
}
-static void transaction_free( Transaction *t )
+static int
+solver_decisions_iterate_callback( const Decision *d )
{
- queue_free( &(t->queue) );
- free( t );
-}
-
-
-/************************************************
- * Decision
- *
- * A successful solver result.
- *
- * Set of 'job items' needed to solve the Transaction.
- *
- */
-
-#define DEC_INSTALL 1
-#define DEC_REMOVE 2
-#define DEC_UPDATE 3
-#define DEC_OBSOLETE 4
-
-typedef struct _Decision {
- int op; /* DEC_{INSTALL,UPDATE,OBSOLETE,REMOVE} */
- Pool *pool;
- Id solvable;
- Id reason;
-} Decision;
-
#if defined(SWIGRUBY)
-static Decision *decision_new( Pool *pool, int op, Id solvable, Id reason )
-{
- Decision *d = (Decision *)malloc( sizeof( Decision ));
- d->pool = pool;
- d->op = op;
- d->solvable = solvable;
- d->reason = reason;
- return d;
-}
+ /* FIXME: how to pass 'break' back to the caller ? */
+ rb_yield(SWIG_NewPointerObj((void*) d, SWIGTYPE_p__Decision, 0));
#endif
-
-/************************************************
- * Problem
- *
- * An unsuccessful solver result
- *
- * If a transaction is not solvable, one or more
- * Problems will be reported by the Solver.
- *
- */
-
-typedef struct _Problem {
- Solver *solver;
- Transaction *transaction;
- Id id; /* [PRIVATE] problem id */
- int reason;
- Id source; /* solvable id */
- Id relation; /* relation id */
- Id target; /* solvable id */
-} Problem;
-
-#if defined(SWIGRUBY)
-static Problem *problem_new( Solver *s, Transaction *t, Id id )
-{
- Id prule;
-
- Problem *p = (Problem *)malloc( sizeof( Problem ));
- p->solver = s;
- p->transaction = t;
- p->id = id;
- prule = solver_findproblemrule( s, id );
- p->reason = solver_problemruleinfo( s, &(t->queue), prule, &(p->relation), &(p->source), &(p->target) );
- return p;
+ return 0;
}
-#endif
-
-/************************************************
- * Solution
- *
- * A possible solution to a Problem.
- *
- * For each reported Problem, the Solver might generate
- * one or more Solutions to make the Transaction solvable.
- *
- */
-
-#define SOLUTION_UNKNOWN 0
-#define SOLUTION_NOKEEP_INSTALLED 1
-#define SOLUTION_NOINSTALL_SOLV 2
-#define SOLUTION_NOREMOVE_SOLV 3
-#define SOLUTION_NOFORBID_INSTALL 4
-#define SOLUTION_NOINSTALL_NAME 5
-#define SOLUTION_NOREMOVE_NAME 6
-#define SOLUTION_NOINSTALL_REL 7
-#define SOLUTION_NOREMOVE_REL 8
-#define SOLUTION_NOUPDATE 9
-#define SOLUTION_ALLOW_DOWNGRADE 10
-#define SOLUTION_ALLOW_ARCHCHANGE 11
-#define SOLUTION_ALLOW_VENDORCHANGE 12
-#define SOLUTION_ALLOW_REPLACEMENT 13
-#define SOLUTION_ALLOW_REMOVE 14
-
-typedef struct _Solution {
- Pool *pool;
- int solution;
- Id s1;
- Id n1;
- Id s2;
- Id n2;
-} Solution;
-
-#if defined(SWIGRUBY)
-static Solution *solution_new( Pool *pool, int solution, Id s1, Id n1, Id s2, Id n2 )
+static int
+solver_problems_iterate_callback( const Problem *p )
{
- Solution *s = (Solution *)malloc( sizeof( Solution ));
- s->pool = pool;
- s->solution = solution;
- s->s1 = s1;
- s->n1 = n1;
- s->s2 = s2;
- s->n2 = n2;
- return s;
-}
+#if defined(SWIGRUBY)
+ /* FIXME: how to pass 'break' back to the caller ? */
+ rb_yield( SWIG_NewPointerObj((void*) p, SWIGTYPE_p__Problem, 0) );
#endif
-
-
-/************************************************
- * Pool/Repo
- *
- */
-
-XSolvable *
-pool_find( Pool *pool, char *name, Repo *repo )
-{
- Id id;
- Queue plist;
- int i, end;
- Solvable *s;
-
- id = str2id( pool, name, 1 );
- queue_init( &plist);
- i = repo ? repo->start : 1;
- end = repo ? repo->start + repo->nsolvables : pool->nsolvables;
- for (; i < end; i++) {
- s = pool->solvables + i;
- if (!pool_installable(pool, s))
- continue;
- if (s->name == id)
- queue_push(&plist, i);
- }
-
- prune_best_arch_name_version(NULL, pool, &plist);
- if (plist.count == 0) {
- return NULL;
- }
-
- id = plist.elements[0];
- queue_free(&plist);
-
- return xsolvable_new( pool, id );
+ return 0;
}
-/************************************************
- * Covenant
- *
- * Covenants ensure specific dependencies in the (installed) system.
- * They are usually used to implement locks.
- *
- */
-
-typedef struct _Covenant {
- Pool *pool;
- SolverCmd cmd;
- Id id;
-} Covenant;
-
-static Covenant *covenant_new( Pool *pool, SolverCmd cmd, Id id )
+static int
+solver_xsolvables_iterate_callback( const XSolvable *xs )
{
- Covenant *covenant = (Covenant *)malloc( sizeof( Covenant ));
- covenant->pool = pool;
- covenant->cmd = cmd;
- covenant->id = id;
- return covenant;
+#if defined(SWIGRUBY)
+ /* FIXME: how to pass 'break' back to the caller ? */
+ rb_yield(SWIG_NewPointerObj((void*)xs, SWIGTYPE_p__Solvable, 0));
+#endif
+ return 0;
}
-
%}
/*=============================================================*/
/* BINDING CODE */
/*=============================================================*/
+%include exception.i
/*-------------------------------------------------------------*/
/* types and typemaps */
@@ -678,7 +320,13 @@
*/
Relation *create_relation( const char *name, int op = REL_NONE, const char *evr = NULL )
- { return relation_create( $self, name, op, evr ); }
+ {
+ if (!evr)
+ SWIG_exception( SWIG_NullReferenceError, "REL_NONE operator with NULL evr" );
+ return relation_create( $self, name, op, evr );
+ fail:
+ return NULL;
+ }
/*
* Solvable management
@@ -711,12 +359,8 @@
* index is _not_ the internal id, but used as an array index
*/
XSolvable *get( int i )
- {
- i += 2; /* adapt to internal Id, see size() above */
- if (i <= 0) return NULL;
- if (i >= $self->nsolvables) return NULL;
- return xsolvable_new( $self, i );
- }
+ { return xsolvable_get( $self, i, NULL ); }
+
#if defined(SWIGRUBY)
void each()
{
@@ -734,7 +378,7 @@
XSolvable *
find( char *name, Repo *repo = NULL )
- { return pool_find( $self, name, repo ); }
+ { return xsolvable_find( $self, name, repo ); }
/**************************
* Transaction management
@@ -829,18 +473,13 @@
* get solvable by index
*/
XSolvable *get( int i )
- {
- if (i < 0) return NULL;
- if (i >= $self->nsolvables) return NULL;
- return xsolvable_new( $self->pool, $self->start + i );
- }
+ { return xsolvable_get( $self->pool, i, $self ); }
/*
* find (best) solvable by name
*/
- XSolvable *
- find( char *name )
- { return pool_find( $self->pool, name, $self ); }
+ XSolvable *find( char *name )
+ { return xsolvable_find( $self->pool, name, $self ); }
}
@@ -865,7 +504,7 @@
Relation( Pool *pool, const char *name, int op = REL_NONE, const char *evr = NULL )
{ return relation_create( pool, name, op, evr ); }
~Relation()
- { free( $self ); }
+ { relation_free( $self ); }
%rename("to_s") asString();
const char *asString()
@@ -929,7 +568,7 @@
Dependency( XSolvable *xsolvable, int dep )
{ return dependency_new( xsolvable, dep ); }
~Dependency()
- { free( $self ); }
+ { dependency_free( $self ); }
XSolvable *solvable()
{ return $self->xsolvable; }
@@ -949,9 +588,7 @@
#endif
Dependency *add( Relation *rel, int pre = 0 )
{
- Solvable *s = xsolvable_solvable( $self->xsolvable );
- Offset *relations = dependency_relations( $self );
- *relations = repo_addid_dep( s->repo, *relations, rel->id, pre ? SOLVABLE_PREREQMARKER : 0 );
+ dependency_relation_add( $self, rel, pre );
return $self;
}
@@ -960,21 +597,7 @@
%alias get "[]";
#endif
Relation *get( int i )
- {
- Solvable *s = xsolvable_solvable( $self->xsolvable );
- Offset *relations = dependency_relations( $self );
- /* loop over it to detect end */
- Id *ids = s->repo->idarraydata + *relations;
- while ( i-- >= 0 ) {
- if ( !*ids )
- break;
- if ( i == 0 ) {
- return relation_new( s->repo->pool, *ids );
- }
- ++ids;
- }
- return NULL;
- }
+ { return dependency_relation_get( $self, i ); }
#if defined(SWIGRUBY)
void each()
@@ -995,6 +618,13 @@
/* Solvable */
%extend XSolvable {
+ %constant int KIND_PACKAGE = KIND_PACKAGE;
+ %constant int KIND_PRODUCT = KIND_PRODUCT;
+ %constant int KIND_PATCH = KIND_PATCH;
+ %constant int KIND_SOURCE = KIND_SOURCE;
+ %constant int KIND_PATTERN = KIND_PATTERN;
+ %constant int KIND_NOSOURCE = KIND_PATTERN;
+
XSolvable( Repo *repo, const char *name, const char *evr, const char *arch = NULL )
{ return xsolvable_create( repo, name, evr, arch ); }
@@ -1060,37 +690,19 @@
/* no constructor defined, Actions are created by accessing a
Transaction */
~Action()
- { free( $self ); }
+ { action_free( $self ); }
int cmd()
{ return $self->cmd; }
XSolvable *solvable()
- {
- if ($self->cmd == SOLVER_INSTALL_SOLVABLE
- || $self->cmd == SOLVER_ERASE_SOLVABLE) {
- return xsolvable_new( $self->pool, $self->id );
- }
- return NULL;
- }
-
+ { return action_xsolvable( $self ); }
const char *name()
- {
- if ($self->cmd == SOLVER_INSTALL_SOLVABLE_NAME
- || $self->cmd == SOLVER_ERASE_SOLVABLE_NAME) {
- return my_id2str( $self->pool, $self->id );
- }
- return NULL;
- }
+ { return action_name( $self ); }
Relation *relation()
- {
- if ($self->cmd == SOLVER_INSTALL_SOLVABLE_PROVIDES
- || $self->cmd == SOLVER_ERASE_SOLVABLE_PROVIDES) {
- return relation_new( $self->pool, $self->id );
- }
- return NULL;
- }
+ { return action_relation( $self ); }
+
}
/*-------------------------------------------------------------*/
@@ -1106,46 +718,28 @@
/*
* Install (specific) solvable
*/
- void install( XSolvable *s )
- {
- if (s == NULL)
- SWIG_exception( SWIG_NullReferenceError, "bad Solvable" );
- queue_push( &($self->queue), SOLVER_INSTALL_SOLVABLE );
- /* FIXME: check: s->repo->pool == $self->pool */
- queue_push( &($self->queue), s->id );
- }
+ void install( XSolvable *xs )
+ { return transaction_install_xsolvable( $self, xs ); }
/*
* Remove (specific) solvable
*/
- void remove( XSolvable *s )
- {
- if (s == NULL)
- SWIG_exception( SWIG_NullReferenceError, "bad Solvable" );
- queue_push( &($self->queue), SOLVER_ERASE_SOLVABLE );
- /* FIXME: check: s->repo->pool == $self->pool */
- queue_push( &($self->queue), s->id );
- }
+ void remove( XSolvable *xs )
+ { return transaction_remove_xsolvable( $self, xs ); }
/*
* Install solvable by name
* The solver is free to choose any solvable with the given name.
*/
void install( const char *name )
- {
- queue_push( &($self->queue), SOLVER_INSTALL_SOLVABLE_NAME );
- queue_push( &($self->queue), str2id( $self->pool, name, 1 ));
- }
+ { return transaction_install_name( $self, name ); }
/*
* Remove solvable by name
* The solver is free to choose any solvable with the given name.
*/
void remove( const char *name )
- {
- queue_push( &($self->queue), SOLVER_ERASE_SOLVABLE_NAME );
- queue_push( &($self->queue), str2id( $self->pool, name, 1 ));
- }
+ { return transaction_remove_name( $self, name ); }
/*
* Install solvable by relation
@@ -1153,13 +747,7 @@
* relation.
*/
void install( const Relation *rel )
- {
- if (rel == NULL)
- SWIG_exception( SWIG_NullReferenceError, "bad Relation" );
- queue_push( &($self->queue), SOLVER_INSTALL_SOLVABLE_PROVIDES );
- /* FIXME: check: rel->pool == $self->pool */
- queue_push( &($self->queue), rel->id );
- }
+ { return transaction_install_relation( $self, rel ); }
/*
* Remove solvable by relation
@@ -1167,13 +755,7 @@
* relation.
*/
void remove( const Relation *rel )
- {
- if (rel == NULL)
- SWIG_exception( SWIG_NullReferenceError, "bad Relation" );
- queue_push( &($self->queue), SOLVER_ERASE_SOLVABLE_PROVIDES );
- /* FIXME: check: rel->pool == $self->pool */
- queue_push( &($self->queue), rel->id );
- }
+ { return transaction_remove_relation( $self, rel ); }
#if defined(SWIGRUBY)
%rename("empty?") empty();
@@ -1212,16 +794,7 @@
* A Transaction is always considered a set of Actions.
*/
Action *get( unsigned int i )
- {
- int size, cmd;
- Id id;
- i <<= 1;
- size = $self->queue.count;
- if (i-1 >= size) return NULL;
- cmd = $self->queue.elements[i];
- id = $self->queue.elements[i+1];
- return action_new( $self->pool, cmd, id );
- }
+ { return transaction_action_get( $self, i ); }
#if defined(SWIGRUBY)
/*
@@ -1243,16 +816,16 @@
/* Decision */
%extend Decision {
- %constant int DEC_INSTALL = 1;
- %constant int DEC_REMOVE = 2;
- %constant int DEC_UPDATE = 3;
- %constant int DEC_OBSOLETE = 4;
+ %constant int DEC_INSTALL = DECISION_INSTALL;
+ %constant int DEC_REMOVE = DECISION_REMOVE;
+ %constant int DEC_UPDATE = DECISION_UPDATE;
+ %constant int DEC_OBSOLETE = DECISION_OBSOLETE;
/* no constructor defined, Decisions are created by accessing
the Solver result. See 'Solver.each_decision'. */
~Decision()
- { free( $self ); }
+ { decision_free( $self ); }
Pool *pool()
{ return $self->pool; }
int op()
@@ -1267,21 +840,21 @@
/* Problem */
%extend Problem {
- %constant int SOLVER_PROBLEM_UPDATE_RULE = 1;
- %constant int SOLVER_PROBLEM_JOB_RULE = 2;
- %constant int SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP = 3;
- %constant int SOLVER_PROBLEM_NOT_INSTALLABLE = 4;
- %constant int SOLVER_PROBLEM_NOTHING_PROVIDES_DEP = 5;
- %constant int SOLVER_PROBLEM_SAME_NAME = 6;
- %constant int SOLVER_PROBLEM_PACKAGE_CONFLICT = 7;
- %constant int SOLVER_PROBLEM_PACKAGE_OBSOLETES = 8;
- %constant int SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE = 8;
+ %constant int SOLVER_PROBLEM_UPDATE_RULE = SOLVER_PROBLEM_UPDATE_RULE;
+ %constant int SOLVER_PROBLEM_JOB_RULE = SOLVER_PROBLEM_JOB_RULE;
+ %constant int SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP = SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
+ %constant int SOLVER_PROBLEM_NOT_INSTALLABLE = SOLVER_PROBLEM_NOT_INSTALLABLE;
+ %constant int SOLVER_PROBLEM_NOTHING_PROVIDES_DEP = SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
+ %constant int SOLVER_PROBLEM_SAME_NAME = SOLVER_PROBLEM_SAME_NAME;
+ %constant int SOLVER_PROBLEM_PACKAGE_CONFLICT = SOLVER_PROBLEM_PACKAGE_CONFLICT;
+ %constant int SOLVER_PROBLEM_PACKAGE_OBSOLETES = SOLVER_PROBLEM_PACKAGE_OBSOLETES;
+ %constant int SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE = SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
/* no constructor defined, Problems are created by accessing
the Solver result. See 'Solver.each_problem'. */
~Problem()
- { free ($self); }
+ { problem_free ($self); }
Solver *solver()
{ return $self->solver; }
@@ -1301,132 +874,32 @@
XSolvable *target()
{ return xsolvable_new( $self->solver->pool, $self->target ); }
-#if defined(SWIGRUBY)
void each_solution()
- {
- Id solution = 0;
- while ((solution = solver_next_solution( $self->solver, $self->id, solution )) != 0) {
- Id p, rp, element, what;
-
- Id s1, s2, n1, n2;
- int code = SOLUTION_UNKNOWN;
-
- Solver *solver = $self->solver;
- Pool *pool = solver->pool;
- element = 0;
- s1 = s2 = n1 = n2 = 0;
-
- while ((element = solver_next_solutionelement( solver, $self->id, solution, element, &p, &rp)) != 0) {
- if (p == 0) {
-
- /* job, rp is index into job queue */
- what = $self->transaction->queue.elements[rp];
-
- switch ($self->transaction->queue.elements[rp - 1]) {
- case SOLVER_INSTALL_SOLVABLE:
- s1 = what;
- if (solver->installed
- && (pool->solvables + s1)->repo == solver->installed)
- code = SOLUTION_NOKEEP_INSTALLED; /* s1 */
- else
- code = SOLUTION_NOINSTALL_SOLV; /* s1 */
- break;
- case SOLVER_ERASE_SOLVABLE:
- s1 = what;
- if (solver->installed
- && (pool->solvables + s1)->repo == solver->installed)
- code = SOLUTION_NOREMOVE_SOLV; /* s1 */
- else
- code = SOLUTION_NOFORBID_INSTALL; /* s1 */
- break;
- case SOLVER_INSTALL_SOLVABLE_NAME:
- n1 = what;
- code = SOLUTION_NOINSTALL_NAME; /* n1 */
- break;
- case SOLVER_ERASE_SOLVABLE_NAME:
- n1 = what;
- code = SOLUTION_NOREMOVE_NAME; /* n1 */
- break;
- case SOLVER_INSTALL_SOLVABLE_PROVIDES:
- n1 = what;
- code = SOLUTION_NOINSTALL_REL; /* r1 */
- break;
- case SOLVER_ERASE_SOLVABLE_PROVIDES:
- n1 = what;
- code = SOLUTION_NOREMOVE_REL; /* r1 */
- break;
- case SOLVER_INSTALL_SOLVABLE_UPDATE:
- s1 = what;
- code = SOLUTION_NOUPDATE;
- break;
- default:
- code = SOLUTION_UNKNOWN;
- break;
- }
- }
- else {
- s1 = p;
- s2 = rp;
- /* policy, replace p with rp */
- Solvable *sp = pool->solvables + p;
- Solvable *sr = rp ? pool->solvables + rp : 0;
- if (sr) {
- if (!solver->allowdowngrade
- && evrcmp( pool, sp->evr, sr->evr, EVRCMP_MATCH_RELEASE ) > 0) {
- code = SOLUTION_ALLOW_DOWNGRADE;
- }
- else if (!solver->allowarchchange
- && sp->name == sr->name
- && sp->arch != sr->arch
- && policy_illegal_archchange(solver, sp, sr ) ) {
- code = SOLUTION_ALLOW_ARCHCHANGE; /* s1, s2 */
- }
- else if (!solver->allowvendorchange
- && sp->name == sr->name
- && sp->vendor != sr->vendor
- && policy_illegal_vendorchange( solver, sp, sr ) ) {
- n1 = sp->vendor;
- n2 = sr->vendor;
- code = SOLUTION_ALLOW_VENDORCHANGE;
- }
- else {
- code = SOLUTION_ALLOW_REPLACEMENT;
- }
- }
- else {
- code = SOLUTION_ALLOW_REMOVE; /* s1 */
- }
-
- }
- }
- Solution *s = solution_new( $self->solver->pool, code, s1, n1, s2, n2 );
- rb_yield( SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solution, 0) );
- }
- }
-#endif
+ { problem_solutions_iterate( $self, problem_solutions_iterate_callback ); }
+
}
/*-------------------------------------------------------------*/
/* Solution */
%extend Solution {
- %constant int SOLUTION_UNKNOWN = 0;
- %constant int SOLUTION_NOKEEP_INSTALLED = 1;
- %constant int SOLUTION_NOINSTALL_SOLV = 2;
- %constant int SOLUTION_NOREMOVE_SOLV = 3;
- %constant int SOLUTION_NOFORBID_INSTALL = 4;
- %constant int SOLUTION_NOINSTALL_NAME = 5;
- %constant int SOLUTION_NOREMOVE_NAME = 6;
- %constant int SOLUTION_NOINSTALL_REL = 7;
- %constant int SOLUTION_NOREMOVE_REL = 8;
- %constant int SOLUTION_NOUPDATE = 9;
- %constant int SOLUTION_ALLOW_DOWNGRADE = 10;
- %constant int SOLUTION_ALLOW_ARCHCHANGE = 11;
- %constant int SOLUTION_ALLOW_VENDORCHANGE = 12;
- %constant int SOLUTION_ALLOW_REPLACEMENT = 13;
- %constant int SOLUTION_ALLOW_REMOVE = 14;
+ %constant int SOLUTION_UNKNOWN = SOLUTION_UNKNOWN;
+ %constant int SOLUTION_NOKEEP_INSTALLED = SOLUTION_NOKEEP_INSTALLED;
+ %constant int SOLUTION_NOINSTALL_SOLV = SOLUTION_NOINSTALL_SOLV;
+ %constant int SOLUTION_NOREMOVE_SOLV = SOLUTION_NOREMOVE_SOLV;
+ %constant int SOLUTION_NOFORBID_INSTALL = SOLUTION_NOFORBID_INSTALL;
+ %constant int SOLUTION_NOINSTALL_NAME = SOLUTION_NOINSTALL_NAME;
+ %constant int SOLUTION_NOREMOVE_NAME = SOLUTION_NOREMOVE_NAME;
+ %constant int SOLUTION_NOINSTALL_REL = SOLUTION_NOINSTALL_REL;
+ %constant int SOLUTION_NOREMOVE_REL = SOLUTION_NOREMOVE_REL;
+ %constant int SOLUTION_NOUPDATE = SOLUTION_NOUPDATE;
+ %constant int SOLUTION_ALLOW_DOWNGRADE = SOLUTION_ALLOW_DOWNGRADE;
+ %constant int SOLUTION_ALLOW_ARCHCHANGE = SOLUTION_ALLOW_ARCHCHANGE;
+ %constant int SOLUTION_ALLOW_VENDORCHANGE = SOLUTION_ALLOW_VENDORCHANGE;
+ %constant int SOLUTION_ALLOW_REPLACEMENT = SOLUTION_ALLOW_REPLACEMENT;
+ %constant int SOLUTION_ALLOW_REMOVE = SOLUTION_ALLOW_REMOVE;
~Solution()
- { free ($self); }
+ { solution_free ($self); }
int solution()
{ return $self->solution; }
/* without the %rename, swig converts it to 's_1'. Ouch! */
@@ -1462,37 +935,19 @@
/* no constructor defined, Covenants are created through the Solver,
see 'Solver.include' and 'Solver.excluding' */
~Covenant()
- { free( $self ); }
+ { covenant_free( $self ); }
int cmd()
{ return $self->cmd; }
XSolvable *solvable()
- {
- if ($self->cmd == SOLVER_INSTALL_SOLVABLE
- || $self->cmd == SOLVER_ERASE_SOLVABLE) {
- return xsolvable_new( $self->pool, $self->id );
- }
- return NULL;
- }
+ { return covenant_xsolvable( $self ); }
const char *name()
- {
- if ($self->cmd == SOLVER_INSTALL_SOLVABLE_NAME
- || $self->cmd == SOLVER_ERASE_SOLVABLE_NAME) {
- return my_id2str( $self->pool, $self->id );
- }
- return NULL;
- }
+ { return covenant_name( $self ); }
Relation *relation()
- {
- if ($self->cmd == SOLVER_INSTALL_SOLVABLE_PROVIDES
- || $self->cmd == SOLVER_ERASE_SOLVABLE_PROVIDES) {
- return relation_new( $self->pool, $self->id );
- }
- return NULL;
- }
+ { return covenant_relation( $self ); }
}
@@ -1557,6 +1012,14 @@
void set_allow_downgrade( int bflag )
{ $self->allowdowngrade = bflag; }
+ solvable_kind limit_to_kind()
+ { return $self->limittokind; }
+#if defined(SWIGRUBY)
+ %rename( "limit_to_kind=" ) set_limit_to_kind( solvable_kind kind );
+#endif
+ void set_limit_to_kind( solvable_kind kind )
+ { $self->limittokind = kind; }
+
/*
* On package removal, also remove dependant packages.
*
@@ -1620,28 +1083,16 @@
* Include (specific) solvable
* Including a solvable means that it must be installed.
*/
- void include( XSolvable *s )
- {
- if (s == NULL)
- SWIG_exception( SWIG_NullReferenceError, "bad Solvable" );
- queue_push( &($self->covenantq), SOLVER_INSTALL_SOLVABLE );
- /* FIXME: check: s->repo->pool == $self->pool */
- queue_push( &($self->covenantq), s->id );
- }
+ void include( XSolvable *xs )
+ { return covenant_include_xsolvable( $self, xs ); }
/*
* Exclude (specific) solvable
* Excluding a (specific) solvable means that it must not
* be installed.
*/
- void exclude( XSolvable *s )
- {
- if (s == NULL)
- SWIG_exception( SWIG_NullReferenceError, "bad Solvable" );
- queue_push( &($self->covenantq), SOLVER_ERASE_SOLVABLE );
- /* FIXME: check: s->repo->pool == $self->pool */
- queue_push( &($self->covenantq), s->id );
- }
+ void exclude( XSolvable *xs )
+ { return covenant_exclude_xsolvable( $self, xs ); }
/*
* Include solvable by name
@@ -1649,10 +1100,7 @@
* with the given name must be installed.
*/
void include( const char *name )
- {
- queue_push( &($self->covenantq), SOLVER_INSTALL_SOLVABLE_NAME );
- queue_push( &($self->covenantq), str2id( $self->pool, name, 1 ));
- }
+ { return covenant_include_name( $self, name ); }
/*
* Exclude solvable by name
@@ -1660,10 +1108,7 @@
* with the given name must not be installed.
*/
void exclude( const char *name )
- {
- queue_push( &($self->covenantq), SOLVER_ERASE_SOLVABLE_NAME );
- queue_push( &($self->covenantq), str2id( $self->pool, name, 1 ));
- }
+ { return covenant_exclude_name( $self, name ); }
/*
* Include solvable by relation
@@ -1671,13 +1116,7 @@
* providing the given relation must be installed.
*/
void include( const Relation *rel )
- {
- if (rel == NULL)
- SWIG_exception( SWIG_NullReferenceError, "bad Relation" );
- queue_push( &($self->covenantq), SOLVER_INSTALL_SOLVABLE_PROVIDES );
- /* FIXME: check: rel->pool == $self->pool */
- queue_push( &($self->covenantq), rel->id );
- }
+ { return covenant_include_relation( $self, rel ); }
/*
* Exclude solvable by relation
@@ -1685,13 +1124,7 @@
* providing the given relation must be installed.
*/
void exclude( const Relation *rel )
- {
- if (rel == NULL)
- SWIG_exception( SWIG_NullReferenceError, "bad Relation" );
- queue_push( &($self->covenantq), SOLVER_ERASE_SOLVABLE_PROVIDES );
- /* FIXME: check: rel->pool == $self->pool */
- queue_push( &($self->covenantq), rel->id );
- }
+ { return covenant_exclude_relation( $self, rel ); }
/*
* Get Covenant by index
@@ -1701,16 +1134,7 @@
* The solver always considers Covenants as a set.
*/
Covenant *get_covenant( unsigned int i )
- {
- int size, cmd;
- Id id;
- i <<= 1;
- size = $self->covenantq.count;
- if (i-1 >= size) return NULL;
- cmd = $self->covenantq.elements[i];
- id = $self->covenantq.elements[i+1];
- return covenant_new( $self->pool, cmd, id );
- }
+ { return covenant_get( $self, i ); }
#if defined(SWIGRUBY)
/*
@@ -1739,7 +1163,7 @@
int solve( Transaction *t )
{
if ($self->covenantq.count) {
- /* Honor covenants */
+ /* FIXME: Honor covenants */
}
solver_solve( $self, &(t->queue));
return $self->problems.count == 0;
@@ -1755,82 +1179,16 @@
*/
int decision_count()
{ return $self->decisionq.count; }
-#if defined(SWIGRUBY)
- void each_decision()
- {
- Pool *pool = $self->pool;
- Repo *installed = $self->installed;
- Id p, *obsoletesmap = create_obsoletesmap( $self );
- Id s, r;
- int op;
- Decision *d;
-#if 0
- if (installed) {
- FOR_REPO_SOLVABLES(installed, p, s) {
- if ($self->decisionmap[p] >= 0)
- continue;
- if (obsoletesmap[p]) {
- d = decision_new( pool, DEC_OBSOLETE, s, pool_id2solvable( pool, obsoletesmap[p] ) );
- }
- else {
- d = decision_new( pool, DEC_REMOVE, s, NULL );
- }
- rb_yield(SWIG_NewPointerObj((void*) d, SWIGTYPE_p__Decision, 0));
- }
- }
-#endif
- int i;
- for ( i = 0; i < $self->decisionq.count; i++)
- {
- p = $self->decisionq.elements[i];
- r = 0;
- if (p < 0) { /* remove */
- p = -p;
- s = p;
- if (obsoletesmap[p]) {
- op = DEC_OBSOLETE;
- r = obsoletesmap[p];
- }
- else {
- op = DEC_REMOVE;
- }
- }
- else if (p == SYSTEMSOLVABLE) {
- continue;
- }
- else {
- s = p;
- if (installed) {
- Solvable *solv = pool_id2solvable( pool, p );
- if (solv->repo == installed)
- continue;
- }
- if (!obsoletesmap[p]) {
- op = DEC_INSTALL;
- }
- else {
- op = DEC_UPDATE;
- int j;
- for (j = installed->start; j < installed->end; j++) {
- if (obsoletesmap[j] == p) {
- r = j;
- break;
- }
- }
- }
- }
- d = decision_new( pool, op, s, r );
- rb_yield(SWIG_NewPointerObj((void*) d, SWIGTYPE_p__Decision, 0));
- }
- }
-#endif
+ void each_decision()
+ { return solver_decisions_iterate( $self, solver_decisions_iterate_callback ); }
#if defined(SWIGRUBY)
%rename("problems?") problems_found();
%typemap(out) int problems_found
"$result = ($1 != 0) ? Qtrue : Qfalse;";
#endif
+
/*
* Return if problems where found during solving.
*
@@ -1839,69 +1197,18 @@
*/
int problems_found()
{ return $self->problems.count != 0; }
-#if defined(SWIGRUBY)
+
void each_problem( Transaction *t )
- {
- Id problem = 0;
- while ((problem = solver_next_problem( $self, problem )) != 0) {
- Problem *p;
- p = problem_new( $self, t, problem );
- rb_yield( SWIG_NewPointerObj((void*) p, SWIGTYPE_p__Problem, 0) );
- }
- }
-#endif
+ { return solver_problems_iterate( $self, t, solver_problems_iterate_callback ); }
-#if defined(SWIGRUBY)
void each_to_install()
- {
- Id p;
- Solvable *s;
- int i;
- for ( i = 0; i < $self->decisionq.count; i++)
- {
- p = $self->decisionq.elements[i];
- if (p <= 0)
- continue; /* conflicting package, ignore */
- if (p == SYSTEMSOLVABLE)
- continue; /* system resolvable, always installed */
-
- // getting repo
- s = $self->pool->solvables + p;
- Repo *repo = s->repo;
- if (!repo || repo == $self->installed)
- continue; /* already installed resolvable */
- rb_yield(SWIG_NewPointerObj((void*) xsolvable_new( $self->pool, p ), SWIGTYPE_p__Solvable, 0));
- }
- }
+ { return solver_installs_iterate( $self, solver_xsolvables_iterate_callback ); }
void each_to_remove()
- {
- Id p;
- Solvable *s;
-
- if (!$self->installed)
- return;
- /* solvables to be removed */
- FOR_REPO_SOLVABLES($self->installed, p, s)
- {
- if ($self->decisionmap[p] >= 0)
- continue; /* we keep this package */
- rb_yield(SWIG_NewPointerObj((void*) xsolvable_new( $self->pool, p ), SWIGTYPE_p__Solvable, 0));
- }
- }
+ { return solver_removals_iterate( $self, solver_xsolvables_iterate_callback ); }
void each_suggested()
- {
- int i;
- Solvable *s;
- for (i = 0; i < $self->suggestions.count; i++) {
- s = $self->pool->solvables + $self->suggestions.elements[i];
- rb_yield(SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solvable, 0));
- }
- }
-
-#endif
-
+ { return solver_suggestions_iterate( $self, solver_xsolvables_iterate_callback); }
#if defined(SWIGPERL)
SV* getInstallList()
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org