blob: b908750775861f249b0393ebd4465e4433f9f1a3 [file] [log] [blame]
taylorchuc27dd482014-05-17 20:06:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014, Regents of the University of California,
4 *
5 * 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"
31// #include "forwarder-status.cpp.moc"
32#endif
33
34namespace ndn {
35
Alexander Afanasyev4086d512014-07-11 15:56:33 -070036ForwarderStatusModel::ForwarderStatusModel(QObject* parent/* = 0*/)
taylorchuc27dd482014-05-17 20:06:49 -070037 : QAbstractListModel(parent)
taylorchuc27dd482014-05-17 20:06:49 -070038{
39 connect(this, SIGNAL(onDataReceived(ndn::shared_ptr<const ndn::Data>)), this,
Alexander Afanasyev4086d512014-07-11 15:56:33 -070040 SLOT(updateStatus(ndn::shared_ptr<const ndn::Data>)),
41 Qt::QueuedConnection);
taylorchuc27dd482014-05-17 20:06:49 -070042}
43
44int
45ForwarderStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const
46{
47 return m_items.count();
48}
49
50void
51ForwarderStatusModel::addItem(const ForwarderStatusItem& item)
52{
53 beginInsertRows(QModelIndex(), rowCount(), rowCount());
54 m_items << item;
55 endInsertRows();
56}
57
58QVariant
59ForwarderStatusModel::data(const QModelIndex& index, int role) const
60{
61 if (index.row() < 0 || index.row() >= m_items.count()) {
62 return QVariant();
63 }
64
65 const ForwarderStatusItem& item = m_items.at(index.row());
66 if (role == TypeRole) {
67 return item.type();
68 }
69 else if (role == ValueRole) {
70 return item.value();
71 }
72 return QVariant();
73}
74
75QHash<int, QByteArray>
76ForwarderStatusModel::roleNames() const
77{
78 QHash<int, QByteArray> roles;
79 roles[TypeRole] = "type";
80 roles[ValueRole] = "value";
81 return roles;
82}
83
taylorchuc27dd482014-05-17 20:06:49 -070084void
85ForwarderStatusModel::clear()
86{
87 beginResetModel();
88 m_items.clear();
89 endResetModel ();
90}
91
92void
93ForwarderStatusModel::afterFetchedVersionInformation(const Data& data)
94{
95 emit onDataReceived(data.shared_from_this());
96}
97
98void
99ForwarderStatusModel::updateStatus(shared_ptr<const Data> data)
100{
101 beginResetModel();
102 m_items.clear();
103 nfd::ForwarderStatus status(data->getContent());
104 addItem(ForwarderStatusItem("version", QString::number(status.getNfdVersion())));
105 addItem(ForwarderStatusItem("startTime", QString::fromStdString(time::toIsoString(status.getStartTimestamp()))));
106 addItem(ForwarderStatusItem("currentTime", QString::fromStdString(time::toIsoString(status.getCurrentTimestamp()))));
107 addItem(ForwarderStatusItem("nNameTreeEntries", QString::number(status.getNNameTreeEntries())));
108 addItem(ForwarderStatusItem("nFibEntries", QString::number(status.getNFibEntries())));
109 addItem(ForwarderStatusItem("nPitEntries", QString::number(status.getNPitEntries())));
110 addItem(ForwarderStatusItem("nMeasurementsEntries", QString::number(status.getNMeasurementsEntries())));
111 addItem(ForwarderStatusItem("nCsEntries", QString::number(status.getNCsEntries())));
112 addItem(ForwarderStatusItem("nInInterests", QString::number(status.getNInInterests())));
113 addItem(ForwarderStatusItem("nOutInterests", QString::number(status.getNOutInterests())));
114 addItem(ForwarderStatusItem("nInDatas", QString::number(status.getNInDatas())));
115 addItem(ForwarderStatusItem("nOutDatas", QString::number(status.getNOutDatas())));
116 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