blob: f4f81f47aff371f4609ca87cea098b8e061314fb [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)
26 : s_face(face)
27 , s_keyChain(keyChain)
28 , s_controller(new nfd::Controller(s_face, s_keyChain))
29 , s_scheduler(s_face.getIoService())
30{
31 QQmlContext* s_context = s_engine.rootContext();
32
33 s_context->setContextProperty("forwarderModel", &s_forwarderStatusModel);
Qi Zhaobd19e072017-03-05 15:12:46 -080034 s_context->setContextProperty("channelModel", &s_channelModel);
Qi Zhao078ac692017-03-02 16:28:51 -080035 s_context->setContextProperty("faceModel", &s_faceModel);
Qi Zhao7e524492017-03-02 15:05:45 -080036 s_context->setContextProperty("fibModel", &s_fibModel);
37 s_context->setContextProperty("ribModel", &s_ribModel);
Qi Zhaobd19e072017-03-05 15:12:46 -080038 s_context->setContextProperty("strategyModel", &s_strategyModel);
Qi Zhao7e524492017-03-02 15:05:45 -080039 s_context->setContextProperty("statusViewer", this);
40
41 s_engine.load((QUrl("qrc:/status.qml")));
42}
43
44void
45StatusViewer::onStatusRetrieved(const nfd::ForwarderStatus& status)
46{
47 emit s_forwarderStatusModel.onDataReceived(status);
48}
49
50void
Qi Zhaobd19e072017-03-05 15:12:46 -080051StatusViewer::onChannelStatusRetrieved(const std::vector<nfd::ChannelStatus>& status)
52{
53 emit s_channelModel.onDataReceived(status);
54}
55
56void
Qi Zhao078ac692017-03-02 16:28:51 -080057StatusViewer::onFaceStatusRetrieved(const std::vector<nfd::FaceStatus>& status)
58{
59 emit s_faceModel.onDataReceived(status);
60}
61
62void
Qi Zhao7e524492017-03-02 15:05:45 -080063StatusViewer::onFibStatusRetrieved(const std::vector<nfd::FibEntry>& status)
64{
65 emit s_fibModel.onDataReceived(status);
66}
67
68void
69StatusViewer::onRibStatusRetrieved(const std::vector<nfd::RibEntry>& status)
70{
71 emit s_ribModel.onDataReceived(status);
72}
73
74void
Qi Zhaobd19e072017-03-05 15:12:46 -080075StatusViewer::onStrategyChoiceStatusRetrieved(const std::vector<nfd::StrategyChoice>& status)
76{
77 emit s_strategyModel.onDataReceived(status);
78}
79
80void
Qi Zhao7e524492017-03-02 15:05:45 -080081StatusViewer::onStatusTimeout()
82{
83 std::cerr << "Should not really happen, most likely a serious problem" << std::endl;
84 s_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
85}
86
87void
88StatusViewer::requestNfdStatus()
89{
90 s_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -080091 bind(&StatusViewer::onStatusTimeout, this));
92 s_controller->fetch<ndn::nfd::ChannelDataset>(bind(&StatusViewer::onChannelStatusRetrieved, this, _1),
93 bind(&StatusViewer::onStatusTimeout, this));
Qi Zhao078ac692017-03-02 16:28:51 -080094 s_controller->fetch<ndn::nfd::FaceDataset>(bind(&StatusViewer::onFaceStatusRetrieved, this, _1),
95 bind(&StatusViewer::onStatusTimeout, this));
Qi Zhao7e524492017-03-02 15:05:45 -080096 s_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -080097 bind(&StatusViewer::onStatusTimeout, this));
Qi Zhao7e524492017-03-02 15:05:45 -080098 s_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1),
Qi Zhaobd19e072017-03-05 15:12:46 -080099 bind(&StatusViewer::onStatusTimeout, this));
100 s_controller->fetch<ndn::nfd::StrategyChoiceDataset>(bind(&StatusViewer::onStrategyChoiceStatusRetrieved, this, _1),
101 bind(&StatusViewer::onStatusTimeout, this));
Qi Zhao7e524492017-03-02 15:05:45 -0800102 s_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
103}
104
105void
106StatusViewer::present()
107{
108 requestNfdStatus();
109 emit showStatus();
110}
111
112} // namespace ndn