blob: 9b885c496e22f042ac0d73b145850120df40fed0 [file] [log] [blame]
Qi Zhaobd19e072017-03-05 15:12:46 -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_STRATEGY_STATUS_HPP
21#define NCC_STRATEGY_STATUS_HPP
22
23#include <QtCore/QAbstractListModel>
24#include <QtCore/QStringList>
25
26#include <ndn-cxx/mgmt/nfd/strategy-choice.hpp>
27
28namespace ndn {
29
30class StrategyStatusItem
31{
32public:
33 StrategyStatusItem(const QString& prefix, const QString& strategy)
34 : m_prefix(prefix)
35 , m_strategy(strategy)
36 {
37 }
38
39 const QString&
40 prefix() const
41 {
42 return m_prefix;
43 }
44
45 const QString&
46 strategy() const
47 {
48 return m_strategy;
49 }
50
51private:
52 QString m_prefix;
53 QString m_strategy;
54};
55
56class StrategyStatusModel : public QAbstractListModel
57{
58 Q_OBJECT
59
60signals:
61 void
62 onDataReceived(std::vector<ndn::nfd::StrategyChoice> status);
63
64public:
65 enum StrategyStatusRoles {
66 PrefixRole = Qt::UserRole + 1,
67 StrategyRole
68 };
69
70 explicit
71 StrategyStatusModel(QObject* parent = 0);
72
73 int
74 rowCount(const QModelIndex& parent = QModelIndex()) const;
75
76 void
77 addItem(const StrategyStatusItem& item);
78
79 QVariant
80 data(const QModelIndex& index, int role) const;
81
82 QHash<int, QByteArray>
83 roleNames() const;
84
85 void
86 clear();
87
88 void
89 onTimeout();
90
91private slots:
92
93 void
94 updateStatus(std::vector<ndn::nfd::StrategyChoice> status);
95
96private:
97 QList<StrategyStatusItem> m_items;
98};
99
100} // namespace ndn
101
102#endif // NCC_STRATEGY_STATUS_HPP