summaryrefslogtreecommitdiff
path: root/test/monitor-services
blob: c1b4cedcdfb5c7ab2280642628253f41aa6908e7 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python

import gobject

import dbus
import dbus.mainloop.glib

def extract_values(values):
	val = "{"
	for key in values.keys():
		val += " " + key + "="
		if key in ["Servers", "Excludes"]:
			val += extract_list(values[key])
		else:
			val += str(values[key])
	val += " }"
	return val

def extract_list(list):
	val = "["
	for i in list:
		val += " " + str(i)
	val += " ]"
	return val

def property_changed(name, value, path):
	service = path[path.rfind("/") + 1:]
	if name in ["Profiles", "Services", "Technologies"]:
		val = "["
		for i in value:
			val = val + " " + i[i.rfind("/") + 1:]
		val = val + " ]"
	elif name in ["IPv4", "IPv4.Configuration",
			"IPv6", "IPv6.Configuration",
			"Proxy", "Proxy.Configuration", "Ethernet"]:
		val = extract_values(value)
	elif name in ["Nameservers", "Nameservers.Configuration",
			"Domains", "Domains.Configuration",
			"Timeservers", "Timeservers.Configuration", "Security"]:
		val = extract_list(value)
	elif name in ["Strength", "Priority"]:
		val = int(value)
	else:
		val = str(value)
	print "[%s] %s = %s" % (service, name, val)

def services_changed(services, removed):
	for i in services:
		service = i[0][i[0].rfind("/") + 1:]
		print "[%s] added / update" % (service)
		for n in i[1].keys():
			property_changed(n, i[1][n], i[0])
	for i in removed:
		service = i[i.rfind("/") + 1:]
		print "[%s] removed" % (service)

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

	bus = dbus.SystemBus()

	bus.add_signal_receiver(property_changed,
				bus_name="net.connman",
				dbus_interface="net.connman.Service",
				signal_name="PropertyChanged",
				path_keyword="path")

	bus.add_signal_receiver(services_changed,
				bus_name="net.connman",
				dbus_interface="net.connman.Manager",
				signal_name="ServicesChanged")

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