From: Max Lapan Date: Thu, 18 Mar 2010 16:53:04 +0000 (+0300) Subject: Abort all connections in progress when device enters disconnected state. X-Git-Tag: v0.1-2~1 X-Git-Url: http://git.maemo.org/git/?p=yandex-traffic;a=commitdiff_plain;h=01f052ad8206fd9d5c7642bb3450db10a440aad4 Abort all connections in progress when device enters disconnected state. --- diff --git a/http_fetcher.cpp b/http_fetcher.cpp index 2d1d030..543260d 100644 --- a/http_fetcher.cpp +++ b/http_fetcher.cpp @@ -39,3 +39,12 @@ void HttpFetcher::requestDone (bool err) _buffer.close (); _buffer.setBuffer (NULL); } + + +void HttpFetcher::reset () +{ + if (!busy ()) + return; + + _http.abort (); +} diff --git a/http_fetcher.hpp b/http_fetcher.hpp index 73a5528..416d62f 100644 --- a/http_fetcher.hpp +++ b/http_fetcher.hpp @@ -24,6 +24,7 @@ public: bool busy () const; void fetch (const QString& url); + void reset (); }; diff --git a/traffic.cpp b/traffic.cpp index 1f2b705..3cc7097 100644 --- a/traffic.cpp +++ b/traffic.cpp @@ -3,6 +3,7 @@ #include "traffic.hpp" #include "log.hpp" +#include "connection.hpp" // -------------------------------------------------- @@ -132,16 +133,21 @@ Traffic::Traffic () { connect (&_fetcher, SIGNAL (done (const QByteArray&)), SLOT (fetchDone (const QByteArray&))); + connect (ConnectionChecker::instance (), SIGNAL (connected (bool)), SLOT (connectionChanged (bool))); } + // Perform asyncronous refresh of traffic information. If another update // request is in progress, new is discarded. If update request finished // successfully, updated() signal called. void Traffic::update () { - if (_fetcher.busy ()) + if (_fetcher.busy ()) { + Log::instance ()->add ("Traffic::update: fetcher is busy"); return; + } + Log::instance ()->add ("Traffic::update: Request status download"); _fetcher.fetch ("http://trf.maps.yandex.net/trf/stat.xml"); } @@ -149,8 +155,12 @@ void Traffic::update () void Traffic::fetchDone (const QByteArray& data) { // parse data got - if (parse_traffic_data (QString::fromUtf8 (data.data ()))) + if (parse_traffic_data (QString::fromUtf8 (data.data ()))) { + Log::instance ()->add ("Traffic::fetchDone: data parsed successfully"); updated (); + } + else + Log::instance ()->add ("Traffic::fetchDone: data parse error"); } @@ -234,3 +244,10 @@ ExtendedTrafficInfo Traffic::lookup_ext (const QString &id) const else return it.value (); } + + +void Traffic::connectionChanged (bool active) +{ + if (!active) + _fetcher.reset (); +} diff --git a/traffic.hpp b/traffic.hpp index 03283b8..4ec08e4 100644 --- a/traffic.hpp +++ b/traffic.hpp @@ -105,6 +105,9 @@ private: private slots: void fetchDone (const QByteArray& data); +protected slots: + void connectionChanged (bool active); + signals: void updated ();