blob: 80d6f63c0b61f768df098dc67df8f5b2bfe5772c [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();
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080086 addItem({"Version", status.getNfdVersion()});
87 addItem({"Start Time", status.getStartTimestamp()});
88 addItem({"Current Time", status.getCurrentTimestamp()});
89 addItem({"Name Tree Entries", status.getNNameTreeEntries()});
90 addItem({"Fib Entries", status.getNFibEntries()});
91 addItem({"PitEntries", status.getNPitEntries()});
92 addItem({"Measurements Entries", status.getNMeasurementsEntries()});
93 addItem({"Content Store Entries", status.getNCsEntries()});
94 addItem({"Incoming Interests", status.getNInInterests()});
95 addItem({"Outgoing Interests", status.getNOutInterests()});
96 addItem({"Incoming Data", status.getNInDatas()});
97 addItem({"Outgoing Data", status.getNOutDatas()});
98 addItem({"Incoming Nacks", status.getNInDatas()});
99 addItem({"Outgoing Nacks", 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