From 007e2c7b70cf9310e9e6056e24ad8f6123958a61 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 26 Mar 2010 07:01:12 -0500 Subject: [PATCH] Switching over to coroutine trampolines --- src/channel/call.py | 47 +++++++++++++++++++++++++++++++++++++++-------- src/channel/text.py | 33 ++++++++++++++++++--------------- 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/channel/call.py b/src/channel/call.py index a2f2ef3..2d3af62 100644 --- a/src/channel/call.py +++ b/src/channel/call.py @@ -104,8 +104,8 @@ class CallChannel( self.remove_from_connection() if self.__calledNumber is not None: - _moduleLogger.debug("Cancelling call") - self._conn.session.backend.cancel(self.__calledNumber) + le = gobject_utils.LinearExecution(self._cancel) + le.start() @misc_utils.log_exception(_moduleLogger) def GetLocalPendingMembersWithInfo(self): @@ -162,13 +162,9 @@ class CallChannel( """ contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId) assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact) - contactNumber = contact.phoneNumber - self.__calledNumber = contactNumber - self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING) - self._conn.session.backend.call(contactNumber) - self._delayedClose.start(seconds=0) - self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED) + le = gobject_utils.LinearExecution(self._call) + le.start(contact) streamId = 0 streamState = telepathy.constants.MEDIA_STREAM_STATE_CONNECTED @@ -176,6 +172,41 @@ class CallChannel( pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)] + def _call(self, contact, on_success, on_error): + contactNumber = contact.phoneNumber + + self.__calledNumber = contactNumber + self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING) + + try: + result = yield self._conn.session.pool.add_task, ( + self._conn.session.backend.call, + (contactNumber, ), + {}, + on_success, + on_error, + ), {} + except Exception: + _moduleLogger.exception(result) + return + + self._delayedClose.start(seconds=0) + self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED) + + def _cancel(self, on_success, on_error): + _moduleLogger.debug("Cancelling call") + try: + result = yield self._conn.session.pool.add_task, ( + self._conn.session.backend.cancel, + (self.__calledNumber, ), + {}, + on_success, + on_error, + ), {} + except Exception: + _moduleLogger.exception(result) + return + @misc_utils.log_exception(_moduleLogger) def GetCallStates(self): """ diff --git a/src/channel/text.py b/src/channel/text.py index 1f15dbf..1fd7d1e 100644 --- a/src/channel/text.py +++ b/src/channel/text.py @@ -6,6 +6,7 @@ import telepathy import tp import util.coroutines as coroutines import util.misc as misc_utils +import util.go_utils as gobject_utils import gvoice @@ -54,27 +55,29 @@ class TextChannel(tp.ChannelTypeText): @misc_utils.log_exception(_moduleLogger) def Send(self, messageType, text): + le = gobject_utils.LinearExecution(self._send) + le.start(messageType, text) + + def _send(self, messageType, text, on_success, on_error): if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: raise telepathy.errors.NotImplemented("Unhandled message type: %r" % messageType) _moduleLogger.info("Sending message to %r" % (self.__otherHandle, )) - self._conn.session.pool.add_task( - self._conn.session.backend.send_sms, - ([self.__otherHandle.phoneNumber], text), - {}, - self._on_send_sms(messageType, text), - self._on_send_sms_failed, - ) - - def _on_send_sms(self, messageType, text): - - @misc_utils.log_exception(_moduleLogger) - def _actual_on_send_sms(self, *args): - self._conn.session.textsStateMachine.reset_timers() + try: + result = yield self._conn.session.pool.add_task, ( + self._conn.session.backend.send_sms, + ([self.__otherHandle.phoneNumber], text), + {}, + on_success, + on_error, + ), {} + except Exception: + _moduleLogger.exception(result) + return - self.Sent(int(time.time()), messageType, text) + self._conn.session.textsStateMachine.reset_timers() - return _actual_on_send_sms + self.Sent(int(time.time()), messageType, text) @misc_utils.log_exception(_moduleLogger) def _on_send_sms_failed(self, error): -- 1.7.9.5