dummy-client-face.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
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 "ndn-cxx/face.hpp"
26 #include "ndn-cxx/util/signal.hpp"
28 
29 namespace ndn {
30 namespace util {
31 
34 class DummyClientFace : public ndn::Face
35 {
36 public:
39  class Options
40  {
41  public:
43  const std::function<void(time::milliseconds)>& processEventsOverride)
44  : enablePacketLogging(enablePacketLogging)
45  , enableRegistrationReply(enableRegistrationReply)
47  {
48  }
49 
50  Options(bool enablePacketLogging, bool enableRegistrationReply)
51  : Options(enablePacketLogging, enableRegistrationReply, nullptr)
52  {
53  }
54 
56  : Options(true, false)
57  {
58  }
59 
60  public:
64 
69 
72  std::function<void(time::milliseconds)> processEventsOverride;
73  };
74 
75  class AlreadyLinkedError : public Error
76  {
77  public:
79  };
80 
83  explicit
84  DummyClientFace(const Options& options = Options());
85 
88  explicit
89  DummyClientFace(KeyChain& keyChain, const Options& options = Options());
90 
93  explicit
94  DummyClientFace(boost::asio::io_service& ioService, const Options& options = Options());
95 
98  DummyClientFace(boost::asio::io_service& ioService, KeyChain& keyChain,
99  const Options& options = Options());
100 
102 
105  void
106  receive(const Interest& interest);
107 
110  void
111  receive(const Data& data);
112 
115  void
116  receive(const lp::Nack& nack);
117 
120  void
121  linkTo(DummyClientFace& other);
122 
125  void
126  unlink();
127 
128 private:
129  class Transport;
130 
131  void
132  construct(const Options& options);
133 
134  void
135  enableBroadcastLink();
136 
137  void
139 
140  void
142 
143  void
144  doProcessEvents(time::milliseconds timeout, bool keepThread) override;
145 
146 public:
153  std::vector<Interest> sentInterests;
154 
161  std::vector<Data> sentData;
162 
169  std::vector<lp::Nack> sentNacks;
170 
176 
182 
188 
190  struct BroadcastLink;
191  shared_ptr<BroadcastLink> m_bcastLink;
192  std::unique_ptr<KeyChain> m_internalKeyChain;
193  KeyChain& m_keyChain;
194  std::function<void(time::milliseconds)> m_processEventsOverride;
195 };
196 
197 } // namespace util
198 } // namespace ndn
199 
200 #endif // NDN_UTIL_DUMMY_CLIENT_FACE_HPP
bool enableRegistrationReply
if true, prefix registration command will be automatically replied with a successful response ...
std::vector< lp::Nack > sentNacks
Nacks sent out of this DummyClientFace.
Definition: data.cpp:26
The interface of signing key management.
Definition: key-chain.hpp:45
Signal< DummyClientFace, Interest > onSendInterest
emits whenever an Interest is sent
std::vector< Interest > sentInterests
Interests sent out of this DummyClientFace.
Represents an Interest packet.
Definition: interest.hpp:50
std::vector< Data > sentData
Data sent out of this DummyClientFace.
provides a lightweight signal / event system
Definition: signal.hpp:52
represents a Network Nack
Definition: nack.hpp:38
options for DummyClientFace
DummyClientFace(const Options &options=Options())
Create a dummy face with internal IO service.
Signal< DummyClientFace, lp::Nack > onSendNack
emits whenever a Nack is sent
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:90
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
void unlink()
unlink the broadcast media if previously linked
void receive(const Interest &interest)
cause the Face to receive an interest
void linkTo(DummyClientFace &other)
link another DummyClientFace through a broadcast media
a client-side face for unit testing
Options(bool enablePacketLogging, bool enableRegistrationReply)
Options(bool enablePacketLogging, bool enableRegistrationReply, const std::function< void(time::milliseconds)> &processEventsOverride)
Represents a Data packet.
Definition: data.hpp:39
bool enablePacketLogging
if true, packets sent out of DummyClientFace will be appended to a container
std::function< void(time::milliseconds)> processEventsOverride
if not empty, face.processEvents() will be overridden by this function