summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-06-08 13:00:44 +0000
committerMarcel Holtmann <marcel@holtmann.org>2008-06-08 13:00:44 +0000
commit9dc4cfca15be6a5ccf0e00864b7cb02c2a0b7ac7 (patch)
tree8c1aea2fe05062193ca9b89cca87e1c767abd327 /hcid
parent87c20ea2e74549cd671767b572bf85dbbc6ff825 (diff)
Allow adapter parameter and automatic device removal
Diffstat (limited to 'hcid')
-rwxr-xr-xhcid/simple-agent32
1 files changed, 21 insertions, 11 deletions
diff --git a/hcid/simple-agent b/hcid/simple-agent
index 47aa917e..86a5fa85 100755
--- a/hcid/simple-agent
+++ b/hcid/simple-agent
@@ -17,37 +17,37 @@ class Agent(dbus.service.Object):
@dbus.service.method("org.bluez.Agent",
in_signature="os", out_signature="")
def Authorize(self, device, uuid):
- print "Authorize (" + device + ", " + uuid + ")"
+ print "Authorize (%s, %s)" % (device, uuid)
return
@dbus.service.method("org.bluez.Agent",
in_signature="o", out_signature="s")
def RequestPinCode(self, device):
- print "RequestPinCode (" + device + ")"
+ print "RequestPinCode (%s)" % (device)
return "1234"
@dbus.service.method("org.bluez.Agent",
in_signature="o", out_signature="u")
def RequestPasskey(self, device):
- print "RequestPasskey (" + device + ")"
+ print "RequestPasskey (%s)" % (device)
return dbus.UInt32(123456)
@dbus.service.method("org.bluez.Agent",
in_signature="ou", out_signature="")
def DisplayPasskey(self, device, passkey):
- print "DisplayPasskey (" + device + ", " + passkey + ")"
+ print "DisplayPasskey (%s, %d)" % (device, passkey)
return
@dbus.service.method("org.bluez.Agent",
in_signature="ou", out_signature="")
def RequestConfirmation(self, device, passkey):
- print "RequestConfirmation (" + device + ", " + passkey + ")"
+ print "RequestConfirmation (%s, %d)" % (device, passkey)
return
@dbus.service.method("org.bluez.Agent",
in_signature="s", out_signature="")
def ConfirmModeChange(self, mode):
- print "ConfirmModeChange (" + mode + ")"
+ print "ConfirmModeChange (%s)" % (mode)
return
@dbus.service.method("org.bluez.Agent",
@@ -57,7 +57,8 @@ class Agent(dbus.service.Object):
return
def create_device_reply(reply):
- print "Got reply"
+ print "New device (%s)" % (reply)
+ sys.exit(0)
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -66,7 +67,11 @@ if __name__ == '__main__':
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
"org.bluez.Manager")
- path = manager.DefaultAdapter()
+ if len(sys.argv) > 1:
+ path = manager.FindAdapter(sys.argv[1])
+ else:
+ path = manager.DefaultAdapter()
+
adapter = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Adapter")
@@ -76,12 +81,17 @@ if __name__ == '__main__':
adapter.RegisterAgent(path, "DisplayOnly")
print "Agent registered"
- if len(sys.argv) > 1:
- adapter.CreatePairedDevice(sys.argv[1], path, "DisplayOnly",
+ mainloop = gobject.MainLoop()
+
+ if len(sys.argv) > 2:
+ if len(sys.argv) > 3:
+ device = adapter.FindDevice(sys.argv[2])
+ adapter.RemoveDevice(device)
+
+ adapter.CreatePairedDevice(sys.argv[2], path, "DisplayOnly",
reply_handler=create_device_reply,
error_handler=create_device_reply)
- mainloop = gobject.MainLoop()
mainloop.run()
#adapter.UnregisterAgent(path)