summaryrefslogtreecommitdiff
path: root/efl/dbus_mainloop
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2013-04-06 12:46:52 +0200
committerdavemds <dave@gurumeditation.it>2013-04-06 12:46:52 +0200
commit0a32be475ac04c91ce8b844fe722772bc230653c (patch)
tree7948ff44c3ccc22a05c54316ba0a604049078073 /efl/dbus_mainloop
parent4fb18e5674c227e02a2006dd0c2cd27b5a15dbc5 (diff)
Python-EFL: first working dbus mainloop wrapper.
This one don't require edbus2 nor the old e_dbus, it reimplement the dbus connection stuff that was in e_dbus (the old) in a py module.
Diffstat (limited to 'efl/dbus_mainloop')
-rw-r--r--efl/dbus_mainloop/e_dbus.c531
-rw-r--r--efl/dbus_mainloop/e_dbus.h69
-rw-r--r--efl/dbus_mainloop/module.c138
3 files changed, 738 insertions, 0 deletions
diff --git a/efl/dbus_mainloop/e_dbus.c b/efl/dbus_mainloop/e_dbus.c
new file mode 100644
index 0000000..a45f00c
--- /dev/null
+++ b/efl/dbus_mainloop/e_dbus.c
@@ -0,0 +1,531 @@
1/*
2 * Copyright (C) 2007-2013 various contributors (see AUTHORS)
3 *
4 * This file is part of Python-EFL.
5 *
6 * Python-EFL is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * Python-EFL is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <stdbool.h>
21#include "e_dbus.h"
22
23
24int E_DBUS_EVENT_SIGNAL = 0;
25static int connection_slot = -1;
26static int e_dbus_idler_active = 0;
27static int close_connection = 0;
28static int _edbus_init_count = 0;
29
30
31static void
32e_dbus_fd_handler_del(E_DBus_Handler_Data *hd)
33{
34 if (!hd->fd_handler) return;
35
36 printf("handler disabled\n");
37 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler);
38 ecore_main_fd_handler_del(hd->fd_handler);
39 hd->fd_handler = NULL;
40}
41
42static Eina_Bool
43e_dbus_fd_handler(void *data, Ecore_Fd_Handler *fd_handler)
44{
45 E_DBus_Handler_Data *hd;
46 unsigned int condition = 0;
47
48 printf("fd handler (%p)!\n", fd_handler);
49
50 hd = data;
51
52 if (!hd->enabled)
53 {
54 e_dbus_fd_handler_del(hd);
55 return ECORE_CALLBACK_CANCEL;
56 }
57 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) condition |= DBUS_WATCH_READABLE;
58 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE)) condition |= DBUS_WATCH_WRITABLE;
59 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) condition |= DBUS_WATCH_ERROR;
60 printf("fdh || READ: %d, WRITE: %d\n",
61 (condition & DBUS_WATCH_READABLE) == DBUS_WATCH_READABLE,
62 (condition & DBUS_WATCH_WRITABLE) == DBUS_WATCH_WRITABLE);
63
64 if (condition & DBUS_WATCH_ERROR) printf("DBUS watch error\n");
65 dbus_watch_handle(hd->watch, condition);
66 hd = NULL;
67
68 return ECORE_CALLBACK_RENEW;
69}
70
71static void
72e_dbus_fd_handler_add(E_DBus_Handler_Data *hd)
73{
74 unsigned int dflags;
75 Ecore_Fd_Handler_Flags eflags;
76 Eina_List *l;
77 Ecore_Fd_Handler *fdh;
78
79 if (hd->fd_handler) return;
80 dflags = dbus_watch_get_flags(hd->watch);
81 eflags = ECORE_FD_ERROR;
82 if (dflags & DBUS_WATCH_READABLE) eflags |= ECORE_FD_READ;
83 if (dflags & DBUS_WATCH_WRITABLE) eflags |= ECORE_FD_WRITE;
84
85 EINA_LIST_FOREACH(hd->cd->fd_handlers, l, fdh)
86 {
87 if (ecore_main_fd_handler_fd_get(fdh) == hd->fd) return;
88 }
89
90 printf("fd handler add (%d)\n", hd->fd);
91 hd->fd_handler = ecore_main_fd_handler_add(hd->fd,
92 eflags,
93 e_dbus_fd_handler,
94 hd,
95 NULL,
96 NULL);
97
98 hd->cd->fd_handlers = eina_list_append(hd->cd->fd_handlers, hd->fd_handler);
99}
100
101static void
102e_dbus_handler_data_free(void *data)
103{
104 E_DBus_Handler_Data *hd = data;
105
106 printf("e_dbus_handler_data_free\n");
107 if (hd->fd_handler)
108 {
109 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler);
110 ecore_main_fd_handler_del(hd->fd_handler);
111 }
112 free(hd);
113}
114
115static void
116e_dbus_connection_data_watch_add(E_DBus_Connection *cd, DBusWatch *watch)
117{
118 E_DBus_Handler_Data *hd;
119
120 hd = calloc(1, sizeof(E_DBus_Handler_Data));
121 dbus_watch_set_data(watch, hd, e_dbus_handler_data_free);
122 hd->cd = cd;
123 hd->watch = watch;
124
125 hd->enabled = dbus_watch_get_enabled(watch);
126// #if (DBUS_VERSION_MAJOR == 1 && DBUS_VERSION_MINOR == 1 && DBUS_VERSION_MICRO>= 1) || (DBUS_VERSION_MAJOR == 1 && DBUS_VERSION_MINOR > 1) || (DBUS_VERSION_MAJOR > 1)
127 hd->fd = dbus_watch_get_unix_fd(hd->watch);
128// #else
129 // hd->fd = dbus_watch_get_fd(hd->watch);
130// #endif
131 printf("watch add (enabled: %d)\n", hd->enabled);
132 if (hd->enabled) e_dbus_fd_handler_add(hd);
133}
134
135static void
136e_dbus_message_free(void *data, void *message)
137{
138 dbus_message_unref(message);
139}
140
141static DBusHandlerResult
142e_dbus_filter(DBusConnection *conn, DBusMessage *message, void *user_data)
143{
144 E_DBus_Connection *cd = user_data;
145 printf("-----------------\n");
146 printf("Message!\n");
147
148 printf("type: %s\n", dbus_message_type_to_string(dbus_message_get_type(message)));
149 printf("path: %s\n", dbus_message_get_path(message));
150 printf("interface: %s\n", dbus_message_get_interface(message));
151 printf("member: %s\n", dbus_message_get_member(message));
152 printf("sender: %s\n", dbus_message_get_sender(message));
153
154 switch (dbus_message_get_type(message))
155 {
156 case DBUS_MESSAGE_TYPE_METHOD_CALL:
157 printf("signature: %s\n", dbus_message_get_signature(message));
158 break;
159 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
160 printf("reply serial %d\n", dbus_message_get_reply_serial(message));
161 break;
162 case DBUS_MESSAGE_TYPE_ERROR:
163 printf("error: %s\n", dbus_message_get_error_name(message));
164 break;
165 case DBUS_MESSAGE_TYPE_SIGNAL:
166 dbus_message_ref(message);
167 if (cd->signal_dispatcher) cd->signal_dispatcher(cd, message);
168 ecore_event_add(E_DBUS_EVENT_SIGNAL, message, e_dbus_message_free, NULL);
169 break;
170 default:
171 break;
172 }
173 printf("-----------------\n");
174
175 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
176}
177
178static Eina_Bool
179e_dbus_idler(void *data)
180{
181 E_DBus_Connection *cd;
182 cd = data;
183
184 if (DBUS_DISPATCH_COMPLETE == dbus_connection_get_dispatch_status(cd->conn))
185 {
186 printf("done dispatching!\n");
187 cd->idler = NULL;
188 return ECORE_CALLBACK_CANCEL;
189 }
190 e_dbus_idler_active++;
191 dbus_connection_ref(cd->conn);
192 printf("dispatch()\n");
193 dbus_connection_dispatch(cd->conn);
194 dbus_connection_unref(cd->conn);
195 e_dbus_idler_active--;
196 // e_dbus_signal_handlers_clean(cd); // TODO XXX
197 if (!e_dbus_idler_active && close_connection)
198 {
199 do
200 {
201 e_dbus_connection_close(cd);
202 } while (--close_connection);
203 }
204 return ECORE_CALLBACK_RENEW;
205}
206
207static void
208cb_dispatch_status(DBusConnection *conn, DBusDispatchStatus new_status, void *data)
209{
210 E_DBus_Connection *cd;
211
212 printf("dispatch status: %d!\n", new_status);
213 cd = data;
214
215 if (new_status == DBUS_DISPATCH_DATA_REMAINS && !cd->idler)
216 cd->idler = ecore_idler_add(e_dbus_idler, cd);
217 else if (new_status != DBUS_DISPATCH_DATA_REMAINS && cd->idler)
218 {
219 ecore_idler_del(cd->idler);
220 cd->idler = NULL;
221 }
222}
223
224
225/* watch */
226static dbus_bool_t
227cb_watch_add(DBusWatch *watch, void *data)
228{
229 E_DBus_Connection *cd;
230 cd = data;
231
232 printf("cb_watch_add\n");
233 e_dbus_connection_data_watch_add(cd, watch);
234
235 return true;
236}
237
238static void
239cb_watch_del(DBusWatch *watch, void *data)
240{
241 E_DBus_Handler_Data *hd;
242
243 printf("cb_watch_del\n");
244 hd = (E_DBus_Handler_Data *)dbus_watch_get_data(watch);
245 e_dbus_fd_handler_del(hd);
246}
247
248static void
249cb_watch_toggle(DBusWatch *watch, void *data)
250{
251 E_DBus_Handler_Data *hd;
252
253 printf("cb_watch_toggle\n");
254 hd = dbus_watch_get_data(watch);
255
256 if (!hd) return;
257
258 hd->enabled = dbus_watch_get_enabled(watch);
259
260 printf("watch %p is %sabled\n", hd, hd->enabled ? "en" : "dis");
261 if (hd->enabled) e_dbus_fd_handler_add(hd);
262 else e_dbus_fd_handler_del(hd);
263}
264
265
266/* timeout */
267static Eina_Bool
268e_dbus_timeout_handler(void *data)
269{
270 E_DBus_Timeout_Data *td;
271
272 td = data;
273
274 if (!dbus_timeout_get_enabled(td->timeout))
275 {
276 printf("timeout_handler (not enabled, ending)\n");
277 td->handler = NULL;
278 return ECORE_CALLBACK_CANCEL;
279 }
280
281 printf("timeout handler!\n");
282 dbus_timeout_handle(td->timeout);
283 return ECORE_CALLBACK_CANCEL;
284}
285
286static void
287e_dbus_timeout_data_free(void *timeout_data)
288{
289 E_DBus_Timeout_Data *td = timeout_data;
290 printf("e_dbus_timeout_data_free\n");
291 if (td->handler) ecore_timer_del(td->handler);
292 free(td);
293}
294
295static dbus_bool_t
296cb_timeout_add(DBusTimeout *timeout, void *data)
297{
298 E_DBus_Connection *cd;
299 E_DBus_Timeout_Data *td;
300
301 cd = data;
302 printf("timeout add!\n");
303 td = calloc(1, sizeof(E_DBus_Timeout_Data));
304 td->cd = cd;
305 dbus_timeout_set_data(timeout, (void *)td, e_dbus_timeout_data_free);
306
307 td->interval = dbus_timeout_get_interval(timeout);
308 td->timeout = timeout;
309
310 if (dbus_timeout_get_enabled(timeout))
311 td->handler = ecore_timer_add(td->interval, e_dbus_timeout_handler, td);
312 td->cd->timeouts = eina_list_append(td->cd->timeouts, td->handler);
313
314 return true;
315}
316
317static void
318cb_timeout_del(DBusTimeout *timeout, void *data)
319{
320 E_DBus_Timeout_Data *td;
321 printf("timeout del!\n");
322
323 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout);
324
325 if (td->handler)
326 {
327 td->cd->timeouts = eina_list_remove(td->cd->timeouts, td->handler);
328 ecore_timer_del(td->handler);
329 td->handler = NULL;
330 }
331
332 /* Note: timeout data gets freed when the timeout itself is freed by dbus */
333}
334
335static void
336cb_timeout_toggle(DBusTimeout *timeout, void *data)
337{
338 E_DBus_Timeout_Data *td;
339 printf("timeout toggle!\n");
340
341 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout);
342
343 if (dbus_timeout_get_enabled(td->timeout))
344 {
345 td->interval = dbus_timeout_get_interval(timeout);
346 td->handler = ecore_timer_add(td->interval, e_dbus_timeout_handler, td);
347 }
348 else
349 {
350 ecore_timer_del(td->handler);
351 td->handler = NULL;
352 }
353}
354
355
356/* dbus connection */
357static E_DBus_Connection *
358e_dbus_connection_new(DBusConnection *conn)
359{
360 E_DBus_Connection *cd;
361 const char *conn_name;
362
363 cd = calloc(1, sizeof(E_DBus_Connection));
364 if (!cd) return NULL;
365
366 cd->conn = conn;
367 conn_name = dbus_bus_get_unique_name(conn);
368 if (conn_name)
369 {
370 printf("Connected! Name: %s\n", conn_name);
371 cd->conn_name = strdup(conn_name);
372 }
373 else
374 printf("Not connected\n");
375
376 cd->shared_type = (unsigned int)-1;
377 cd->fd_handlers = NULL;
378 cd->timeouts = NULL;
379
380 return cd;
381}
382
383static void
384e_dbus_connection_free(void *data)
385{
386 E_DBus_Connection *cd = data;
387 Ecore_Fd_Handler *fd_handler;
388 Ecore_Timer *timer;
389 printf("e_dbus_connection free!\n");
390
391 EINA_LIST_FREE(cd->fd_handlers, fd_handler)
392 ecore_main_fd_handler_del(fd_handler);
393
394 EINA_LIST_FREE(cd->timeouts, timer)
395 ecore_timer_del(timer);
396
397 // if (cd->shared_type != (unsigned int)-1)
398 // shared_connections[cd->shared_type] = NULL;
399
400 // e_dbus_signal_handlers_free_all(cd);
401
402 if (cd->conn_name) free(cd->conn_name);
403
404 if (cd->idler) ecore_idler_del(cd->idler);
405
406 free(cd);
407}
408
409
410/* public functions */
411int
412e_dbus_init(void)
413{
414 if (++_edbus_init_count != 1)
415 return _edbus_init_count;
416
417 if (!eina_init())
418 {
419 fprintf(stderr,"E-dbus: Enable to initialize eina\n");
420 return --_edbus_init_count;
421 }
422
423 if (!ecore_init())
424 {
425 fprintf(stderr, "E-dbus: Unable to initialize ecore\n");
426 eina_shutdown();
427 return --_edbus_init_count;
428 }
429
430 E_DBUS_EVENT_SIGNAL = ecore_event_type_new();
431 // e_dbus_object_init();
432
433 return _edbus_init_count;
434}
435
436int
437e_dbus_shutdown(void)
438{
439 if (_edbus_init_count <= 0)
440 {
441 fprintf(stderr, "Init count not greater than 0 in shutdown.\n");
442 return 0;
443 }
444 if (--_edbus_init_count)
445 return _edbus_init_count;
446
447 // e_dbus_object_shutdown();
448 ecore_shutdown();
449 eina_shutdown();
450
451 return _edbus_init_count;
452}
453
454E_DBus_Connection *
455e_dbus_connection_setup(DBusConnection *conn)
456{
457 E_DBus_Connection *cd;
458
459 cd = e_dbus_connection_new(conn);
460 if (!cd) return NULL;
461
462 /* connection_setup */
463 dbus_connection_set_exit_on_disconnect(cd->conn, EINA_FALSE);
464 dbus_connection_allocate_data_slot(&connection_slot);
465
466 dbus_connection_set_data(cd->conn, connection_slot, (void *)cd, e_dbus_connection_free);
467 dbus_connection_set_watch_functions(cd->conn,
468 cb_watch_add,
469 cb_watch_del,
470 cb_watch_toggle,
471 cd,
472 NULL);
473
474 dbus_connection_set_timeout_functions(cd->conn,
475 cb_timeout_add,
476 cb_timeout_del,
477 cb_timeout_toggle,
478 cd,
479 NULL);
480
481 dbus_connection_set_dispatch_status_function(cd->conn, cb_dispatch_status, cd, NULL);
482 dbus_connection_add_filter(cd->conn, e_dbus_filter, cd, NULL);
483
484 cb_dispatch_status(cd->conn, dbus_connection_get_dispatch_status(cd->conn), cd);
485
486 return cd;
487}
488
489void
490e_dbus_connection_close(E_DBus_Connection *conn)
491{
492 if (!conn) return;
493 printf("e_dbus_connection_close\n");
494
495 if (e_dbus_idler_active)
496 {
497 close_connection++;
498 return;
499 }
500 if (--(conn->refcount) != 0) return;
501
502 dbus_connection_free_data_slot(&connection_slot);
503 dbus_connection_remove_filter(conn->conn, e_dbus_filter, conn);
504 dbus_connection_set_watch_functions (conn->conn,
505 NULL,
506 NULL,
507 NULL,
508 NULL, NULL);
509
510 dbus_connection_set_timeout_functions (conn->conn,
511 NULL,
512 NULL,
513 NULL,
514 NULL, NULL);
515
516 dbus_connection_set_dispatch_status_function (conn->conn, NULL, NULL, NULL);
517
518 /* Idler functin must be cancelled when dbus connection is unreferenced */
519 if (conn->idler)
520 {
521 ecore_idler_del(conn->idler);
522 conn->idler = NULL;
523 }
524
525 dbus_connection_close(conn->conn);
526 dbus_connection_unref(conn->conn);
527
528 // Note: the E_DBus_Connection gets freed when the dbus_connection is cleaned up by the previous unref
529}
530
531
diff --git a/efl/dbus_mainloop/e_dbus.h b/efl/dbus_mainloop/e_dbus.h
new file mode 100644
index 0000000..8df98ae
--- /dev/null
+++ b/efl/dbus_mainloop/e_dbus.h
@@ -0,0 +1,69 @@
1/*
2 * Copyright (C) 2007-2013 various contributors (see AUTHORS)
3 *
4 * This file is part of Python-EFL.
5 *
6 * Python-EFL is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * Python-EFL is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * Glue code to attach the Ecore main loop to D-Bus from within Python.
22 */
23
24#include <dbus/dbus.h>
25#include <Ecore.h>
26
27
28typedef struct E_DBus_Connection E_DBus_Connection;
29typedef struct E_DBus_Handler_Data E_DBus_Handler_Data;
30typedef struct E_DBus_Timeout_Data E_DBus_Timeout_Data;
31
32struct E_DBus_Connection
33{
34 DBusBusType shared_type;
35 DBusConnection *conn;
36 char *conn_name;
37
38 Eina_List *fd_handlers;
39 Eina_List *timeouts;
40 Eina_List *signal_handlers;
41 void (*signal_dispatcher)(E_DBus_Connection *conn, DBusMessage *msg);
42
43 Ecore_Idler *idler;
44
45 int refcount;
46};
47
48struct E_DBus_Handler_Data
49{
50 int fd;
51 Ecore_Fd_Handler *fd_handler;
52 E_DBus_Connection *cd;
53 DBusWatch *watch;
54 int enabled;
55};
56
57struct E_DBus_Timeout_Data
58{
59 Ecore_Timer *handler;
60 DBusTimeout *timeout;
61 E_DBus_Connection *cd;
62 int interval;
63};
64
65
66int e_dbus_init(void);
67int e_dbus_shutdown(void);
68E_DBus_Connection *e_dbus_connection_setup(DBusConnection *conn);
69void e_dbus_connection_close(E_DBus_Connection *conn);
diff --git a/efl/dbus_mainloop/module.c b/efl/dbus_mainloop/module.c
new file mode 100644
index 0000000..7f4068f
--- /dev/null
+++ b/efl/dbus_mainloop/module.c
@@ -0,0 +1,138 @@
1/*
2 * Copyright (C) 2007-2013 various contributors (see AUTHORS)
3 *
4 * This file is part of Python-EFL.
5 *
6 * Python-EFL is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * Python-EFL is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * Glue code to attach the Ecore main loop to D-Bus from within Python.
22 */
23
24#include <Python.h>
25#include <dbus/dbus-python.h>
26#include "e_dbus.h"
27
28
29static dbus_bool_t
30dbus_py_ecore_set_up_conn(DBusConnection *conn, void *data)
31{
32 Py_BEGIN_ALLOW_THREADS
33 e_dbus_connection_setup(conn);
34 Py_END_ALLOW_THREADS
35
36 return TRUE;
37}
38
39static PyObject *
40dbus_ecore_native_mainloop(void *data)
41{
42 return DBusPyNativeMainLoop_New4(dbus_py_ecore_set_up_conn,
43 NULL, NULL, NULL);
44}
45
46PyDoc_STRVAR(DBusEcoreMainLoop__doc__,
47"Returns a NativeMainLoop to attach the Ecore main loop to D-Bus\n"
48"from within Python.\n");
49static PyObject *
50dbus_ecore_main_loop(PyObject *self, PyObject *args, PyObject *kwargs)
51{
52 static char *kwlist[] = { "set_as_default", NULL };
53 int set_as_default = 0;
54 PyObject *ml;
55
56 if (PyTuple_Size(args) != 0) {
57 PyErr_SetString(PyExc_TypeError,
58 "DBusEcoreMainLoop() takes no positional arguments");
59 return NULL;
60 }
61
62 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i",
63 kwlist, &set_as_default))
64 return NULL;
65
66 ml = dbus_ecore_native_mainloop(NULL);
67
68 if (ml && set_as_default) {
69 PyObject *func, *res;
70
71 if (!_dbus_bindings_module) {
72 PyErr_SetString(PyExc_ImportError, "_dbus_bindings not imported");
73 Py_DECREF(ml);
74 return NULL;
75 }
76
77 func = PyObject_GetAttrString(_dbus_bindings_module,
78 "set_default_main_loop");
79 if (!func) {
80 Py_DECREF(ml);
81 return NULL;
82 }
83
84 res = PyObject_CallFunctionObjArgs(func, ml, NULL);
85 Py_DECREF(func);
86 if (!res) {
87 Py_DECREF(ml);
88 return NULL;
89 }
90
91 Py_DECREF(res);
92 }
93
94 return ml;
95}
96
97static PyMethodDef module_functions[] = {
98 { "DBusEcoreMainLoop", (PyCFunction)dbus_ecore_main_loop,
99 METH_VARARGS | METH_KEYWORDS, DBusEcoreMainLoop__doc__ },
100 { NULL, NULL, 0, NULL }
101};
102
103static void
104module_cleanup(void)
105{
106 e_dbus_shutdown();
107 ecore_shutdown();
108}
109
110PyDoc_STRVAR(module_doc,
111"D-Bus python integration for Ecore main loop.\n");
112
113#if defined(__GNUC__) && (__GNUC__ >= 4)
114__attribute__ ((visibility("default")))
115#endif
116
117PyMODINIT_FUNC
118initdbus_mainloop(void)
119{
120 PyObject *mod;
121
122 if (import_dbus_bindings("efl.dbus_mainloop") < 0) {
123 PyErr_SetString(PyExc_ImportError, "failed to import D-Bus bindings");
124 return;
125 }
126
127 mod = Py_InitModule3("efl.dbus_mainloop", module_functions, module_doc);
128 if (!mod) {
129 PyErr_SetString(PyExc_ImportError,
130 "Py_InitModule3(\"efl.dbus_mainloop\") failed");
131 return;
132 }
133
134 ecore_init();
135 e_dbus_init();
136
137 Py_AtExit(module_cleanup);
138}