1515import dbus_objects .types
1616
1717
18- class _StandardInterfacesObject (dbus_objects .object .DBusObject ):
18+ class _Introspectable (dbus_objects .object .DBusObject ):
1919 '''
20- Standard DBus interfaces implementation
21-
22- Provides:
23- - org.freedesktop.DBus.Peer
24- - org.freedesktop.DBus.Introspectable
25- - org.freedesktop.DBus.Properties
26- - org.freedesktop.DBus.ObjectManager
20+ https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-introspectable
2721 '''
2822 _XML_DOCTYPE = textwrap .dedent ('''\
2923 <!DOCTYPE node PUBLIC
@@ -33,20 +27,17 @@ class _StandardInterfacesObject(dbus_objects.object.DBusObject):
3327
3428 def __init__ (self , path : str , dbus_tree : treelib .Tree ):
3529 '''
36- :param methods: dictionary holding the registered DBus methods
30+ :param path: path where the onject is being resgistered
31+ :param dbus_tree: DBus server tree
3732 '''
38- super ().__init__ ()
33+ super ().__init__ (
34+ name = 'Introspectable' ,
35+ default_interface_root = 'org.freedesktop.DBus' ,
36+ )
3937 self ._path = path
4038 self ._tree = dbus_tree
4139
42- @dbus_objects .object .dbus_method (interface = 'org.freedesktop.DBus.Peer' )
43- def ping (self ) -> None :
44- return
45-
46- @dbus_objects .object .dbus_method (
47- interface = 'org.freedesktop.DBus.Introspectable' ,
48- return_names = ('xml' ,),
49- )
40+ @dbus_objects .object .dbus_method (return_names = ('xml' ,))
5041 def introspect (self ) -> str :
5142 xml = ET .Element ('node' , {'xmlns:doc' : 'http://www.freedesktop.org/dbus/1.0/doc.dtd' })
5243
@@ -65,10 +56,53 @@ def introspect(self) -> str:
6556
6657 return self ._XML_DOCTYPE + ET .tostring (xml ).decode ()
6758
68- @dbus_objects .object .dbus_method (interface = 'org.freedesktop.DBus.Properties' )
59+
60+ class _Peer (dbus_objects .object .DBusObject ):
61+ '''
62+ https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-peer
63+ '''
64+ def __init__ (self ) -> None :
65+ super ().__init__ (
66+ name = 'Peer' ,
67+ default_interface_root = 'org.freedesktop.DBus' ,
68+ )
69+
70+ @dbus_objects .object .dbus_method ()
71+ def ping (self ) -> None :
72+ return
73+
74+ # TODO: GetMachineId() - how to reliably get the ID?
75+
76+
77+ class _Properties (dbus_objects .object .DBusObject ):
78+ '''
79+ https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties
80+ '''
81+ def __init__ (self ) -> None :
82+ super ().__init__ (
83+ name = 'Properties' ,
84+ default_interface_root = 'org.freedesktop.DBus' ,
85+ )
86+
87+ @dbus_objects .object .dbus_method ()
88+ def get (self , interface_name : str , property_name : str ) -> dbus_objects .types .Variant :
89+ # TODO: interface == ''
90+ return '' , None
91+
92+ @dbus_objects .object .dbus_method (name = 'set' )
93+ def set_ (self , interface_name : str , property_name : str , value : dbus_objects .types .Variant ) -> None :
94+ # TODO: interface == ''
95+ pass
96+
97+ @dbus_objects .object .dbus_method ()
6998 def get_all (self , interface_name : str ) -> Dict [str , dbus_objects .types .Variant ]:
7099 return {}
71100
101+ # TODO: PropertiesChanged
102+
103+
104+ # TODO: org.freedesktop.DBus.ObjectManager
105+
72106
73107class DBusServerBase ():
74108 def __init__ (self , bus : str , name : str ) -> None :
@@ -139,11 +173,13 @@ def register_object(self, path: str, obj: dbus_objects.object.DBusObject) -> Non
139173 self .__logger .debug (f'registering { obj .dbus_name } in { path } ' )
140174 # TODO: validate paths, interfaces and method names
141175 self ._register_object (path , obj )
176+ self ._register_object (path , _Properties (), ignore_warn = True )
142177 do = True
143178 while do :
179+ self ._register_object (path , _Peer (), ignore_warn = True )
144180 self ._register_object (
145181 path ,
146- _StandardInterfacesObject (path , self ._tree ),
182+ _Introspectable (path , self ._tree ),
147183 ignore_warn = True
148184 )
149185 do = path != '/'
0 commit comments