test/, include/: remove accidentally duplicated lines from license statement
[dbus-python-phuang.git] / include / dbus-python.h
blob330f27344b9144d018cc7896f0b8d12718381b7f
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 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program 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 General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifndef DBUS_PYTHON_H
27 #define DBUS_PYTHON_H
29 #include <Python.h>
30 #define DBUS_API_SUBJECT_TO_CHANGE 1
31 #include <dbus/dbus.h>
33 DBUS_BEGIN_DECLS
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,
48 _dbus_py_free_func,
49 void *);
51 #else
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])
62 static int
63 import_dbus_bindings(const char *this_module_name)
65 PyObject *c_api;
66 int count;
68 _dbus_bindings_module = PyImport_ImportModule("_dbus_bindings");
69 if (!_dbus_bindings_module) {
70 return -1;
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);
77 else {
78 Py_DECREF(c_api);
79 PyErr_SetString(PyExc_RuntimeError, "C API is not a PyCObject");
80 return -1;
82 Py_DECREF (c_api);
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);
90 return -1;
92 return 0;
95 #endif
97 DBUS_END_DECLS
99 #endif