From 0f22a40ee65ae6b886cdeb4de68b2780579bc169 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 16 Apr 2009 10:00:27 +0000 Subject: make AcceptStreamTube async --- diff --git a/readactivity.py b/readactivity.py index 5714ae8..8e8b09c 100644 --- a/readactivity.py +++ b/readactivity.py @@ -400,29 +400,36 @@ class ReadActivity(activity.Activity): conn = self.shared_activity.telepathy_conn tube_chan = Channel(conn.dbus_proxy.bus_name, tube_path) - # FIXME: async + def accept_stream_tube_reply_cb(addr): + _logger.debug('Accepted stream tube: listening address is %r', addr) + + # SOCKET_ADDRESS_TYPE_IPV4 is defined to have addresses of type '(sq)' + assert isinstance(addr, dbus.Struct) + assert len(addr) == 2 + assert isinstance(addr[0], str) + assert isinstance(addr[1], (int, long)) + assert addr[1] > 0 and addr[1] < 65536 + port = int(addr[1]) + + getter = ReadURLDownloader("http://%s:%d/document" + % (addr[0], port)) + getter.connect("finished", self._download_result_cb, tube_path) + getter.connect("progress", self._download_progress_cb, tube_path) + getter.connect("error", self._download_error_cb, tube_path) + _logger.debug("Starting download to %s...", path) + getter.start(path) + self._download_content_length = getter.get_content_length() + self._download_content_type = getter.get_content_type() + + def accept_stream_tube_error_cb(e): + _logger.error('OfferStreamTube failed: %s' % e) + addr = tube_chan[CHANNEL_TYPE_STREAM_TUBE].AcceptStreamTube( SOCKET_ADDRESS_TYPE_IPV4, SOCKET_ACCESS_CONTROL_LOCALHOST, 0, - utf8_strings=True) - _logger.debug('Accepted stream tube: listening address is %r', addr) - - # SOCKET_ADDRESS_TYPE_IPV4 is defined to have addresses of type '(sq)' - assert isinstance(addr, dbus.Struct) - assert len(addr) == 2 - assert isinstance(addr[0], str) - assert isinstance(addr[1], (int, long)) - assert addr[1] > 0 and addr[1] < 65536 - port = int(addr[1]) - - getter = ReadURLDownloader("http://%s:%d/document" - % (addr[0], port)) - getter.connect("finished", self._download_result_cb, tube_path) - getter.connect("progress", self._download_progress_cb, tube_path) - getter.connect("error", self._download_error_cb, tube_path) - _logger.debug("Starting download to %s...", path) - getter.start(path) - self._download_content_length = getter.get_content_length() - self._download_content_type = getter.get_content_type() + utf8_strings=True, + reply_handler=accept_stream_tube_reply_cb, + error_handler=accept_stream_tube_error_cb) + return False def _get_document(self): -- cgit v0.9.1