summaryrefslogtreecommitdiffstats
path: root/hcid/simple-agent
blob: d233464f448bd5ba64eb8725aa386915fac46ae2 (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
#!/usr/bin/python

import gobject

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

class Agent(dbus.service.Object):
	@dbus.service.method("org.bluez.Agent",
					in_signature="", out_signature="")
	def Release(self):
		print "Release"
		mainloop.quit()

	@dbus.service.method("org.bluez.Agent",
					in_signature="o", out_signature="s")
	def RequestPasskey(self, device):
		print "RequestPasskey (" + device + ")"
		return "1234"

	@dbus.service.method("org.bluez.Agent",
					in_signature="s", out_signature="")
	def ConfirmModeChange(self, mode):
		print "ConfirmModeChange (" + mode + ")"
		return

	@dbus.service.method("org.bluez.Agent",
					in_signature="", out_signature="")
	def Cancel(self):
		print "Cancel"
		return

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

	bus = dbus.SystemBus()
	manager = dbus.Interface(bus.get_object("org.bluez", "/"),
							"org.bluez.Manager")

	path = manager.DefaultAdapter()
	adapter = dbus.Interface(bus.get_object("org.bluez", path),
							"org.bluez.Adapter")

	path = "/test/agent"
	object = Agent(bus, path)

	adapter.RegisterAgent(path)
	print "Agent registered"

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

	#adapter.UnregisterAgent(path)
	#print "Agent unregistered"