blob: 263a23ac1e1d999cbbe7be7a24c1526a06d49289 [file] [log] [blame]
Chengyu Fan4381fb62015-01-14 11:37:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NFD_TESTS_DAEMON_FACE_FACE_HISTORY_HPP
27#define NFD_TESTS_DAEMON_FACE_FACE_HISTORY_HPP
28
29#include "face/face.hpp"
30
31namespace nfd {
32namespace tests {
33
34/** \brief captures signals from Face
35 */
36class FaceHistory : noncopyable
37{
38public:
39 explicit
40 FaceHistory(Face& face)
41 : m_limitedIo(nullptr)
42 {
43 this->construct(face);
44 }
45
46 FaceHistory(Face& face, LimitedIo& limitedIo)
47 : m_limitedIo(&limitedIo)
48 {
49 this->construct(face);
50 }
51
52private:
53 void
54 construct(Face& face)
55 {
56 m_receiveInterestConn = face.onReceiveInterest.connect([this] (const Interest& interest) {
57 this->receivedInterests.push_back(interest);
58 this->afterOp();
59 });
60 m_receiveDataConn = face.onReceiveData.connect([this] (const Data& data) {
61 this->receivedData.push_back(data);
62 this->afterOp();
63 });
64 m_failConn = face.onFail.connect([this] (const std::string& reason) {
65 this->failures.push_back(reason);
66 this->afterOp();
67 });
68 }
69
70 void
71 afterOp()
72 {
73 if (m_limitedIo != nullptr) {
74 m_limitedIo->afterOp();
75 }
76 }
77
78public:
79 std::vector<Interest> receivedInterests;
80 std::vector<Data> receivedData;
81 std::vector<std::string> failures;
82
83private:
84 LimitedIo* m_limitedIo;
85 signal::ScopedConnection m_receiveInterestConn;
86 signal::ScopedConnection m_receiveDataConn;
87 signal::ScopedConnection m_failConn;
88};
89
90} // namespace tests
91} // namespace nfd
92
93#endif // NFD_TESTS_DAEMON_FACE_FACE_HISTORY_HPP