blob: df203e50a5582aede0d54382eed0ee1aa7b04a91 [file] [log] [blame]
taylorchuc27dd482014-05-17 20:06:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev37667752017-02-02 13:52:12 -08003 * Copyright (c) 2013-2017, Regents of the University of California,
Qi Zhao0e043e52016-12-05 18:27:09 -08004 *
taylorchuc27dd482014-05-17 20:06:49 -07005 * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
6 * authors and contributors.
7 *
8 * NFD Control Center is free software: you can redistribute it and/or modify it under the
9 * terms of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with NFD
17 * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "forwarder-status.hpp"
Alexander Afanasyev37667752017-02-02 13:52:12 -080021#include "forwarder-status.moc"
taylorchuc27dd482014-05-17 20:06:49 -070022
taylorchuc27dd482014-05-17 20:06:49 -070023namespace ndn {
24
Alexander Afanasyev4086d512014-07-11 15:56:33 -070025ForwarderStatusModel::ForwarderStatusModel(QObject* parent/* = 0*/)
taylorchuc27dd482014-05-17 20:06:49 -070026 : QAbstractListModel(parent)
taylorchuc27dd482014-05-17 20:06:49 -070027{
Qi Zhao0e043e52016-12-05 18:27:09 -080028 connect(this, SIGNAL(onDataReceived(ndn::nfd::ForwarderStatus)), this,
29 SLOT(updateStatus(ndn::nfd::ForwarderStatus)),
Alexander Afanasyev4086d512014-07-11 15:56:33 -070030 Qt::QueuedConnection);
taylorchuc27dd482014-05-17 20:06:49 -070031}
32
33int
34ForwarderStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const
35{
36 return m_items.count();
37}
38
39void
40ForwarderStatusModel::addItem(const ForwarderStatusItem& item)
41{
42 beginInsertRows(QModelIndex(), rowCount(), rowCount());
43 m_items << item;
44 endInsertRows();
45}
46
47QVariant
48ForwarderStatusModel::data(const QModelIndex& index, int role) const
49{
50 if (index.row() < 0 || index.row() >= m_items.count()) {
51 return QVariant();
52 }
53
54 const ForwarderStatusItem& item = m_items.at(index.row());
55 if (role == TypeRole) {
56 return item.type();
57 }
58 else if (role == ValueRole) {
59 return item.value();
60 }
61 return QVariant();
62}
63
64QHash<int, QByteArray>
65ForwarderStatusModel::roleNames() const
66{
67 QHash<int, QByteArray> roles;
68 roles[TypeRole] = "type";
69 roles[ValueRole] = "value";
70 return roles;
71}
72
taylorchuc27dd482014-05-17 20:06:49 -070073void
74ForwarderStatusModel::clear()
75{
76 beginResetModel();
77 m_items.clear();
78 endResetModel ();
79}
80
81void
Qi Zhao0e043e52016-12-05 18:27:09 -080082ForwarderStatusModel::updateStatus(ndn::nfd::ForwarderStatus status)
taylorchuc27dd482014-05-17 20:06:49 -070083{
84 beginResetModel();
85 m_items.clear();
susmit4fe3cb92016-03-20 17:08:41 -070086 addItem(ForwarderStatusItem("Version", QString::fromStdString(status.getNfdVersion())));
87 addItem(ForwarderStatusItem("Start Time", QString::fromStdString(time::toIsoString(status.getStartTimestamp()))));
88 addItem(ForwarderStatusItem("Current Time", QString::fromStdString(time::toIsoString(status.getCurrentTimestamp()))));
89 addItem(ForwarderStatusItem("Name Tree Entries", QString::number(status.getNNameTreeEntries())));
90 addItem(ForwarderStatusItem("Fib Entries", QString::number(status.getNFibEntries())));
91 addItem(ForwarderStatusItem("PitEntries", QString::number(status.getNPitEntries())));
92 addItem(ForwarderStatusItem("Measurements Entries", QString::number(status.getNMeasurementsEntries())));
93 addItem(ForwarderStatusItem("Content Store Entries", QString::number(status.getNCsEntries())));
94 addItem(ForwarderStatusItem("Incoming Interests", QString::number(status.getNInInterests())));
95 addItem(ForwarderStatusItem("Outgoing Interests", QString::number(status.getNOutInterests())));
96 addItem(ForwarderStatusItem("Incoming Data", QString::number(status.getNInDatas())));
97 addItem(ForwarderStatusItem("Outgoing Data", QString::number(status.getNOutDatas())));
98 addItem(ForwarderStatusItem("Incoming Nacks", QString::number(status.getNInDatas())));
99 addItem(ForwarderStatusItem("Outgoing Nacks", QString::number(status.getNOutDatas())));
taylorchuc27dd482014-05-17 20:06:49 -0700100 endResetModel();
101}
102
103void
104ForwarderStatusModel::onTimeout(const Interest& interest)
105{
106 std::cerr << "Request timed out (should not really happen)" << std::endl;
107}
108
109} // namespace ndn