diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2009-06-15 15:12:32 (GMT) |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2009-06-15 15:12:32 (GMT) |
commit | 4e66feba4fa946401e05542b525e64f45ac5873f (patch) | |
tree | 3170bb9a7284994a8398572fad25684ea9971060 | |
parent | b731f55b26d3e34a44faf7c4b2ef2e8ef8cc70d6 (diff) |
make AcceptStreamTube asynctube-stable-api
-rw-r--r-- | readactivity.py | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/readactivity.py b/readactivity.py index 1e97ba0..ac97af2 100644 --- a/readactivity.py +++ b/readactivity.py @@ -396,29 +396,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].Accept( 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): |