dummy-client-face.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_UTIL_DUMMY_CLIENT_FACE_HPP
23 #define NDN_UTIL_DUMMY_CLIENT_FACE_HPP
24 
25 #include "../face.hpp"
26 #include "signal.hpp"
27 #include "../security/key-chain.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 
77  explicit
78  DummyClientFace(const Options& options = Options());
79 
82  explicit
83  DummyClientFace(security::v1::KeyChain& keyChain, const Options& options = Options());
84 
87  explicit
88  DummyClientFace(boost::asio::io_service& ioService, const Options& options = Options());
89 
92  DummyClientFace(boost::asio::io_service& ioService, security::v1::KeyChain& keyChain,
93  const Options& options = Options());
94 
97  void
98  receive(const Interest& interest);
99 
102  void
103  receive(const Data& data);
104 
107  void
108  receive(const lp::Nack& nack);
109 
110 private:
111  class Transport;
112 
113  void
114  construct(const Options& options);
115 
116  void
117  enablePacketLogging();
118 
119  void
120  enableRegistrationReply();
121 
122  void
123  doProcessEvents(const time::milliseconds& timeout, bool keepThread) override;
124 
125 public:
132  std::vector<Interest> sentInterests;
133 
140  std::vector<Data> sentData;
141 
148  std::vector<lp::Nack> sentNacks;
149 
154  Signal<DummyClientFace, Interest> onSendInterest;
155 
160  Signal<DummyClientFace, Data> onSendData;
161 
166  Signal<DummyClientFace, lp::Nack> onSendNack;
167 
168 private:
169  std::unique_ptr<security::v1::KeyChain> m_internalKeyChain;
170  security::v1::KeyChain& m_keyChain;
171  std::function<void(time::milliseconds)> m_processEventsOverride;
172 };
173 
174 } // namespace util
175 } // namespace ndn
176 
177 #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.
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
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:42
std::vector< Data > sentData
Data sent out of this DummyClientFace.
represents a Network Nack
Definition: nack.hpp:40
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:121
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
void receive(const Interest &interest)
cause the Face to receive an interest
a client-side face for unit testing
Options(bool enablePacketLogging, bool enableRegistrationReply)
The packet signing interface.
Options(bool enablePacketLogging, bool enableRegistrationReply, const std::function< void(time::milliseconds)> &processEventsOverride)
represents a Data packet
Definition: data.hpp:37
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