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 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 23 | namespace ndn { |
| 24 | |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 25 | ForwarderStatusModel::ForwarderStatusModel(QObject* parent/* = 0*/) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 26 | : QAbstractListModel(parent) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 27 | { |
Qi Zhao | 0e043e5 | 2016-12-05 18:27:09 -0800 | [diff] [blame] | 28 | connect(this, SIGNAL(onDataReceived(ndn::nfd::ForwarderStatus)), this, |
| 29 | SLOT(updateStatus(ndn::nfd::ForwarderStatus)), |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 30 | Qt::QueuedConnection); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | int |
| 34 | ForwarderStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const |
| 35 | { |
| 36 | return m_items.count(); |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | ForwarderStatusModel::addItem(const ForwarderStatusItem& item) |
| 41 | { |
| 42 | beginInsertRows(QModelIndex(), rowCount(), rowCount()); |
| 43 | m_items << item; |
| 44 | endInsertRows(); |
| 45 | } |
| 46 | |
| 47 | QVariant |
| 48 | ForwarderStatusModel::data(const QModelIndex& index, int role) const |
| 49 | { |
| 50 | if (index.row() < 0 || index.row() >= m_items.count()) { |
| 51 | return QVariant(); |
| 52 | } |
| 53 | |
| 54 | const ForwarderStatusItem& item = m_items.at(index.row()); |
| 55 | if (role == TypeRole) { |
| 56 | return item.type(); |
| 57 | } |
| 58 | else if (role == ValueRole) { |
| 59 | return item.value(); |
| 60 | } |
| 61 | return QVariant(); |
| 62 | } |
| 63 | |
| 64 | QHash<int, QByteArray> |
| 65 | ForwarderStatusModel::roleNames() const |
| 66 | { |
| 67 | QHash<int, QByteArray> roles; |
| 68 | roles[TypeRole] = "type"; |
| 69 | roles[ValueRole] = "value"; |
| 70 | return roles; |
| 71 | } |
| 72 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 73 | void |
| 74 | ForwarderStatusModel::clear() |
| 75 | { |
| 76 | beginResetModel(); |
| 77 | m_items.clear(); |
| 78 | endResetModel (); |
| 79 | } |
| 80 | |
| 81 | void |
Qi Zhao | 0e043e5 | 2016-12-05 18:27:09 -0800 | [diff] [blame] | 82 | ForwarderStatusModel::updateStatus(ndn::nfd::ForwarderStatus status) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 83 | { |
| 84 | beginResetModel(); |
| 85 | m_items.clear(); |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 86 | addItem({"Version", status.getNfdVersion()}); |
| 87 | addItem({"Start Time", status.getStartTimestamp()}); |
| 88 | addItem({"Current Time", status.getCurrentTimestamp()}); |
| 89 | addItem({"Name Tree Entries", status.getNNameTreeEntries()}); |
| 90 | addItem({"Fib Entries", status.getNFibEntries()}); |
| 91 | addItem({"PitEntries", status.getNPitEntries()}); |
| 92 | addItem({"Measurements Entries", status.getNMeasurementsEntries()}); |
| 93 | addItem({"Content Store Entries", status.getNCsEntries()}); |
| 94 | addItem({"Incoming Interests", status.getNInInterests()}); |
| 95 | addItem({"Outgoing Interests", status.getNOutInterests()}); |
| 96 | addItem({"Incoming Data", status.getNInDatas()}); |
| 97 | addItem({"Outgoing Data", status.getNOutDatas()}); |
| 98 | addItem({"Incoming Nacks", status.getNInDatas()}); |
| 99 | addItem({"Outgoing Nacks", status.getNOutDatas()}); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 100 | endResetModel(); |
| 101 | } |
| 102 | |
| 103 | void |
| 104 | ForwarderStatusModel::onTimeout(const Interest& interest) |
| 105 | { |
| 106 | std::cerr << "Request timed out (should not really happen)" << std::endl; |
| 107 | } |
| 108 | |
| 109 | } // namespace ndn |