Author: kkaempf Date: Wed Feb 13 13:29:13 2008 New Revision: 8653 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8653&view=rev Log: move more stuff from swig bindings to applayer Modified: trunk/sat-solver/applayer/dependency.c trunk/sat-solver/applayer/dependency.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/satsolver.i Modified: trunk/sat-solver/applayer/dependency.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/dependency.c?... ============================================================================== --- trunk/sat-solver/applayer/dependency.c (original) +++ trunk/sat-solver/applayer/dependency.c Wed Feb 13 13:29:13 2008 @@ -101,3 +101,17 @@ return NULL; } + +void +dependency_relations_iterate( Dependency *dep, int (*callback)(const Relation *rel)) +{ + Solvable *s = xsolvable_solvable( dep->xsolvable ); + Offset *relations = dependency_relations( dep ); + Id *ids = s->repo->idarraydata + *relations; + while (*ids) + { + if (callback( relation_new( s->repo->pool, *ids ) ) ) + break; + ++ids; + } +} Modified: trunk/sat-solver/applayer/dependency.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/dependency.h?... ============================================================================== --- trunk/sat-solver/applayer/dependency.h (original) +++ trunk/sat-solver/applayer/dependency.h Wed Feb 13 13:29:13 2008 @@ -44,5 +44,6 @@ void dependency_relation_add( Dependency *dep, Relation *rel, int pre ); Relation *dependency_relation_get( Dependency *dep, int i ); +void dependency_relations_iterate( Dependency *dep, int (*callback)(const Relation *rel)); #endif /* SATSOLVER_DEPENDENCY_H */ Modified: trunk/sat-solver/applayer/transaction.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/transaction.c... ============================================================================== --- trunk/sat-solver/applayer/transaction.c (original) +++ trunk/sat-solver/applayer/transaction.c Wed Feb 13 13:29:13 2008 @@ -34,6 +34,18 @@ } +/* + * number of actions in transaction + * every two queue elements make one action + */ + +int +transaction_size( Transaction *t ) +{ + return t->queue.count >> 1; +} + + void transaction_install_xsolvable( Transaction *t, XSolvable *xs ) { @@ -99,3 +111,17 @@ id = t->queue.elements[i+1]; return action_new( t->pool, cmd, id ); } + + +void +transaction_actions_iterate( Transaction *t, int (*callback)( const Action *a)) +{ + int i; + for (i = 0; i < t->queue.count-1; ) + { + int cmd = t->queue.elements[i++]; + Id id = t->queue.elements[i++]; + if (callback( action_new( t->pool, cmd, id ) ) ) + break; + } +} Modified: trunk/sat-solver/applayer/transaction.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/transaction.h... ============================================================================== --- trunk/sat-solver/applayer/transaction.h (original) +++ trunk/sat-solver/applayer/transaction.h Wed Feb 13 13:29:13 2008 @@ -33,6 +33,9 @@ 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 ); +int transaction_size( Transaction *t ); Action *transaction_action_get( Transaction *t, int i ); +void transaction_actions_iterate( Transaction *t, int (*callback)( const Action *a)); + #endif /* SATSOLVER_TRANSACTION_H */ Modified: trunk/sat-solver/applayer/xsolvable.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/xsolvable.c?r... ============================================================================== --- trunk/sat-solver/applayer/xsolvable.c (original) +++ trunk/sat-solver/applayer/xsolvable.c Wed Feb 13 13:29:13 2008 @@ -196,3 +196,18 @@ break; } } + + +void +repo_xsolvables_iterate( Repo *repo, int (*callback)( const XSolvable *xs ) ) +{ + Solvable *s; + Id p; + for (p = 0, s = repo->pool->solvables + repo->start; p < repo->nsolvables; p++, s++) + { + if (!s) + continue; + if (callback( xsolvable_new( repo->pool, repo->start + p ) ) ) + break; + } +} Modified: trunk/sat-solver/applayer/xsolvable.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/xsolvable.h?r... ============================================================================== --- trunk/sat-solver/applayer/xsolvable.h (original) +++ trunk/sat-solver/applayer/xsolvable.h Wed Feb 13 13:29:13 2008 @@ -37,8 +37,11 @@ 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 ) ); +void repo_xsolvables_iterate( Repo *repo, int (*callback)( const XSolvable *xs ) ); + #endif /* SATSOLVER_XSOLVABLE_H */ Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?r... ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Wed Feb 13 13:29:13 2008 @@ -98,6 +98,26 @@ return 0; } +static int +dependency_relations_iterate_callback( const Relation *rel ) +{ +#if defined(SWIGRUBY) + /* FIXME: how to pass 'break' back to the caller ? */ + rb_yield( SWIG_NewPointerObj((void*) rel, SWIGTYPE_p__Relation, 0) ); +#endif + return 0; +} + +static int +transaction_actions_iterate_callback( const Action *a ) +{ +#if defined(SWIGRUBY) + /* FIXME: how to pass 'break' back to the caller ? */ + rb_yield(SWIG_NewPointerObj((void*) a, SWIGTYPE_p__Action, 0)); +#endif + return 0; +} + %} /*=============================================================*/ @@ -358,10 +378,8 @@ XSolvable *get( int i ) { return xsolvable_get( $self, i, NULL ); } -#if defined(SWIGRUBY) void each() { pool_xsolvables_iterate( $self, generic_xsolvables_iterate_callback ); } -#endif XSolvable * find( char *name, Repo *repo = NULL ) @@ -438,19 +456,8 @@ XSolvable *create_solvable( const char *name, const char *evr, const char *arch = NULL ) { return xsolvable_create( $self, name, evr, arch ); } -#if defined(SWIGRUBY) void each() - { - Solvable *s; - Id p; - for (p = 0, s = $self->pool->solvables + $self->start; p < $self->nsolvables; p++, s++) - { - if (!s) - continue; - rb_yield( SWIG_NewPointerObj((void*) xsolvable_new( $self->pool, $self->start + p ), SWIGTYPE_p__Solvable, 0) ); - } - } -#endif + { repo_xsolvables_iterate( $self, generic_xsolvables_iterate_callback ); } #if defined(SWIGRUBY) /* %rename is rejected by swig for [] */ @@ -586,18 +593,8 @@ Relation *get( int i ) { return dependency_relation_get( $self, i ); } -#if defined(SWIGRUBY) void each() - { - Solvable *s = xsolvable_solvable( $self->xsolvable ); - Offset *relations = dependency_relations( $self ); - Id *ids = s->repo->idarraydata + *relations; - while (*ids) { - rb_yield( SWIG_NewPointerObj((void*) relation_new( s->repo->pool, *ids ), SWIGTYPE_p__Relation, 0) ); - ++ids; - } - } -#endif + { dependency_relations_iterate( $self, dependency_relations_iterate_callback ); } } @@ -759,7 +756,7 @@ * Return number of actions of this transaction */ int size() - { return $self->queue.count >> 1; } + { return transaction_size( $self ); } #if defined(SWIGRUBY) %rename("clear!") clear(); @@ -783,20 +780,11 @@ Action *get( unsigned int i ) { return transaction_action_get( $self, i ); } -#if defined(SWIGRUBY) /* * Iterate over each Action of the Transaction. */ void each() - { - int i; - for (i = 0; i < $self->queue.count-1; ) { - int cmd = $self->queue.elements[i++]; - Id id = $self->queue.elements[i++]; - rb_yield(SWIG_NewPointerObj((void*) action_new( $self->pool, cmd, id ), SWIGTYPE_p__Action, 0)); - } - } -#endif + { transaction_actions_iterate( $self, transaction_actions_iterate_callback ); } } /*-------------------------------------------------------------*/ -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org