home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / include / dbus-1.0 / dbus / dbus-python.h
Encoding:
C/C++ Source or Header  |  2007-02-19  |  3.2 KB  |  100 lines

  1. /* C API for _dbus_bindings, used by _dbus_glib_bindings and any third-party
  2.  * main loop integration which might happen in future.
  3.  *
  4.  * This file is currently Python-version-independent - please keep it that way.
  5.  *
  6.  * Copyright (C) 2006 Collabora Ltd.
  7.  *
  8.  * Licensed under the Academic Free License version 2.1
  9.  *
  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.
  14.  *
  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.
  19.  *
  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
  23.  *
  24.  */
  25.  
  26. #ifndef DBUS_PYTHON_H
  27. #define DBUS_PYTHON_H
  28.  
  29. #include <Python.h>
  30. #define DBUS_API_SUBJECT_TO_CHANGE 1
  31. #include <dbus/dbus.h>
  32.  
  33. DBUS_BEGIN_DECLS
  34.  
  35. typedef void (*_dbus_py_func_ptr)(void);
  36.  
  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 *);
  40.  
  41. #define DBUS_BINDINGS_API_COUNT 3
  42.  
  43. #ifdef INSIDE_DBUS_PYTHON_BINDINGS
  44.  
  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 *);
  50.  
  51. #else
  52.  
  53. static PyObject *_dbus_bindings_module = NULL;
  54. static _dbus_py_func_ptr *dbus_bindings_API;
  55.  
  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])
  61.  
  62. static int
  63. import_dbus_bindings(const char *this_module_name)
  64. {
  65.     PyObject *c_api;
  66.     int count;
  67.  
  68.     _dbus_bindings_module = PyImport_ImportModule("_dbus_bindings");
  69.     if (!_dbus_bindings_module) {
  70.         return -1;
  71.     }
  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);
  76.     }
  77.     else {
  78.         Py_DECREF(c_api);
  79.         PyErr_SetString(PyExc_RuntimeError, "C API is not a PyCObject");
  80.         return -1;
  81.     }
  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;
  91.     }
  92.     return 0;
  93. }
  94.  
  95. #endif
  96.  
  97. DBUS_END_DECLS
  98.  
  99. #endif
  100.