blob: c521b202e98fa2ca6ad765d04d5baf4f322df2d9 [file] [log] [blame]
Eric Newberry4164b8e2015-04-23 17:29:18 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2015, Arizona Board of Regents.
4 *
5 * This file is part of ndn-tools (Named Data Networking Essential Tools).
6 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
7 *
8 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
9 * 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 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * 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
17 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author: Eric Newberry <enewberry@email.arizona.edu>
20 */
21
22#include "tracer.hpp"
23
24namespace ndn {
25namespace ping {
26namespace client {
27
28Tracer::Tracer(Ping& ping, const Options& options)
29 : m_options(options)
30{
31 ping.afterResponse.connect(bind(&Tracer::onResponse, this, _1, _2));
32 ping.afterTimeout.connect(bind(&Tracer::onTimeout, this, _1));
33}
34
35void
36Tracer::onResponse(uint64_t seq, Rtt rtt)
37{
38 if (m_options.shouldPrintTimestamp) {
39 std::cout << time::toIsoString(time::system_clock::now()) << " - ";
40 }
41
42 std::cout << "content from " << m_options.prefix << ": seq=" << seq << " time="
43 << rtt.count() << " ms" << std::endl;
44}
45
46void
47Tracer::onTimeout(uint64_t seq)
48{
49 if (m_options.shouldPrintTimestamp) {
50 std::cout << time::toIsoString(time::system_clock::now()) << " - ";
51 }
52
53 std::cout << "timeout from " << m_options.prefix << ": seq=" << seq << std::endl;
54}
55
56void
57Tracer::onError(std::string msg)
58{
59 std::cerr << "ERROR: " << msg << std::endl;
60}
61
62} // namespace client
63} // namespace ping
64} // namespace ndn