3 from __future__ import absolute_import, print_function, unicode_literals
5 from optparse import OptionParser, make_option
11 import dbus.mainloop.glib
13 from gi.repository import GObject
15 import gobject as GObject
17 class Profile(dbus.service.Object):
20 @dbus.service.method("org.bluez.Profile1",
21 in_signature="", out_signature="")
26 @dbus.service.method("org.bluez.Profile1",
27 in_signature="", out_signature="")
31 @dbus.service.method("org.bluez.Profile1",
32 in_signature="oha{sv}", out_signature="")
33 def NewConnection(self, path, fd, properties):
35 print("NewConnection(%s, %d)" % (path, self.fd))
36 for key in properties.keys():
37 if key == "Version" or key == "Features":
38 print(" %s = 0x%04x" % (key, properties[key]))
40 print(" %s = %s" % (key, properties[key]))
42 @dbus.service.method("org.bluez.Profile1",
43 in_signature="o", out_signature="")
44 def RequestDisconnection(self, path):
45 print("RequestDisconnection(%s)" % (path))
51 if __name__ == '__main__':
52 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
54 bus = dbus.SystemBus()
56 manager = dbus.Interface(bus.get_object("org.bluez",
57 "/org/bluez"), "org.bluez.ProfileManager1")
60 make_option("-u", "--uuid", action="store",
61 type="string", dest="uuid",
63 make_option("-p", "--path", action="store",
64 type="string", dest="path",
65 default="/foo/bar/profile"),
66 make_option("-n", "--name", action="store",
67 type="string", dest="name",
69 make_option("-s", "--server",
71 const="server", dest="role"),
72 make_option("-c", "--client",
74 const="client", dest="role"),
75 make_option("-a", "--auto-connect",
77 dest="auto_connect", default=False),
78 make_option("-P", "--PSM", action="store",
79 type="int", dest="psm",
81 make_option("-C", "--channel", action="store",
82 type="int", dest="channel",
84 make_option("-r", "--record", action="store",
85 type="string", dest="record",
87 make_option("-S", "--service", action="store",
88 type="string", dest="service",
92 parser = OptionParser(option_list=option_list)
94 (options, args) = parser.parse_args()
96 profile = Profile(bus, options.path)
98 mainloop = GObject.MainLoop()
101 "AutoConnect" : options.auto_connect,
105 opts["Name"] = options.name
108 opts["Role"] = options.role
110 if (options.psm is not None):
111 opts["PSM"] = dbus.UInt16(options.psm)
113 if (options.channel is not None):
114 opts["Channel"] = dbus.UInt16(options.channel)
117 opts["ServiceRecord"] = options.record
119 if (options.service):
120 opts["Service"] = options.service
123 options.uuid = str(uuid.uuid4())
125 manager.RegisterProfile(options.path, options.uuid, opts)