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"
This commit is contained in:
parent
4d13ecf15d
commit
cca2e94bb3
@ -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<int> &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<DeviceGroup*>(
|
||||
deviceGroupById(deviceGroupId));
|
||||
|
||||
if (!devGrp) {
|
||||
qDebug("%s: deviceGroup id %u does not exist", __FUNCTION__,
|
||||
|
@ -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
|
||||
|
@ -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 - <b>click Apply</b> "
|
||||
"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;
|
||||
|
@ -66,6 +66,7 @@ public slots:
|
||||
void showMyReservedPortsOnly(bool enabled);
|
||||
|
||||
private slots:
|
||||
void updateApplyHint(bool configChanged);
|
||||
void updatePortViewActions(const QModelIndex& currentIndex);
|
||||
void updateStreamViewActions();
|
||||
|
||||
|
@ -150,12 +150,25 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<widget class="QLabel" name="applyHint">
|
||||
<property name="text">
|
||||
<string>Configuration Changed? Click Apply on the right to activate the changes</string>
|
||||
<string>Apply Hint</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbApply">
|
||||
<property name="text">
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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;
|
||||
|
@ -145,7 +145,7 @@ ProtocolListIterator* StreamBase::createProtocolListIterator() const
|
||||
return new ProtocolListIterator(*currentFrameProtocols);
|
||||
}
|
||||
|
||||
quint32 StreamBase::id()
|
||||
quint32 StreamBase::id() const
|
||||
{
|
||||
return mStreamId->id();
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
e_nw_goto_id
|
||||
};
|
||||
|
||||
quint32 id();
|
||||
quint32 id() const;
|
||||
bool setId(quint32 id);
|
||||
|
||||
#if 0 // FIXME(HI): needed?
|
||||
|
Loading…
Reference in New Issue
Block a user