X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fchannel_manager.py;h=2331063b9a0f624aa86c2a9d6909e781aa208275;hb=155d582be8f8606989447364d93f754751e6820e;hp=ba069573cf8c829c3706a6b9fe304b2931fb25ec;hpb=ab4da214c520d763bbbddeb828c8e7c838374fe3;p=theonering diff --git a/src/channel_manager.py b/src/channel_manager.py index ba06957..2331063 100644 --- a/src/channel_manager.py +++ b/src/channel_manager.py @@ -6,44 +6,60 @@ import telepathy import channel +_moduleLogger = logging.getLogger("channel_manager") + + class ChannelManager(object): def __init__(self, connection): self._connRef = weakref.ref(connection) self._listChannels = weakref.WeakValueDictionary() self._textChannels = weakref.WeakValueDictionary() + self._callChannels = weakref.WeakValueDictionary() def close(self): for chan in self._listChannels.values(): - chan.remove_from_connection()# so that dbus lets it die. + chan.Close() for chan in self._textChannels.values(): chan.Close() + for chan in self._callChannels.values(): + chan.Close() def channel_for_list(self, handle, suppress_handler=False): - if handle in self._listChannels: + try: chan = self._listChannels[handle] - else: - if handle.get_type() == telepathy.HANDLE_TYPE_GROUP: - chan = channel.group.GroupChannel(self._connRef(), handle) - elif handle.get_type() == telepathy.HANDLE_TYPE_CONTACT: - chan = channel.contact_list.creat_contact_list_channel(self._connRef(), handle) - else: - logging.warn("Unknown channel type %r" % handle.get_type()) + except KeyError, e: + if handle.get_type() != telepathy.HANDLE_TYPE_LIST: + raise telepathy.errors.NotImplemented("Only server lists are allowed") + _moduleLogger.debug("Requesting new contact list channel") + + chan = channel.contact_list.create_contact_list_channel(self._connRef(), handle) self._listChannels[handle] = chan self._connRef().add_channel(chan, handle, suppress_handler) return chan - def channel_for_text(self, handle, conversation=None, suppress_handler=False): - if handle in self._textChannels: + def channel_for_text(self, handle, suppress_handler=False): + try: chan = self._textChannels[handle] - else: - logging.debug("Requesting new text channel") - contact = handle.contact - - if conversation is None: - client = self._connRef().msn_client - conversation = None - chan = channel.text.TextChannel(self._connRef(), conversation) + except KeyError, e: + if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT: + raise telepathy.errors.NotImplemented("Only Contacts are allowed") + _moduleLogger.debug("Requesting new text channel") + + chan = channel.text.TextChannel(self._connRef(), handle) self._textChannels[handle] = chan self._connRef().add_channel(chan, handle, suppress_handler) return chan + + def channel_for_call(self, handle, suppress_handler=False): + try: + chan = self._callChannels[handle] + except KeyError, e: + if handle.get_type() != telepathy.HANDLE_TYPE_NONE: + raise telepathy.errors.NotImplemented("Using deprecated means to create a call") + _moduleLogger.debug("Requesting new call channel") + + chan = channel.call.CallChannel(self._connRef(), handle) + self._callChannels[handle] = chan + self._connRef().add_channel(chan, handle, suppress_handler) + return chan