blob: 6f365753b49b9cd8888953d3cdb1545cccad9d90 [file] [log] [blame]
Qi Zhao7e524492017-03-02 15:05:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 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#include "status-viewer.hpp"
21#include "status-viewer.moc"
22
23namespace ndn {
24
25StatusViewer::StatusViewer(Face& face, KeyChain& keyChain)
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080026 : m_face(face)
27 , m_keyChain(keyChain)
28 , m_controller(new nfd::Controller(m_face, m_keyChain))
29 , m_scheduler(m_face.getIoService())
30 , m_nextStatusRetrieval(m_scheduler)
Qi Zhao7e524492017-03-02 15:05:45 -080031{
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080032 QQmlContext* m_context = m_engine.rootContext();
Qi Zhao7e524492017-03-02 15:05:45 -080033
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080034 m_context->setContextProperty("forwarderModel", &m_forwarderStatusModel);
35 m_context->setContextProperty("channelModel", &m_channelModel);
36 m_context->setContextProperty("faceModel", &m_faceModel);
37 m_context->setContextProperty("fibModel", &m_fibModel);
38 m_context->setContextProperty("ribModel", &m_ribModel);
39 m_context->setContextProperty("strategyModel", &m_strategyModel);
40 m_context->setContextProperty("statusViewer", this);
Qi Zhao7e524492017-03-02 15:05:45 -080041
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080042 m_engine.load((QUrl("qrc:/status.qml")));
Qi Zhao7e524492017-03-02 15:05:45 -080043}
44
45void
46StatusViewer::onStatusRetrieved(const nfd::ForwarderStatus& status)
47{
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080048 emit m_forwarderStatusModel.onDataReceived(status);
Qi Zhao7e524492017-03-02 15:05:45 -080049}
50
51void
Qi Zhaobd19e072017-03-05 15:12:46 -080052StatusViewer::onChannelStatusRetrieved(const std::vector<nfd::ChannelStatus>& status)
53{
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080054 emit m_channelModel.onDataReceived(status);
Qi Zhaobd19e072017-03-05 15:12:46 -080055}
56
57void
Qi Zhao078ac692017-03-02 16:28:51 -080058StatusViewer::onFaceStatusRetrieved(const std::vector<nfd::FaceStatus>& status)
59{
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080060 emit m_faceModel.onDataReceived(status);
Qi Zhao078ac692017-03-02 16:28:51 -080061}
62
63void
Qi Zhao7e524492017-03-02 15:05:45 -080064StatusViewer::onFibStatusRetrieved(const std::vector<nfd::FibEntry>& status)
65{
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080066 emit m_fibModel.onDataReceived(status);
Qi Zhao7e524492017-03-02 15:05:45 -080067}
68
69void
70StatusViewer::onRibStatusRetrieved(const std::vector<nfd::RibEntry>& status)
71{
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080072 emit m_ribModel.onDataReceived(status);
Qi Zhao7e524492017-03-02 15:05:45 -080073}
74
75void
Qi Zhaobd19e072017-03-05 15:12:46 -080076StatusViewer::onStrategyChoiceStatusRetrieved(const std::vector<nfd::StrategyChoice>& status)
77{
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080078 emit m_strategyModel.onDataReceived(status);
Qi Zhaobd19e072017-03-05 15:12:46 -080079}
80
81void
Qi Zhao7e524492017-03-02 15:05:45 -080082StatusViewer::onStatusTimeout()
83{
84 std::cerr << "Should not really happen, most likely a serious problem" << std::endl;
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080085 m_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
86}
87
88void
89StatusViewer::cancelEvents()
90{
91 m_nextStatusRetrieval.cancel();
Qi Zhao7e524492017-03-02 15:05:45 -080092}
93
94void
95StatusViewer::requestNfdStatus()
96{
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080097 m_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -080098 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080099 m_controller->fetch<ndn::nfd::ChannelDataset>(bind(&StatusViewer::onChannelStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -0800100 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800101 m_controller->fetch<ndn::nfd::FaceDataset>(bind(&StatusViewer::onFaceStatusRetrieved, this, _1),
Qi Zhao078ac692017-03-02 16:28:51 -0800102 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800103 m_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -0800104 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800105 m_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -0800106 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800107 m_controller->fetch<ndn::nfd::StrategyChoiceDataset>(bind(&StatusViewer::onStrategyChoiceStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -0800108 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800109 m_nextStatusRetrieval = m_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
Qi Zhao7e524492017-03-02 15:05:45 -0800110}
111
112void
113StatusViewer::present()
114{
115 requestNfdStatus();
116 emit showStatus();
117}
118
119} // namespace ndn