1 """Support code for implementing D-Bus services via GObjects."""
3 # Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation
7 # files (the "Software"), to deal in the Software without
8 # restriction, including without limitation the rights to use, copy,
9 # modify, merge, publish, distribute, sublicense, and/or sell copies
10 # of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 # DEALINGS IN THE SOFTWARE.
28 class ExportedGObjectType(gobject
.GObjectMeta
, dbus
.service
.InterfaceType
):
29 """A metaclass which inherits from both GObjectMeta and
30 `dbus.service.InterfaceType`. Used as the metaclass for `ExportedGObject`.
32 def __init__(cls
, name
, bases
, dct
):
33 gobject
.GObjectMeta
.__init
__(cls
, name
, bases
, dct
)
34 dbus
.service
.InterfaceType
.__init
__(cls
, name
, bases
, dct
)
36 class ExportedGObject(gobject
.GObject
, dbus
.service
.Object
):
37 """A GObject which is exported on the D-Bus.
39 Because GObject and `dbus.service.Object` both have custom metaclasses,
40 the naive approach using simple multiple inheritance won't work. This
41 class has `ExportedGObjectType` as its metaclass, which is sufficient
42 to make it work correctly.
44 __metaclass__
= ExportedGObjectType
46 def __init__(self
, conn
=None, object_path
=None, **kwargs
):
47 """Initialize an exported GObject.
50 `conn` : dbus.connection.Connection
51 The D-Bus connection or bus
53 The object path at which to register this object.
55 `bus_name` : dbus.service.BusName
56 A bus name to be held on behalf of this object, or None.
57 `gobject_properties` : dict
58 GObject properties to be set on the constructed object.
60 Any unrecognised keyword arguments will also be interpreted
61 as GObject properties.
63 bus_name
= kwargs
.pop('bus_name', None)
64 gobject_properties
= kwargs
.pop('gobject_properties', None)
66 if gobject_properties
is not None:
67 kwargs
.update(gobject_properties
)
68 gobject
.GObject
.__init
__(self
, **kwargs
)
69 dbus
.service
.Object
.__init
__(self
, conn
=conn
,
70 object_path
=object_path
,