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 library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define DBUS_API_SUBJECT_TO_CHANGE 1
31 #include <dbus/dbus.h>
35 typedef void (*_dbus_py_func_ptr
)(void);
37 typedef dbus_bool_t (*_dbus_py_conn_setup_func
)(DBusConnection
*, void *);
38 typedef dbus_bool_t (*_dbus_py_srv_setup_func
)(DBusServer
*, void *);
39 typedef void (*_dbus_py_free_func
)(void *);
41 #define DBUS_BINDINGS_API_COUNT 3
43 #ifdef INSIDE_DBUS_PYTHON_BINDINGS
45 extern DBusConnection
*DBusPyConnection_BorrowDBusConnection(PyObject
*);
46 extern PyObject
*DBusPyNativeMainLoop_New4(_dbus_py_conn_setup_func
,
47 _dbus_py_srv_setup_func
,
53 static PyObject
*_dbus_bindings_module
= NULL
;
54 static _dbus_py_func_ptr
*dbus_bindings_API
;
56 #define DBusPyConnection_BorrowDBusConnection \
57 (*(DBusConnection *(*)(PyObject *))dbus_bindings_API[1])
58 #define DBusPyNativeMainLoop_New4 \
59 ((PyObject *(*)(_dbus_py_conn_setup_func, _dbus_py_srv_setup_func, \
60 _dbus_py_free_func, void *))dbus_bindings_API[2])
63 import_dbus_bindings(const char *this_module_name
)
68 _dbus_bindings_module
= PyImport_ImportModule("_dbus_bindings");
69 if (!_dbus_bindings_module
) {
72 c_api
= PyObject_GetAttrString(_dbus_bindings_module
, "_C_API");
73 if (c_api
== NULL
) return -1;
74 if (PyCObject_Check(c_api
)) {
75 dbus_bindings_API
= (_dbus_py_func_ptr
*)PyCObject_AsVoidPtr(c_api
);
79 PyErr_SetString(PyExc_RuntimeError
, "C API is not a PyCObject");
83 count
= *(int *)dbus_bindings_API
[0];
84 if (count
< DBUS_BINDINGS_API_COUNT
) {
85 PyErr_Format(PyExc_RuntimeError
,
86 "_dbus_bindings has API version %d but %s needs "
87 "_dbus_bindings API version at least %d",
88 count
, this_module_name
,
89 DBUS_BINDINGS_API_COUNT
);