Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 23 | namespace ndn { |
| 24 | |
| 25 | StatusViewer::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 Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame^] | 34 | s_context->setContextProperty("channelModel", &s_channelModel); |
Qi Zhao | 078ac69 | 2017-03-02 16:28:51 -0800 | [diff] [blame] | 35 | s_context->setContextProperty("faceModel", &s_faceModel); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 36 | s_context->setContextProperty("fibModel", &s_fibModel); |
| 37 | s_context->setContextProperty("ribModel", &s_ribModel); |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame^] | 38 | s_context->setContextProperty("strategyModel", &s_strategyModel); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 39 | s_context->setContextProperty("statusViewer", this); |
| 40 | |
| 41 | s_engine.load((QUrl("qrc:/status.qml"))); |
| 42 | } |
| 43 | |
| 44 | void |
| 45 | StatusViewer::onStatusRetrieved(const nfd::ForwarderStatus& status) |
| 46 | { |
| 47 | emit s_forwarderStatusModel.onDataReceived(status); |
| 48 | } |
| 49 | |
| 50 | void |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame^] | 51 | StatusViewer::onChannelStatusRetrieved(const std::vector<nfd::ChannelStatus>& status) |
| 52 | { |
| 53 | emit s_channelModel.onDataReceived(status); |
| 54 | } |
| 55 | |
| 56 | void |
Qi Zhao | 078ac69 | 2017-03-02 16:28:51 -0800 | [diff] [blame] | 57 | StatusViewer::onFaceStatusRetrieved(const std::vector<nfd::FaceStatus>& status) |
| 58 | { |
| 59 | emit s_faceModel.onDataReceived(status); |
| 60 | } |
| 61 | |
| 62 | void |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 63 | StatusViewer::onFibStatusRetrieved(const std::vector<nfd::FibEntry>& status) |
| 64 | { |
| 65 | emit s_fibModel.onDataReceived(status); |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | StatusViewer::onRibStatusRetrieved(const std::vector<nfd::RibEntry>& status) |
| 70 | { |
| 71 | emit s_ribModel.onDataReceived(status); |
| 72 | } |
| 73 | |
| 74 | void |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame^] | 75 | StatusViewer::onStrategyChoiceStatusRetrieved(const std::vector<nfd::StrategyChoice>& status) |
| 76 | { |
| 77 | emit s_strategyModel.onDataReceived(status); |
| 78 | } |
| 79 | |
| 80 | void |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 81 | StatusViewer::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 | |
| 87 | void |
| 88 | StatusViewer::requestNfdStatus() |
| 89 | { |
| 90 | s_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1), |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame^] | 91 | bind(&StatusViewer::onStatusTimeout, this)); |
| 92 | s_controller->fetch<ndn::nfd::ChannelDataset>(bind(&StatusViewer::onChannelStatusRetrieved, this, _1), |
| 93 | bind(&StatusViewer::onStatusTimeout, this)); |
Qi Zhao | 078ac69 | 2017-03-02 16:28:51 -0800 | [diff] [blame] | 94 | s_controller->fetch<ndn::nfd::FaceDataset>(bind(&StatusViewer::onFaceStatusRetrieved, this, _1), |
| 95 | bind(&StatusViewer::onStatusTimeout, this)); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 96 | s_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1), |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame^] | 97 | bind(&StatusViewer::onStatusTimeout, this)); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 98 | s_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1), |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame^] | 99 | bind(&StatusViewer::onStatusTimeout, this)); |
| 100 | s_controller->fetch<ndn::nfd::StrategyChoiceDataset>(bind(&StatusViewer::onStrategyChoiceStatusRetrieved, this, _1), |
| 101 | bind(&StatusViewer::onStatusTimeout, this)); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 102 | s_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this)); |
| 103 | } |
| 104 | |
| 105 | void |
| 106 | StatusViewer::present() |
| 107 | { |
| 108 | requestNfdStatus(); |
| 109 | emit showStatus(); |
| 110 | } |
| 111 | |
| 112 | } // namespace ndn |