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 RuntimeError("Unsupported channel type %r" % handle.get_type())
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.NotImplemented("Only Contacts are allowed")
47 _moduleLogger.debug("Requesting new text channel")
49 contact = handle.contact
50 chan = channel.text.TextChannel(self._connRef())
51 self._textChannels[handle] = chan
52 self._connRef().add_channel(chan, handle, suppress_handler)
55 def channel_for_call(self, handle, suppress_handler=False):
57 chan = self._callChannels[handle]
59 if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT:
60 raise telepathy.NotImplemented("Only Contacts are allowed")
61 _moduleLogger.debug("Requesting new call channel")
63 contact = handle.contact
64 chan = channel.call.CallChannel(self._connRef())
65 self._callChannels[handle] = chan
66 self._connRef().add_channel(chan, handle, suppress_handler)