9 import util.go_utils as gobject_utils
13 _moduleLogger = logging.getLogger("tp_utils")
14 DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
17 class WasMissedCall(object):
19 def __init__(self, bus, conn, chan, on_success, on_error):
20 self._on_success = on_success
21 self._on_error = on_error
23 self._requested = None
24 self._didMembersChange = False
25 self._didClose = False
26 self._didReport = False
28 self._onTimeout = misc.Timeout(self._on_timeout)
29 self._onTimeout.start(seconds=10)
31 chan[telepathy.interfaces.CHANNEL_INTERFACE_GROUP].connect_to_signal(
33 self._on_members_changed,
36 chan[telepathy.interfaces.CHANNEL].connect_to_signal(
41 chan[DBUS_PROPERTIES].GetAll(
42 telepathy.interfaces.CHANNEL_INTERFACE,
43 reply_handler = self._on_got_all,
44 error_handler = self._on_got_all,
48 self._report_error("by request")
50 def _report_missed_if_ready(self):
53 elif self._requested is not None and (self._didMembersChange or self._didClose):
55 self._report_error("wrong direction")
57 self._report_success()
59 self._report_error("members added")
62 self._report_error("closed too early")
64 def _report_success(self):
65 assert not self._didReport
66 self._didReport = True
67 self._onTimeout.cancel()
68 self._on_success(self)
70 def _report_error(self, reason):
71 assert not self._didReport
72 self._didReport = True
73 self._onTimeout.cancel()
74 self._on_error(self, reason)
76 @misc.log_exception(_moduleLogger)
77 def _on_got_all(self, properties):
78 self._requested = properties["Requested"]
79 self._report_missed_if_ready()
81 @misc.log_exception(_moduleLogger)
82 def _on_members_changed(self, message, added, removed, lp, rp, actor, reason):
84 self._didMembersChange = True
85 self._report_missed_if_ready()
87 @misc.log_exception(_moduleLogger)
90 self._report_missed_if_ready()
92 @misc.log_exception(_moduleLogger)
93 def _on_error(self, *args):
94 self._report_error(args)
96 @misc.log_exception(_moduleLogger)
97 def _on_timeout(self):
98 self._report_error("timeout")
102 class NewChannelSignaller(object):
104 def __init__(self, on_new_channel):
105 self._sessionBus = dbus.SessionBus()
106 self._on_user_new_channel = on_new_channel
109 self._sessionBus.add_signal_receiver(
110 self._on_new_channel,
112 "org.freedesktop.Telepathy.Connection",
118 self._sessionBus.remove_signal_receiver(
119 self._on_new_channel,
121 "org.freedesktop.Telepathy.Connection",
126 @misc.log_exception(_moduleLogger)
128 self, channelObjectPath, channelType, handleType, handle, supressHandler
130 connObjectPath = channel_path_to_conn_path(channelObjectPath)
131 serviceName = path_to_service_name(channelObjectPath)
132 self._on_user_new_channel(
133 self._sessionBus, serviceName, connObjectPath, channelObjectPath, channelType
137 def channel_path_to_conn_path(channelObjectPath):
139 >>> channel_path_to_conn_path("/org/freedesktop/Telepathy/ConnectionManager/theonering/sip/USERNAME/Channel1")
140 '/org/freedesktop/Telepathy/ConnectionManager/theonering/sip/USERNAME'
142 return channelObjectPath.rsplit("/", 1)[0]
145 def path_to_service_name(path):
147 >>> path_to_service_name("/org/freedesktop/Telepathy/ConnectionManager/theonering/sip/USERNAME/Channel1")
148 'org.freedesktop.Telepathy.ConnectionManager.theonering.sip.USERNAME'
150 return ".".join(path[1:].split("/")[0:7])
153 def cm_from_path(path):
155 >>> cm_from_path("/org/freedesktop/Telepathy/ConnectionManager/theonering/sip/USERNAME/Channel1")
158 return path[1:].split("/")[4]