blob: 48738256c07bf732757ae6b4e7c33d9b7287ad7a [file] [log] [blame]
Qi Zhaoec8ddd22017-02-24 05:16:15 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2017, Regents of the University of California,
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_RIB_STATUS_HPP
21#define NCC_RIB_STATUS_HPP
22
23#include <QtCore/QAbstractListModel>
24#include <QtCore/QStringList>
25
26#include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
27
28namespace ndn {
29
30class RibStatusItem
31{
32public:
33 RibStatusItem(const QString& prefix, uint64_t faceId, uint64_t origin, uint64_t cost, bool child, bool ribcap,
34 const QString& exp)
35 : m_prefix(prefix)
36 , m_faceId(faceId)
37 , m_origin(origin)
38 , m_cost(cost)
39 , m_child(child)
40 , m_ribcap(ribcap)
41 , m_exp(exp)
42 {
43 }
44
45 const QString&
46 prefix() const
47 {
48 return m_prefix;
49 }
50
51 uint64_t
52 faceId() const
53 {
54 return m_faceId;
55 }
56
57 uint64_t
58 origin() const
59 {
60 return m_origin;
61 }
62
63 uint64_t
64 cost() const
65 {
66 return m_cost;
67 }
68
69 bool
70 child() const
71 {
72 return m_child;
73 }
74
75 bool
76 ribcap() const
77 {
78 return m_ribcap;
79 }
80
81 const QString&
82 exp() const
83 {
84 return m_exp;
85 }
86
87private:
88 QString m_prefix;
89 uint64_t m_faceId;
90 uint64_t m_origin;
91 uint64_t m_cost;
92 bool m_child;
93 bool m_ribcap;
94 QString m_exp;
95};
96
97class RibStatusModel : public QAbstractListModel
98{
99 Q_OBJECT
100
101signals:
102 void
103 onDataReceived(std::vector<ndn::nfd::RibEntry> status);
104
105public:
106 enum RibStatusRoles {
107 PrefixRole = Qt::UserRole + 1,
108 FaceIdRole,
109 OriginRole,
110 CostRole,
111 ChildRole,
112 RibCapRole,
113 ExpRole
114 };
115
116 explicit
117 RibStatusModel(QObject* parent = 0);
118
119 int
120 rowCount(const QModelIndex& parent = QModelIndex()) const;
121
122 void
123 addItem(const RibStatusItem& item);
124
125 QVariant
126 data(const QModelIndex& index, int role) const;
127
128 QHash<int, QByteArray>
129 roleNames() const;
130
131 void
132 clear();
133
134 void
135 onTimeout();
136
137private slots:
138
139 void
140 updateStatus(std::vector<ndn::nfd::RibEntry> status);
141
142private:
143 QList<RibStatusItem> m_items;
144};
145
146} // namespace ndn
147
148#endif // NCC_RIB_STATUS_HPP