qtmobility/src/bearer/qnetworksession_maemo.cpp
branchRCL_3
changeset 8 885c2596c964
parent 6 4203353e74ea
equal deleted inserted replaced
7:e2d33e235f7e 8:885c2596c964
   206 	}
   206 	}
   207     }
   207     }
   208 }
   208 }
   209 
   209 
   210 
   210 
   211 quint64 QNetworkSessionPrivate::getStatistics(bool sent) const
   211 QNetworkSessionPrivate::Statistics QNetworkSessionPrivate::getStatistics() const
   212 {
   212 {
   213     /* This could be also implemented by using the Maemo::Icd::statistics()
   213     /* This could be also implemented by using the Maemo::Icd::statistics()
   214      * that gets the statistics data for a specific IAP. Change if
   214      * that gets the statistics data for a specific IAP. Change if
   215      * necessary.
   215      * necessary.
   216      */
   216      */
   217     Maemo::Icd icd;
   217     Maemo::Icd icd;
   218     QList<Maemo::IcdStatisticsResult> stats_results;
   218     QList<Maemo::IcdStatisticsResult> stats_results;
   219     quint64 counter_rx = 0, counter_tx = 0;
   219     Statistics stats = { 0, 0, 0};
   220 
   220 
   221     if (!icd.statistics(stats_results)) {
   221     if (!icd.statistics(stats_results))
   222 	return 0;
   222         return stats;
   223     }
       
   224 
   223 
   225     foreach (const Maemo::IcdStatisticsResult &res, stats_results) {
   224     foreach (const Maemo::IcdStatisticsResult &res, stats_results) {
   226 	if (res.params.network_attrs & ICD_NW_ATTR_IAPNAME) {
   225         if (res.params.network_attrs & ICD_NW_ATTR_IAPNAME) {
   227 	    /* network_id is the IAP UUID */
   226             /* network_id is the IAP UUID */
   228 	    if (QString(res.params.network_id.data()) == activeConfig.identifier()) {
   227             if (QString(res.params.network_id.data()) == activeConfig.identifier()) {
   229 		counter_tx = res.bytes_sent;
   228                 stats.txData = res.bytes_sent;
   230 		counter_rx = res.bytes_received;
   229                 stats.rxData = res.bytes_received;
   231 	    }
   230                 stats.activeTime = res.time_active;
   232 	} else {
   231             }
   233 	    /* We probably will never get to this branch */
   232         } else {
   234 	    QNetworkConfigurationPrivate *d = activeConfig.d.data();
   233             /* We probably will never get to this branch */
   235 	    if (res.params.network_id == d->network_id) {
   234             QNetworkConfigurationPrivate *d = activeConfig.d.data();
   236 		counter_tx = res.bytes_sent;
   235             if (res.params.network_id == d->network_id) {
   237 		counter_rx = res.bytes_received;
   236                 stats.txData = res.bytes_sent;
   238 	    }
   237                 stats.rxData = res.bytes_received;
   239 	}
   238                 stats.activeTime = res.time_active;
   240     }
   239             }
   241 
   240         }
   242     if (sent)
   241     }
   243 	return counter_tx;
   242 
   244     else
   243     return stats;
   245 	return counter_rx;
       
   246 }
   244 }
   247 
   245 
   248 
   246 
   249 quint64 QNetworkSessionPrivate::bytesWritten() const
   247 quint64 QNetworkSessionPrivate::bytesWritten() const
   250 {
   248 {
   251     return getStatistics(true);
   249     return getStatistics().txData;
   252 }
   250 }
   253 
   251 
   254 quint64 QNetworkSessionPrivate::bytesReceived() const
   252 quint64 QNetworkSessionPrivate::bytesReceived() const
   255 {
   253 {
   256     return getStatistics(false);
   254     return getStatistics().rxData;
   257 }
   255 }
   258 
   256 
   259 quint64 QNetworkSessionPrivate::activeTime() const
   257 quint64 QNetworkSessionPrivate::activeTime() const
   260 {
   258 {
   261     if (startTime.isNull()) {
   259     return getStatistics().activeTime;
   262         return 0;
       
   263     }
       
   264     return startTime.secsTo(QDateTime::currentDateTime());
       
   265 }
   260 }
   266 
   261 
   267 
   262 
   268 QNetworkConfiguration& QNetworkSessionPrivate::copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy)
   263 QNetworkConfiguration& QNetworkSessionPrivate::copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy)
   269 {
   264 {