From 3602d24767164745bb930a1c4ca077d5e194fb05 Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Sat, 14 Nov 2009 15:09:19 +0000 Subject: [PATCH] Fixes - LinkState is now updated in PortWindow as soon as a change is detected; the required minimal refactoring of the Port class usage has been done - Fixed a compiler warning in portgrouplist.cpp Others - PortStatsFilter: Ui change - added left and right arrow icons --- client/icons/arrow_left.png | Bin 0 -> 345 bytes client/ostinato.qrc | 1 + client/port.cpp | 6 ++-- client/port.h | 17 +++-------- client/portgroup.cpp | 57 ++++++++++++++++++++---------------- client/portgroup.h | 4 +-- client/portgrouplist.cpp | 27 +++++------------ client/portmodel.cpp | 41 ++++++++------------------ client/portmodel.h | 2 +- client/portstatsfilter.ui | 6 ++++ client/portstatsmodel.cpp | 2 +- client/streammodel.cpp | 2 +- 12 files changed, 71 insertions(+), 94 deletions(-) create mode 100644 client/icons/arrow_left.png diff --git a/client/icons/arrow_left.png b/client/icons/arrow_left.png new file mode 100644 index 0000000000000000000000000000000000000000..5dc696781e6135d37b5bf2e98e46fd94f020c48d GIT binary patch literal 345 zcmV-f0jBq$gGR5;6H z{Qv(y10{fofkH6I3@AO3$p*x`Nil#0jeqs;pT9Ds7{CaN1)$9r#n~kE{`~pF@bLXZ zhF?E_GyM7i!oL`P0x_8Wj$ni2F7#hzWPxfvDaI icons/arrow_down.png + icons/arrow_left.png icons/arrow_right.png icons/arrow_up.png icons/bullet_error.png diff --git a/client/port.cpp b/client/port.cpp index d7e2b4c..87f0e07 100644 --- a/client/port.cpp +++ b/client/port.cpp @@ -187,9 +187,11 @@ void Port::updateStats(OstProto::PortStats *portStats) oldState = stats.state(); stats.MergeFrom(*portStats); -#if 0 + if (oldState.link_state() != stats.state().link_state()) + { + qDebug("portstate changed"); emit portDataChanged(mPortGroupId, mPortId); -#endif + } } diff --git a/client/port.h b/client/port.h index bdafdb9..9be12ed 100644 --- a/client/port.h +++ b/client/port.h @@ -1,18 +1,17 @@ #ifndef _PORT_H #define _PORT_H -#include +#include #include #include #include "stream.h" //class StreamModel; -class Port { +class Port : public QObject { - //friend class StreamModel; + Q_OBJECT -private: static uint mAllocStreamId; OstProto::Port d; OstProto::PortStats stats; @@ -28,6 +27,7 @@ private: uint newStreamId(); void updateStreamOrdinalsFromIndex(); void reorderStreamsByOrdinals(); + public: enum AdminStatus { AdminDisable, AdminEnable }; enum ControlMode { ControlShared, ControlExclusive }; @@ -50,13 +50,6 @@ public: ControlMode controlMode() { return (d.is_exclusive_control()?ControlExclusive:ControlShared); } -#if 0 - void setName(QString &name) { d.name; } - void setName(const char* name) { mName = QString(name); } - void setDescription(QString &description) { mDescription = description; } - void setDescription(const char *description) - { mDescription = QString(description); } -#endif //void setAdminEnable(AdminStatus status) { mAdminStatus = status; } void setAlias(QString &alias) { mUserAlias = alias; } //void setExclusive(bool flag); @@ -97,10 +90,8 @@ public: void updateStats(OstProto::PortStats *portStats); -#if 0 signals: void portDataChanged(int portGroupId, int portId); -#endif }; diff --git a/client/portgroup.cpp b/client/portgroup.cpp index 76888f3..9e17ae8 100644 --- a/client/portgroup.cpp +++ b/client/portgroup.cpp @@ -51,7 +51,7 @@ PortGroup::~PortGroup() void PortGroup::on_rpcChannel_stateChanged() { qDebug("state changed"); - emit portGroupDataChanged(this); + emit portGroupDataChanged(mPortGroupId); } void PortGroup::on_rpcChannel_connected() @@ -60,7 +60,7 @@ void PortGroup::on_rpcChannel_connected() OstProto::PortIdList *portIdList; qDebug("connected\n"); - emit portGroupDataChanged(this); + emit portGroupDataChanged(mPortGroupId); qDebug("requesting portlist ..."); portIdList = new OstProto::PortIdList(); @@ -73,15 +73,18 @@ void PortGroup::on_rpcChannel_disconnected() { qDebug("disconnected\n"); emit portListAboutToBeChanged(mPortGroupId); - mPorts.clear(); + + while (!mPorts.isEmpty()) + delete mPorts.takeFirst(); + emit portListChanged(mPortGroupId); - emit portGroupDataChanged(this); + emit portGroupDataChanged(mPortGroupId); } void PortGroup::on_rpcChannel_error(QAbstractSocket::SocketError socketError) { qDebug("error\n"); - emit portGroupDataChanged(this); + emit portGroupDataChanged(mPortGroupId); } void PortGroup::when_configApply(int portIndex, uint *cookie) @@ -124,8 +127,8 @@ void PortGroup::when_configApply(int portIndex, uint *cookie) qDebug("applying 'deleted streams' ..."); - streamIdList.mutable_port_id()->set_id(mPorts[portIndex].id()); - mPorts[portIndex].getDeletedStreamsSinceLastSync(streamIdList); + streamIdList.mutable_port_id()->set_id(mPorts[portIndex]->id()); + mPorts[portIndex]->getDeletedStreamsSinceLastSync(streamIdList); (*op)++; rpcController->Reset(); @@ -140,8 +143,8 @@ void PortGroup::when_configApply(int portIndex, uint *cookie) qDebug("applying 'new streams' ..."); - streamIdList.mutable_port_id()->set_id(mPorts[portIndex].id()); - mPorts[portIndex].getNewStreamsSinceLastSync(streamIdList); + streamIdList.mutable_port_id()->set_id(mPorts[portIndex]->id()); + mPorts[portIndex]->getNewStreamsSinceLastSync(streamIdList); (*op)++; rpcController->Reset(); @@ -156,8 +159,8 @@ void PortGroup::when_configApply(int portIndex, uint *cookie) qDebug("applying 'modified streams' ..."); - streamConfigList.mutable_port_id()->set_id(mPorts[portIndex].id()); - mPorts[portIndex].getModifiedStreamsSinceLastSync(streamConfigList); + streamConfigList.mutable_port_id()->set_id(mPorts[portIndex]->id()); + mPorts[portIndex]->getModifiedStreamsSinceLastSync(streamConfigList); (*op)++; rpcController->Reset(); @@ -168,7 +171,7 @@ void PortGroup::when_configApply(int portIndex, uint *cookie) case 3: qDebug("apply completed"); - mPorts[portIndex].when_syncComplete(); + mPorts[portIndex]->when_syncComplete(); delete cookie; break; @@ -195,8 +198,10 @@ void PortGroup::processPortIdList(OstProto::PortIdList *portIdList) Port *p; p = new Port(portIdList->port_id(i).id(), mPortGroupId); + connect(p, SIGNAL(portDataChanged(int, int)), + this, SIGNAL(portGroupDataChanged(int, int))); qDebug("before port append\n"); - mPorts.append(*p); + mPorts.append(p); } emit portListChanged(mPortGroupId); @@ -240,7 +245,7 @@ void PortGroup::processPortConfigList(OstProto::PortConfigList *portConfigList) id = portConfigList->port(i).port_id().id(); // FIXME: don't mix port id & index into mPorts[] - mPorts[id].updatePortConfig(portConfigList->mutable_port(i)); + mPorts[id]->updatePortConfig(portConfigList->mutable_port(i)); } emit portListChanged(mPortGroupId); @@ -284,10 +289,10 @@ void PortGroup::getStreamIdList(int portIndex, Q_ASSERT(portIndex < numPorts()); - if (streamIdList->port_id().id() != mPorts[portIndex].id()) + if (streamIdList->port_id().id() != mPorts[portIndex]->id()) { qDebug("%s: Invalid portId %d (expected %d) received for portIndex %d", - __FUNCTION__, streamIdList->port_id().id(), mPorts[portIndex].id(), + __FUNCTION__, streamIdList->port_id().id(), mPorts[portIndex]->id(), portIndex); goto _next_port; // FIXME(MED): Partial RPC } @@ -298,14 +303,14 @@ void PortGroup::getStreamIdList(int portIndex, uint streamId; streamId = streamIdList->stream_id(i).id(); - mPorts[portIndex].insertStream(streamId); + mPorts[portIndex]->insertStream(streamId); } _next_port: // FIXME(HI): ideally we shd use signals/slots but this means // we will have to use Port* instead of Port with QList<> - // need to find a way for this - mPorts[portIndex].when_syncComplete(); + mPorts[portIndex]->when_syncComplete(); portIndex++; if (portIndex >= numPorts()) { @@ -322,7 +327,7 @@ _next_port: } _request: - portId.set_id(mPorts[portIndex].id()); + portId.set_id(mPorts[portIndex]->id()); streamIdList->Clear(); rpcController->Reset(); @@ -368,11 +373,11 @@ void PortGroup::getStreamConfigList(int portIndex, Q_ASSERT(portIndex < numPorts()); - if (streamConfigList->port_id().id() != mPorts[portIndex].id()) + if (streamConfigList->port_id().id() != mPorts[portIndex]->id()) { qDebug("%s: Invalid portId %d (expected %d) received for portIndex %d", __FUNCTION__, streamConfigList->port_id().id(), - mPorts[portIndex].id(), portIndex); + mPorts[portIndex]->id(), portIndex); goto _next_port; // FIXME(MED): Partial RPC } @@ -382,7 +387,7 @@ void PortGroup::getStreamConfigList(int portIndex, uint streamId; streamId = streamConfigList->stream(i).stream_id().id(); - mPorts[portIndex].updateStream(streamId, + mPorts[portIndex]->updateStream(streamId, streamConfigList->mutable_stream(i)); } @@ -403,13 +408,13 @@ _request: qDebug("requesting stream config list ..."); streamIdList.Clear(); - streamIdList.mutable_port_id()->set_id(mPorts[portIndex].id()); - for (int j = 0; j < mPorts[portIndex].numStreams(); j++) + streamIdList.mutable_port_id()->set_id(mPorts[portIndex]->id()); + for (int j = 0; j < mPorts[portIndex]->numStreams(); j++) { OstProto::StreamId *s; s = streamIdList.add_stream_id(); - s->set_id(mPorts[portIndex].streamByIndex(j)->id()); + s->set_id(mPorts[portIndex]->streamByIndex(j)->id()); } streamConfigList->Clear(); @@ -657,7 +662,7 @@ void PortGroup::processPortStatsList(OstProto::PortStatsList *portStatsList) id = portStatsList->port_stats(i).port_id().id(); // FIXME: don't mix port id & index into mPorts[] - mPorts[id].updateStats(portStatsList->mutable_port_stats(i)); + mPorts[id]->updateStats(portStatsList->mutable_port_stats(i)); } emit statsChanged(mPortGroupId); diff --git a/client/portgroup.h b/client/portgroup.h index 81363cc..c63d739 100644 --- a/client/portgroup.h +++ b/client/portgroup.h @@ -38,7 +38,7 @@ private: ::OstProto::PortIdList portIdList; public: // FIXME(HIGH): member access - QList mPorts; + QList mPorts; public: PortGroup(QHostAddress ip = QHostAddress::LocalHost, @@ -91,7 +91,7 @@ public: void processClearStatsAck(OstProto::Ack *ack); signals: - void portGroupDataChanged(PortGroup* portGroup, int portId = 0xFFFF); + void portGroupDataChanged(int portGroupId, int portId = 0xFFFF); void portListAboutToBeChanged(quint32 portGroupId); void portListChanged(quint32 portGroupId); void statsChanged(quint32 portGroupId); diff --git a/client/portgrouplist.cpp b/client/portgrouplist.cpp index 4387aee..e5aa69e 100644 --- a/client/portgrouplist.cpp +++ b/client/portgrouplist.cpp @@ -32,36 +32,23 @@ bool PortGroupList::isPort(const QModelIndex& index) PortGroup& PortGroupList::portGroup(const QModelIndex& index) { - if (mPortGroupListModel.isPortGroup(index)) - { - //return *(mPortGroups[mPortGroupListModel.portGroupId(index)]); - return *(mPortGroups[index.row()]); - } -#if 0 // FIXME(MED) - else - return NULL; -#endif + Q_ASSERT(mPortGroupListModel.isPortGroup(index)); + + return *(mPortGroups[index.row()]); } Port& PortGroupList::port(const QModelIndex& index) { - if (mPortGroupListModel.isPort(index)) - { - return (mPortGroups.at(index.parent().row())-> - mPorts[index.row()]); - } -#if 0 // FIXME(MED) - else - return NULL; -#endif + Q_ASSERT(mPortGroupListModel.isPort(index)); + return (*mPortGroups.at(index.parent().row())->mPorts[index.row()]); } void PortGroupList::addPortGroup(PortGroup &portGroup) { mPortGroupListModel.portGroupAboutToBeAppended(); - connect(&portGroup, SIGNAL(portGroupDataChanged(PortGroup*, int)), - &mPortGroupListModel, SLOT(when_portGroupDataChanged(PortGroup*, int))); + connect(&portGroup, SIGNAL(portGroupDataChanged(int, int)), + &mPortGroupListModel, SLOT(when_portGroupDataChanged(int, int))); #if 0 connect(&portGroup, SIGNAL(portListAboutToBeChanged(quint32)), &mPortGroupListModel, SLOT(triggerLayoutAboutToBeChanged())); diff --git a/client/portmodel.cpp b/client/portmodel.cpp index 9397cc1..480b642 100644 --- a/client/portmodel.cpp +++ b/client/portmodel.cpp @@ -132,19 +132,19 @@ QVariant PortModel::data(const QModelIndex &index, int role) const return QString("Port %1: %2 [%3] (%4)"). arg(pgl->mPortGroups.at( - parent.row())->mPorts[index.row()].id()). + parent.row())->mPorts[index.row()]->id()). arg(pgl->mPortGroups.at( - parent.row())->mPorts[index.row()].name()). + parent.row())->mPorts[index.row()]->name()). arg(QHostAddress("0.0.0.0").toString()). // FIXME(LOW) arg(pgl->mPortGroups.at( - parent.row())->mPorts[index.row()].description()); + parent.row())->mPorts[index.row()]->description()); } else if ((role == Qt::DecorationRole)) { DBG0("Exit PortModel data 5\n"); if (pgl->mPortGroups.at(parent.row())->numPorts() == 0) return QVariant(); - switch(pgl->mPortGroups.at(parent.row())->mPorts[index.row()].linkState()) + switch(pgl->mPortGroups.at(parent.row())->mPorts[index.row()]->linkState()) { case OstProto::LinkStateUnknown: return QIcon(":/icons/bullet_white.png"); @@ -198,7 +198,7 @@ QModelIndex PortModel::index (int row, int col, else { quint16 pg = parent.internalId() >> 16; - quint16 p = pgl->mPortGroups.value(parent.row())->mPorts.value(row).id(); + quint16 p = pgl->mPortGroups.value(parent.row())->mPorts.value(row)->id(); quint32 id = (pg << 16) | p; //qDebug("index (nontop) dbg: PG=%d, P=%d, ID=%x\n", pg, p, id); @@ -264,21 +264,18 @@ quint32 PortModel::portId(const QModelIndex& index) // ---------------------------------------------- // Slots // ---------------------------------------------- -void PortModel::when_portGroupDataChanged(PortGroup* portGroup, int portId) +void PortModel::when_portGroupDataChanged(int portGroupId, int portId) { QModelIndex index; + int row; - if (!pgl->mPortGroups.contains(portGroup)) - { - qDebug("when_portGroupDataChanged(): pg not in list - do nothing"); - return; - } + if (portId == 0xFFFF) + row = pgl->indexOfPortGroup(portGroupId); + else + row = portId; + + index = createIndex(row, 0, (portGroupId << 16) | portId); - qDebug("when_portGroupDataChanged pgid = %d", portGroup->id()); - qDebug("when_portGroupDataChanged idx = %d", pgl->mPortGroups.indexOf(portGroup)); - - index = createIndex(pgl->mPortGroups.indexOf(portGroup), 0, - (portGroup->id() << 16) | portId); emit dataChanged(index, index); } @@ -308,18 +305,6 @@ void PortModel::portGroupRemoved() endRemoveRows(); } -#if 0 -void PortModel::triggerLayoutAboutToBeChanged() -{ - emit layoutAboutToBeChanged(); -} - -void PortModel::triggerLayoutChanged() -{ - emit layoutChanged(); -} -#endif - void PortModel::when_portListChanged() { reset(); diff --git a/client/portmodel.h b/client/portmodel.h index de2b140..bd4b791 100644 --- a/client/portmodel.h +++ b/client/portmodel.h @@ -32,7 +32,7 @@ class PortModel : public QAbstractItemModel private slots: - void when_portGroupDataChanged(PortGroup *portGroup, int portId); + void when_portGroupDataChanged(int portGroupId, int portId); void portGroupAboutToBeAppended(); void portGroupAppended(); diff --git a/client/portstatsfilter.ui b/client/portstatsfilter.ui index af9af02..61aa7a7 100644 --- a/client/portstatsfilter.ui +++ b/client/portstatsfilter.ui @@ -57,6 +57,9 @@ > + + :/icons/arrow_right.png + @@ -64,6 +67,9 @@ < + + :/icons/arrow_left.png + diff --git a/client/portstatsmodel.cpp b/client/portstatsmodel.cpp index 6d77945..ce75846 100644 --- a/client/portstatsmodel.cpp +++ b/client/portstatsmodel.cpp @@ -91,7 +91,7 @@ QVariant PortStatsModel::data(const QModelIndex &index, int role) const { OstProto::PortStats stats; - stats = pgl->mPortGroups.at(pgidx)->mPorts[pidx].getStats(); + stats = pgl->mPortGroups.at(pgidx)->mPorts[pidx]->getStats(); switch(row) { diff --git a/client/streammodel.cpp b/client/streammodel.cpp index cba20e6..a3036fb 100644 --- a/client/streammodel.cpp +++ b/client/streammodel.cpp @@ -236,7 +236,7 @@ void StreamModel::setCurrentPortIndex(const QModelIndex ¤t) { qDebug("change to valid port"); quint16 pg = current.internalId() >> 16; - mCurrentPort = &pgl->mPortGroups[pgl->indexOfPortGroup(pg)]->mPorts[current.row()]; + mCurrentPort = pgl->mPortGroups[pgl->indexOfPortGroup(pg)]->mPorts[current.row()]; } reset(); }