Debian Codegraph @

test/test-profile

raw symbols SCIP
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 from __future__ import absolute_import, print_function, unicode_literals
5
6 from optparse import OptionParser, make_option
7 import os
8 import sys
9 import uuid
10 import dbus
11 import dbus.service
12 import dbus.mainloop.glib
13 try:
14 from gi.repository import GObject
15 except ImportError:
16 import gobject as GObject
17
18 class Profile(dbus.service.Object):
19 fd = -1
20
21 @dbus.service.method("org.bluez.Profile1",
22 in_signature="", out_signature="")
23 def Release(self):
24 print("Release")
25 mainloop.quit()
26
27 @dbus.service.method("org.bluez.Profile1",
28 in_signature="", out_signature="")
29 def Cancel(self):
30 print("Cancel")
31
32 @dbus.service.method("org.bluez.Profile1",
33 in_signature="oha{sv}", out_signature="")
34 def NewConnection(self, path, fd, properties):
35 self.fd = fd.take()
36 print("NewConnection(%s, %d)" % (path, self.fd))
37 for key in properties.keys():
38 if key == "Version" or key == "Features":
39 print(" %s = 0x%04x" % (key, properties[key]))
40 else:
41 print(" %s = %s" % (key, properties[key]))
42
43 @dbus.service.method("org.bluez.Profile1",
44 in_signature="o", out_signature="")
45 def RequestDisconnection(self, path):
46 print("RequestDisconnection(%s)" % (path))
47
48 if (self.fd > 0):
49 os.close(self.fd)
50 self.fd = -1
51
52 if __name__ == '__main__':
53 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
54
55 bus = dbus.SystemBus()
56
57 manager = dbus.Interface(bus.get_object("org.bluez",
58 "/org/bluez"), "org.bluez.ProfileManager1")
59
60 option_list = [
61 make_option("-u", "--uuid", action="store",
62 type="string", dest="uuid",
63 default=None),
64 make_option("-p", "--path", action="store",
65 type="string", dest="path",
66 default="/foo/bar/profile"),
67 make_option("-n", "--name", action="store",
68 type="string", dest="name",
69 default=None),
70 make_option("-s", "--server",
71 action="store_const",
72 const="server", dest="role"),
73 make_option("-c", "--client",
74 action="store_const",
75 const="client", dest="role"),
76 make_option("-a", "--auto-connect",
77 action="store_true",
78 dest="auto_connect", default=False),
79 make_option("-P", "--PSM", action="store",
80 type="int", dest="psm",
81 default=None),
82 make_option("-C", "--channel", action="store",
83 type="int", dest="channel",
84 default=None),
85 make_option("-r", "--record", action="store",
86 type="string", dest="record",
87 default=None),
88 make_option("-S", "--service", action="store",
89 type="string", dest="service",
90 default=None),
91 ]
92
93 parser = OptionParser(option_list=option_list)
94
95 (options, args) = parser.parse_args()
96
97 profile = Profile(bus, options.path)
98
99 mainloop = GObject.MainLoop()
100
101 opts = {
102 "AutoConnect" : options.auto_connect,
103 }
104
105 if (options.name):
106 opts["Name"] = options.name
107
108 if (options.role):
109 opts["Role"] = options.role
110
111 if (options.psm is not None):
112 opts["PSM"] = dbus.UInt16(options.psm)
113
114 if (options.channel is not None):
115 opts["Channel"] = dbus.UInt16(options.channel)
116
117 if (options.record):
118 opts["ServiceRecord"] = options.record
119
120 if (options.service):
121 opts["Service"] = options.service
122
123 if not options.uuid:
124 options.uuid = str(uuid.uuid4())
125
126 manager.RegisterProfile(options.path, options.uuid, opts)
127
128 mainloop.run()