X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fchannel%2Fcall.py;h=aefc59861a1cede286d4094bf8fc35101f2ff19d;hb=9a66ee82112baa3a5271f26432fa688097b2a133;hp=621c9e6f38a53b9d4adc2c71d80f7716eac14b2d;hpb=de06f51c7500af5a758dd8314a01b45047a6da70;p=theonering diff --git a/src/channel/call.py b/src/channel/call.py index 621c9e6..aefc598 100644 --- a/src/channel/call.py +++ b/src/channel/call.py @@ -13,8 +13,9 @@ _moduleLogger = logging.getLogger(__name__) class CallChannel( tp.ChannelTypeStreamedMedia, - tp.ChannelInterfaceCallState, tp.ChannelInterfaceGroup, + tp.ChannelInterfaceCallState, + tp.ChannelInterfaceHold, ): def __init__(self, connection, manager, props, contactHandle): @@ -42,10 +43,11 @@ class CallChannel( self._initiator = connection.GetSelfHandle() tp.ChannelTypeStreamedMedia.__init__(self, connection, manager, props) - tp.ChannelInterfaceCallState.__init__(self) tp.ChannelInterfaceGroup.__init__(self) + tp.ChannelInterfaceCallState.__init__(self) + tp.ChannelInterfaceHold.__init__(self) self.__contactHandle = contactHandle - self.__calledNumer = None + self.__calledNumber = None self._implement_property_get( telepathy.interfaces.CHANNEL_INTERFACE, @@ -77,8 +79,10 @@ class CallChannel( }) self.GroupFlagsChanged(0, 0) + added, removed = [self._conn.GetSelfHandle()], [] + localPending, remotePending = [], [contactHandle] self.MembersChanged( - '', [self._conn.GetSelfHandle()], [], [], [contactHandle], + '', added, removed, localPending, remotePending, 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE ) @@ -94,11 +98,14 @@ class CallChannel( def close(self): _moduleLogger.debug("Closing call") + self._delayedClose.cancel() + tp.ChannelTypeStreamedMedia.Close(self) self.remove_from_connection() - if self.__calledNumer is not None: - self._conn.session.backend.cancel(self.__calledNumer) - self._delayedClose.cancel() + + if self.__calledNumber is not None: + le = gobject_utils.AsyncLinearExecution(self._conn.session.pool, self._cancel) + le.start() @misc_utils.log_exception(_moduleLogger) def GetLocalPendingMembersWithInfo(self): @@ -155,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.__calledNumer = contactNumber - self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING) - self._conn.session.backend.call(contactNumber) - self._delayedClose.start(seconds=5) - self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED) + le = gobject_utils.AsyncLinearExecution(self._conn.session.pool, self._call) + le.start(contact) streamId = 0 streamState = telepathy.constants.MEDIA_STREAM_STATE_CONNECTED @@ -170,6 +173,39 @@ class CallChannel( return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)] @misc_utils.log_exception(_moduleLogger) + def _call(self, contact): + contactNumber = contact.phoneNumber + + self.__calledNumber = contactNumber + self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING) + + try: + result = yield ( + self._conn.session.backend.call, + (contactNumber, ), + {}, + ) + except Exception: + _moduleLogger.exception("While placing call to %s" % (self.__calledNumber, )) + return + + self._delayedClose.start(seconds=0) + self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED) + + @misc_utils.log_exception(_moduleLogger) + def _cancel(self): + _moduleLogger.debug("Cancelling call") + try: + result = yield ( + self._conn.session.backend.cancel, + (self.__calledNumber, ), + {}, + ) + except Exception: + _moduleLogger.exception("While canceling a call to %s" % (self.__calledNumber, )) + return + + @misc_utils.log_exception(_moduleLogger) def GetCallStates(self): """ For org.freedesktop.Telepathy.Channel.Interface.CallState @@ -180,7 +216,31 @@ class CallChannel( return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED} @misc_utils.log_exception(_moduleLogger) + def GetHoldState(self): + """ + For org.freedesktop.Telepathy.Channel.Interface.Hold + + Get the current hold state + @returns (HoldState, Reason) + """ + return ( + telepathy.constants.LOCAL_HOLD_STATE_UNHELD, + telepathy.constants.LOCAL_HOLD_STATE_REASON_NONE, + ) + + @misc_utils.log_exception(_moduleLogger) + def RequestHold(self, Hold): + """ + For org.freedesktop.Telepathy.Channel.Interface.Hold + """ + if not Hold: + return + _moduleLogger.debug("Closing without cancel to get out of users way") + self.__calledNumber = None + self.close() + + @misc_utils.log_exception(_moduleLogger) def _on_close_requested(self, *args): _moduleLogger.debug("Cancel now disallowed") - self.__calledNumer = None + self.__calledNumber = None self.close()