Apply systemd-based dbus activation
[platform/upstream/at-spi2-core.git] / registryd / testregistry.py
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5 import dbus.service
6 import gobject
7
8 from dbus.mainloop.glib import DBusGMainLoop
9
10 DBusGMainLoop(set_as_default=True)
11
12 class IdleStateM (object):
13         def __init__(self, bus, loop):
14                 self._bus = bus
15                 self._loop = loop
16                 self._func = self.setup
17
18         def idle_handler(self):
19                 self._func = self._func()
20                 if self._func == None:
21                         self._func = self.teardown
22                 return True
23
24         def setup(self):
25                 self.obj = self._bus.get_object("org.a11y.atspi.Registry",
26                                                 "/org/a11y/atspi/accessible/root",
27                                                 introspect=False)
28                 self.itf = dbus.Interface(self.obj, dbus_interface="org.a11y.atspi.Accessible")
29                 return self.register_apps
30
31         def register_apps(self):
32                 #self.itf.registerApplication(":R456", ignore_reply=True)
33                 #self.itf.registerApplication(":R123", ignore_reply=True)
34                 return self.print_applications
35
36         def print_applications(self):
37                 apps = self.itf.GetChildren()
38                 print apps
39                 return self.teardown
40
41         def teardown(self):
42                 self._loop.quit()
43
44 def main(argv):
45         bus = dbus.SessionBus()
46         obj = bus.get_object("org.a11y.Bus",
47                              "/org/a11y/bus",
48                              introspect=False)
49         itf = dbus.Interface(obj, dbus_interface="org.a11y.Bus")
50         address = itf.GetAddress()
51
52         bus = dbus.bus.BusConnection(str(address))
53         loop = gobject.MainLoop()
54         stateM = IdleStateM(bus, loop)
55         gobject.idle_add(stateM.idle_handler)
56         loop.run()
57
58 if __name__=="__main__":
59         sys.exit(main(sys.argv))