Dr Andrew Scott G7VAV

My photo
 
June 2025
Mo Tu We Th Fr Sa Su
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 1 2 3 4 5 6


dbus-python.h
001: /* C API for _dbus_bindings, used by _dbus_glib_bindings and any third-party
002:  * main loop integration which might happen in future.
003:  *
004:  * This file is currently Python-version-independent - please keep it that way.
005:  *
006:  * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
007:  *
008:  * Permission is hereby granted, free of charge, to any person
009:  * obtaining a copy of this software and associated documentation
010:  * files (the "Software"), to deal in the Software without
011:  * restriction, including without limitation the rights to use, copy,
012:  * modify, merge, publish, distribute, sublicense, and/or sell copies
013:  * of the Software, and to permit persons to whom the Software is
014:  * furnished to do so, subject to the following conditions:
015:  *
016:  * The above copyright notice and this permission notice shall be
017:  * included in all copies or substantial portions of the Software.
018:  *
019:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
020:  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
021:  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
022:  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
023:  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
024:  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
025:  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
026:  * DEALINGS IN THE SOFTWARE.
027:  */
028: 
029: #ifndef DBUS_PYTHON_H
030: #define DBUS_PYTHON_H
031: 
032: #include <Python.h>
033: #include <dbus/dbus.h>
034: 
035: #if PY_MAJOR_VERSION >= 3
036: #define PY3
037: #define PYDBUS_CAPSULE_NAME "_dbus_bindings._C_API"
038: #endif
039: 
040: DBUS_BEGIN_DECLS
041: 
042: typedef void (*_dbus_py_func_ptr)(void);
043: 
044: typedef dbus_bool_t (*_dbus_py_conn_setup_func)(DBusConnection *, void *);
045: typedef dbus_bool_t (*_dbus_py_srv_setup_func)(DBusServer *, void *);
046: typedef void (*_dbus_py_free_func)(void *);
047: 
048: #define DBUS_BINDINGS_API_COUNT 3
049: 
050: #ifdef INSIDE_DBUS_PYTHON_BINDINGS
051: 
052: extern DBusConnection *DBusPyConnection_BorrowDBusConnection(PyObject *);
053: extern PyObject *DBusPyNativeMainLoop_New4(_dbus_py_conn_setup_func,
054:                                            _dbus_py_srv_setup_func,
055:                                            _dbus_py_free_func,
056:                                            void *);
057: 
058: #else
059: 
060: static PyObject *_dbus_bindings_module = NULL;
061: static _dbus_py_func_ptr *dbus_bindings_API;
062: 
063: #define DBusPyConnection_BorrowDBusConnection \
064:         (*(DBusConnection *(*)(PyObject *))dbus_bindings_API[1])
065: #define DBusPyNativeMainLoop_New4 \
066:     ((PyObject *(*)(_dbus_py_conn_setup_func, _dbus_py_srv_setup_func, \
067:                     _dbus_py_free_func, void *))dbus_bindings_API[2])
068: 
069: static int
070: import_dbus_bindings(const char *this_module_name)
071: {
072:     PyObject *c_api;
073:     int count;
074: 
075:     _dbus_bindings_module = PyImport_ImportModule("_dbus_bindings");
076:     if (!_dbus_bindings_module) {
077:         return -1;
078:     }
079:     c_api = PyObject_GetAttrString(_dbus_bindings_module, "_C_API");
080:     if (c_api == NULL) return -1;
081: #ifdef PY3
082:     dbus_bindings_API = NULL;
083:     if (PyCapsule_IsValid(c_api, PYDBUS_CAPSULE_NAME)) {
084:         dbus_bindings_API = (_dbus_py_func_ptr *)PyCapsule_GetPointer(
085:             c_api, PYDBUS_CAPSULE_NAME);
086:     }
087:     Py_CLEAR(c_api);
088:     if (!dbus_bindings_API) {
089:         PyErr_SetString(PyExc_RuntimeError, "C API is not a PyCapsule");
090:         return -1;
091:     }
092: #else
093:     if (PyCObject_Check(c_api)) {
094:         dbus_bindings_API = (_dbus_py_func_ptr *)PyCObject_AsVoidPtr(c_api);
095:     }
096:     else {
097:         Py_DECREF(c_api);
098:         PyErr_SetString(PyExc_RuntimeError, "C API is not a PyCObject");
099:         return -1;
100:     }
101:     Py_DECREF (c_api);
102: #endif
103:     count = *(int *)dbus_bindings_API[0];
104:     if (count < DBUS_BINDINGS_API_COUNT) {
105:         PyErr_Format(PyExc_RuntimeError,
106:                      "_dbus_bindings has API version %d but %s needs "
107:                      "_dbus_bindings API version at least %d",
108:                      count, this_module_name,
109:                      DBUS_BINDINGS_API_COUNT);
110:         return -1;
111:     }
112:     return 0;
113: }
114: 
115: #endif
116: 
117: DBUS_END_DECLS
118: 
119: #endif
120: 


for client (none)
© Andrew Scott 2006 - 2025,
All Rights Reserved
http://www.andrew-scott.uk/
Andrew Scott
http://www.andrew-scott.co.uk/