summaryrefslogtreecommitdiff
path: root/test/monitor-state
blob: d17c0e5ab240acd81c8df5c29fd90f4af29d924b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python

import gobject

import dbus
import dbus.service
import dbus.mainloop.glib

internet_path = ""

def get_properties(path):
	element = dbus.Interface(bus.get_object("org.moblin.connman", path),
						"org.moblin.connman.Element")

	return element.GetProperties()

def element_added(path):
	global internet_path
	properties = get_properties(path)
	if (properties["Type"] == "dhcp"):
		print "Aquiring IP address"
	if (properties["Type"] == "ipv4"):
		print "IP address assigned"
	if (properties["Type"] == "internet"):
		internet_path = path
		print "Succesfully connected"

def element_updated(path):
	properties = get_properties(path)
	if (properties["Type"] == "network" and properties["Connected"] == 1):
		print "Associated with %s" % (properties["SSID"])

def element_removed(path):
	global internet_path
	if (path == internet_path):
		internet_path = ""
		print "Connection terminated"

if __name__ == '__main__':
	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

	bus = dbus.SystemBus()

	bus.add_signal_receiver(element_added,
				dbus_interface = "org.moblin.connman.Manager",
						signal_name = "ElementAdded")

	bus.add_signal_receiver(element_updated,
				dbus_interface = "org.moblin.connman.Manager",
						signal_name = "ElementUpdated")

	bus.add_signal_receiver(element_removed,
				dbus_interface = "org.moblin.connman.Manager",
						signal_name = "ElementRemoved")

	mainloop = gobject.MainLoop()
	mainloop.run()