blob: a6b76609fab2ccd3a9adc7d8b8c39f77b803fb05 [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());
Alexander Afanasyev5f14bee2016-03-20 11:38:07 -0700103 addItem(ForwarderStatusItem("version", QString::fromStdString(status.getNfdVersion())));
taylorchuc27dd482014-05-17 20:06:49 -0700104 addItem(ForwarderStatusItem("startTime", QString::fromStdString(time::toIsoString(status.getStartTimestamp()))));
105 addItem(ForwarderStatusItem("currentTime", QString::fromStdString(time::toIsoString(status.getCurrentTimestamp()))));
106 addItem(ForwarderStatusItem("nNameTreeEntries", QString::number(status.getNNameTreeEntries())));
107 addItem(ForwarderStatusItem("nFibEntries", QString::number(status.getNFibEntries())));
108 addItem(ForwarderStatusItem("nPitEntries", QString::number(status.getNPitEntries())));
109 addItem(ForwarderStatusItem("nMeasurementsEntries", QString::number(status.getNMeasurementsEntries())));
110 addItem(ForwarderStatusItem("nCsEntries", QString::number(status.getNCsEntries())));
111 addItem(ForwarderStatusItem("nInInterests", QString::number(status.getNInInterests())));
112 addItem(ForwarderStatusItem("nOutInterests", QString::number(status.getNOutInterests())));
113 addItem(ForwarderStatusItem("nInDatas", QString::number(status.getNInDatas())));
susmita71cf412016-03-20 15:02:29 -0600114 addItem(ForwarderStatusItem("nNInNacks", QString::number(status.getNInDatas())));
115 addItem(ForwarderStatusItem("nNOutNacks", QString::number(status.getNOutDatas())));
taylorchuc27dd482014-05-17 20:06:49 -0700116 endResetModel();
117}
118
119void
120ForwarderStatusModel::onTimeout(const Interest& interest)
121{
122 std::cerr << "Request timed out (should not really happen)" << std::endl;
123}
124
125} // namespace ndn