| #!/usr/bin/python |
| |
| from __future__ import absolute_import, print_function, unicode_literals |
| |
| from gi.repository import GObject |
| |
| import sys |
| import dbus |
| import dbus.service |
| import dbus.mainloop.glib |
| from optparse import OptionParser, make_option |
| |
| class Profile(dbus.service.Object): |
| @dbus.service.method("org.bluez.Profile", |
| in_signature="", out_signature="") |
| def Release(self): |
| print("Release") |
| mainloop.quit() |
| |
| @dbus.service.method("org.bluez.Profile", |
| in_signature="", out_signature="") |
| def Cancel(self): |
| print("Cancel") |
| |
| @dbus.service.method("org.bluez.Profile", |
| in_signature="oh", out_signature="") |
| def NewConnection(self, path, fd): |
| print("NewConnection(%s, %d)" % (path, fd)) |
| |
| 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") |
| |
| option_list = [ |
| make_option("-u", "--uuid", action="store", |
| type="string", dest="uuid", |
| default="spp"), |
| make_option("-p", "--path", action="store", |
| type="string", dest="path", |
| default="/foo/bar/profile"), |
| make_option("-n", "--name", action="store", |
| type="string", dest="name", |
| default="Test Profile"), |
| make_option("-s", "--server", |
| action="store_const", |
| const="server", dest="role"), |
| make_option("-c", "--client", |
| action="store_const", |
| const="client", dest="role"), |
| make_option("-a", "--auto-connect", |
| action="store_true", |
| dest="auto_connect", default=False), |
| make_option("-P", "--PSM", action="store", |
| type="int", dest="psm"), |
| make_option("-C", "--channel", action="store", |
| type="int", dest="channel") |
| ] |
| |
| parser = OptionParser(option_list=option_list) |
| |
| (options, args) = parser.parse_args() |
| |
| profile = Profile(bus, options.path) |
| |
| mainloop = GObject.MainLoop() |
| |
| opts = { |
| "Name" : options.name, |
| "AutoConnect" : options.auto_connect, |
| } |
| |
| if (options.role): |
| opts["Role"] = options.role |
| |
| if (options.psm): |
| opts["PSM"] = dbus.UInt16(options.psm) |
| |
| if (options.channel): |
| opts["Channel"] = dbus.UInt16(options.channel) |
| |
| manager.RegisterProfile(options.path, options.uuid, opts) |
| |
| mainloop.run() |