1 /* C API for _dbus_bindings, used by _dbus_glib_bindings and any third-party
2 * main loop integration which might happen in future.
4 * This file is currently Python-version-independent - please keep it that way.
6 * Copyright (C) 2006 Collabora Ltd.
8 * Licensed under the Academic Free License version 2.1
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #define DBUS_API_SUBJECT_TO_CHANGE 1
33 #include <dbus/dbus.h>
37 typedef void (*_dbus_py_func_ptr
)(void);
39 typedef dbus_bool_t (*_dbus_py_conn_setup_func
)(DBusConnection
*, void *);
40 typedef dbus_bool_t (*_dbus_py_srv_setup_func
)(DBusServer
*, void *);
41 typedef void (*_dbus_py_free_func
)(void *);
43 #define DBUS_BINDINGS_API_COUNT 3
45 #ifdef INSIDE_DBUS_PYTHON_BINDINGS
47 extern DBusConnection
*DBusPyConnection_BorrowDBusConnection(PyObject
*);
48 extern PyObject
*DBusPyNativeMainLoop_New4(_dbus_py_conn_setup_func
,
49 _dbus_py_srv_setup_func
,
55 static PyObject
*_dbus_bindings_module
= NULL
;
56 static _dbus_py_func_ptr
*dbus_bindings_API
;
58 #define DBusPyConnection_BorrowDBusConnection \
59 (*(DBusConnection *(*)(PyObject *))dbus_bindings_API[1])
60 #define DBusPyNativeMainLoop_New4 \
61 ((PyObject *(*)(_dbus_py_conn_setup_func, _dbus_py_srv_setup_func, \
62 _dbus_py_free_func, void *))dbus_bindings_API[2])
65 import_dbus_bindings(const char *this_module_name
)
70 _dbus_bindings_module
= PyImport_ImportModule("_dbus_bindings");
71 if (!_dbus_bindings_module
) {
74 c_api
= PyObject_GetAttrString(_dbus_bindings_module
, "_C_API");
75 if (c_api
== NULL
) return -1;
76 if (PyCObject_Check(c_api
)) {
77 dbus_bindings_API
= (_dbus_py_func_ptr
*)PyCObject_AsVoidPtr(c_api
);
81 PyErr_SetString(PyExc_RuntimeError
, "C API is not a PyCObject");
85 count
= *(int *)dbus_bindings_API
[0];
86 if (count
< DBUS_BINDINGS_API_COUNT
) {
87 PyErr_Format(PyExc_RuntimeError
,
88 "_dbus_bindings has API version %d but %s needs "
89 "_dbus_bindings API version at least %d",
90 count
, this_module_name
,
91 DBUS_BINDINGS_API_COUNT
);