dbus.service: Don't assume that exceptions passed to asynchronous callbacks are the...
[dbus-python-phuang.git] / dbus / gobject_service.py
blob17749ca6f67e0cb51fd418ea9367b15cae3fd4c3
1 """Support code for implementing D-Bus services via GObjects."""
3 # Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
5 # Licensed under the Academic Free License version 2.1
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Library General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library General Public License for more details.
17 # You should have received a copy of the GNU Library General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 import gobject
22 import dbus.service
24 class ExportedGObjectType(gobject.GObjectMeta, dbus.service.InterfaceType):
25 """A metaclass which inherits from both GObjectMeta and
26 `dbus.service.InterfaceType`. Used as the metaclass for `ExportedGObject`.
27 """
28 def __init__(cls, name, bases, dct):
29 gobject.GObjectMeta.__init__(cls, name, bases, dct)
30 dbus.service.InterfaceType.__init__(cls, name, bases, dct)
32 class ExportedGObject(gobject.GObject, dbus.service.Object):
33 """A GObject which is exported on the D-Bus.
35 Because GObject and `dbus.service.Object` both have custom metaclasses,
36 the naive approach using simple multiple inheritance won't work. This
37 class has `ExportedGObjectType` as its metaclass, which is sufficient
38 to make it work correctly.
39 """
40 __metaclass__ = ExportedGObjectType
42 def __init__(self, conn=None, object_path=None, **kwargs):
43 """Initialize an exported GObject.
45 :Parameters:
46 `conn` : dbus.connection.Connection
47 The D-Bus connection or bus
48 `object_path` : str
49 The object path at which to register this object.
50 :Keywords:
51 `bus_name` : dbus.service.BusName
52 A bus name to be held on behalf of this object, or None.
53 `gobject_properties` : dict
54 GObject properties to be set on the constructed object.
56 Any unrecognised keyword arguments will also be interpreted
57 as GObject properties.
58 """
59 bus_name = kwargs.pop('bus_name', None)
60 gobject_properties = kwargs.pop('gobject_properties', None)
62 if gobject_properties is not None:
63 kwargs.update(gobject_properties)
64 gobject.GObject.__init__(self, **kwargs)
65 dbus.service.Object.__init__(self, conn=conn,
66 object_path=object_path,
67 bus_name=bus_name)