3 from __future__ import absolute_import, print_function, unicode_literals
10 import dbus.mainloop.glib
12 from gi.repository import GObject
14 import gobject as GObject
16 BUS_NAME = 'org.bluez'
17 ALERT_INTERFACE = 'org.bluez.Alert1'
18 ALERT_AGENT_INTERFACE = 'org.bluez.AlertAgent1'
19 BLUEZ_OBJECT_PATH = '/org/bluez'
20 TEST_OBJECT_PATH = '/org/bluez/test'
22 class AlertAgent(dbus.service.Object):
23 def __init__(self, bus, object_path, alert, mainloop):
24 dbus.service.Object.__init__(self, bus, object_path)
26 self.mainloop = mainloop
28 @dbus.service.method(ALERT_AGENT_INTERFACE, in_signature='',
31 print('method MuteOnce() was called')
32 self.alert.NewAlert('ringer', 1, 'not active')
34 @dbus.service.method(ALERT_AGENT_INTERFACE, in_signature='s',
36 def SetRinger(self, mode):
37 print('method SetRinger(%s) was called' % mode)
38 self.alert.NewAlert('ringer', 1, mode)
40 @dbus.service.method(ALERT_AGENT_INTERFACE, in_signature='',
43 print('method Release() was called')
46 def print_command_line(options):
47 if not options.verbose:
50 print('-w: ' + str(options.wait))
53 print('-t: ' + str(options.times))
56 print('-r: ' + options.register)
58 print('-r: ' + str(None))
62 for i in options.new_alert:
63 print(' ' + i[0] + ', ' + i[1] + ', ' + i[2])
65 print('-n: ' + str(None))
67 if options.unread_alert:
69 for i in options.unread_alert:
70 print(' ' + i[0] + ', ' + i[1])
72 print('-u: ' + str(None))
78 def read_count(param):
82 print('<count> must be integer, not \"%s\"' % param)
85 def new_alert(alert, params):
91 count = read_count(param[1])
92 description = param[2]
94 alert.NewAlert(category, count, description)
96 def unread_alert(alert, params):
102 count = read_count(param[1])
104 alert.UnreadAlert(category, count)
107 optparse.make_option('-v', None,
108 action = 'store_true',
113 optparse.make_option('-w', None,
114 action = 'store_true',
117 help = 'wait for dbus events'),
119 optparse.make_option('-t', None,
124 help = 'repeat UnreadAlert/NewAlert <times> times',
125 metavar = '<times>'),
127 optparse.make_option('-r', None,
131 metavar = '<category>',
132 help = 'register alert'),
134 optparse.make_option('-n', None,
139 metavar = '<category> <count> <description>',
140 help = 'send new alert'),
142 optparse.make_option('-u', None,
144 dest = 'unread_alert',
147 metavar = '<category> <count>',
148 help = 'send unread alert'),
151 parser = optparse.OptionParser(option_list=option_list)
152 parser.disable_interspersed_args()
153 (options, args) = parser.parse_args()
155 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
156 bus = dbus.SystemBus()
157 mainloop = GObject.MainLoop()
158 alert = dbus.Interface(bus.get_object(BUS_NAME, BLUEZ_OBJECT_PATH),
160 alert_agent = AlertAgent(bus, TEST_OBJECT_PATH, alert, mainloop)
162 print_command_line(options)
164 if not (options.register or options.new_alert or options.unread_alert or
170 alert.RegisterAlert(options.register, TEST_OBJECT_PATH)
173 while times < options.times:
176 new_alert(alert, options.new_alert)
177 unread_alert(alert, options.unread_alert)