1 """Support code for implementing D-Bus services via GObjects."""
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import gobject
26 import dbus.service
27
29 """A metaclass which inherits from both GObjectMeta and
30 `dbus.service.InterfaceType`. Used as the metaclass for `ExportedGObject`.
31 """
35
37 """A GObject which is exported on the D-Bus.
38
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.
43 """
44 __metaclass__ = ExportedGObjectType
45
46 - def __init__(self, conn=None, object_path=None, **kwargs):
47 """Initialize an exported GObject.
48
49 :Parameters:
50 `conn` : dbus.connection.Connection
51 The D-Bus connection or bus
52 `object_path` : str
53 The object path at which to register this object.
54 :Keywords:
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.
59
60 Any unrecognised keyword arguments will also be interpreted
61 as GObject properties.
62 """
63 bus_name = kwargs.pop('bus_name', None)
64 gobject_properties = kwargs.pop('gobject_properties', None)
65
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,
71 bus_name=bus_name)
72