10 _moduleLogger = logging.getLogger("channel_manager")
13 class ChannelManager(object):
15 def __init__(self, connection):
16 self._connRef = weakref.ref(connection)
17 self._listChannels = weakref.WeakValueDictionary()
18 self._textChannels = weakref.WeakValueDictionary()
19 self._callChannels = weakref.WeakValueDictionary()
22 for chan in itertools.chain(
23 self._listChannels.values(), self._textChannels.values(), self._callChannels.values()
28 _moduleLogger.exception("Shutting down %r" % (chan, ))
30 def channel_for_list(self, handle, suppress_handler=False):
32 chan = self._listChannels[handle]
34 if handle.get_type() != telepathy.HANDLE_TYPE_LIST:
35 raise telepathy.errors.NotImplemented("Only server lists are allowed")
36 _moduleLogger.debug("Requesting new contact list channel")
38 chan = channel.contact_list.create_contact_list_channel(self._connRef(), handle)
39 self._listChannels[handle] = chan
40 self._connRef().add_channel(chan, handle, suppress_handler)
43 def channel_for_text(self, handle, suppress_handler=False):
45 chan = self._textChannels[handle]
47 if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT:
48 raise telepathy.errors.NotImplemented("Only Contacts are allowed")
49 _moduleLogger.debug("Requesting new text channel")
51 chan = channel.text.TextChannel(self._connRef(), handle)
52 self._textChannels[handle] = chan
53 self._connRef().add_channel(chan, handle, suppress_handler)
56 def channel_for_call(self, handle, suppress_handler=False):
58 chan = self._callChannels[handle]
60 if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT:
61 _moduleLogger.warning("Using deprecated means to create a call")
62 raise telepathy.errors.NotImplemented("Not implementing depcrecated means")
63 _moduleLogger.debug("Requesting new call channel")
65 chan = channel.call.CallChannel(self._connRef(), handle)
66 self._callChannels[handle] = chan
67 self._connRef().add_channel(chan, handle, suppress_handler)