blob: de7bab9a2c856c50d4de8db3e35fd43fbad196ae [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);
34 s_context->setContextProperty("fibModel", &s_fibModel);
35 s_context->setContextProperty("ribModel", &s_ribModel);
36 s_context->setContextProperty("statusViewer", this);
37
38 s_engine.load((QUrl("qrc:/status.qml")));
39}
40
41void
42StatusViewer::onStatusRetrieved(const nfd::ForwarderStatus& status)
43{
44 emit s_forwarderStatusModel.onDataReceived(status);
45}
46
47void
48StatusViewer::onFibStatusRetrieved(const std::vector<nfd::FibEntry>& status)
49{
50 emit s_fibModel.onDataReceived(status);
51}
52
53void
54StatusViewer::onRibStatusRetrieved(const std::vector<nfd::RibEntry>& status)
55{
56 emit s_ribModel.onDataReceived(status);
57}
58
59void
60StatusViewer::onStatusTimeout()
61{
62 std::cerr << "Should not really happen, most likely a serious problem" << std::endl;
63 s_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
64}
65
66void
67StatusViewer::requestNfdStatus()
68{
69 s_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1),
70 bind(&StatusViewer::onStatusTimeout, this));
71 s_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1),
72 bind(&StatusViewer::onStatusTimeout, this));
73 s_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1),
74 bind(&StatusViewer::onStatusTimeout, this));
75 s_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
76}
77
78void
79StatusViewer::present()
80{
81 requestNfdStatus();
82 emit showStatus();
83}
84
85} // namespace ndn