pygobject r735 - in trunk: . gio
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: pygobject r735 - in trunk: . gio
- Date: Sat, 19 Jan 2008 18:55:51 +0000 (GMT)
Author: johan
Date: Sat Jan 19 18:55:51 2008
New Revision: 735
URL: http://svn.gnome.org/viewvc/pygobject?rev=735&view=rev
Log:
2008-01-19 Johan Dahlin <johan gnome org>
* gio/gio.override (async_result_callback_marshal): New marshaller
for async results
(_wrap_g_input_stream_read_async): Impl.
* gio/gio-types.defs: Add SimpleAsyncRequest
* gio/giomodule.c: Register enums/constants
Modified:
trunk/ChangeLog
trunk/gio/gio-types.defs
trunk/gio/gio.override
trunk/gio/giomodule.c
Modified: trunk/gio/gio-types.defs
==============================================================================
--- trunk/gio/gio-types.defs (original)
+++ trunk/gio/gio-types.defs Sat Jan 19 18:55:51 2008
@@ -171,6 +171,13 @@
(gtype-id "G_TYPE_FILE_OUTPUT_STREAM")
)
+(define-object SimpleAsyncResult
+ (in-module "gio")
+ (parent "GObject")
+ (c-name "GSimpleAsyncResult")
+ (gtype-id "G_TYPE_SIMPLE_ASYNC_RESULT")
+)
+
(define-object Vfs
(in-module "gio")
(parent "GObject")
Modified: trunk/gio/gio.override
==============================================================================
--- trunk/gio/gio.override (original)
+++ trunk/gio/gio.override Sat Jan 19 18:55:51 2008
@@ -5,7 +5,46 @@
#include <pygobject.h>
#include <gio/gio.h>
-#DEFINE BUFSIZE
+#define BUFSIZE 8192
+
+typedef struct {
+ PyObject *callback;
+ PyObject *data;
+} PyGAsyncRequestNotify;
+
+static void
+async_result_callback_marshal(GObject *source_object,
+ GAsyncResult *result,
+ PyGAsyncRequestNotify *notify)
+{
+ PyObject *ret;
+ PyGILState_STATE state;
+
+ state = pyg_gil_state_ensure();
+
+ if (notify->data)
+ ret = PyEval_CallFunction(notify->callback, "(OOO)",
+ pygobject_new(source_object),
+ pygobject_new((GObject *)result),
+ notify->data);
+ else
+ ret = PyObject_CallFunction(notify->callback, "(OO)",
+ pygobject_new(source_object),
+ pygobject_new((GObject *)result));
+
+ if (ret == NULL) {
+ PyErr_Print();
+ PyErr_Clear();
+ }
+
+ Py_XDECREF(ret);
+
+ Py_DECREF(notify->callback);
+ Py_XDECREF(notify->data);
+ g_slice_free(PyGAsyncRequestNotify, notify);
+
+ pyg_gil_state_release(state);
+}
%%
modulename gio
@@ -96,8 +135,8 @@
"|iO!:InputStream.read",
kwlist, &count,
&PyGCancellable_Type, &pycancellable))
- return NULL;
-
+ return NULL;
+
buffersize = BUFSIZE;
cancellable = pycancellable ? G_CANCELLABLE(pycancellable->obj) : NULL;
@@ -149,3 +188,63 @@
return v;
}
+%%
+override g_input_stream_read_async kwargs
+static PyObject *
+_wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "count", "io_priority", "cancellable", "callback",
+ "user_data", NULL };
+ long count = -1;
+ int io_priority = G_PRIORITY_DEFAULT;
+ PyGObject *pycancellable = NULL;
+ PyObject *buffer;
+ GCancellable *cancellable;
+ PyGAsyncRequestNotify *notify;
+
+ notify = g_slice_new0(PyGAsyncRequestNotify);
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "iiOO|O:InputStream.read_async",
+ kwlist, &count,
+ &io_priority,
+ &pycancellable,
+ ¬ify->callback,
+ ¬ify->data))
+ {
+ g_slice_free(PyGAsyncRequestNotify, notify);
+ return NULL;
+ }
+
+ if ((PyObject*)pycancellable == Py_None)
+ cancellable = NULL;
+ else if (pygobject_check(pycancellable, &PyGCancellable_Type))
+ cancellable = G_CANCELLABLE(pycancellable->obj);
+ else
+ {
+ PyErr_SetString(PyExc_TypeError, "cancellable should be a gio.Cancellable");
+ return NULL;
+ }
+
+ if (!PyCallable_Check(notify->callback))
+ {
+ PyErr_SetString(PyExc_TypeError, "callback argument not callable");
+ g_slice_free(PyGAsyncRequestNotify, notify);
+ return NULL;
+ }
+
+ buffer = PyString_FromStringAndSize((char *)NULL, count);
+ if (buffer == NULL)
+ return NULL;
+
+ g_input_stream_read_async(G_INPUT_STREAM(self->obj),
+ PyString_AS_STRING((PyStringObject *)buffer),
+ count,
+ io_priority,
+ cancellable,
+ (GAsyncReadyCallback)async_result_callback_marshal,
+ notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
Modified: trunk/gio/giomodule.c
==============================================================================
--- trunk/gio/giomodule.c (original)
+++ trunk/gio/giomodule.c Sat Jan 19 18:55:51 2008
@@ -47,6 +47,7 @@
init_pygobject();
pygio_register_classes(d);
+ pygio_add_constants(m, "G_");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]