blob: ea97b1b0e96d846e562eeb73524c7f5da510f57c [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();
92 std::cerr << "Future events canceled" << std::endl;
Qi Zhao7e524492017-03-02 15:05:45 -080093}
94
95void
96StatusViewer::requestNfdStatus()
97{
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -080098 std::cerr << "requestNfdStatus" << std::endl;
99
100 m_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -0800101 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800102 m_controller->fetch<ndn::nfd::ChannelDataset>(bind(&StatusViewer::onChannelStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -0800103 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800104 m_controller->fetch<ndn::nfd::FaceDataset>(bind(&StatusViewer::onFaceStatusRetrieved, this, _1),
Qi Zhao078ac692017-03-02 16:28:51 -0800105 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800106 m_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -0800107 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800108 m_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -0800109 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800110 m_controller->fetch<ndn::nfd::StrategyChoiceDataset>(bind(&StatusViewer::onStrategyChoiceStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -0800111 bind(&StatusViewer::onStatusTimeout, this));
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800112 m_nextStatusRetrieval = m_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
Qi Zhao7e524492017-03-02 15:05:45 -0800113}
114
115void
116StatusViewer::present()
117{
118 requestNfdStatus();
119 emit showStatus();
120}
121
122} // namespace ndn