taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
susmit | a71cf41 | 2016-03-20 15:02:29 -0600 | [diff] [blame^] | 3 | * Copyright (c) 2013-2016, Regents of the University of California, |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 4 | * 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/>. |
susmit | a71cf41 | 2016-03-20 15:02:29 -0600 | [diff] [blame^] | 17 | * TODO:Add others |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 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" |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | namespace ndn { |
| 34 | |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 35 | ForwarderStatusModel::ForwarderStatusModel(QObject* parent/* = 0*/) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 36 | : QAbstractListModel(parent) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 37 | { |
| 38 | connect(this, SIGNAL(onDataReceived(ndn::shared_ptr<const ndn::Data>)), this, |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 39 | SLOT(updateStatus(ndn::shared_ptr<const ndn::Data>)), |
| 40 | Qt::QueuedConnection); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int |
| 44 | ForwarderStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const |
| 45 | { |
| 46 | return m_items.count(); |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | ForwarderStatusModel::addItem(const ForwarderStatusItem& item) |
| 51 | { |
| 52 | beginInsertRows(QModelIndex(), rowCount(), rowCount()); |
| 53 | m_items << item; |
| 54 | endInsertRows(); |
| 55 | } |
| 56 | |
| 57 | QVariant |
| 58 | ForwarderStatusModel::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 | |
| 74 | QHash<int, QByteArray> |
| 75 | ForwarderStatusModel::roleNames() const |
| 76 | { |
| 77 | QHash<int, QByteArray> roles; |
| 78 | roles[TypeRole] = "type"; |
| 79 | roles[ValueRole] = "value"; |
| 80 | return roles; |
| 81 | } |
| 82 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 83 | void |
| 84 | ForwarderStatusModel::clear() |
| 85 | { |
| 86 | beginResetModel(); |
| 87 | m_items.clear(); |
| 88 | endResetModel (); |
| 89 | } |
| 90 | |
| 91 | void |
| 92 | ForwarderStatusModel::afterFetchedVersionInformation(const Data& data) |
| 93 | { |
| 94 | emit onDataReceived(data.shared_from_this()); |
| 95 | } |
| 96 | |
| 97 | void |
| 98 | ForwarderStatusModel::updateStatus(shared_ptr<const Data> data) |
| 99 | { |
| 100 | beginResetModel(); |
| 101 | m_items.clear(); |
| 102 | nfd::ForwarderStatus status(data->getContent()); |
Alexander Afanasyev | 5f14bee | 2016-03-20 11:38:07 -0700 | [diff] [blame] | 103 | addItem(ForwarderStatusItem("version", QString::fromStdString(status.getNfdVersion()))); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 104 | 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()))); |
susmit | a71cf41 | 2016-03-20 15:02:29 -0600 | [diff] [blame^] | 114 | addItem(ForwarderStatusItem("nNInNacks", QString::number(status.getNInDatas()))); |
| 115 | addItem(ForwarderStatusItem("nNOutNacks", QString::number(status.getNOutDatas()))); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 116 | endResetModel(); |
| 117 | } |
| 118 | |
| 119 | void |
| 120 | ForwarderStatusModel::onTimeout(const Interest& interest) |
| 121 | { |
| 122 | std::cerr << "Request timed out (should not really happen)" << std::endl; |
| 123 | } |
| 124 | |
| 125 | } // namespace ndn |