Abort all connections in progress when device enters disconnected state.
authorMax Lapan <max.lapan@gmail.com>
Thu, 18 Mar 2010 16:53:04 +0000 (19:53 +0300)
committerMax Lapan <max.lapan@gmail.com>
Thu, 18 Mar 2010 17:09:25 +0000 (20:09 +0300)
http_fetcher.cpp
http_fetcher.hpp
traffic.cpp
traffic.hpp

index 2d1d030..543260d 100644 (file)
@@ -39,3 +39,12 @@ void HttpFetcher::requestDone (bool err)
     _buffer.close ();
     _buffer.setBuffer (NULL);
 }
+
+
+void HttpFetcher::reset ()
+{
+    if (!busy ())
+        return;
+
+    _http.abort ();
+}
index 73a5528..416d62f 100644 (file)
@@ -24,6 +24,7 @@ public:
 
     bool busy () const;
     void fetch (const QString& url);
+    void reset ();
 };
 
 
index 1f2b705..3cc7097 100644 (file)
@@ -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 ();
+}
index 03283b8..4ec08e4 100644 (file)
@@ -105,6 +105,9 @@ private:
 private slots:
     void fetchDone (const QByteArray& data);
 
+protected slots:
+    void connectionChanged (bool active);
+
 signals:
     void updated ();