summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2008-07-14 16:41:28 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2008-07-14 16:41:28 +0100
commit87a86d7d6033cbb61271a84f20d5d25c4b4182c0 (patch)
tree9faa100c0c6552fcc168f7f257aca73f36d08c4c
parent8e213001de0523bd7971fc9251c56635a9e943db (diff)
downloaddbus-python-87a86d7d6033cbb61271a84f20d5d25c4b4182c0.tar.gz
DBusPyServer: construct a user-specified subtype of Connection
-rw-r--r--_dbus_bindings/server.c32
-rw-r--r--dbus/server.py20
2 files changed, 45 insertions, 7 deletions
diff --git a/_dbus_bindings/server.c b/_dbus_bindings/server.c
index 33dbaae..6f86417 100644
--- a/_dbus_bindings/server.c
+++ b/_dbus_bindings/server.c
@@ -2,6 +2,7 @@
* for DBusServer.
*
* Copyright (C) 2008 Openismus GmbH <http://openismus.com/>
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@@ -32,6 +33,9 @@ typedef struct {
PyObject_HEAD
DBusServer *server;
+ /* The Connection subtype for which this Server is a factory */
+ PyObject *conn_class;
+
/* Weak-references list to make server weakly referenceable */
PyObject *weaklist;
@@ -199,6 +203,7 @@ out:
static PyObject *
DBusPyServer_NewConsumingDBusServer(PyTypeObject *cls,
DBusServer *server,
+ PyObject *conn_class,
PyObject *mainloop,
PyObject *auth_mechanisms)
{
@@ -255,6 +260,9 @@ DBusPyServer_NewConsumingDBusServer(PyTypeObject *cls,
self->server = NULL;
+ Py_INCREF(conn_class);
+ self->conn_class = conn_class;
+
self->mainloop = mainloop;
mainloop = NULL; /* don't DECREF it - the DBusServer owns it now */
@@ -331,12 +339,22 @@ Server_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
DBusServer *server;
const char *address;
DBusError error;
- PyObject *self, *mainloop = NULL, *auth_mechanisms = NULL;
- static char *argnames[] = {"address", "mainloop", "auth_mechanisms", NULL};
+ PyObject *self, *conn_class, *mainloop = NULL, *auth_mechanisms = NULL;
+ static char *argnames[] = { "address", "connection_class", "mainloop",
+ "auth_mechanisms", NULL};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OO", argnames,
+ &address, &conn_class, &mainloop, &auth_mechanisms)) {
+ return NULL;
+ }
-printf("%s:%d\n", __func__, __LINE__);
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OO", argnames,
- &address, &mainloop, &auth_mechanisms)) {
+ if (!PyType_Check(conn_class) ||
+ !PyType_IsSubtype((PyTypeObject *) conn_class, &DBusPyConnection_Type)) {
+ /* strictly speaking, it can be any subtype of
+ * _dbus_bindings._Connection - but nobody else should be subtyping
+ * that, so let's keep this slightly inaccurate message */
+ PyErr_SetString(PyExc_TypeError, "connection_class must be "
+ "dbus.connection.Connection or a subtype");
return NULL;
}
@@ -351,8 +369,8 @@ printf("%s:%d\n", __func__, __LINE__);
return NULL;
}
- self = DBusPyServer_NewConsumingDBusServer(cls, server, mainloop,
- auth_mechanisms);
+ self = DBusPyServer_NewConsumingDBusServer(cls, server, conn_class,
+ mainloop, auth_mechanisms);
TRACE(self);
return self;
diff --git a/dbus/server.py b/dbus/server.py
index c7a6184..632e7cd 100644
--- a/dbus/server.py
+++ b/dbus/server.py
@@ -1,4 +1,5 @@
# Copyright (C) 2008 Openismus GmbH <http://openismus.com/>
+# Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
@@ -24,6 +25,7 @@ __all__ = ('Server', )
__docformat__ = 'reStructuredText'
from _dbus_bindings import Server as _Server
+from dbus.connection import Connection
class Server(_Server):
"""An opaque object representing a server that listens for connections from
@@ -32,6 +34,24 @@ class Server(_Server):
:Since: 0.82.5
"""
+ def __new__(cls, address, connection_class=Connection,
+ mainloop=None, auth_mechanisms=None):
+ """Construct a new Server.
+
+ :Parameters:
+ `address` : str
+ Listen on this address.
+ `connection_class` : type
+ When new connections come in, instantiate this subclass
+ of dbus.connection.Connection to represent them.
+ The default is Connection.
+ `mainloop` : dbus.mainloop.NativeMainLoop or None
+ The main loop with which to associate the new connections.
+ `auth_mechanisms` : sequence of str
+ Authentication mechanisms to allow. The default is to allow
+ any authentication mechanism supported by ``libdbus``.
+ """
+
address = property(_Server.get_address)
id = property(_Server.get_id)
is_connected = property(_Server.get_is_connected)