1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
#!/usr/bin/python
import gobject
import dbus
import dbus.mainloop.glib
_dbus2py = {
dbus.String : unicode,
dbus.UInt32 : int,
dbus.Int32 : int,
dbus.Int16 : int,
dbus.UInt16 : int,
dbus.UInt64 : int,
dbus.Int64 : int,
dbus.Byte : int,
dbus.Boolean : bool,
dbus.ByteArray : str,
dbus.ObjectPath : str
}
def dbus2py(d):
t = type(d)
if t in _dbus2py:
return _dbus2py[t](d)
if t is dbus.Dictionary:
return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()])
if t is dbus.Array and d.signature == "y":
return "".join([chr(b) for b in d])
if t is dbus.Array or t is list:
return [dbus2py(v) for v in d]
if t is dbus.Struct or t is tuple:
return tuple([dbus2py(v) for v in d])
return d
def pretty(d):
d = dbus2py(d)
t = type(d)
if t in (dict, tuple, list) and len(d) > 0:
if t is dict:
d = ", ".join(["%s = %s" % (k, pretty(v))
for k, v in d.items()])
return "{ %s }" % d
d = " ".join([pretty(e) for e in d])
if t is tuple:
return "( %s )" % d
return str(d)
def property_changed(name, value, path, interface):
iface = interface[interface.rfind(".") + 1:]
print "{%s} [%s] %s = %s" % (iface, path, name, pretty(value))
def added(name, value, member, path, interface):
iface = interface[interface.rfind(".") + 1:]
print "{%s} [%s] %s %s" % (iface, member, name, pretty(value))
def removed(name, member, path, interface):
iface = interface[interface.rfind(".") + 1:]
print "{%s} [%s] %s" % (iface, name, member)
def event(member, path, interface):
iface = interface[interface.rfind(".") + 1:]
print "{%s} [%s] %s" % (iface, path, member)
def message(msg, args, member, path, interface):
iface = interface[interface.rfind(".") + 1:]
print "{%s} [%s] %s %s (%s)" % (iface, path, member,
msg, pretty(args))
def ussd(msg, member, path, interface):
iface = interface[interface.rfind(".") + 1:]
print "{%s} [%s] %s %s" % (iface, path, member, msg)
def value(value, member, path, interface):
iface = interface[interface.rfind(".") + 1:]
print "{%s} [%s] %s %s" % (iface, path, member, str(value))
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(property_changed,
bus_name="org.ofono",
signal_name = "PropertyChanged",
path_keyword="path",
interface_keyword="interface")
for member in ["IncomingBarringInEffect",
"OutgoingBarringInEffect",
"NearMaximumWarning"]:
bus.add_signal_receiver(event,
bus_name="org.ofono",
signal_name = member,
member_keyword="member",
path_keyword="path",
interface_keyword="interface")
for member in ["ModemAdded",
"ContextAdded",
"CallAdded",
"MessageAdded"]:
bus.add_signal_receiver(added,
bus_name="org.ofono",
signal_name = member,
member_keyword="member",
path_keyword="path",
interface_keyword="interface")
for member in ["ModemRemoved",
"ContextRemoved",
"CallRemoved",
"MessageRemoved"]:
bus.add_signal_receiver(removed,
bus_name="org.ofono",
signal_name = member,
member_keyword="member",
path_keyword="path",
interface_keyword="interface")
for member in ["DisconnectReason", "Forwarded", "BarringActive"]:
bus.add_signal_receiver(value,
bus_name="org.ofono",
signal_name = member,
member_keyword="member",
path_keyword="path",
interface_keyword="interface")
for member in ["IncomingBroadcast", "EmergencyBroadcast",
"IncomingMessage", "ImmediateMessage"]:
bus.add_signal_receiver(message,
bus_name="org.ofono",
signal_name = member,
member_keyword="member",
path_keyword="path",
interface_keyword="interface")
for member in ["NotificationReceived", "RequestReceived"]:
bus.add_signal_receiver(ussd,
bus_name="org.ofono",
signal_name = member,
member_keyword="member",
path_keyword="path",
interface_keyword="interface")
mainloop = gobject.MainLoop()
mainloop.run()
|