summaryrefslogtreecommitdiff
path: root/swig/zypp.i
diff options
context:
space:
mode:
authorKlaus Kämpf <kkaempf@suse.de>2010-11-06 22:11:06 +0100
committerKlaus Kämpf <kkaempf@suse.de>2010-11-06 22:11:06 +0100
commite5a53c804d294b76cc529f28efca16ad52d07fd9 (patch)
tree04ecb93b5f74b01fde8d2a73e08f86ee6177a312 /swig/zypp.i
parent78111f8aa14af7693e771897c65f286f858330bf (diff)
downloadlibzypp-bindings-e5a53c804d294b76cc529f28efca16ad52d07fd9.tar.gz
libzypp-bindings-e5a53c804d294b76cc529f28efca16ad52d07fd9.tar.bz2
libzypp-bindings-e5a53c804d294b76cc529f28efca16ad52d07fd9.zip
Initial step towards callbacks support
This commit introduces generic (all target languages) support for callbacks. Callbacks are sent to a 'callback object instance' which must be instantiated. Currently implemented are commit callbacks, requiring an instance of 'CommitCallbacks' ** this is work in progress ** Next: Provide example code and tests for Python and Ruby
Diffstat (limited to 'swig/zypp.i')
-rw-r--r--swig/zypp.i92
1 files changed, 89 insertions, 3 deletions
diff --git a/swig/zypp.i b/swig/zypp.i
index d005d51..7dd31e6 100644
--- a/swig/zypp.i
+++ b/swig/zypp.i
@@ -19,6 +19,93 @@
#define REG_NOSUB (REG_NEWLINE << 1)
#endif
+/*
+ * type definitions to keep the C code generic
+ */
+
+#if defined(SWIGPYTHON)
+#define Target_Null_p(x) (x == Py_None)
+#define Target_INCREF(x) Py_INCREF(x)
+#define Target_DECREF(x) Py_DECREF(x)
+#define Target_True Py_True
+#define Target_False Py_False
+#define Target_Null NULL
+#define Target_Void Py_None
+#define Target_Type PyObject*
+#define Target_Bool(x) PyBool_FromLong(x)
+#define Target_WChar(x) PyInt_FromLong(x)
+#define Target_Int(x) PyInt_FromLong(x)
+#define Target_String(x) PyString_FromString(x)
+#define Target_Real(x) Py_None
+#define Target_Array() PyList_New(0)
+#define Target_SizedArray(len) PyList_New(len)
+#define Target_Append(x,y) PyList_Append(x,y)
+#define Target_DateTime(x) Py_None
+#include <Python.h>
+#define TARGET_THREAD_BEGIN_BLOCK SWIG_PYTHON_THREAD_BEGIN_BLOCK
+#define TARGET_THREAD_END_BLOCK SWIG_PYTHON_THREAD_END_BLOCK
+#define TARGET_THREAD_BEGIN_ALLOW SWIG_PYTHON_THREAD_BEGIN_ALLOW
+#define TARGET_THREAD_END_ALLOW SWIG_PYTHON_THREAD_END_ALLOW
+#endif
+
+#if defined(SWIGRUBY)
+#define Target_Null_p(x) NIL_P(x)
+#define Target_INCREF(x)
+#define Target_DECREF(x)
+#define Target_True Qtrue
+#define Target_False Qfalse
+#define Target_Null Qnil
+#define Target_Void Qnil
+#define Target_Type VALUE
+#define Target_Bool(x) ((x)?Qtrue:Qfalse)
+#define Target_WChar(x) INT2FIX(x)
+#define Target_Int(x) INT2FIX(x)
+#define Target_String(x) rb_str_new2(x)
+#define Target_Real(x) rb_float_new(x)
+#define Target_Array() rb_ary_new()
+#define Target_SizedArray(len) rb_ary_new2(len)
+#define Target_Append(x,y) rb_ary_push(x,y)
+#define Target_DateTime(x) Qnil
+#define TARGET_THREAD_BEGIN_BLOCK do {} while(0)
+#define TARGET_THREAD_END_BLOCK do {} while(0)
+#define TARGET_THREAD_BEGIN_ALLOW do {} while(0)
+#define TARGET_THREAD_END_ALLOW do {} while(0)
+#include <ruby.h>
+#include <rubyio.h>
+#endif
+
+#if defined(SWIGPERL)
+#define TARGET_THREAD_BEGIN_BLOCK do {} while(0)
+#define TARGET_THREAD_END_BLOCK do {} while(0)
+#define TARGET_THREAD_BEGIN_ALLOW do {} while(0)
+#define TARGET_THREAD_END_ALLOW do {} while(0)
+
+SWIGINTERNINLINE SV *SWIG_From_long SWIG_PERL_DECL_ARGS_1(long value);
+SWIGINTERNINLINE SV *SWIG_FromCharPtr(const char *cptr);
+SWIGINTERNINLINE SV *SWIG_From_double SWIG_PERL_DECL_ARGS_1(double value);
+
+#define Target_Null_p(x) (x == NULL)
+#define Target_INCREF(x)
+#define Target_DECREF(x)
+#define Target_True (&PL_sv_yes)
+#define Target_False (&PL_sv_no)
+#define Target_Null NULL
+#define Target_Void NULL
+#define Target_Type SV *
+#define Target_Bool(x) (x)?Target_True:Target_False
+#define Target_WChar(x) NULL
+#define Target_Int(x) SWIG_From_long(x)
+#define Target_String(x) SWIG_FromCharPtr(x)
+#define Target_Real(x) SWIG_From_double(x)
+#define Target_Array() (SV *)newAV()
+#define Target_SizedArray(len) (SV *)newAV()
+#define Target_Append(x,y) av_push(((AV *)(x)), y)
+#define Target_DateTime(x) NULL
+#include <perl.h>
+#include <EXTERN.h>
+#endif
+
+
#include <sstream>
#include "zypp/base/PtrTypes.h"
#include "zypp/base/ReferenceCounted.h"
@@ -51,6 +138,7 @@ using namespace zypp::resfilter;
using namespace zypp::filesystem;
typedef std::list<std::string> StringList;
+
%}
%nodefault ByKind;
@@ -143,9 +231,7 @@ namespace zypp {
%include "TmpPath.i"
%include "Resolver.i"
%include "ZConfig.i"
-#ifdef SWIGPYTHON
-%include "python/callbacks.i"
-#endif
+%include "Callbacks.i"
%ignore zypp::ZYpp::setTextLocale;
%ignore zypp::ZYpp::getTextLocale;