From cca2e94bb3cec2f4f9a052efc34e92f0647af60a Mon Sep 17 00:00:00 2001 From: Srivats P Date: Thu, 14 Sep 2017 20:38:13 +0530 Subject: [PATCH] Detect when port config has changed and needs to APPLY'd For now we prompt user to click Apply, in future we can use this to do a "Auto Apply" --- client/port.cpp | 30 ++++++++++++++++++++++++++++-- client/port.h | 29 ++++++++++++++++++++++++----- client/portswindow.cpp | 21 +++++++++++++++++++++ client/portswindow.h | 1 + client/portswindow.ui | 17 +++++++++++++++-- client/streamconfigdialog.cpp | 2 +- client/streammodel.cpp | 8 +++++--- common/streambase.cpp | 2 +- common/streambase.h | 2 +- 9 files changed, 97 insertions(+), 15 deletions(-) diff --git a/client/port.cpp b/client/port.cpp index 50f1716..bf245c7 100644 --- a/client/port.cpp +++ b/client/port.cpp @@ -57,6 +57,7 @@ Port::Port(quint32 id, quint32 portGroupId) stats.mutable_port_id()->set_id(id); mPortGroupId = portGroupId; capFile_ = NULL; + dirty_ = false; } Port::~Port() @@ -100,6 +101,15 @@ void Port::reorderStreamsByOrdinals() qSort(mStreams.begin(), mStreams.end(), StreamBase::StreamLessThan); } +void Port::setDirty(bool dirty) +{ + if (dirty == dirty_) + return; + + dirty_ = dirty; + emit localConfigChanged(dirty_); +} + void Port::recalculateAverageRates() { double pps = 0; @@ -209,6 +219,7 @@ void Port::setAveragePacketRate(double packetsPerSec) Q_ASSERT(false); // Unreachable!! } numActiveStreams_ = n; + setDirty(true); } else avgPacketsPerSec_ = avgBitsPerSec_ = numActiveStreams_ = 0; @@ -282,6 +293,7 @@ void Port::setAverageBitRate(double bitsPerSec) Q_ASSERT(false); // Unreachable!! } numActiveStreams_ = n; + setDirty(true); } else avgPacketsPerSec_ = avgBitsPerSec_ = numActiveStreams_ = 0; @@ -305,6 +317,7 @@ bool Port::newStreamAt(int index, OstProto::Stream const *stream) mStreams.insert(index, s); updateStreamOrdinalsFromIndex(); recalculateAverageRates(); + setDirty(true); return true; } @@ -317,6 +330,7 @@ bool Port::deleteStreamAt(int index) delete mStreams.takeAt(index); updateStreamOrdinalsFromIndex(); recalculateAverageRates(); + setDirty(true); return true; } @@ -506,6 +520,8 @@ void Port::when_syncComplete() deviceGroups_.at(i)->device_group_id().id()); } modifiedDeviceGroupList_.clear(); + + setDirty(false); } void Port::updateStats(OstProto::PortStats *portStats) @@ -543,6 +559,7 @@ void Port::duplicateStreams(const QList &list, int count) insertAt++; } } + setDirty(true); emit streamListChanged(mPortGroupId, mPortId); } @@ -625,6 +642,7 @@ bool Port::openStreams(QString fileName, bool append, QString &error) if (i % 32 == 0) qApp->processEvents(); } + setDirty(true); _user_cancel: emit streamListChanged(mPortGroupId, mPortId); @@ -743,11 +761,12 @@ OstProto::DeviceGroup* Port::mutableDeviceGroupByIndex(int index) // Caller can modify DeviceGroup - assume she will modifiedDeviceGroupList_.insert(devGrp->device_group_id().id()); + setDirty(true); return devGrp; } -OstProto::DeviceGroup* Port::deviceGroupById(uint deviceGroupId) +const OstProto::DeviceGroup* Port::deviceGroupById(uint deviceGroupId) const { for (int i = 0; i < deviceGroups_.size(); i++) { OstProto::DeviceGroup *devGrp = deviceGroups_.at(i); @@ -776,6 +795,7 @@ bool Port::newDeviceGroupAt(int index, const OstProto::DeviceGroup *deviceGroup) devGrp->mutable_device_group_id()->set_id(newDeviceGroupId()); deviceGroups_.insert(index, devGrp); modifiedDeviceGroupList_.insert(devGrp->device_group_id().id()); + setDirty(true); return true; } @@ -788,6 +808,7 @@ bool Port::deleteDeviceGroupAt(int index) OstProto::DeviceGroup *devGrp = deviceGroups_.takeAt(index); modifiedDeviceGroupList_.remove(devGrp->device_group_id().id()); delete devGrp; + setDirty(true); return true; } @@ -818,7 +839,12 @@ bool Port::updateDeviceGroup( uint deviceGroupId, OstProto::DeviceGroup *deviceGroup) { - OstProto::DeviceGroup *devGrp = deviceGroupById(deviceGroupId); + using OstProto::DeviceGroup; + + // XXX: We should not call mutableDeviceGroupById() because that will + // implicitly set the port as dirty, so we use a const_cast hack instead + DeviceGroup *devGrp = const_cast( + deviceGroupById(deviceGroupId)); if (!devGrp) { qDebug("%s: deviceGroup id %u does not exist", __FUNCTION__, diff --git a/client/port.h b/client/port.h index 281a61a..c1141f5 100644 --- a/client/port.h +++ b/client/port.h @@ -50,6 +50,7 @@ class Port : public QObject { quint32 mPortId; quint32 mPortGroupId; QString mUserAlias; // user defined + bool dirty_; double avgPacketsPerSec_; double avgBitsPerSec_; @@ -70,6 +71,7 @@ class Port : public QObject { void updateStreamOrdinalsFromIndex(); void reorderStreamsByOrdinals(); + void setDirty(bool dirty); public: enum AdminStatus { AdminDisable, AdminEnable }; @@ -108,11 +110,17 @@ public: //void setExclusive(bool flag); int numStreams() { return mStreams.size(); } - Stream* streamByIndex(int index) + const Stream* streamByIndex(int index) const { Q_ASSERT(index < mStreams.size()); return mStreams[index]; } + Stream* mutableStreamByIndex(int index) + { + Q_ASSERT(index < mStreams.size()); + setDirty(true); // assume - that's the best we can do atm + return mStreams[index]; + } OstProto::LinkState linkState() { return stats.state().link_state(); } @@ -129,6 +137,7 @@ public: void protoDataCopyInto(OstProto::Port *data); + //! Used when config received from server // FIXME(MED): naming inconsistency - PortConfig/Stream; also retVal void updatePortConfig(OstProto::Port *port); @@ -144,6 +153,7 @@ public: bool updateStream(uint streamId, OstProto::Stream *stream); //@} + bool isDirty() { return dirty_; } void getDeletedStreamsSinceLastSync(OstProto::StreamIdList &streamIdList); void getNewStreamsSinceLastSync(OstProto::StreamIdList &streamIdList); void getModifiedStreamsSinceLastSync( @@ -178,7 +188,7 @@ public: int numDeviceGroups() const; const OstProto::DeviceGroup* deviceGroupByIndex(int index) const; OstProto::DeviceGroup* mutableDeviceGroupByIndex(int index); - OstProto::DeviceGroup* deviceGroupById(uint deviceGroupId); + const OstProto::DeviceGroup* deviceGroupById(uint deviceGroupId) const; //! Used by StreamModel //@{ @@ -216,11 +226,20 @@ public: void deviceInfoRefreshed(); signals: + //! Used when local config changed and when config received from server void portRateChanged(int portGroupId, int portId); - void portDataChanged(int portGroupId, int portId); - void streamListChanged(int portGroupId, int portId); - void deviceInfoChanged(); + //! Used by MyService::Stub to update from config received from server + //@{ + void portDataChanged(int portGroupId, int portId); + void deviceInfoChanged(); + //@} + + //! Used when local config changed + //@{ + void streamListChanged(int portGroupId, int portId); + void localConfigChanged(bool changed); + //@} }; #endif diff --git a/client/portswindow.cpp b/client/portswindow.cpp index b3a31d5..51e4152 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -345,6 +345,8 @@ void PortsWindow::when_portView_currentChanged(const QModelIndex& currentIndex, { disconnect(&(plm->port(previous)), SIGNAL(portRateChanged(int, int)), this, SLOT(updatePortRates())); + disconnect(&(plm->port(previous)), SIGNAL(localConfigChanged(bool)), + this, SLOT(updateApplyHint(bool))); } if (!current.isValid()) @@ -364,6 +366,15 @@ void PortsWindow::when_portView_currentChanged(const QModelIndex& currentIndex, updatePortRates(); connect(&(plm->port(current)), SIGNAL(portRateChanged(int, int)), SLOT(updatePortRates())); + connect(&(plm->port(current)), SIGNAL(localConfigChanged(bool)), + SLOT(updateApplyHint(bool))); + if (plm->port(current).isDirty()) + updateApplyHint(true); + else if (plm->port(current).numStreams()) + applyHint->setText("Use the Statistics window to transmit " + "packets"); + else + applyHint->setText(""); } } @@ -511,6 +522,16 @@ void PortsWindow::updateStreamViewActions() actionSave_Streams->setEnabled(tvStreamList->model()->rowCount() > 0); } +void PortsWindow::updateApplyHint(bool configChanged) +{ + if (configChanged) + applyHint->setText("Configuration has changed - click Apply " + "to activate the changes"); + else + applyHint->setText("Configuration activated. Use the Statistics " + "window to transmit packets"); +} + void PortsWindow::updatePortViewActions(const QModelIndex& currentIndex) { QModelIndex current = currentIndex; diff --git a/client/portswindow.h b/client/portswindow.h index b407270..e67bcea 100644 --- a/client/portswindow.h +++ b/client/portswindow.h @@ -66,6 +66,7 @@ public slots: void showMyReservedPortsOnly(bool enabled); private slots: + void updateApplyHint(bool configChanged); void updatePortViewActions(const QModelIndex& currentIndex); void updateStreamViewActions(); diff --git a/client/portswindow.ui b/client/portswindow.ui index c15737e..f4f1c58 100644 --- a/client/portswindow.ui +++ b/client/portswindow.ui @@ -150,12 +150,25 @@ - + - Configuration Changed? Click Apply on the right to activate the changes + Apply Hint + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/client/streamconfigdialog.cpp b/client/streamconfigdialog.cpp index 8db5b08..0ef56de 100644 --- a/client/streamconfigdialog.cpp +++ b/client/streamconfigdialog.cpp @@ -1222,7 +1222,7 @@ void StreamConfigDialog::on_pbOk_clicked() // Copy the data from the "local working copy of stream" to "actual stream" mpStream->protoDataCopyInto(s); - mPort.streamByIndex(mCurrentStreamIndex)->protoDataCopyFrom(s); + mPort.mutableStreamByIndex(mCurrentStreamIndex)->protoDataCopyFrom(s); qDebug("stream stored"); diff --git a/client/streammodel.cpp b/client/streammodel.cpp index c66f02c..99c12ef 100644 --- a/client/streammodel.cpp +++ b/client/streammodel.cpp @@ -155,19 +155,21 @@ bool StreamModel::setData(const QModelIndex &index, const QVariant &value, int r { // Edit Supported Fields case StreamName: - mCurrentPort->streamByIndex(index.row())->setName(value.toString()); + mCurrentPort->mutableStreamByIndex(index.row()) + ->setName(value.toString()); emit(dataChanged(index, index)); return true; case StreamStatus: - mCurrentPort->streamByIndex(index.row())->setEnabled(value.toBool()); + mCurrentPort->mutableStreamByIndex(index.row()) + ->setEnabled(value.toBool()); emit(dataChanged(index, index)); return true; case StreamNextWhat: if (role == Qt::EditRole) { - mCurrentPort->streamByIndex(index.row())->setNextWhat( + mCurrentPort->mutableStreamByIndex(index.row())->setNextWhat( (Stream::NextWhat)value.toInt()); emit(dataChanged(index, index)); return true; diff --git a/common/streambase.cpp b/common/streambase.cpp index 622e3d5..e3ac38d 100644 --- a/common/streambase.cpp +++ b/common/streambase.cpp @@ -145,7 +145,7 @@ ProtocolListIterator* StreamBase::createProtocolListIterator() const return new ProtocolListIterator(*currentFrameProtocols); } -quint32 StreamBase::id() +quint32 StreamBase::id() const { return mStreamId->id(); } diff --git a/common/streambase.h b/common/streambase.h index ca6e6be..6fe156b 100644 --- a/common/streambase.h +++ b/common/streambase.h @@ -68,7 +68,7 @@ public: e_nw_goto_id }; - quint32 id(); + quint32 id() const; bool setId(quint32 id); #if 0 // FIXME(HI): needed?