diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-12-28 16:55:45 -0600 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2007-12-28 11:03:01 -0600 |
commit | 57d62f4361822a2f8cbc9635427e4afc2fb503f5 (patch) | |
tree | e36f97c0f3b35fa03d635ed85b2e3642c2ae3736 /source4 | |
parent | 68b698270481f2b033046dcd6e0a293c1cdaf838 (diff) | |
download | samba-57d62f4361822a2f8cbc9635427e4afc2fb503f5.tar.gz samba-57d62f4361822a2f8cbc9635427e4afc2fb503f5.tar.bz2 samba-57d62f4361822a2f8cbc9635427e4afc2fb503f5.zip |
r26625: Wrap some more events functions for Python and add a trivial test for it.
(This used to be commit 7873666a958a0b92c979dba93f3c3e5136e28d29)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/events/config.mk | 2 | ||||
-rw-r--r-- | source4/lib/events/events.i | 16 | ||||
-rw-r--r-- | source4/lib/events/events.py | 15 | ||||
-rw-r--r-- | source4/lib/events/events_wrap.c | 142 | ||||
-rw-r--r-- | source4/lib/events/tests.py | 31 | ||||
-rwxr-xr-x | source4/selftest/samba4_tests.sh | 1 |
6 files changed, 170 insertions, 37 deletions
diff --git a/source4/lib/events/config.mk b/source4/lib/events/config.mk index 6750ca2d49..910cf3738f 100644 --- a/source4/lib/events/config.mk +++ b/source4/lib/events/config.mk @@ -37,6 +37,6 @@ PUBLIC_DEPENDENCIES = LIBTALLOC LIBSAMBA-UTIL # End SUBSYSTEM LIBEVENTS ############################## -[PYTHON::swig_python] +[PYTHON::swig_events] SWIG_FILE = events.i PRIVATE_DEPENDENCIES = LIBEVENTS diff --git a/source4/lib/events/events.i b/source4/lib/events/events.i index 4b4d265e10..263605b176 100644 --- a/source4/lib/events/events.i +++ b/source4/lib/events/events.i @@ -22,18 +22,22 @@ %{ #include "lib/events/events.h" -typedef struct event_context event_context; +typedef struct event_context event; %} -%talloctype(event_context); -typedef struct event_context {} event_context; +typedef struct event_context { + %extend { + event(TALLOC_CTX *mem_ctx) { return event_context_init(mem_ctx); } + int loop_once(void); + int loop_wait(void); + } +} event; +%talloctype(event); %typemap(default,noblock=1) struct event_context * { $1 = event_context_init(NULL); } -struct event_context *event_context_init(TALLOC_CTX *mem_ctx); - %typemap(default,noblock=1) struct event_context * { $1 = event_context_init(NULL); } @@ -41,3 +45,5 @@ struct event_context *event_context_init(TALLOC_CTX *mem_ctx); struct event_context *event_context_init_byname(TALLOC_CTX *mem_ctx, const char *name); const char **event_backend_list(TALLOC_CTX *mem_ctx); +%rename(set_default_backend) event_set_default_backend; +void event_set_default_backend(const char *backend); diff --git a/source4/lib/events/events.py b/source4/lib/events/events.py index 19494c60b3..d8f70f6319 100644 --- a/source4/lib/events/events.py +++ b/source4/lib/events/events.py @@ -57,16 +57,19 @@ def _swig_setattr_nondynamic_method(set): return set_attr -class event_context(object): +class event(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - def __init__(self): raise AttributeError, "No constructor defined" __repr__ = _swig_repr - __swig_destroy__ = _events.delete_event_context -event_context_swigregister = _events.event_context_swigregister -event_context_swigregister(event_context) + def __init__(self, *args, **kwargs): + _events.event_swiginit(self,_events.new_event(*args, **kwargs)) + __swig_destroy__ = _events.delete_event +event.loop_once = new_instancemethod(_events.event_loop_once,None,event) +event.loop_wait = new_instancemethod(_events.event_loop_wait,None,event) +event_swigregister = _events.event_swigregister +event_swigregister(event) -event_context_init = _events.event_context_init event_context_init_byname = _events.event_context_init_byname event_backend_list = _events.event_backend_list +set_default_backend = _events.set_default_backend diff --git a/source4/lib/events/events_wrap.c b/source4/lib/events/events_wrap.c index 4a0685971e..b220d320cf 100644 --- a/source4/lib/events/events_wrap.c +++ b/source4/lib/events/events_wrap.c @@ -2502,9 +2502,20 @@ static swig_module_info swig_module = {swig_types, 4, 0, 0, 0, 0}; #include "lib/events/events.h" -typedef struct event_context event_context; +typedef struct event_context event; -SWIGINTERN void delete_event_context(event_context *self){ talloc_free(self); } +SWIGINTERN event *new_event(TALLOC_CTX *mem_ctx){ return event_context_init(mem_ctx); } + + #define SWIG_From_long PyInt_FromLong + + +SWIGINTERNINLINE PyObject * +SWIG_From_int (int value) +{ + return SWIG_From_long (value); +} + +SWIGINTERN void delete_event(event *self){ talloc_free(self); } SWIGINTERN swig_type_info* SWIG_pchar_descriptor(void) @@ -2576,9 +2587,70 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) #ifdef __cplusplus extern "C" { #endif -SWIGINTERN PyObject *_wrap_delete_event_context(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_new_event(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; + event *result = 0 ; + + arg1 = NULL; + if (!SWIG_Python_UnpackTuple(args,"new_event",0,0,0)) SWIG_fail; + result = (event *)new_event(arg1); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_event_context, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_event_loop_once(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; - event_context *arg1 = (event_context *) 0 ; + event *arg1 = (event *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_event_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "event_loop_once" "', argument " "1"" of type '" "event *""'"); + } + arg1 = (event *)(argp1); + result = (int)event_loop_once(arg1); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_event_loop_wait(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + event *arg1 = (event *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_event_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "event_loop_wait" "', argument " "1"" of type '" "event *""'"); + } + arg1 = (event *)(argp1); + result = (int)event_loop_wait(arg1); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_delete_event(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + event *arg1 = (event *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; @@ -2587,10 +2659,10 @@ SWIGINTERN PyObject *_wrap_delete_event_context(PyObject *SWIGUNUSEDPARM(self), swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_event_context, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_event_context" "', argument " "1"" of type '" "event_context *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_event" "', argument " "1"" of type '" "event *""'"); } - arg1 = (event_context *)(argp1); - delete_event_context(arg1); + arg1 = (event *)(argp1); + delete_event(arg1); resultobj = SWIG_Py_Void(); return resultobj; @@ -2599,28 +2671,17 @@ fail: } -SWIGINTERN PyObject *event_context_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *event_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_event_context, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } -SWIGINTERN PyObject *_wrap_event_context_init(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; - struct event_context *result = 0 ; - - arg1 = NULL; - if (!SWIG_Python_UnpackTuple(args,"event_context_init",0,0,0)) SWIG_fail; - result = (struct event_context *)event_context_init(arg1); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_event_context, 0 | 0 ); - return resultobj; -fail: - return NULL; +SWIGINTERN PyObject *event_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); } - SWIGINTERN PyObject *_wrap_event_context_init_byname(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; @@ -2666,12 +2727,43 @@ fail: } +SWIGINTERN PyObject *_wrap_set_default_backend(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + char *arg1 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + PyObject * obj0 = 0 ; + char * kwnames[] = { + (char *) "backend", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:set_default_backend",kwnames,&obj0)) SWIG_fail; + res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "set_default_backend" "', argument " "1"" of type '" "char const *""'"); + } + arg1 = (char *)(buf1); + event_set_default_backend((char const *)arg1); + resultobj = SWIG_Py_Void(); + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return resultobj; +fail: + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return NULL; +} + + static PyMethodDef SwigMethods[] = { - { (char *)"delete_event_context", (PyCFunction)_wrap_delete_event_context, METH_O, NULL}, - { (char *)"event_context_swigregister", event_context_swigregister, METH_VARARGS, NULL}, - { (char *)"event_context_init", (PyCFunction)_wrap_event_context_init, METH_NOARGS, NULL}, + { (char *)"new_event", (PyCFunction)_wrap_new_event, METH_NOARGS, NULL}, + { (char *)"event_loop_once", (PyCFunction)_wrap_event_loop_once, METH_O, NULL}, + { (char *)"event_loop_wait", (PyCFunction)_wrap_event_loop_wait, METH_O, NULL}, + { (char *)"delete_event", (PyCFunction)_wrap_delete_event, METH_O, NULL}, + { (char *)"event_swigregister", event_swigregister, METH_VARARGS, NULL}, + { (char *)"event_swiginit", event_swiginit, METH_VARARGS, NULL}, { (char *)"event_context_init_byname", (PyCFunction) _wrap_event_context_init_byname, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"event_backend_list", (PyCFunction)_wrap_event_backend_list, METH_NOARGS, NULL}, + { (char *)"set_default_backend", (PyCFunction) _wrap_set_default_backend, METH_VARARGS | METH_KEYWORDS, NULL}, { NULL, NULL, 0, NULL } }; @@ -2680,7 +2772,7 @@ static PyMethodDef SwigMethods[] = { static swig_type_info _swigt__p_TALLOC_CTX = {"_p_TALLOC_CTX", "TALLOC_CTX *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_event_context = {"_p_event_context", "struct event_context *|event_context *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_event_context = {"_p_event_context", "struct event_context *|event *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0, 0}; static swig_type_info *swig_type_initial[] = { diff --git a/source4/lib/events/tests.py b/source4/lib/events/tests.py new file mode 100644 index 0000000000..b14f7e6250 --- /dev/null +++ b/source4/lib/events/tests.py @@ -0,0 +1,31 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import events +import unittest + +# Just test the bindings are there and that calling them doesn't crash +# anything. + +class EventTestCase(unittest.TestCase): + def test_create(self): + self.assertTrue(events.event() is not None) + + def test_loop_wait(self): + self.assertEquals(0, events.event().loop_wait()) diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh index cff868877a..05035ddac2 100755 --- a/source4/selftest/samba4_tests.sh +++ b/source4/selftest/samba4_tests.sh @@ -296,6 +296,7 @@ then plantest "samba.python" none $SUBUNITRUN samba.tests plantest "provision.python" none $SUBUNITRUN samba.tests.provision plantest "samba3.python" none $SUBUNITRUN samba.tests.samba3 + plantest "events.python" none PYTHONPATH="$PYTHONPATH:lib/events" $SUBUNITRUN tests plantest "samba3sam.python" none PYTHONPATH="$PYTHONPATH:dsdb/samdb/ldb_modules/tests" $SUBUNITRUN samba3sam plantest "ldap.python" dc $PYTHON $samba4srcdir/lib/ldb/tests/python/ldap.py \$SERVER -U\$USERNAME%\$PASSWORD plantest "blackbox.samba3dump" none $PYTHON scripting/bin/samba3dump $samba4srcdir/../testdata/samba3 |