blob: 8b37990f752c831c0845928eabd6848e433d08a4 [file] [log] [blame]
taylorchuc27dd482014-05-17 20:06:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Qi Zhao0e043e52016-12-05 18:27:09 -08003 * Copyright (c) 2013-2016, Regents of the University of California.
4 *
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"
21
22#include <ndn-cxx/face.hpp>
23#include <ndn-cxx/name.hpp>
24#include <ndn-cxx/interest.hpp>
25#include <ndn-cxx/management/nfd-fib-entry.hpp>
26#include <ndn-cxx/management/nfd-face-status.hpp>
27#include <ndn-cxx/management/nfd-forwarder-status.hpp>
28
29#ifdef WAF
30#include "forwarder-status.moc"
taylorchuc27dd482014-05-17 20:06:49 -070031#endif
32
33namespace ndn {
34
Alexander Afanasyev4086d512014-07-11 15:56:33 -070035ForwarderStatusModel::ForwarderStatusModel(QObject* parent/* = 0*/)
taylorchuc27dd482014-05-17 20:06:49 -070036 : QAbstractListModel(parent)
taylorchuc27dd482014-05-17 20:06:49 -070037{
Qi Zhao0e043e52016-12-05 18:27:09 -080038 connect(this, SIGNAL(onDataReceived(ndn::nfd::ForwarderStatus)), this,
39 SLOT(updateStatus(ndn::nfd::ForwarderStatus)),
Alexander Afanasyev4086d512014-07-11 15:56:33 -070040 Qt::QueuedConnection);
taylorchuc27dd482014-05-17 20:06:49 -070041}
42
43int
44ForwarderStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const
45{
46 return m_items.count();
47}
48
49void
50ForwarderStatusModel::addItem(const ForwarderStatusItem& item)
51{
52 beginInsertRows(QModelIndex(), rowCount(), rowCount());
53 m_items << item;
54 endInsertRows();
55}
56
57QVariant
58ForwarderStatusModel::data(const QModelIndex& index, int role) const
59{
60 if (index.row() < 0 || index.row() >= m_items.count()) {
61 return QVariant();
62 }
63
64 const ForwarderStatusItem& item = m_items.at(index.row());
65 if (role == TypeRole) {
66 return item.type();
67 }
68 else if (role == ValueRole) {
69 return item.value();
70 }
71 return QVariant();
72}
73
74QHash<int, QByteArray>
75ForwarderStatusModel::roleNames() const
76{
77 QHash<int, QByteArray> roles;
78 roles[TypeRole] = "type";
79 roles[ValueRole] = "value";
80 return roles;
81}
82
taylorchuc27dd482014-05-17 20:06:49 -070083void
84ForwarderStatusModel::clear()
85{
86 beginResetModel();
87 m_items.clear();
88 endResetModel ();
89}
90
91void
Qi Zhao0e043e52016-12-05 18:27:09 -080092ForwarderStatusModel::updateStatus(ndn::nfd::ForwarderStatus status)
taylorchuc27dd482014-05-17 20:06:49 -070093{
94 beginResetModel();
95 m_items.clear();
susmit4fe3cb92016-03-20 17:08:41 -070096 addItem(ForwarderStatusItem("Version", QString::fromStdString(status.getNfdVersion())));
97 addItem(ForwarderStatusItem("Start Time", QString::fromStdString(time::toIsoString(status.getStartTimestamp()))));
98 addItem(ForwarderStatusItem("Current Time", QString::fromStdString(time::toIsoString(status.getCurrentTimestamp()))));
99 addItem(ForwarderStatusItem("Name Tree Entries", QString::number(status.getNNameTreeEntries())));
100 addItem(ForwarderStatusItem("Fib Entries", QString::number(status.getNFibEntries())));
101 addItem(ForwarderStatusItem("PitEntries", QString::number(status.getNPitEntries())));
102 addItem(ForwarderStatusItem("Measurements Entries", QString::number(status.getNMeasurementsEntries())));
103 addItem(ForwarderStatusItem("Content Store Entries", QString::number(status.getNCsEntries())));
104 addItem(ForwarderStatusItem("Incoming Interests", QString::number(status.getNInInterests())));
105 addItem(ForwarderStatusItem("Outgoing Interests", QString::number(status.getNOutInterests())));
106 addItem(ForwarderStatusItem("Incoming Data", QString::number(status.getNInDatas())));
107 addItem(ForwarderStatusItem("Outgoing Data", QString::number(status.getNOutDatas())));
108 addItem(ForwarderStatusItem("Incoming Nacks", QString::number(status.getNInDatas())));
109 addItem(ForwarderStatusItem("Outgoing Nacks", QString::number(status.getNOutDatas())));
taylorchuc27dd482014-05-17 20:06:49 -0700110 endResetModel();
111}
112
113void
114ForwarderStatusModel::onTimeout(const Interest& interest)
115{
116 std::cerr << "Request timed out (should not really happen)" << std::endl;
117}
118
119} // namespace ndn