Imported Upstream version 2.28.6
[platform/upstream/pygobject2.git] / gio / gsocket.override
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2  * pygobject - Python bindings for GObject
3  * Copyright (C) 2009  Gian Mario Tagliaretti
4  *
5  *   gsocket.override: module overrides for GSocket and related types
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  * USA
21  */
22
23 %%
24 override g_socket_condition_check kwargs
25 static PyObject *
26 _wrap_g_socket_condition_check(PyGObject *self,
27                                PyObject *args,
28                                PyObject *kwargs)
29 {
30     static char *kwlist[] = { "condition", NULL };
31     gint condition, ret;
32
33     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
34                                      "i:gio.Socket.condition_check",
35                                      kwlist, &condition))
36         return NULL;
37     
38     ret = g_socket_condition_check(G_SOCKET(self->obj), condition);
39     
40     return pyg_flags_from_gtype(G_TYPE_IO_CONDITION, ret);
41 }
42 %%
43 override g_socket_condition_wait kwargs
44 static PyObject *
45 _wrap_g_socket_condition_wait(PyGObject *self,
46                               PyObject *args,
47                               PyObject *kwargs)
48 {
49     static char *kwlist[] = { "condition", "cancellable", NULL };
50     gboolean ret;
51     gint condition;
52     PyGObject *py_cancellable = NULL;
53     GCancellable *cancellable;
54     GError *error;
55
56     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
57                                      "i|O:gio.Socket.condition_wait",
58                                      kwlist, &condition, &cancellable))
59         return NULL;
60
61     if (!pygio_check_cancellable(py_cancellable, &cancellable))
62         return NULL;
63     
64     ret = g_socket_condition_wait(G_SOCKET(self->obj), condition,
65                                   cancellable, &error);
66     
67     return PyBool_FromLong(ret);
68 }
69 %%
70 override g_socket_address_enumerator_next_async kwargs
71 static PyObject *
72 _wrap_g_socket_address_enumerator_next_async(PyGObject *self,
73                                              PyObject *args,
74                                              PyObject *kwargs)
75 {
76     static char *kwlist[] = { "callback", "cancellable", "user_data", NULL };
77     PyGIONotify *notify;
78     PyGObject *py_cancellable = NULL;
79     GCancellable *cancellable;
80
81     notify = pygio_notify_new();
82
83     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
84                                     "O|OO:gio.SocketAddressEnumerator.next_async",
85                                     kwlist,
86                                     &notify->callback,
87                                     &py_cancellable,
88                                     &notify->data))
89         goto error;
90       
91     if (!pygio_notify_callback_is_valid(notify))
92         goto error;
93
94     if (!pygio_check_cancellable(py_cancellable, &cancellable))
95         goto error;
96
97     pygio_notify_reference_callback(notify);
98
99     g_socket_address_enumerator_next_async(G_SOCKET_ADDRESS_ENUMERATOR(self->obj),
100                           cancellable,
101                           (GAsyncReadyCallback) async_result_callback_marshal,
102                           notify);
103
104     Py_INCREF(Py_None);
105     return Py_None;
106
107  error:
108     pygio_notify_free(notify);
109     return NULL;
110 }
111 %%
112 override g_socket_client_connect_async kwargs
113 static PyObject *
114 _wrap_g_socket_client_connect_async(PyGObject *self,
115                                     PyObject *args,
116                                     PyObject *kwargs)
117 {
118     static char *kwlist[] = { "callback", "connectable", "cancellable", "user_data", NULL };
119     PyGIONotify *notify;
120     PyGObject *py_cancellable = NULL;
121     GCancellable *cancellable;
122     PyGObject *py_connectable;
123
124     notify = pygio_notify_new();
125
126     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
127                                     "OO|OO:gio.SocketClient.connect_async",
128                                     kwlist,
129                                     &notify->callback,
130                                     &py_connectable,
131                                     &py_cancellable,
132                                     &notify->data))
133         goto error;
134       
135     if (!pygio_notify_callback_is_valid(notify))
136         goto error;
137
138     if (!pygio_check_cancellable(py_cancellable, &cancellable))
139         goto error;
140
141     pygio_notify_reference_callback(notify);
142
143     g_socket_client_connect_async(G_SOCKET_CLIENT(self->obj),
144                           G_SOCKET_CONNECTABLE(py_connectable->obj),
145                           cancellable,
146                           (GAsyncReadyCallback) async_result_callback_marshal,
147                           notify);
148
149     Py_INCREF(Py_None);
150     return Py_None;
151
152  error:
153     pygio_notify_free(notify);
154     return NULL;
155 }
156 %%
157 override g_socket_client_connect_to_host_async kwargs
158 static PyObject *
159 _wrap_g_socket_client_connect_to_host_async(PyGObject *self,
160                                             PyObject *args,
161                                             PyObject *kwargs)
162 {
163     static char *kwlist[] = { "callback", "host_and_port", "default_port",
164                               "cancellable", "user_data", NULL };
165     PyGIONotify *notify;
166     PyGObject *py_cancellable = NULL;
167     GCancellable *cancellable;
168     gchar *host_and_port;
169     guint16 default_port;
170
171     notify = pygio_notify_new();
172
173     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
174                                 "OsH|OO:gio.SocketClient.connect_to_host_async",
175                                 kwlist,
176                                 &notify->callback,
177                                 &host_and_port,
178                                 &default_port,
179                                 &py_cancellable,
180                                 &notify->data))
181         goto error;
182       
183     if (!pygio_notify_callback_is_valid(notify))
184         goto error;
185
186     if (!pygio_check_cancellable(py_cancellable, &cancellable))
187         goto error;
188
189     pygio_notify_reference_callback(notify);
190
191     g_socket_client_connect_to_host_async(G_SOCKET_CLIENT(self->obj),
192                           host_and_port, default_port,
193                           cancellable,
194                           (GAsyncReadyCallback) async_result_callback_marshal,
195                           notify);
196
197     Py_INCREF(Py_None);
198     return Py_None;
199
200  error:
201     pygio_notify_free(notify);
202     return NULL;
203 }
204 %%
205 override g_socket_client_connect_to_service_async kwargs
206 static PyObject *
207 _wrap_g_socket_client_connect_to_service_async(PyGObject *self,
208                                                PyObject *args,
209                                                PyObject *kwargs)
210 {
211     static char *kwlist[] = { "callback", "domain", "service",
212                               "cancellable", "user_data", NULL };
213     PyGIONotify *notify;
214     PyGObject *py_cancellable = NULL;
215     GCancellable *cancellable;
216     gchar *domain, *service;
217
218     notify = pygio_notify_new();
219
220     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
221                             "Oss|OO:gio.SocketClient.connect_to_service_async",
222                             kwlist,
223                             &notify->callback,
224                             &domain,
225                             &service,
226                             &py_cancellable,
227                             &notify->data))
228         goto error;
229       
230     if (!pygio_notify_callback_is_valid(notify))
231         goto error;
232
233     if (!pygio_check_cancellable(py_cancellable, &cancellable))
234         goto error;
235
236     pygio_notify_reference_callback(notify);
237
238     g_socket_client_connect_to_service_async(G_SOCKET_CLIENT(self->obj),
239                           domain, service,
240                           cancellable,
241                           (GAsyncReadyCallback) async_result_callback_marshal,
242                           notify);
243
244     Py_INCREF(Py_None);
245     return Py_None;
246
247  error:
248     pygio_notify_free(notify);
249     return NULL;
250 }
251 %%
252 override g_socket_listener_add_address kwargs
253 static PyObject *
254 _wrap_g_socket_listener_add_address(PyGObject *self, PyObject *args, PyObject *kwargs)
255 {
256     static char *kwlist[] = { "address", "type", "protocol",
257                               "source_object", NULL };
258     GSocketProtocol protocol;
259     PyObject *py_type = NULL, *py_protocol = NULL;
260     GError *error = NULL;
261     gboolean ret;
262     GSocketType type;
263     GSocketAddress *effective_address;
264     PyGObject *address, *py_source_object = NULL;
265     GObject *source_object;
266
267     if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!OO|O!:gio.SocketListener.add_address",
268                                      kwlist,
269                                      &PyGSocketAddress_Type, &address,
270                                      &py_type, &py_protocol,
271                                      &PyGObject_Type, &source_object,
272                                      &PyGSocketAddress_Type, &effective_address))
273         return NULL;
274
275     if (pyg_enum_get_value(G_TYPE_SOCKET_TYPE, py_type, (gpointer)&type))
276         return NULL;
277
278     if (pyg_enum_get_value(G_TYPE_SOCKET_PROTOCOL, py_protocol, (gpointer)&protocol))
279         return NULL;
280     
281     if (py_source_object == NULL || (PyObject*)py_source_object == Py_None)
282         source_object = NULL;
283     else if (pygobject_check(py_source_object, &PyGObject_Type))
284         source_object = G_OBJECT(py_source_object->obj);
285     else {
286       PyErr_SetString(PyExc_TypeError, "source_object should be a gobject.GObject or None");
287       return NULL;
288     }
289     
290     ret = g_socket_listener_add_address(G_SOCKET_LISTENER(self->obj),
291                                         G_SOCKET_ADDRESS(address->obj),
292                                         type, protocol,
293                                         source_object,
294                                         &effective_address,
295                                         &error);
296     
297     if (pyg_error_check(&error))
298         return NULL;
299     
300     if (ret)
301         return pygobject_new((GObject *)effective_address);
302     else {
303         Py_INCREF(Py_None);
304         return Py_None;
305     }
306 }
307 %%
308 override g_socket_listener_accept kwargs
309 static PyObject *
310 _wrap_g_socket_listener_accept(PyGObject *self, PyObject *args, PyObject *kwargs)
311 {
312     static char *kwlist[] = { "cancellable", NULL };
313     GError *error = NULL;
314     PyGObject *py_cancellable = NULL;
315     GCancellable *cancellable;
316     PyObject *py_connection, *py_source_object;
317     GObject *source_object;
318     GSocketConnection *connection;
319
320     if (!PyArg_ParseTupleAndKeywords(args, kwargs,"|O:gio.SocketListener.accept",
321                                      kwlist,
322                                      &py_cancellable))
323         return NULL;
324
325
326     if (!pygio_check_cancellable(py_cancellable, &cancellable))
327         return NULL;
328
329     connection = g_socket_listener_accept(G_SOCKET_LISTENER(self->obj),
330                                           &source_object,
331                                           cancellable,
332                                           &error);
333
334     if (pyg_error_check(&error))
335         return NULL;
336
337     if (connection)
338         py_connection = pygobject_new((GObject *)connection);
339     else {
340         py_connection = Py_None;
341         Py_INCREF(py_connection);
342     }
343
344     if (source_object)
345         py_source_object = pygobject_new((GObject *)source_object);
346     else {
347         py_source_object= Py_None;
348         Py_INCREF(py_source_object);
349     }
350     return Py_BuildValue("(NN)", py_connection, py_source_object);
351 }
352 %%
353 override g_socket_listener_accept_async kwargs
354 static PyObject *
355 _wrap_g_socket_listener_accept_async(PyGObject *self,
356                                      PyObject *args,
357                                      PyObject *kwargs)
358 {
359     static char *kwlist[] = { "callback", "cancellable", "user_data", NULL };
360     PyGIONotify *notify;
361     PyGObject *py_cancellable = NULL;
362     GCancellable *cancellable;
363
364     notify = pygio_notify_new();
365
366     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
367                             "O|OO:gio.SocketListener.accept_async",
368                             kwlist,
369                             &notify->callback,
370                             &py_cancellable,
371                             &notify->data))
372         goto error;
373       
374     if (!pygio_notify_callback_is_valid(notify))
375         goto error;
376
377     if (!pygio_check_cancellable(py_cancellable, &cancellable))
378         goto error;
379
380     pygio_notify_reference_callback(notify);
381
382     g_socket_listener_accept_async(G_SOCKET_LISTENER(self->obj),
383                           cancellable,
384                           (GAsyncReadyCallback) async_result_callback_marshal,
385                           notify);
386
387     Py_INCREF(Py_None);
388     return Py_None;
389
390  error:
391     pygio_notify_free(notify);
392     return NULL;
393 }
394 %%
395 override g_socket_listener_accept_finish kwargs
396 static PyObject *
397 _wrap_g_socket_listener_accept_finish(PyGObject *self,
398                                       PyObject *args,
399                                       PyObject *kwargs)
400 {
401     static char *kwlist[] = { "result", NULL };
402     GError *error = NULL;
403     PyGObject *result;
404     PyObject *py_connection, *py_source_object;
405     GObject *source_object;
406     GSocketConnection *connection;
407
408     if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:gio.SocketListener.accept_finish",
409                                      kwlist,
410                                      &PyGAsyncResult_Type, &result))
411         return NULL;
412
413     connection = g_socket_listener_accept_finish(G_SOCKET_LISTENER(self->obj),
414                                                  G_ASYNC_RESULT(result->obj),
415                                                  &source_object,
416                                                  &error);
417
418     if (pyg_error_check(&error))
419         return NULL;
420
421     if (connection)
422         py_connection = pygobject_new((GObject *)connection);
423     else {
424         py_connection = Py_None;
425         Py_INCREF(py_connection);
426     }
427
428     if (source_object)
429         py_source_object = pygobject_new((GObject *)source_object);
430     else {
431         py_source_object= Py_None;
432         Py_INCREF(py_source_object);
433     }
434     return Py_BuildValue("(NN)", py_connection, py_source_object);
435 }
436 %%
437 override g_socket_listener_accept_socket kwargs
438 static PyObject *
439 _wrap_g_socket_listener_accept_socket(PyGObject *self,
440                                       PyObject *args,
441                                       PyObject *kwargs)
442 {
443     static char *kwlist[] = { "cancellable", NULL };
444     GError *error = NULL;
445     PyGObject *py_cancellable = NULL;
446     GCancellable *cancellable;
447     PyObject *py_socket, *py_source_object;
448     GObject *source_object;
449     GSocket *socket;
450
451     if (!PyArg_ParseTupleAndKeywords(args, kwargs,"|O:gio.SocketListener.accept_socket",
452                                      kwlist,
453                                      &py_cancellable))
454         return NULL;
455
456
457     if (!pygio_check_cancellable(py_cancellable, &cancellable))
458         return NULL;
459
460     socket = g_socket_listener_accept_socket(G_SOCKET_LISTENER(self->obj),
461                                              &source_object,
462                                              cancellable,
463                                              &error);
464
465     if (pyg_error_check(&error))
466         return NULL;
467
468     if (socket)
469         py_socket = pygobject_new((GObject *)socket);
470     else {
471         py_socket = Py_None;
472         Py_INCREF(py_socket);
473     }
474
475     if (source_object)
476         py_source_object = pygobject_new((GObject *)source_object);
477     else {
478         py_source_object= Py_None;
479         Py_INCREF(py_source_object);
480     }
481     return Py_BuildValue("(NN)", py_socket, py_source_object);
482 }
483 %%
484 override g_socket_listener_accept_socket_async kwargs
485 static PyObject *
486 _wrap_g_socket_listener_accept_socket_async(PyGObject *self,
487                                             PyObject *args,
488                                             PyObject *kwargs)
489 {
490     static char *kwlist[] = { "callback", "cancellable", "user_data", NULL };
491     PyGIONotify *notify;
492     PyGObject *py_cancellable = NULL;
493     GCancellable *cancellable;
494
495     notify = pygio_notify_new();
496
497     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
498                             "O|OO:gio.SocketListener.accept_socket_async",
499                             kwlist,
500                             &notify->callback,
501                             &py_cancellable,
502                             &notify->data))
503         goto error;
504       
505     if (!pygio_notify_callback_is_valid(notify))
506         goto error;
507
508     if (!pygio_check_cancellable(py_cancellable, &cancellable))
509         goto error;
510
511     pygio_notify_reference_callback(notify);
512
513     g_socket_listener_accept_socket_async(G_SOCKET_LISTENER(self->obj),
514                           cancellable,
515                           (GAsyncReadyCallback) async_result_callback_marshal,
516                           notify);
517
518     Py_INCREF(Py_None);
519     return Py_None;
520
521  error:
522     pygio_notify_free(notify);
523     return NULL;
524 }
525 %%
526 override g_socket_listener_accept_socket_finish kwargs
527 static PyObject *
528 _wrap_g_socket_listener_accept_socket_finish(PyGObject *self,
529                                             PyObject *args,
530                                             PyObject *kwargs)
531 {
532     static char *kwlist[] = { "result", NULL };
533     GError *error = NULL;
534     PyGObject *result;
535     PyObject *py_socket, *py_source_object;
536     GObject *source_object;
537     GSocket *socket;
538
539     if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:gio.SocketListener.accept_socket_finish",
540                                      kwlist,
541                                      &PyGAsyncResult_Type, &result))
542         return NULL;
543
544     socket = g_socket_listener_accept_socket_finish(G_SOCKET_LISTENER(self->obj),
545                                                     G_ASYNC_RESULT(result->obj),
546                                                     &source_object,
547                                                     &error);
548
549     if (pyg_error_check(&error))
550         return NULL;
551
552     if (socket)
553         py_socket = pygobject_new((GObject *)socket);
554     else {
555         py_socket= Py_None;
556         Py_INCREF(py_socket);
557     }
558
559     if (source_object)
560         py_source_object = pygobject_new((GObject *)source_object);
561     else {
562         py_source_object= Py_None;
563         Py_INCREF(py_source_object);
564     }
565     return Py_BuildValue("(NN)", py_socket, py_source_object);
566 }
567
568 /* Could not write method GSocketAddress.to_native: No ArgType for gpointer */
569 /* Could not write method GSocket.receive_from: No ArgType for GSocketAddress** */
570 /* Could not write method GSocket.receive_message: No ArgType for GSocketAddress** */
571 /* Could not write method GSocket.send_message: No ArgType for GOutputVector* */
572 /* Could not write method GSocket.create_source: No ArgType for GIOCondition */
573 /* Could not write method GSocketControlMessage.serialize: No ArgType for gpointer */
574 /* Could not write function socket_address_new_from_native: No ArgType for gpointer */
575 /* Could not write function socket_control_message_deserialize: No ArgType for gpointer */