aboutsummaryrefslogtreecommitdiff
path: root/tools/tiny_subscribe_frontend.py
blob: cfc56c7a1dc0affbb8c329bf2717df2166efb035 (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
import traceback
import dbus
import sys
import gobject

from dbus.mainloop.glib import DBusGMainLoop

def handle_signal(changed, undet):
	print "Got signal"
	print changed
	print undet

def execute_subscribe(property_names):
	bus = dbus.SessionBus()
	try:
		proxy_object_manager = bus.get_object("org.freedesktop.ContextKit","/org/freedesktop/ContextKit/Manager")
		iface_manager = dbus.Interface(proxy_object_manager, "org.freedesktop.ContextKit.Manager")
		print "Requesting the subscriber object"
		# Get the subscriber object
		new_object_path = iface_manager.GetSubscriber()
		
		print "Got an object path", new_object_path
		# And then execute the actual subscribe property_names
		
		proxy_object_subscriber = bus.get_object("org.freedesktop.ContextKit", new_object_path)
		iface_subscriber = dbus.Interface(proxy_object_subscriber, "org.freedesktop.ContextKit.Subscriber")
		
		# Connect to the signal
		print "Connecting to the signal"
		iface_subscriber.connect_to_signal("Changed", handle_signal)
		
		print "Executing the Subscribe"
		ret = iface_subscriber.Subscribe(property_names)
		
		print "Returned:", ret
		
		loop = gobject.MainLoop()
		loop.run()

	except dbus.DBusException:
		print "Caught an exception"
		traceback.print_exc()


if __name__ == "__main__":
	DBusGMainLoop(set_as_default=True)
	
	# You can write the properties of intrest directly here
	#execute_get(["Context.Device.Orientation.facingUp", "Context.Environment.Location.latitude", "Context.Environment.Location.longitude", "Context.Environment.Location.altitude"])
	
	# Or use the command line parameters
	print "Executing Subscribe with the properties", sys.argv[1:]
	execute_subscribe(sys.argv[1:])