]> git.mxchange.org Git - simgear.git/commitdiff
Add total bytes downloaded tracking.
authorJames Turner <zakalawe@mac.com>
Thu, 24 Oct 2013 22:35:34 +0000 (23:35 +0100)
committerJames Turner <zakalawe@mac.com>
Thu, 24 Oct 2013 22:35:44 +0000 (23:35 +0100)
simgear/io/HTTPClient.cxx
simgear/io/HTTPClient.hxx
simgear/scene/tsync/terrasync.cxx

index 4cc93f2f889e8a331780fa076692d5c72be14547..1686fb2193707359616723e94def32a4dfc80397 100644 (file)
@@ -87,6 +87,7 @@ public:
     SGTimeStamp timeTransferSample;
     unsigned int bytesTransferred;
     unsigned int lastTransferRate;
+    uint64_t totalBytesDownloaded;
 };
   
 class Connection : public NetChat
@@ -603,6 +604,7 @@ Client::Client() :
     d->bytesTransferred = 0;
     d->lastTransferRate = 0;
     d->timeTransferSample.stamp();
+    d->totalBytesDownloaded = 0;
     
     setUserAgent("SimGear-" SG_STRINGIZE(SIMGEAR_VERSION));
 }
@@ -784,6 +786,7 @@ bool Client::hasActiveRequests() const
 void Client::receivedBytes(unsigned int count)
 {
     d->bytesTransferred += count;
+    d->totalBytesDownloaded += count;
 }
     
 unsigned int Client::transferRateBytesPerSec() const
@@ -812,6 +815,11 @@ unsigned int Client::transferRateBytesPerSec() const
     return smoothed;
 }
 
+uint64_t Client::totalBytesDownloaded() const
+{
+    return d->totalBytesDownloaded;
+}
+
 } // of namespace HTTP
 
 } // of namespace simgear
index 7f19d95ab292dd29bb264ec47eaf0f921c42105c..0831d8ae7b9c8561845a90d6abdec35ee891645e 100644 (file)
@@ -25,6 +25,7 @@
 #define SG_HTTP_CLIENT_HXX
 
 #include <memory> // for std::auto_ptr
+#include <stdint.h> // for uint_64t
 
 #include <simgear/io/HTTPRequest.hxx>
 
@@ -73,6 +74,12 @@ public:
      * suitable for user feedback and rough profiling, nothing more.
      */
     unsigned int transferRateBytesPerSec() const;
+    
+    /**
+     * total bytes downloaded by this HTTP client, for bandwidth usage
+     * monitoring
+     */
+    uint64_t totalBytesDownloaded() const;
 private:
     void requestFinished(Connection* con);
     
index 38cd0c96d0d0c4d303458c33374fc97472d72369..afe89639df3ecf43e562fac53897f174a720a96b 100644 (file)
@@ -243,6 +243,9 @@ public:
    volatile int  _allowed_errors;
    volatile int  _cache_hits;
    volatile int _transfer_rate;
+   // kbytes, not bytes, because bytes might overflow 2^31
+   volatile int _total_kb_downloaded;
+   
 private:
    virtual void run();
     
@@ -293,6 +296,7 @@ SGTerraSync::SvnThread::SvnThread() :
     _allowed_errors(6),
     _cache_hits(0),
     _transfer_rate(0),
+    _total_kb_downloaded(0),
     _use_built_in(true),
     _is_dirty(false),
     _stop(false),
@@ -609,6 +613,9 @@ void SGTerraSync::SvnThread::runInternal()
     while (!_stop) {
         _http.update(100);
         _transfer_rate = _http.transferRateBytesPerSec();
+        // convert from bytes to kbytes
+        _total_kb_downloaded = static_cast<int>(_http.totalBytesDownloaded() / 1024);
+        
         if (_stop)
             break;
  
@@ -835,6 +842,10 @@ void SGTerraSync::bind()
     _tiedProperties.Tie( _terraRoot->getNode("cache-hits", true), (int*) &_svnThread->_cache_hits );
     _tiedProperties.Tie( _terraRoot->getNode("transfer-rate-bytes-sec", true), (int*) &_svnThread->_transfer_rate );
     
+    // use kbytes here because propety doesn't support 64-bit and we might conceivably
+    // download more than 2G in a single session
+    _tiedProperties.Tie( _terraRoot->getNode("downloaded-kbytes", true), (int*) &_svnThread->_total_kb_downloaded );
+    
     _terraRoot->getNode("busy", true)->setAttribute(SGPropertyNode::WRITE,false);
     _terraRoot->getNode("active", true)->setAttribute(SGPropertyNode::WRITE,false);
     _terraRoot->getNode("update-count", true)->setAttribute(SGPropertyNode::WRITE,false);