337a84c8d39deb6f0f430e5b5853a7aebd7325bd
[platform/upstream/pygobject2.git] / gio / goutputstream.override
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2  * pygobject - Python bindings for GObject
3  * Copyright (C) 2008  Johan Dahlin
4  *
5  *   goutputstream.override: module overrides for GOutputStream
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 %%
23 override g_output_stream_write kwargs
24 static PyObject *
25 _wrap_g_output_stream_write(PyGObject *self,
26                             PyObject *args,
27                             PyObject *kwargs)
28 {
29   static char *kwlist[] = { "buffer", "cancellable", NULL };
30   PyGObject *pycancellable = NULL;
31   gchar *buffer;
32   long count = 0; 
33   GCancellable *cancellable;
34   GError *error = NULL;
35   gssize written;
36   
37   if (!PyArg_ParseTupleAndKeywords(args, kwargs,
38                                    "s#|O!:OutputStream.write",
39                                    kwlist, &buffer, &count,
40                                    &PyGCancellable_Type, &pycancellable))
41     return NULL;
42   
43   if (!pygio_check_cancellable(pycancellable, &cancellable))
44       return NULL;
45
46   pyg_begin_allow_threads;
47   written = g_output_stream_write(G_OUTPUT_STREAM(self->obj),
48                                   buffer, count, cancellable, &error);
49   pyg_end_allow_threads;
50
51   if (pyg_error_check(&error))
52     return NULL;
53       
54   return PyInt_FromLong(written);
55 }
56 %%
57 override g_output_stream_write_all kwargs
58 static PyObject *
59 _wrap_g_output_stream_write_all(PyGObject *self,
60                                 PyObject *args,
61                                 PyObject *kwargs)
62 {
63   static char *kwlist[] = { "buffer", "cancellable", NULL };
64   PyGObject *pycancellable = NULL;
65   gchar *buffer;
66   long count = 0; 
67   GCancellable *cancellable;
68   GError *error = NULL;
69   gsize written;
70
71   if (!PyArg_ParseTupleAndKeywords(args, kwargs,
72                                    "s#|O!:OutputStream.write",
73                                    kwlist, &buffer, &count,
74                                    &PyGCancellable_Type, &pycancellable))
75     return NULL;
76
77   if (!pygio_check_cancellable(pycancellable, &cancellable))
78       return NULL;
79
80   pyg_begin_allow_threads;
81   g_output_stream_write_all(G_OUTPUT_STREAM(self->obj),
82                             buffer, count, &written, cancellable, &error);
83   pyg_end_allow_threads;
84
85   if (pyg_error_check(&error))
86     return NULL;
87       
88   return PyInt_FromLong(written);
89 }
90 %%
91 override g_output_stream_write_async kwargs
92 static PyObject *
93 _wrap_g_output_stream_write_async(PyGObject *self,
94                                   PyObject *args,
95                                   PyObject *kwargs)
96 {
97   static char *kwlist[] = { "buffer", "callback", "io_priority", "cancellable",
98                             "user_data", NULL };
99   gchar *buffer;
100   long count = -1;
101   int io_priority = G_PRIORITY_DEFAULT;
102   PyGObject *pycancellable = NULL;
103   GCancellable *cancellable;
104   PyGIONotify *notify;
105
106   notify = pygio_notify_new();
107
108   if (!PyArg_ParseTupleAndKeywords(args, kwargs,
109                                    "s#O|iOO:OutputStream.write_async",
110                                    kwlist, &buffer,
111                                    &count,
112                                    &notify->callback,
113                                    &io_priority,
114                                    &pycancellable,
115                                    &notify->data))
116       goto error;
117
118   if (!pygio_notify_callback_is_valid(notify))
119       goto error;
120   
121   if (!pygio_check_cancellable(pycancellable, &cancellable))
122       goto error;
123
124   pygio_notify_reference_callback(notify);
125   pygio_notify_copy_buffer(notify, buffer, count);
126
127   g_output_stream_write_async(G_OUTPUT_STREAM(self->obj),
128                               notify->buffer,
129                               notify->buffer_size,
130                               io_priority,
131                               cancellable,
132                               (GAsyncReadyCallback)async_result_callback_marshal,
133                               notify);
134   
135   Py_INCREF(Py_None);
136   return Py_None;
137
138  error:
139   pygio_notify_free(notify);
140   return NULL;
141 }
142 %%
143 override g_output_stream_close_async kwargs
144 static PyObject *
145 _wrap_g_output_stream_close_async(PyGObject *self,
146                                   PyObject *args,
147                                   PyObject *kwargs)
148 {
149   static char *kwlist[] = { "callback", "io_priority",
150                             "cancellable", "user_data", NULL };
151   int io_priority = G_PRIORITY_DEFAULT;
152   PyGObject *pycancellable = NULL;
153   GCancellable *cancellable;
154   PyGIONotify *notify;
155
156   notify = pygio_notify_new();
157
158   if (!PyArg_ParseTupleAndKeywords(args, kwargs,
159                                    "O|iOO:OutputStream.close_async",
160                                    kwlist,
161                                    &notify->callback,
162                                    &io_priority,
163                                    &pycancellable,
164                                    &notify->data))
165       goto error;
166
167   if (!pygio_notify_callback_is_valid(notify))
168       goto error;
169
170   if (!pygio_check_cancellable(pycancellable, &cancellable))
171       goto error;
172
173   pygio_notify_reference_callback(notify);
174   
175   g_output_stream_close_async(G_OUTPUT_STREAM(self->obj),
176                               io_priority,
177                               cancellable,
178                               (GAsyncReadyCallback)async_result_callback_marshal,
179                               notify);
180   
181   Py_INCREF(Py_None);
182   return Py_None;
183
184  error:
185   pygio_notify_free(notify);
186   return NULL;
187 }
188 %%
189 override g_output_stream_flush_async kwargs
190 static PyObject *
191 _wrap_g_output_stream_flush_async(PyGObject *self,
192                                   PyObject *args,
193                                   PyObject *kwargs)
194 {
195   static char *kwlist[] = { "callback", "io_priority",
196                             "cancellable", "user_data", NULL };
197   int io_priority = G_PRIORITY_DEFAULT;
198   PyGObject *pycancellable = NULL;
199   GCancellable *cancellable;
200   PyGIONotify *notify;
201
202   notify = pygio_notify_new();
203
204   if (!PyArg_ParseTupleAndKeywords(args, kwargs,
205                                    "O|iOO:OutputStream.flush_async",
206                                    kwlist,
207                                    &notify->callback,
208                                    &io_priority,
209                                    &pycancellable,
210                                    &notify->data))
211       goto error;
212
213   if (!pygio_notify_callback_is_valid(notify))
214       goto error;
215
216   if (!pygio_check_cancellable(pycancellable, &cancellable))
217       goto error;
218
219   pygio_notify_reference_callback(notify);
220   
221   g_output_stream_flush_async(G_OUTPUT_STREAM(self->obj),
222                               io_priority,
223                               cancellable,
224                               (GAsyncReadyCallback)async_result_callback_marshal,
225                               notify);
226   
227   Py_INCREF(Py_None);
228   return Py_None;
229
230  error:
231   pygio_notify_free(notify);
232   return NULL;
233 }
234 %%
235 override g_output_stream_splice_async kwargs
236 static PyObject *
237 _wrap_g_output_stream_splice_async(PyGObject *self,
238                                    PyObject *args,
239                                    PyObject *kwargs)
240 {
241     static char *kwlist[] = { "source", "callback", "flags", "io_priority",
242                               "cancellable", "user_data", NULL };
243     
244     int io_priority = G_PRIORITY_DEFAULT;
245     GOutputStreamSpliceFlags flags = G_OUTPUT_STREAM_SPLICE_NONE;
246     PyObject *py_flags = NULL;
247     PyGObject *source;
248     PyGObject *pycancellable = NULL;
249     GCancellable *cancellable;
250     PyGIONotify *notify;
251   
252     notify = pygio_notify_new();
253   
254     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
255                                      "O!O|OiOO:OutputStream.splice_async",
256                                      kwlist,
257                                      &PyGInputStream_Type,
258                                      &source,
259                                      &notify->callback,
260                                      &py_flags,
261                                      &io_priority,
262                                      &pycancellable,
263                                      &notify->data))
264         goto error;
265   
266     if (!pygio_notify_callback_is_valid(notify))
267         goto error;
268   
269     if (py_flags && pyg_flags_get_value(G_TYPE_OUTPUT_STREAM_SPLICE_FLAGS,
270                                         py_flags, (gpointer)&flags))
271         goto error;
272     
273     if (!pygio_check_cancellable(pycancellable, &cancellable))
274         goto error;
275   
276     pygio_notify_reference_callback(notify);
277     
278     g_output_stream_splice_async(G_OUTPUT_STREAM(self->obj),
279                             G_INPUT_STREAM(source->obj), flags, io_priority,
280                             cancellable,
281                             (GAsyncReadyCallback)async_result_callback_marshal,
282                             notify);
283     
284     Py_INCREF(Py_None);
285         return Py_None;
286   
287     error:
288         pygio_notify_free(notify);
289         return NULL;
290 }
291
292 /* GOutputStream.write_all: No ArgType for const-void* */