X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fchannel_manager.py;h=592a59c5d48d2e138201dbc099356bdd7ee4b2f8;hp=2331063b9a0f624aa86c2a9d6909e781aa208275;hb=f782e49000db36c075673d22223bc02464155e4e;hpb=ce4c05e738f65ca74316c59651bf63fb67329e06 diff --git a/src/channel_manager.py b/src/channel_manager.py index 2331063..592a59c 100644 --- a/src/channel_manager.py +++ b/src/channel_manager.py @@ -1,65 +1,93 @@ -import weakref import logging +import dbus import telepathy +import tp import channel +import util.misc as misc_utils -_moduleLogger = logging.getLogger("channel_manager") +_moduleLogger = logging.getLogger(__name__) -class ChannelManager(object): +class ChannelManager(tp.ChannelManager): 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.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): - try: - chan = self._listChannels[handle] - 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) + tp.ChannelManager.__init__(self, connection) + + fixed = { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST + } + self._implement_channel_class( + telepathy.CHANNEL_TYPE_CONTACT_LIST, + self._get_list_channel, + fixed, + [] + ) + + fixed = { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT, + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT) + } + self._implement_channel_class( + telepathy.CHANNEL_TYPE_TEXT, + self._get_text_channel, + fixed, + [] + ) + + fixed = { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_FILE_TRANSFER, + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT) + } + self._implement_channel_class( + telepathy.CHANNEL_TYPE_FILE_TRANSFER, + self._get_file_transfer_channel, + fixed, + [] + ) + + fixed = { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_STREAMED_MEDIA, + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT) + } + self._implement_channel_class( + telepathy.CHANNEL_TYPE_STREAMED_MEDIA, + self._get_media_channel, + fixed, + [telepathy.CHANNEL_INTERFACE + '.TargetHandle'] + ) + + def _get_list_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) + + _moduleLogger.debug('New contact list channel') + chan = channel.contact_list.create_contact_list_channel(self._conn, self, props, h) return chan - def channel_for_text(self, handle, suppress_handler=False): - try: - chan = self._textChannels[handle] - 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) + def _get_text_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) + + accountNumber = misc_utils.normalize_number(self._conn.session.backend.get_account_number()) + if h.phoneNumber == accountNumber: + _moduleLogger.debug('New Debug channel') + chan = channel.debug_prompt.DebugPromptChannel(self._conn, self, props, h) + else: + _moduleLogger.debug('New text channel') + chan = channel.text.TextChannel(self._conn, self, props, h) 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) + def _get_file_transfer_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) + + _moduleLogger.debug('New file transfer channel') + chan = channel.debug_log.DebugLogChannel(self._conn, self, props, h) + return chan + + def _get_media_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) + + _moduleLogger.debug('New media channel') + chan = channel.call.CallChannel(self._conn, self, props, h) return chan