blob: 80ccc6333f1b238285d11b43db9180a748e26521 [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
23#include <ndn-cxx/face.hpp>
24#include <ndn-cxx/name.hpp>
25#include <ndn-cxx/interest.hpp>
26#include <ndn-cxx/management/nfd-fib-entry.hpp>
27#include <ndn-cxx/management/nfd-face-status.hpp>
28#include <ndn-cxx/management/nfd-forwarder-status.hpp>
29
taylorchuc27dd482014-05-17 20:06:49 -070030namespace ndn {
31
Alexander Afanasyev4086d512014-07-11 15:56:33 -070032ForwarderStatusModel::ForwarderStatusModel(QObject* parent/* = 0*/)
taylorchuc27dd482014-05-17 20:06:49 -070033 : QAbstractListModel(parent)
taylorchuc27dd482014-05-17 20:06:49 -070034{
Qi Zhao0e043e52016-12-05 18:27:09 -080035 connect(this, SIGNAL(onDataReceived(ndn::nfd::ForwarderStatus)), this,
36 SLOT(updateStatus(ndn::nfd::ForwarderStatus)),
Alexander Afanasyev4086d512014-07-11 15:56:33 -070037 Qt::QueuedConnection);
taylorchuc27dd482014-05-17 20:06:49 -070038}
39
40int
41ForwarderStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const
42{
43 return m_items.count();
44}
45
46void
47ForwarderStatusModel::addItem(const ForwarderStatusItem& item)
48{
49 beginInsertRows(QModelIndex(), rowCount(), rowCount());
50 m_items << item;
51 endInsertRows();
52}
53
54QVariant
55ForwarderStatusModel::data(const QModelIndex& index, int role) const
56{
57 if (index.row() < 0 || index.row() >= m_items.count()) {
58 return QVariant();
59 }
60
61 const ForwarderStatusItem& item = m_items.at(index.row());
62 if (role == TypeRole) {
63 return item.type();
64 }
65 else if (role == ValueRole) {
66 return item.value();
67 }
68 return QVariant();
69}
70
71QHash<int, QByteArray>
72ForwarderStatusModel::roleNames() const
73{
74 QHash<int, QByteArray> roles;
75 roles[TypeRole] = "type";
76 roles[ValueRole] = "value";
77 return roles;
78}
79
taylorchuc27dd482014-05-17 20:06:49 -070080void
81ForwarderStatusModel::clear()
82{
83 beginResetModel();
84 m_items.clear();
85 endResetModel ();
86}
87
88void
Qi Zhao0e043e52016-12-05 18:27:09 -080089ForwarderStatusModel::updateStatus(ndn::nfd::ForwarderStatus status)
taylorchuc27dd482014-05-17 20:06:49 -070090{
91 beginResetModel();
92 m_items.clear();
susmit4fe3cb92016-03-20 17:08:41 -070093 addItem(ForwarderStatusItem("Version", QString::fromStdString(status.getNfdVersion())));
94 addItem(ForwarderStatusItem("Start Time", QString::fromStdString(time::toIsoString(status.getStartTimestamp()))));
95 addItem(ForwarderStatusItem("Current Time", QString::fromStdString(time::toIsoString(status.getCurrentTimestamp()))));
96 addItem(ForwarderStatusItem("Name Tree Entries", QString::number(status.getNNameTreeEntries())));
97 addItem(ForwarderStatusItem("Fib Entries", QString::number(status.getNFibEntries())));
98 addItem(ForwarderStatusItem("PitEntries", QString::number(status.getNPitEntries())));
99 addItem(ForwarderStatusItem("Measurements Entries", QString::number(status.getNMeasurementsEntries())));
100 addItem(ForwarderStatusItem("Content Store Entries", QString::number(status.getNCsEntries())));
101 addItem(ForwarderStatusItem("Incoming Interests", QString::number(status.getNInInterests())));
102 addItem(ForwarderStatusItem("Outgoing Interests", QString::number(status.getNOutInterests())));
103 addItem(ForwarderStatusItem("Incoming Data", QString::number(status.getNInDatas())));
104 addItem(ForwarderStatusItem("Outgoing Data", QString::number(status.getNOutDatas())));
105 addItem(ForwarderStatusItem("Incoming Nacks", QString::number(status.getNInDatas())));
106 addItem(ForwarderStatusItem("Outgoing Nacks", QString::number(status.getNOutDatas())));
taylorchuc27dd482014-05-17 20:06:49 -0700107 endResetModel();
108}
109
110void
111ForwarderStatusModel::onTimeout(const Interest& interest)
112{
113 std::cerr << "Request timed out (should not really happen)" << std::endl;
114}
115
116} // namespace ndn