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
This commit is contained in:
Srivats P 2016-12-07 18:19:09 +05:30
parent 35c56b9181
commit 8f97a69220
4 changed files with 31 additions and 25 deletions

View File

@ -182,12 +182,9 @@ void AbstractPort::addNote(QString note)
bool AbstractPort::setTrackStreamStats(bool enable) bool AbstractPort::setTrackStreamStats(bool enable)
{ {
bool val = enable ? startStreamStatsTracking() : stopStreamStatsTracking(); data_.set_track_stream_stats(enable);
if (val) return true;
data_.set_track_stream_stats(enable);
return val;
} }
AbstractPort::Accuracy AbstractPort::rateAccuracy() AbstractPort::Accuracy AbstractPort::rateAccuracy()

View File

@ -116,8 +116,6 @@ public:
void stats(PortStats *stats); void stats(PortStats *stats);
void resetStats() { epochStats_ = stats_; } void resetStats() { epochStats_ = stats_; }
virtual bool startStreamStatsTracking() = 0;
virtual bool stopStreamStatsTracking() = 0;
// FIXME: combine single and All calls? // FIXME: combine single and All calls?
void streamStats(uint guid, OstProto::StreamStatsList *stats); void streamStats(uint guid, OstProto::StreamStatsList *stats);
void streamStatsAll(OstProto::StreamStatsList *stats); void streamStatsAll(OstProto::StreamStatsList *stats);

View File

@ -121,6 +121,16 @@ void PcapPort::updateNotes()
arg(notes).toStdString()); 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) bool PcapPort::setRateAccuracy(AbstractPort::Accuracy accuracy)
{ {
if (transmitter_->setRateAccuracy(accuracy)) { if (transmitter_->setRateAccuracy(accuracy)) {
@ -130,6 +140,21 @@ bool PcapPort::setRateAccuracy(AbstractPort::Accuracy accuracy)
return false; return false;
} }
void PcapPort::startDeviceEmulation()
{
emulXcvr_->start();
}
void PcapPort::stopDeviceEmulation()
{
emulXcvr_->stop();
}
int PcapPort::sendEmulationPacket(PacketBuffer *pktBuf)
{
return emulXcvr_->transmitPacket(pktBuf);
}
bool PcapPort::startStreamStatsTracking() bool PcapPort::startStreamStatsTracking()
{ {
if (!transmitter_->setStreamStatsTracking(true)) if (!transmitter_->setStreamStatsTracking(true))
@ -160,21 +185,6 @@ _tx_fail:
return false; return false;
} }
void PcapPort::startDeviceEmulation()
{
emulXcvr_->start();
}
void PcapPort::stopDeviceEmulation()
{
emulXcvr_->stop();
}
int PcapPort::sendEmulationPacket(PacketBuffer *pktBuf)
{
return emulXcvr_->transmitPacket(pktBuf);
}
/* /*
* ------------------------------------------------------------------- * * ------------------------------------------------------------------- *
* Port Monitor * Port Monitor

View File

@ -40,6 +40,7 @@ public:
virtual bool hasExclusiveControl() { return false; } virtual bool hasExclusiveControl() { return false; }
virtual bool setExclusiveControl(bool /*exclusive*/) { return false; } virtual bool setExclusiveControl(bool /*exclusive*/) { return false; }
virtual bool setTrackStreamStats(bool enable);
virtual bool setRateAccuracy(AbstractPort::Accuracy accuracy); virtual bool setRateAccuracy(AbstractPort::Accuracy accuracy);
virtual void clearPacketList() { virtual void clearPacketList() {
@ -72,9 +73,6 @@ public:
virtual bool isCaptureOn() { return capturer_->isRunning(); } virtual bool isCaptureOn() { return capturer_->isRunning(); }
virtual QIODevice* captureData() { return capturer_->captureFile(); } virtual QIODevice* captureData() { return capturer_->captureFile(); }
virtual bool startStreamStatsTracking();
virtual bool stopStreamStatsTracking();
virtual void startDeviceEmulation(); virtual void startDeviceEmulation();
virtual void stopDeviceEmulation(); virtual void stopDeviceEmulation();
virtual int sendEmulationPacket(PacketBuffer *pktBuf); virtual int sendEmulationPacket(PacketBuffer *pktBuf);
@ -167,6 +165,9 @@ protected:
void updateNotes(); void updateNotes();
private: private:
bool startStreamStatsTracking();
bool stopStreamStatsTracking();
PcapTransmitter *transmitter_; PcapTransmitter *transmitter_;
PortCapturer *capturer_; PortCapturer *capturer_;
EmulationTransceiver *emulXcvr_; EmulationTransceiver *emulXcvr_;