taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Qi Zhao | d3de12b | 2017-02-21 20:11:58 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, Regents of the University of California, |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 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 | #ifndef NCC_FIB_STATUS_HPP |
| 21 | #define NCC_FIB_STATUS_HPP |
| 22 | |
| 23 | #include <QtCore/QAbstractListModel> |
| 24 | #include <QtCore/QStringList> |
| 25 | |
Qi Zhao | d3de12b | 2017-02-21 20:11:58 -0800 | [diff] [blame] | 26 | #include <ndn-cxx/mgmt/nfd/fib-entry.hpp> |
| 27 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 28 | namespace ndn { |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 29 | |
| 30 | class FibStatusItem |
| 31 | { |
| 32 | public: |
Qi Zhao | d3de12b | 2017-02-21 20:11:58 -0800 | [diff] [blame] | 33 | FibStatusItem(const QString& prefix, uint64_t faceId, uint64_t cost) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 34 | : m_prefix(prefix) |
| 35 | , m_faceId(faceId) |
| 36 | , m_cost(cost) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | const QString& |
| 41 | prefix() const |
| 42 | { |
| 43 | return m_prefix; |
| 44 | } |
| 45 | |
| 46 | uint64_t |
| 47 | faceId() const |
| 48 | { |
| 49 | return m_faceId; |
| 50 | } |
| 51 | |
| 52 | uint64_t |
| 53 | cost() const |
| 54 | { |
| 55 | return m_cost; |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | QString m_prefix; |
| 60 | uint64_t m_faceId; |
| 61 | uint64_t m_cost; |
| 62 | }; |
| 63 | |
| 64 | class FibStatusModel : public QAbstractListModel |
| 65 | { |
| 66 | Q_OBJECT |
| 67 | |
Qi Zhao | d3de12b | 2017-02-21 20:11:58 -0800 | [diff] [blame] | 68 | signals: |
| 69 | void |
| 70 | onDataReceived(std::vector<ndn::nfd::FibEntry> status); |
| 71 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 72 | public: |
| 73 | enum FibStatusRoles { |
| 74 | PrefixRole = Qt::UserRole + 1, |
| 75 | FaceIdRole, |
| 76 | CostRole |
| 77 | }; |
| 78 | |
| 79 | explicit |
Qi Zhao | d3de12b | 2017-02-21 20:11:58 -0800 | [diff] [blame] | 80 | FibStatusModel(QObject* parent = 0); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 81 | |
| 82 | int |
Qi Zhao | d3de12b | 2017-02-21 20:11:58 -0800 | [diff] [blame] | 83 | rowCount(const QModelIndex& parent = QModelIndex()) const; |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 84 | |
| 85 | void |
Qi Zhao | d3de12b | 2017-02-21 20:11:58 -0800 | [diff] [blame] | 86 | addItem(const FibStatusItem& item); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 87 | |
| 88 | QVariant |
Qi Zhao | d3de12b | 2017-02-21 20:11:58 -0800 | [diff] [blame] | 89 | data(const QModelIndex& index, int role) const; |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 90 | |
| 91 | QHash<int, QByteArray> |
| 92 | roleNames() const; |
| 93 | |
| 94 | void |
| 95 | clear(); |
| 96 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 97 | void |
| 98 | onTimeout(); |
| 99 | |
Qi Zhao | d3de12b | 2017-02-21 20:11:58 -0800 | [diff] [blame] | 100 | private slots: |
| 101 | |
| 102 | void |
| 103 | updateStatus(std::vector<ndn::nfd::FibEntry> status); |
| 104 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 105 | private: |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 106 | QList<FibStatusItem> m_items; |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | } // namespace ndn |
| 110 | |
| 111 | #endif // NCC_FIB_STATUS_HPP |