taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 3766775 | 2017-02-02 13:52:12 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, Regents of the University of California, |
Qi Zhao | 0e043e5 | 2016-12-05 18:27:09 -0800 | [diff] [blame] | 4 | * |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 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" |
Alexander Afanasyev | 3766775 | 2017-02-02 13:52:12 -0800 | [diff] [blame] | 21 | #include "forwarder-status.moc" |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 22 | |
| 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 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 30 | namespace ndn { |
| 31 | |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 32 | ForwarderStatusModel::ForwarderStatusModel(QObject* parent/* = 0*/) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 33 | : QAbstractListModel(parent) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 34 | { |
Qi Zhao | 0e043e5 | 2016-12-05 18:27:09 -0800 | [diff] [blame] | 35 | connect(this, SIGNAL(onDataReceived(ndn::nfd::ForwarderStatus)), this, |
| 36 | SLOT(updateStatus(ndn::nfd::ForwarderStatus)), |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 37 | Qt::QueuedConnection); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int |
| 41 | ForwarderStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const |
| 42 | { |
| 43 | return m_items.count(); |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | ForwarderStatusModel::addItem(const ForwarderStatusItem& item) |
| 48 | { |
| 49 | beginInsertRows(QModelIndex(), rowCount(), rowCount()); |
| 50 | m_items << item; |
| 51 | endInsertRows(); |
| 52 | } |
| 53 | |
| 54 | QVariant |
| 55 | ForwarderStatusModel::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 | |
| 71 | QHash<int, QByteArray> |
| 72 | ForwarderStatusModel::roleNames() const |
| 73 | { |
| 74 | QHash<int, QByteArray> roles; |
| 75 | roles[TypeRole] = "type"; |
| 76 | roles[ValueRole] = "value"; |
| 77 | return roles; |
| 78 | } |
| 79 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 80 | void |
| 81 | ForwarderStatusModel::clear() |
| 82 | { |
| 83 | beginResetModel(); |
| 84 | m_items.clear(); |
| 85 | endResetModel (); |
| 86 | } |
| 87 | |
| 88 | void |
Qi Zhao | 0e043e5 | 2016-12-05 18:27:09 -0800 | [diff] [blame] | 89 | ForwarderStatusModel::updateStatus(ndn::nfd::ForwarderStatus status) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 90 | { |
| 91 | beginResetModel(); |
| 92 | m_items.clear(); |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 93 | 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()))); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 107 | endResetModel(); |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | ForwarderStatusModel::onTimeout(const Interest& interest) |
| 112 | { |
| 113 | std::cerr << "Request timed out (should not really happen)" << std::endl; |
| 114 | } |
| 115 | |
| 116 | } // namespace ndn |