blob: 28137795a816cd107bf6f6a938150c4e8a4316b5 [file] [log] [blame]
Junxiao Shia60d9362014-11-12 09:38:21 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevaf99f462015-01-19 21:43:09 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Junxiao Shia60d9362014-11-12 09:38:21 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_UTIL_DUMMY_CLIENT_FACE_HPP
23#define NDN_UTIL_DUMMY_CLIENT_FACE_HPP
24
25#include "../face.hpp"
Junxiao Shi27913b42014-12-23 14:49:38 -070026#include "signal.hpp"
Junxiao Shia60d9362014-11-12 09:38:21 -070027
28namespace ndn {
29namespace util {
30
31/** \brief a client-side face for unit testing
32 */
33class DummyClientFace : public ndn::Face
34{
35public:
36 /** \brief options for DummyClientFace
37 */
38 struct Options
39 {
40 /** \brief if true, packets sent out of DummyClientFace will be appended to a container
41 */
42 bool enablePacketLogging;
43
44 /** \brief if true, prefix registration command will be automatically
45 * replied with a successful response
46 */
47 bool enableRegistrationReply;
48 };
49
50 /** \brief cause the Face to receive a packet
51 * \tparam Packet either Interest or Data
52 */
53 template<typename Packet>
54 void
55 receive(const Packet& packet);
56
57private: // constructors
58 class Transport;
59
60 // constructors are private; use makeDummyClientFace to create DummyClientFace
61
62 DummyClientFace(const Options& options, shared_ptr<Transport> transport);
63
64 DummyClientFace(const Options& options, shared_ptr<Transport> transport,
65 boost::asio::io_service& ioService);
66
67 void
68 construct(const Options& options);
69
70 friend shared_ptr<DummyClientFace>
71 makeDummyClientFace(const DummyClientFace::Options& options);
72
73 friend shared_ptr<DummyClientFace>
74 makeDummyClientFace(boost::asio::io_service& ioService, const DummyClientFace::Options& options);
75
76private:
77 void
78 enablePacketLogging();
79
80 void
81 enableRegistrationReply();
82
83public:
84 /** \brief default options
85 *
86 * enablePacketLogging=true
87 * enableRegistrationReply=false
88 */
89 static const Options DEFAULT_OPTIONS;
90
91 /** \brief Interests sent out of this DummyClientFace
92 *
93 * Sent Interests are appended to this container if options.enablePacketLogger is true.
94 * User of this class is responsible for cleaning up the container, if necessary.
95 * After .expressInterest, .processEvents must be called before the Interest would show up here.
96 */
97 std::vector<Interest> sentInterests;
98
99 /** \brief Data sent out of this DummyClientFace
100 *
101 * Sent Data are appended to this container if options.enablePacketLogger is true.
102 * User of this class is responsible for cleaning up the container, if necessary.
103 * After .put, .processEvents must be called before the Data would show up here.
104 */
105 std::vector<Data> sentDatas;
106
Junxiao Shi27913b42014-12-23 14:49:38 -0700107 /** \brief emits whenever an Interest is sent
Junxiao Shia60d9362014-11-12 09:38:21 -0700108 *
Junxiao Shi27913b42014-12-23 14:49:38 -0700109 * After .expressInterest, .processEvents must be called before this signal would be emitted.
110 */
111 Signal<DummyClientFace, Interest> onSendInterest;
112
113 /** \brief emits whenever a Data packet is sent
114 *
115 * After .put, .processEvents must be called before this signal would be emitted.
116 */
117 Signal<DummyClientFace, Data> onSendData;
118
Junxiao Shia60d9362014-11-12 09:38:21 -0700119private:
120 shared_ptr<Transport> m_transport;
121};
122
123shared_ptr<DummyClientFace>
124makeDummyClientFace(const DummyClientFace::Options& options = DummyClientFace::DEFAULT_OPTIONS);
125
126shared_ptr<DummyClientFace>
127makeDummyClientFace(boost::asio::io_service& ioService,
128 const DummyClientFace::Options& options = DummyClientFace::DEFAULT_OPTIONS);
129
130} // namespace util
131} // namespace ndn
132
133#endif // NDN_UTIL_DUMMY_CLIENT_FACE_HPP