/* */ #include "NetStat.h" #include "wallclock.h" namespace aria2 { NetStat::NetStat() : status_(NetStat::IDLE), avgDownloadSpeed_(0), avgUploadSpeed_(0), sessionDownloadLength_(0), sessionUploadLength_(0) {} NetStat::~NetStat() {} /** * Returns current download speed in byte per sec. */ int NetStat::calculateDownloadSpeed() { return downloadSpeed_.calculateSpeed(); } int NetStat::calculateAvgDownloadSpeed() { return avgDownloadSpeed_ = downloadSpeed_.calculateAvgSpeed(); } int NetStat::calculateUploadSpeed() { return uploadSpeed_.calculateSpeed(); } int NetStat::calculateAvgUploadSpeed() { return avgUploadSpeed_ = uploadSpeed_.calculateAvgSpeed(); } void NetStat::updateDownloadLength(size_t bytes) { downloadSpeed_.update(bytes); sessionDownloadLength_ += bytes; } void NetStat::updateUploadLength(size_t bytes) { uploadSpeed_.update(bytes); sessionUploadLength_ += bytes; } int NetStat::getMaxDownloadSpeed() const { return downloadSpeed_.getMaxSpeed(); } int NetStat::getMaxUploadSpeed() const { return uploadSpeed_.getMaxSpeed(); } void NetStat::reset() { downloadSpeed_.reset(); uploadSpeed_.reset(); downloadStartTime_ = global::wallclock(); status_ = IDLE; } void NetStat::downloadStart() { reset(); status_ = ACTIVE; } void NetStat::downloadStop() { calculateAvgDownloadSpeed(); calculateAvgUploadSpeed(); status_ = IDLE; } TransferStat NetStat::toTransferStat() { TransferStat stat; stat.downloadSpeed = calculateDownloadSpeed(); stat.uploadSpeed = calculateUploadSpeed(); stat.sessionDownloadLength = getSessionDownloadLength(); stat.sessionUploadLength = getSessionUploadLength(); return stat; } } // namespace aria2