Blame _dbus_bindings/libdbusconn.c

Packit 130fc8
/* An extremely thin wrapper around a libdbus Connection, for use by
Packit 130fc8
 * Server.
Packit 130fc8
 *
Packit 130fc8
 * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
Packit 130fc8
 *
Packit 130fc8
 * Permission is hereby granted, free of charge, to any person
Packit 130fc8
 * obtaining a copy of this software and associated documentation
Packit 130fc8
 * files (the "Software"), to deal in the Software without
Packit 130fc8
 * restriction, including without limitation the rights to use, copy,
Packit 130fc8
 * modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 130fc8
 * of the Software, and to permit persons to whom the Software is
Packit 130fc8
 * furnished to do so, subject to the following conditions:
Packit 130fc8
 *
Packit 130fc8
 * The above copyright notice and this permission notice shall be
Packit 130fc8
 * included in all copies or substantial portions of the Software.
Packit 130fc8
 *
Packit 130fc8
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 130fc8
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 130fc8
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 130fc8
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Packit 130fc8
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
Packit 130fc8
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit 130fc8
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Packit 130fc8
 * DEALINGS IN THE SOFTWARE.
Packit 130fc8
 */
Packit 130fc8
Packit 130fc8
#include "dbus_bindings-internal.h"
Packit 130fc8
#include "conn-internal.h"
Packit 130fc8
Packit 130fc8
PyDoc_STRVAR(DBusPyLibDBusConnection_tp_doc,
Packit 130fc8
"A reference to a ``DBusConnection`` from ``libdbus``, which might not\n"
Packit 130fc8
"have been attached to a `dbus.connection.Connection` yet.\n"
Packit 130fc8
"\n"
Packit 130fc8
"Cannot be instantiated from Python. The only use of this object is to\n"
Packit 130fc8
"pass it to the ``dbus.connection.Connection`` constructor instead of an\n"
Packit 130fc8
"address.\n"
Packit 130fc8
);
Packit 130fc8
Packit 130fc8
/** Create a DBusPyLibDBusConnection from a DBusConnection.
Packit 130fc8
 */
Packit 130fc8
PyObject *
Packit 130fc8
DBusPyLibDBusConnection_New(DBusConnection *conn)
Packit 130fc8
{
Packit 130fc8
    DBusPyLibDBusConnection *self = NULL;
Packit 130fc8
Packit 130fc8
    DBUS_PY_RAISE_VIA_NULL_IF_FAIL(conn);
Packit 130fc8
Packit 130fc8
    self = (DBusPyLibDBusConnection *)(DBusPyLibDBusConnection_Type.tp_alloc(
Packit 130fc8
        &DBusPyLibDBusConnection_Type, 0));
Packit 130fc8
Packit 130fc8
    if (!self)
Packit 130fc8
        return NULL;
Packit 130fc8
Packit 130fc8
    self->conn = dbus_connection_ref (conn);
Packit 130fc8
Packit 130fc8
    return (PyObject *)self;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
/* Destructor */
Packit 130fc8
static void
Packit 130fc8
DBusPyLibDBusConnection_tp_dealloc(Connection *self)
Packit 130fc8
{
Packit 130fc8
    DBusConnection *conn = self->conn;
Packit 130fc8
    PyObject *et, *ev, *etb;
Packit 130fc8
Packit 130fc8
    /* avoid clobbering any pending exception */
Packit 130fc8
    PyErr_Fetch(&et, &ev, &etb;;
Packit 130fc8
Packit 130fc8
    self->conn = NULL;
Packit 130fc8
Packit 130fc8
    if (conn) {
Packit 130fc8
        dbus_connection_unref(conn);
Packit 130fc8
    }
Packit 130fc8
Packit 130fc8
    PyErr_Restore(et, ev, etb);
Packit 130fc8
    (Py_TYPE(self)->tp_free)((PyObject *) self);
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
PyTypeObject DBusPyLibDBusConnection_Type = {
Packit 130fc8
    PyVarObject_HEAD_INIT(NULL, 0)
Packit 130fc8
    "_dbus_bindings._LibDBusConnection",
Packit 130fc8
    sizeof(DBusPyLibDBusConnection),
Packit 130fc8
    0,                      /*tp_itemsize*/
Packit 130fc8
    /* methods */
Packit 130fc8
    (destructor)DBusPyLibDBusConnection_tp_dealloc,
Packit 130fc8
    0,                      /*tp_print*/
Packit 130fc8
    0,                      /*tp_getattr*/
Packit 130fc8
    0,                      /*tp_setattr*/
Packit 130fc8
    0,                      /*tp_compare*/
Packit 130fc8
    0,                      /*tp_repr*/
Packit 130fc8
    0,                      /*tp_as_number*/
Packit 130fc8
    0,                      /*tp_as_sequence*/
Packit 130fc8
    0,                      /*tp_as_mapping*/
Packit 130fc8
    0,                      /*tp_hash*/
Packit 130fc8
    0,                      /*tp_call*/
Packit 130fc8
    0,                      /*tp_str*/
Packit 130fc8
    0,                      /*tp_getattro*/
Packit 130fc8
    0,                      /*tp_setattro*/
Packit 130fc8
    0,                      /*tp_as_buffer*/
Packit 130fc8
    Py_TPFLAGS_DEFAULT,
Packit 130fc8
    DBusPyLibDBusConnection_tp_doc,
Packit 130fc8
};
Packit 130fc8
Packit 130fc8
dbus_bool_t
Packit 130fc8
dbus_py_init_libdbus_conn_types(void)
Packit 130fc8
{
Packit 130fc8
    if (PyType_Ready(&DBusPyLibDBusConnection_Type) < 0)
Packit 130fc8
        return FALSE;
Packit 130fc8
Packit 130fc8
    return TRUE;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
dbus_bool_t
Packit 130fc8
dbus_py_insert_libdbus_conn_types(PyObject *this_module)
Packit 130fc8
{
Packit 130fc8
    /* PyModule_AddObject steals a ref */
Packit 130fc8
    Py_INCREF (&DBusPyLibDBusConnection_Type);
Packit 130fc8
Packit 130fc8
    if (PyModule_AddObject(this_module, "_LibDBusConnection",
Packit 130fc8
                           (PyObject *)&DBusPyLibDBusConnection_Type) < 0)
Packit 130fc8
        return FALSE;
Packit 130fc8
Packit 130fc8
    return TRUE;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
/* vim:set ft=c cino< sw=4 sts=4 et: */