type & squish

This commit is contained in:
Brad Davis 2015-03-19 17:24:58 -07:00
parent bf607e4c9c
commit 599fe09e75

View file

@ -102,33 +102,32 @@ QDebug operator<<(QDebug debug, const NetworkPeer &peer) {
// FIXME this is a temporary implementation to determine if this is the right approach. // FIXME this is a temporary implementation to determine if this is the right approach.
// If so, migrate the BandwidthRecorder into the NetworkPeer class // If so, migrate the BandwidthRecorder into the NetworkPeer class
using BandwidthRecorderPtr = QSharedPointer < BandwidthRecorder > ; using BandwidthRecorderPtr = QSharedPointer<BandwidthRecorder>;
static QHash<QUuid, BandwidthRecorderPtr> PEER_BANDWIDTH; static QHash<QUuid, BandwidthRecorderPtr> PEER_BANDWIDTH;
BandwidthRecorder & getBandwidthRecorder(const QUuid & uuid) { BandwidthRecorder& getBandwidthRecorder(const QUuid & uuid) {
if (!PEER_BANDWIDTH.count(uuid)) { if (!PEER_BANDWIDTH.count(uuid)) {
PEER_BANDWIDTH.insert(uuid, BandwidthRecorderPtr(new BandwidthRecorder())); PEER_BANDWIDTH.insert(uuid, BandwidthRecorderPtr(new BandwidthRecorder()));
} }
return *PEER_BANDWIDTH[uuid].data(); return *PEER_BANDWIDTH[uuid].data();
} }
void NetworkPeer::recordBytesSent(int count) { void NetworkPeer::recordBytesSent(int count) {
auto & bw = getBandwidthRecorder(_uuid); auto& bw = getBandwidthRecorder(_uuid);
bw.updateOutboundData(0, count); bw.updateOutboundData(0, count);
} }
void NetworkPeer::recordBytesReceived(int count) { void NetworkPeer::recordBytesReceived(int count) {
auto & bw = getBandwidthRecorder(_uuid); auto& bw = getBandwidthRecorder(_uuid);
bw.updateInboundData(0, count); bw.updateInboundData(0, count);
} }
float NetworkPeer::getOutboundBandwidth() { float NetworkPeer::getOutboundBandwidth() {
auto & bw = getBandwidthRecorder(_uuid); auto& bw = getBandwidthRecorder(_uuid);
return bw.getAverageOutputKilobitsPerSecond(0); return bw.getAverageOutputKilobitsPerSecond(0);
} }
float NetworkPeer::getInboundBandwidth() { float NetworkPeer::getInboundBandwidth() {
auto & bw = getBandwidthRecorder(_uuid); auto& bw = getBandwidthRecorder(_uuid);
return bw.getAverageInputKilobitsPerSecond(0); return bw.getAverageInputKilobitsPerSecond(0);
} }