test: simple-agent must monitor vpn status
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Wed, 5 Dec 2012 11:11:41 +0000 (13:11 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Wed, 5 Dec 2012 13:58:52 +0000 (15:58 +0200)
simple-agent needs to monitor vpnd status as vpnd can stop if there
are no vpn configured. When vpnd quits we must not quit the agent
as then wifi questions would not be asked from the user any more.

test/simple-agent

index f501b1e..ebb44c5 100755 (executable)
@@ -180,7 +180,6 @@ class VpnAgent(dbus.service.Object):
                                        in_signature='', out_signature='')
        def Release(self):
                print("Release VPN agent")
-               mainloop.quit()
 
        def input_cookie(self):
                response = {}
@@ -267,6 +266,21 @@ class VpnAgent(dbus.service.Object):
        def Cancel(self):
                print "Cancel"
 
+def vpnNameOwnerChanged(proxy):
+       if proxy:
+               print("vpnd is connected to system bus")
+               try:
+                       path = "/test/vpn_agent"
+                       vpn_manager = dbus.Interface(bus.get_object('net.connman.vpn',
+                                                                   "/"),
+                                                    'net.connman.vpn.Manager')
+                       vpn_manager.RegisterAgent(path)
+               except:
+                       print "vpn agent registered"
+       else:
+               print("vpnd is disconnected from system bus")
+               vpn_manager = None
+
 def print_usage():
        print "Usage:"
        print "For hidden service:"
@@ -328,6 +342,8 @@ if __name__ == '__main__':
 
        vpn_manager.RegisterAgent(path)
 
+        bus.watch_name_owner('net.connman.vpn', vpnNameOwnerChanged)
+
        mainloop = gobject.MainLoop()
        mainloop.run()