blob: 6bc58790dbaa8bd876170c24668ae2d8a0d00f58 [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 Zhao078ac692017-03-02 16:28:51 -080034 s_context->setContextProperty("faceModel", &s_faceModel);
Qi Zhao7e524492017-03-02 15:05:45 -080035 s_context->setContextProperty("fibModel", &s_fibModel);
36 s_context->setContextProperty("ribModel", &s_ribModel);
37 s_context->setContextProperty("statusViewer", this);
38
39 s_engine.load((QUrl("qrc:/status.qml")));
40}
41
42void
43StatusViewer::onStatusRetrieved(const nfd::ForwarderStatus& status)
44{
45 emit s_forwarderStatusModel.onDataReceived(status);
46}
47
48void
Qi Zhao078ac692017-03-02 16:28:51 -080049StatusViewer::onFaceStatusRetrieved(const std::vector<nfd::FaceStatus>& status)
50{
51 emit s_faceModel.onDataReceived(status);
52}
53
54void
Qi Zhao7e524492017-03-02 15:05:45 -080055StatusViewer::onFibStatusRetrieved(const std::vector<nfd::FibEntry>& status)
56{
57 emit s_fibModel.onDataReceived(status);
58}
59
60void
61StatusViewer::onRibStatusRetrieved(const std::vector<nfd::RibEntry>& status)
62{
63 emit s_ribModel.onDataReceived(status);
64}
65
66void
67StatusViewer::onStatusTimeout()
68{
69 std::cerr << "Should not really happen, most likely a serious problem" << std::endl;
70 s_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
71}
72
73void
74StatusViewer::requestNfdStatus()
75{
76 s_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1),
77 bind(&StatusViewer::onStatusTimeout, this));
Qi Zhao078ac692017-03-02 16:28:51 -080078 s_controller->fetch<ndn::nfd::FaceDataset>(bind(&StatusViewer::onFaceStatusRetrieved, this, _1),
79 bind(&StatusViewer::onStatusTimeout, this));
Qi Zhao7e524492017-03-02 15:05:45 -080080 s_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1),
81 bind(&StatusViewer::onStatusTimeout, this));
82 s_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1),
83 bind(&StatusViewer::onStatusTimeout, this));
84 s_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
85}
86
87void
88StatusViewer::present()
89{
90 requestNfdStatus();
91 emit showStatus();
92}
93
94} // namespace ndn