From 8f97a69220e7c4e61dc102c9e042227912b5b49a Mon Sep 17 00:00:00 2001 From: Srivats P Date: Wed, 7 Dec 2016 18:19:09 +0530 Subject: [PATCH] sign: Refactor StreamStatsTracking methods Start/StopStreamStatsTracking() methods made private helper functions specific to PcapPort. AbstractPort::setStreamStatsTracking() virtual function should be implemented by subclasses as required --- server/abstractport.cpp | 7 ++----- server/abstractport.h | 2 -- server/pcapport.cpp | 40 +++++++++++++++++++++++++--------------- server/pcapport.h | 7 ++++--- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/server/abstractport.cpp b/server/abstractport.cpp index 6beb539..4259863 100644 --- a/server/abstractport.cpp +++ b/server/abstractport.cpp @@ -182,12 +182,9 @@ void AbstractPort::addNote(QString note) bool AbstractPort::setTrackStreamStats(bool enable) { - bool val = enable ? startStreamStatsTracking() : stopStreamStatsTracking(); + data_.set_track_stream_stats(enable); - if (val) - data_.set_track_stream_stats(enable); - - return val; + return true; } AbstractPort::Accuracy AbstractPort::rateAccuracy() diff --git a/server/abstractport.h b/server/abstractport.h index da346de..b0e5744 100644 --- a/server/abstractport.h +++ b/server/abstractport.h @@ -116,8 +116,6 @@ public: void stats(PortStats *stats); void resetStats() { epochStats_ = stats_; } - virtual bool startStreamStatsTracking() = 0; - virtual bool stopStreamStatsTracking() = 0; // FIXME: combine single and All calls? void streamStats(uint guid, OstProto::StreamStatsList *stats); void streamStatsAll(OstProto::StreamStatsList *stats); diff --git a/server/pcapport.cpp b/server/pcapport.cpp index 7f2e398..9729960 100644 --- a/server/pcapport.cpp +++ b/server/pcapport.cpp @@ -121,6 +121,16 @@ void PcapPort::updateNotes() arg(notes).toStdString()); } +bool PcapPort::setTrackStreamStats(bool enable) +{ + bool val = enable ? startStreamStatsTracking() : stopStreamStatsTracking(); + + if (val) + AbstractPort::setTrackStreamStats(enable); + + return val; +} + bool PcapPort::setRateAccuracy(AbstractPort::Accuracy accuracy) { if (transmitter_->setRateAccuracy(accuracy)) { @@ -130,6 +140,21 @@ bool PcapPort::setRateAccuracy(AbstractPort::Accuracy accuracy) return false; } +void PcapPort::startDeviceEmulation() +{ + emulXcvr_->start(); +} + +void PcapPort::stopDeviceEmulation() +{ + emulXcvr_->stop(); +} + +int PcapPort::sendEmulationPacket(PacketBuffer *pktBuf) +{ + return emulXcvr_->transmitPacket(pktBuf); +} + bool PcapPort::startStreamStatsTracking() { if (!transmitter_->setStreamStatsTracking(true)) @@ -160,21 +185,6 @@ _tx_fail: return false; } -void PcapPort::startDeviceEmulation() -{ - emulXcvr_->start(); -} - -void PcapPort::stopDeviceEmulation() -{ - emulXcvr_->stop(); -} - -int PcapPort::sendEmulationPacket(PacketBuffer *pktBuf) -{ - return emulXcvr_->transmitPacket(pktBuf); -} - /* * ------------------------------------------------------------------- * * Port Monitor diff --git a/server/pcapport.h b/server/pcapport.h index dcf662f..cb99f34 100644 --- a/server/pcapport.h +++ b/server/pcapport.h @@ -40,6 +40,7 @@ public: virtual bool hasExclusiveControl() { return false; } virtual bool setExclusiveControl(bool /*exclusive*/) { return false; } + virtual bool setTrackStreamStats(bool enable); virtual bool setRateAccuracy(AbstractPort::Accuracy accuracy); virtual void clearPacketList() { @@ -72,9 +73,6 @@ public: virtual bool isCaptureOn() { return capturer_->isRunning(); } virtual QIODevice* captureData() { return capturer_->captureFile(); } - virtual bool startStreamStatsTracking(); - virtual bool stopStreamStatsTracking(); - virtual void startDeviceEmulation(); virtual void stopDeviceEmulation(); virtual int sendEmulationPacket(PacketBuffer *pktBuf); @@ -167,6 +165,9 @@ protected: void updateNotes(); private: + bool startStreamStatsTracking(); + bool stopStreamStatsTracking(); + PcapTransmitter *transmitter_; PortCapturer *capturer_; EmulationTransceiver *emulXcvr_;