blob: 145b3bd0d4dfa74e81b665a3f470da86892ec0c7 [file] [log] [blame]
taylorchuc27dd482014-05-17 20:06:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Qi Zhaod3de12b2017-02-21 20:11:58 -08003 * Copyright (c) 2013-2017, Regents of the University of California,
taylorchuc27dd482014-05-17 20:06:49 -07004 *
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 Zhaod3de12b2017-02-21 20:11:58 -080026#include <ndn-cxx/mgmt/nfd/fib-entry.hpp>
27
taylorchuc27dd482014-05-17 20:06:49 -070028namespace ndn {
taylorchuc27dd482014-05-17 20:06:49 -070029
30class FibStatusItem
31{
32public:
Qi Zhaod3de12b2017-02-21 20:11:58 -080033 FibStatusItem(const QString& prefix, uint64_t faceId, uint64_t cost)
taylorchuc27dd482014-05-17 20:06:49 -070034 : 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
58private:
59 QString m_prefix;
60 uint64_t m_faceId;
61 uint64_t m_cost;
62};
63
64class FibStatusModel : public QAbstractListModel
65{
66 Q_OBJECT
67
Qi Zhaod3de12b2017-02-21 20:11:58 -080068signals:
69 void
70 onDataReceived(std::vector<ndn::nfd::FibEntry> status);
71
taylorchuc27dd482014-05-17 20:06:49 -070072public:
73 enum FibStatusRoles {
74 PrefixRole = Qt::UserRole + 1,
75 FaceIdRole,
76 CostRole
77 };
78
79 explicit
Qi Zhaod3de12b2017-02-21 20:11:58 -080080 FibStatusModel(QObject* parent = 0);
taylorchuc27dd482014-05-17 20:06:49 -070081
82 int
Qi Zhaod3de12b2017-02-21 20:11:58 -080083 rowCount(const QModelIndex& parent = QModelIndex()) const;
taylorchuc27dd482014-05-17 20:06:49 -070084
85 void
Qi Zhaod3de12b2017-02-21 20:11:58 -080086 addItem(const FibStatusItem& item);
taylorchuc27dd482014-05-17 20:06:49 -070087
88 QVariant
Qi Zhaod3de12b2017-02-21 20:11:58 -080089 data(const QModelIndex& index, int role) const;
taylorchuc27dd482014-05-17 20:06:49 -070090
91 QHash<int, QByteArray>
92 roleNames() const;
93
94 void
95 clear();
96
taylorchuc27dd482014-05-17 20:06:49 -070097 void
98 onTimeout();
99
Qi Zhaod3de12b2017-02-21 20:11:58 -0800100private slots:
101
102 void
103 updateStatus(std::vector<ndn::nfd::FibEntry> status);
104
taylorchuc27dd482014-05-17 20:06:49 -0700105private:
taylorchuc27dd482014-05-17 20:06:49 -0700106 QList<FibStatusItem> m_items;
taylorchuc27dd482014-05-17 20:06:49 -0700107};
108
109} // namespace ndn
110
111#endif // NCC_FIB_STATUS_HPP