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) |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 26 | : 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 Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 31 | { |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 32 | QQmlContext* m_context = m_engine.rootContext(); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 33 | |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 34 | 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 Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 41 | |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 42 | m_engine.load((QUrl("qrc:/status.qml"))); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void |
| 46 | StatusViewer::onStatusRetrieved(const nfd::ForwarderStatus& status) |
| 47 | { |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 48 | emit m_forwarderStatusModel.onDataReceived(status); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame] | 52 | StatusViewer::onChannelStatusRetrieved(const std::vector<nfd::ChannelStatus>& status) |
| 53 | { |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 54 | emit m_channelModel.onDataReceived(status); |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void |
Qi Zhao | 078ac69 | 2017-03-02 16:28:51 -0800 | [diff] [blame] | 58 | StatusViewer::onFaceStatusRetrieved(const std::vector<nfd::FaceStatus>& status) |
| 59 | { |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 60 | emit m_faceModel.onDataReceived(status); |
Qi Zhao | 078ac69 | 2017-03-02 16:28:51 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 64 | StatusViewer::onFibStatusRetrieved(const std::vector<nfd::FibEntry>& status) |
| 65 | { |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 66 | emit m_fibModel.onDataReceived(status); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void |
| 70 | StatusViewer::onRibStatusRetrieved(const std::vector<nfd::RibEntry>& status) |
| 71 | { |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 72 | emit m_ribModel.onDataReceived(status); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame] | 76 | StatusViewer::onStrategyChoiceStatusRetrieved(const std::vector<nfd::StrategyChoice>& status) |
| 77 | { |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 78 | emit m_strategyModel.onDataReceived(status); |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 82 | StatusViewer::onStatusTimeout() |
| 83 | { |
| 84 | std::cerr << "Should not really happen, most likely a serious problem" << std::endl; |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 85 | m_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this)); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | StatusViewer::cancelEvents() |
| 90 | { |
| 91 | m_nextStatusRetrieval.cancel(); |
| 92 | std::cerr << "Future events canceled" << std::endl; |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void |
| 96 | StatusViewer::requestNfdStatus() |
| 97 | { |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 98 | std::cerr << "requestNfdStatus" << std::endl; |
| 99 | |
| 100 | m_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1), |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame] | 101 | bind(&StatusViewer::onStatusTimeout, this)); |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 102 | m_controller->fetch<ndn::nfd::ChannelDataset>(bind(&StatusViewer::onChannelStatusRetrieved, this, _1), |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame] | 103 | bind(&StatusViewer::onStatusTimeout, this)); |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 104 | m_controller->fetch<ndn::nfd::FaceDataset>(bind(&StatusViewer::onFaceStatusRetrieved, this, _1), |
Qi Zhao | 078ac69 | 2017-03-02 16:28:51 -0800 | [diff] [blame] | 105 | bind(&StatusViewer::onStatusTimeout, this)); |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 106 | m_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1), |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame] | 107 | bind(&StatusViewer::onStatusTimeout, this)); |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 108 | m_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1), |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame] | 109 | bind(&StatusViewer::onStatusTimeout, this)); |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 110 | m_controller->fetch<ndn::nfd::StrategyChoiceDataset>(bind(&StatusViewer::onStrategyChoiceStatusRetrieved, this, _1), |
Qi Zhao | bd19e07 | 2017-03-05 15:12:46 -0800 | [diff] [blame] | 111 | bind(&StatusViewer::onStatusTimeout, this)); |
Alexander Afanasyev | 8d1a3a0 | 2017-03-11 13:00:24 -0800 | [diff] [blame^] | 112 | m_nextStatusRetrieval = m_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this)); |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void |
| 116 | StatusViewer::present() |
| 117 | { |
| 118 | requestNfdStatus(); |
| 119 | emit showStatus(); |
| 120 | } |
| 121 | |
| 122 | } // namespace ndn |