blob: 742b5da06cf1a51055c5a78ea28911711220ca63 [file] [log] [blame]
taylorchuc27dd482014-05-17 20:06:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Qi Zhao7e524492017-03-02 15:05:45 -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_FORWARDER_STATUS_HPP
21#define NCC_FORWARDER_STATUS_HPP
22
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080023#include <QAbstractListModel>
24#include <QStringList>
25#include <QDateTime>
taylorchuc27dd482014-05-17 20:06:49 -070026
Qi Zhao7e524492017-03-02 15:05:45 -080027#include <ndn-cxx/interest.hpp>
Qi Zhao0e043e52016-12-05 18:27:09 -080028#include <ndn-cxx/mgmt/nfd/forwarder-status.hpp>
taylorchuc27dd482014-05-17 20:06:49 -070029
30namespace ndn {
31
32class ForwarderStatusItem
33{
34public:
35 ForwarderStatusItem(const QString& type, const QString& value)
36 : m_type(type)
37 , m_value(value)
38 {
39 }
40
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080041 ForwarderStatusItem(const QString& type, const std::string& value)
42 : m_type(type)
43 , m_value(QString::fromStdString(value))
44 {
45 }
46
47 ForwarderStatusItem(const QString& type, uint64_t value)
48 : m_type(type)
49 , m_value(QString::number(value))
50 {
51 }
52
53 ForwarderStatusItem(const QString& type, const time::system_clock::TimePoint& value)
54 : ForwarderStatusItem(type, time::toString(value))
55 {
56 }
57
taylorchuc27dd482014-05-17 20:06:49 -070058 const QString&
59 type() const
60 {
61 return m_type;
62 }
63
64 const QString&
65 value() const
66 {
67 return m_value;
68 }
69
70private:
71 QString m_type;
72 QString m_value;
73};
74
75
76class ForwarderStatusModel : public QAbstractListModel
77{
78 Q_OBJECT
79
80signals:
81 void
Qi Zhao0e043e52016-12-05 18:27:09 -080082 onDataReceived(ndn::nfd::ForwarderStatus status);
taylorchuc27dd482014-05-17 20:06:49 -070083
84public:
85
86 enum ForwarderStatusRoles {
87 TypeRole = Qt::UserRole + 1,
88 ValueRole
89 };
90
91 explicit
Alexander Afanasyev4086d512014-07-11 15:56:33 -070092 ForwarderStatusModel(QObject* parent = 0);
taylorchuc27dd482014-05-17 20:06:49 -070093
94 int
95 rowCount(const QModelIndex& parent = QModelIndex()) const;
96
97 void
98 addItem(const ForwarderStatusItem& item);
99
100 QVariant
101 data(const QModelIndex& index, int role) const;
102
103 QHash<int, QByteArray>
104 roleNames() const;
105
taylorchuc27dd482014-05-17 20:06:49 -0700106 void
107 clear();
108
109 void
taylorchuc27dd482014-05-17 20:06:49 -0700110 onTimeout(const Interest& interest);
111
112private slots:
113
114 void
Qi Zhao0e043e52016-12-05 18:27:09 -0800115 updateStatus(ndn::nfd::ForwarderStatus status);
taylorchuc27dd482014-05-17 20:06:49 -0700116
117private:
taylorchuc27dd482014-05-17 20:06:49 -0700118 QList<ForwarderStatusItem> m_items;
119};
120
121} // namespace ndn
122
123#endif // NCC_FORWARDER_STATUS_HPP