All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
threadsafe-face.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_THREADSAFE_FACE_HPP
23 #define NDN_THREADSAFE_FACE_HPP
24 
25 // Only compile if ndn-cpp-config.h defines NDN_CPP_HAVE_BOOST_ASIO.
26 #include "ndn-cpp-config.h"
27 #ifdef NDN_CPP_HAVE_BOOST_ASIO
28 
29 #include <boost/asio.hpp>
30 #include "face.hpp"
31 
32 namespace ndn {
33 
40 class ThreadsafeFace : public Face {
41 public:
54  ThreadsafeFace
55  (boost::asio::io_service& ioService,
56  const ptr_lib::shared_ptr<Transport>& transport,
57  const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo);
58 
68  ThreadsafeFace
69  (boost::asio::io_service& ioService, const char *host,
70  unsigned short port = 6363);
71 
81  ThreadsafeFace(boost::asio::io_service& ioService);
82 
88  virtual uint64_t
89  expressInterest
90  (const Interest& interest, const OnData& onData,
91  const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
92  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
93 
99  virtual uint64_t
100  expressInterest
101  (const Name& name, const Interest *interestTemplate, const OnData& onData,
102  const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
103  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
104 
105  uint64_t
106  expressInterest
107  (const Name& name, const OnData& onData, const OnTimeout& onTimeout = OnTimeout(),
108  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
109  {
110  // This is needed, otherwise C++ will use the signature with
111  // const Interest& by automatically converting the Name to an Interest
112  // using the constructor Interest(const Name& name). Just call the Face
113  // method with the same signature as this.
114  return Face::expressInterest(name, onData, onTimeout, wireFormat);
115  }
116 
122  virtual void
123  removePendingInterest(uint64_t pendingInterestId);
124 
130  virtual uint64_t
131  registerPrefix
132  (const Name& prefix, const OnInterestCallback& onInterest,
133  const OnRegisterFailed& onRegisterFailed,
134  const OnRegisterSuccess& onRegisterSuccess,
135  const ForwardingFlags& flags = ForwardingFlags(),
136  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
137 
138  uint64_t
139  registerPrefix
140  (const Name& prefix, const OnInterestCallback& onInterest,
141  const OnRegisterFailed& onRegisterFailed,
142  const ForwardingFlags& flags,
143  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
144  {
145  // This is needed, otherwise C++ will try to use the signature with
146  // const OnRegisterSuccess&. Just call the Face method with the same
147  // signature as this.
148  return Face::registerPrefix
149  (prefix, onInterest, onRegisterFailed, flags, wireFormat);
150  }
151 
152  uint64_t
153  registerPrefix
154  (const Name& prefix, const OnInterestCallback& onInterest,
155  const OnRegisterFailed& onRegisterFailed)
156  {
157  // This is needed, otherwise C++ will try to use the signature with
158  // const OnRegisterSuccess&. Just call the Face method with the same
159  // signature as this.
160  return Face::registerPrefix(prefix, onInterest, onRegisterFailed);
161  }
162 
168  virtual void
169  removeRegisteredPrefix(uint64_t registeredPrefixId);
170 
176  virtual uint64_t
177  setInterestFilter
178  (const InterestFilter& filter, const OnInterestCallback& onInterest);
179 
185  virtual uint64_t
186  setInterestFilter(const Name& prefix, const OnInterestCallback& onInterest);
187 
193  virtual void
194  unsetInterestFilter(uint64_t interestFilterId);
195 
200  virtual void
201  putData
202  (const Data& data,
203  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
204 
209  virtual void
210  send(const uint8_t *encoding, size_t encodingLength);
211 
216  virtual void
217  shutdown();
218 
226  virtual void
227  callLater(Milliseconds delayMilliseconds, const Callback& callback);
228 
229 private:
230  static ptr_lib::shared_ptr<Transport>
231  getDefaultTransport(boost::asio::io_service& ioService);
232 
233  static ptr_lib::shared_ptr<Transport::ConnectionInfo>
234  getDefaultConnectionInfo();
235 
236  boost::asio::io_service& ioService_;
237 };
238 
239 }
240 
241 #endif // NDN_CPP_HAVE_BOOST_ASIO
242 
243 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:114
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &prefix, const ptr_lib::shared_ptr< const Interest > &interest, Face &face, uint64_t interestFilterId, const ptr_lib::shared_ptr< const InterestFilter > &filter)> OnInterestCallback
An OnInterestCallback function object is used to pass a callback to setInterestFilter and optionally ...
Definition: face.hpp:65
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &prefix, uint64_t registeredPrefixId)> OnRegisterSuccess
An OnRegisterSuccess function object is used to report when registerPrefix succeeds.
Definition: face.hpp:78
virtual uint64_t expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout, const OnNetworkNack &onNetworkNack, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Send the Interest through the transport, read the entire response and call onData, onTimeout or onNetworkNack as described below.
Definition: face.cpp:101
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &interest, const ptr_lib::shared_ptr< NetworkNack > &networkNack)> OnNetworkNack
An OnNetworkNack function object is used to pass a callback to expressInterest.
Definition: face.hpp:55
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &interest)> OnTimeout
An OnTimeout function object is used to pass a callback to expressInterest.
Definition: face.hpp:48
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &interest, const ptr_lib::shared_ptr< Data > &data)> OnData
An OnData function object is used to pass a callback to expressInterest.
Definition: face.hpp:35
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &prefix)> OnRegisterFailed
An OnRegisterFailed function object is used to report when registerPrefix fails.
Definition: face.hpp:71
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
virtual uint64_t registerPrefix(const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Register prefix with the connected NDN hub and call onInterest when a matching interest is received...
Definition: face.cpp:145