1 /* Implementation of normal Python-accessible methods on the _dbus_bindings
2 * Connection type; separated out to keep the file size manageable.
4 * Copyright (C) 2008 Huang Peng <phuang@redhat.com> .
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 #include "dbus_bindings-internal.h"
28 #include "server-internal.h"
30 PyDoc_STRVAR(Server_disconnect__doc__
,
32 "Releases the server's address and stops listening for new clients.\n");
34 Server_disconnect (Server
*self
, PyObject
*args UNUSED
)
37 DBUS_PY_RAISE_VIA_NULL_IF_FAIL(self
->server
);
38 Py_BEGIN_ALLOW_THREADS
39 dbus_server_disconnect(self
->server
);
48 PyDoc_STRVAR(Server_get_address__doc__
,
49 "get_address() -> String\n\n"
50 "Return the address of the server.\n");
52 Server_get_address (Server
*self
, PyObject
*args UNUSED
)
58 DBUS_PY_RAISE_VIA_NULL_IF_FAIL(self
->server
);
59 Py_BEGIN_ALLOW_THREADS
60 address
= dbus_server_get_address(self
->server
);
62 ret
= PyString_FromString(address
);
67 PyDoc_STRVAR(Server_get_id__doc__
,
68 "get_id() -> String\n\n"
69 "Return the id of the server.\n");
71 Server_get_id (Server
*self
, PyObject
*args UNUSED
)
77 DBUS_PY_RAISE_VIA_NULL_IF_FAIL(self
->server
);
78 Py_BEGIN_ALLOW_THREADS
79 id
= dbus_server_get_id(self
->server
);
82 ret
= PyString_FromString(id
);
88 PyDoc_STRVAR(Server_get_is_connected__doc__
,
89 "get_is_connected() -> bool\n\n"
90 "Return True if server is istill listening new connections.\n");
92 Server_get_is_connected (Server
*self
, PyObject
*args UNUSED
)
97 DBUS_PY_RAISE_VIA_NULL_IF_FAIL(self
->server
);
98 Py_BEGIN_ALLOW_THREADS
99 if (dbus_server_get_is_connected(self
->server
))
111 PyDoc_STRVAR(Server_set_new_connection_function__doc__
,
112 "set_new_connection_function()\n\n"
113 "Set a function for handling new connections.\n");
115 Server_set_new_connection_function (Server
*self
, PyObject
*args
)
119 PyTypeObject
*conn_type
= NULL
;
121 if (!PyArg_ParseTuple(args
, "O|O:set_new_connection_function",
122 &callback
, &conn_type
)) {
126 if (callback
!= Py_None
&& ! PyCallable_Check (callback
)) {
127 PyErr_SetString (PyExc_TypeError
,
128 "The first argument must be a callable object");
132 if (!conn_type
|| (PyObject
*)conn_type
== Py_None
) {
133 conn_type
= &DBusPyConnection_Type
;
136 if (!PyType_IsSubtype (conn_type
, &DBusPyConnection_Type
)) {
137 PyErr_SetString (PyExc_TypeError
,
138 "The second argument must be None or Subclass of _dbus_bindings_.Connection");
143 DBUS_PY_RAISE_VIA_NULL_IF_FAIL(self
->server
);
144 Py_BEGIN_ALLOW_THREADS
145 Py_XDECREF (self
->new_connection_callback
);
146 if (callback
!= Py_None
) {
147 Py_INCREF (callback
);
148 self
->new_connection_callback
= callback
;
151 self
->new_connection_callback
= NULL
;
153 Py_XDECREF (self
->new_connection_type
);
154 Py_INCREF (conn_type
);
155 self
->new_connection_type
= conn_type
;
164 PyDoc_STRVAR(Server_set_auth_mechanisms__doc__
,
165 "set_auth_mechanisms (...)\n\n"
166 "Set the authentication mechanisms that this server offers to clients.\n");
168 Server_set_auth_mechanisms (Server
*self
, PyObject
*args
)
172 const char ** _mechanisms
= NULL
;
174 len
= PyTuple_Size (args
);
177 _mechanisms
= (const char **)malloc (sizeof (char *) * (len
+ 1));
178 for (i
= 0; i
< len
; i
++) {
179 PyObject
*mechanism
= PyTuple_GetItem (args
, i
);
180 if (!PyString_Check (mechanism
)) {
182 PyErr_SetString(PyExc_TypeError
,
183 "arguments must be strings");
186 _mechanisms
[i
] = PyString_AS_STRING (mechanism
);
188 _mechanisms
[len
] = NULL
;
192 DBUS_PY_RAISE_VIA_NULL_IF_FAIL(self
->server
);
193 Py_BEGIN_ALLOW_THREADS
194 dbus_server_set_auth_mechanisms (self
->server
, _mechanisms
);
197 if (_mechanisms
!= NULL
)
203 struct PyMethodDef DBusPyServer_tp_methods
[] = {
204 #define ENTRY(name, flags) {#name, (PyCFunction)Server_##name, flags, Server_##name##__doc__}
205 ENTRY(disconnect
, METH_NOARGS
),
206 ENTRY(get_address
, METH_NOARGS
),
207 ENTRY(get_id
, METH_NOARGS
),
208 ENTRY(get_is_connected
, METH_NOARGS
),
209 ENTRY(set_new_connection_function
, METH_VARARGS
),
210 ENTRY(set_auth_mechanisms
, METH_VARARGS
),
215 /* vim:set ft=c cino< sw=4 sts=4 et: */