diff --git a/client/streamstatsmodel.cpp b/client/streamstatsmodel.cpp
index d7946de..f397334 100644
--- a/client/streamstatsmodel.cpp
+++ b/client/streamstatsmodel.cpp
@@ -21,23 +21,133 @@ along with this program. If not, see
#include "protocol.pb.h"
+// XXX: Keep the enum in sync with it's string
+enum {
+ kRxPkts,
+ kTxPkts,
+ kRxBytes,
+ kTxBytes,
+ kMaxStreamStats
+};
+static QStringList statTitles = QStringList()
+ << "Rx Pkts"
+ << "Tx Pkts"
+ << "Rx Bytes"
+ << "Tx Bytes";
+
StreamStatsModel::StreamStatsModel(QObject *parent)
- : QStringListModel(parent)
+ : QAbstractTableModel(parent)
{
}
+int StreamStatsModel::rowCount(const QModelIndex &parent) const
+{
+ return guidList_.size();
+}
+
+int StreamStatsModel::columnCount(const QModelIndex &parent) const
+{
+ return portList_.size() * kMaxStreamStats;
+}
+
+QVariant StreamStatsModel::headerData(
+ int section, Qt::Orientation orientation, int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ switch (orientation) {
+ case Qt::Horizontal: // Column Header
+ return QString("Port %1-%2\n%3")
+ .arg(portList_.at(section/kMaxStreamStats).first)
+ .arg(portList_.at(section/kMaxStreamStats).second)
+ .arg(statTitles.at(section % kMaxStreamStats));
+ case Qt::Vertical: // Row Header
+ return QString("Stream GUID %1")
+ .arg(guidList_.at(section));
+ default:
+ break;
+ }
+ return QVariant();
+}
+
+QVariant StreamStatsModel::data(const QModelIndex &index, int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ Guid guid = guidList_.at(index.row());
+ PortGroupPort pgp = portList_.at(index.column()/kMaxStreamStats);
+ int stat = index.column() % kMaxStreamStats;
+
+ switch (stat) {
+ case kRxPkts:
+ return streamStats_.value(guid).value(pgp).rxPkts;
+ case kTxPkts:
+ return streamStats_.value(guid).value(pgp).txPkts;
+ case kRxBytes:
+ return streamStats_.value(guid).value(pgp).rxBytes;
+ case kTxBytes:
+ return streamStats_.value(guid).value(pgp).txBytes;
+ default:
+ break;
+ }
+
+ return QVariant();
+}
+
+// --------------------------------------------- //
+// Slots
+// --------------------------------------------- //
void StreamStatsModel::clearStats()
{
- stats_.clear();
- setStringList(stats_);
+#if QT_VERSION >= 0x040600
+ beginResetModel();
+#endif
+
+ guidList_.clear();
+ portList_.clear();
+ streamStats_.clear();
+
+#if QT_VERSION >= 0x040600
+ endResetModel();
+#else
+ reset();
+#endif
}
void StreamStatsModel::appendStreamStatsList(
- quint32 /*portGroupId*/,
+ quint32 portGroupId,
const OstProto::StreamStatsList *stats)
{
- stats_.append(stats->DebugString().c_str());
- setStringList(stats_);
+ int n = stats->stream_stats_size();
+
+#if QT_VERSION >= 0x040600
+ beginResetModel();
+#endif
+
+ for (int i = 0; i < n; i++) {
+ const OstProto::StreamStats &s = stats->stream_stats(i);
+ PortGroupPort pgp = PortGroupPort(portGroupId, s.port_id().id());
+ Guid guid = s.stream_guid().id();
+ StreamStats &ss = streamStats_[guid][pgp];
+
+ ss.rxPkts = s.rx_pkts();
+ ss.txPkts = s.tx_pkts();
+ ss.rxBytes = s.rx_bytes();
+ ss.txBytes = s.tx_bytes();
+
+ if (!portList_.contains(pgp))
+ portList_.append(pgp);
+ if (!guidList_.contains(guid))
+ guidList_.append(guid);
+ }
+
+#if QT_VERSION >= 0x040600
+ endResetModel();
+#else
+ reset();
+#endif
// Prevent receiving any future updates from this sender
disconnect(sender(), 0, this, 0);
diff --git a/client/streamstatsmodel.h b/client/streamstatsmodel.h
index 934fded..0e884ef 100644
--- a/client/streamstatsmodel.h
+++ b/client/streamstatsmodel.h
@@ -20,24 +20,45 @@ along with this program. If not, see
#ifndef _STREAM_STATS_MODEL_H
#define _STREAM_STATS_MODEL_H
-#include // FIXME: remove
+#include
+#include
+#include
+#include
+#include
namespace OstProto {
class StreamStatsList;
}
-class StreamStatsModel: public QStringListModel // FIXME: change to TableModel
+class StreamStatsModel: public QAbstractTableModel
{
Q_OBJECT
public:
StreamStatsModel(QObject *parent = 0);
+ int rowCount(const QModelIndex &parent=QModelIndex()) const;
+ int columnCount(const QModelIndex &parent=QModelIndex()) const;
+
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
public slots:
void clearStats();
void appendStreamStatsList(quint32 portGroupId,
const OstProto::StreamStatsList *stats);
private:
- QList stats_; // FIXME: remove
+ typedef QPair PortGroupPort; // Pair = (PortGroupId, PortId)
+ typedef uint Guid;
+ struct StreamStats {
+ quint64 rxPkts;
+ quint64 txPkts;
+ quint64 rxBytes;
+ quint64 txBytes;
+ };
+ QList guidList_;
+ QList portList_;
+ QHash > streamStats_;
};
#endif
diff --git a/client/streamstatswindow.ui b/client/streamstatswindow.ui
index ffebeba..7a15ffa 100644
--- a/client/streamstatswindow.ui
+++ b/client/streamstatswindow.ui
@@ -1,6 +1,6 @@
StreamStatsWindow
-
+
0
@@ -14,7 +14,7 @@
-
-
+