blob: 5850b36500fa6b4b7327f291b2d790a0153cefa9 [file] [log] [blame]
taylorchuc27dd482014-05-17 20:06:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
susmita71cf412016-03-20 15:02:29 -06003 * Copyright (c) 2013-2016, Regents of the University of California,
taylorchuc27dd482014-05-17 20:06:49 -07004 * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
5 * authors and contributors.
6 *
7 * NFD Control Center is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU General Public License as published by the Free Software Foundation,
9 * either version 3 of the License, or (at your option) any later version.
10 *
11 * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along with NFD
16 * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
susmita71cf412016-03-20 15:02:29 -060017 * TODO:Add others
taylorchuc27dd482014-05-17 20:06:49 -070018 */
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{
38 connect(this, SIGNAL(onDataReceived(ndn::shared_ptr<const ndn::Data>)), this,
Alexander Afanasyev4086d512014-07-11 15:56:33 -070039 SLOT(updateStatus(ndn::shared_ptr<const ndn::Data>)),
40 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
92ForwarderStatusModel::afterFetchedVersionInformation(const Data& data)
93{
94 emit onDataReceived(data.shared_from_this());
95}
96
97void
98ForwarderStatusModel::updateStatus(shared_ptr<const Data> data)
99{
100 beginResetModel();
101 m_items.clear();
102 nfd::ForwarderStatus status(data->getContent());
susmit4fe3cb92016-03-20 17:08:41 -0700103 addItem(ForwarderStatusItem("Version", QString::fromStdString(status.getNfdVersion())));
104 addItem(ForwarderStatusItem("Start Time", QString::fromStdString(time::toIsoString(status.getStartTimestamp()))));
105 addItem(ForwarderStatusItem("Current Time", QString::fromStdString(time::toIsoString(status.getCurrentTimestamp()))));
106 addItem(ForwarderStatusItem("Name Tree Entries", QString::number(status.getNNameTreeEntries())));
107 addItem(ForwarderStatusItem("Fib Entries", QString::number(status.getNFibEntries())));
108 addItem(ForwarderStatusItem("PitEntries", QString::number(status.getNPitEntries())));
109 addItem(ForwarderStatusItem("Measurements Entries", QString::number(status.getNMeasurementsEntries())));
110 addItem(ForwarderStatusItem("Content Store Entries", QString::number(status.getNCsEntries())));
111 addItem(ForwarderStatusItem("Incoming Interests", QString::number(status.getNInInterests())));
112 addItem(ForwarderStatusItem("Outgoing Interests", QString::number(status.getNOutInterests())));
113 addItem(ForwarderStatusItem("Incoming Data", QString::number(status.getNInDatas())));
114 addItem(ForwarderStatusItem("Outgoing Data", QString::number(status.getNOutDatas())));
115 addItem(ForwarderStatusItem("Incoming Nacks", QString::number(status.getNInDatas())));
116 addItem(ForwarderStatusItem("Outgoing Nacks", QString::number(status.getNOutDatas())));
taylorchuc27dd482014-05-17 20:06:49 -0700117 endResetModel();
118}
119
120void
121ForwarderStatusModel::onTimeout(const Interest& interest)
122{
123 std::cerr << "Request timed out (should not really happen)" << std::endl;
124}
125
126} // namespace ndn