9 _moduleLogger = logging.getLogger("channel_manager")
12 class ChannelManager(object):
14 def __init__(self, connection):
15 self._connRef = weakref.ref(connection)
16 self._listChannels = weakref.WeakValueDictionary()
17 self._textChannels = weakref.WeakValueDictionary()
18 self._callChannels = weakref.WeakValueDictionary()
21 for chan in self._listChannels.values():
22 chan.remove_from_connection()# so that dbus lets it die.
23 for chan in self._textChannels.values():
25 for chan in self._callChannels.values():
28 def channel_for_list(self, handle, suppress_handler=False):
30 chan = self._listChannels[handle]
32 if handle.get_type() != telepathy.HANDLE_TYPE_LIST:
33 raise telepathy.errors.NotImplemented("Only server lists are allowed")
34 _moduleLogger.debug("Requesting new contact list channel")
36 chan = channel.contact_list.create_contact_list_channel(self._connRef(), handle)
37 self._listChannels[handle] = chan
38 self._connRef().add_channel(chan, handle, suppress_handler)
41 def channel_for_text(self, handle, suppress_handler=False):
43 chan = self._textChannels[handle]
45 if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT:
46 raise telepathy.errors.NotImplemented("Only Contacts are allowed")
47 _moduleLogger.debug("Requesting new text channel")
49 chan = channel.text.TextChannel(self._connRef(), handle)
50 self._textChannels[handle] = chan
51 self._connRef().add_channel(chan, handle, suppress_handler)
54 def channel_for_call(self, handle, suppress_handler=False):
56 chan = self._callChannels[handle]
58 if handle.get_type() != telepathy.HANDLE_TYPE_NONE:
59 raise telepathy.errors.NotImplemented("Using deprecated means to create a call")
60 _moduleLogger.debug("Requesting new call channel")
62 chan = channel.call.CallChannel(self._connRef(), handle)
63 self._callChannels[handle] = chan
64 self._connRef().add_channel(chan, handle, suppress_handler)