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 #include "face.hpp"
26 
27 namespace boost { namespace asio { class io_service; }}
28 
29 namespace ndn {
30 
37 class ThreadsafeFace : public Face {
38 public:
52  (boost::asio::io_service& ioService,
53  const ptr_lib::shared_ptr<Transport>& transport,
54  const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo);
55 
66  (boost::asio::io_service& ioService, const char *host,
67  unsigned short port = 6363);
68 
78  ThreadsafeFace(boost::asio::io_service& ioService);
79 
85  virtual uint64_t
87  (const Interest& interest, const OnData& onData,
88  const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
90 
96  virtual uint64_t
98  (const Name& name, const Interest *interestTemplate, const OnData& onData,
99  const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
101 
102  uint64_t
104  (const Name& name, const OnData& onData, const OnTimeout& onTimeout = OnTimeout(),
106  {
107  // This is needed, otherwise C++ will use the signature with
108  // const Interest& by automatically converting the Name to an Interest
109  // using the constructor Interest(const Name& name). Just call the Face
110  // method with the same signature as this.
111  return Face::expressInterest(name, onData, onTimeout, wireFormat);
112  }
113 
119  virtual void
120  removePendingInterest(uint64_t pendingInterestId);
121 
127  virtual uint64_t
129  (const Name& prefix, const OnInterestCallback& onInterest,
130  const OnRegisterFailed& onRegisterFailed,
131  const OnRegisterSuccess& onRegisterSuccess,
132  const ForwardingFlags& flags = ForwardingFlags(),
134 
135  uint64_t
137  (const Name& prefix, const OnInterestCallback& onInterest,
138  const OnRegisterFailed& onRegisterFailed,
139  const ForwardingFlags& flags,
141  {
142  // This is needed, otherwise C++ will try to use the signature with
143  // const OnRegisterSuccess&. Just call the Face method with the same
144  // signature as this.
145  return Face::registerPrefix
146  (prefix, onInterest, onRegisterFailed, flags, wireFormat);
147  }
148 
149  uint64_t
151  (const Name& prefix, const OnInterestCallback& onInterest,
152  const OnRegisterFailed& onRegisterFailed)
153  {
154  // This is needed, otherwise C++ will try to use the signature with
155  // const OnRegisterSuccess&. Just call the Face method with the same
156  // signature as this.
157  return Face::registerPrefix(prefix, onInterest, onRegisterFailed);
158  }
159 
160  uint64_t
161  DEPRECATED_IN_NDN_CPP registerPrefix
162  (const Name& prefix, const OnInterest& onInterest,
163  const OnRegisterFailed& onRegisterFailed,
164  const ForwardingFlags& flags = ForwardingFlags(),
166  {
167  // This is needed, otherwise C++ will try to use the signature with
168  // const OnInterestCallback&. Just call the Face method with the
169  // same signature as this.
170  return Face::registerPrefix
171  (prefix, onInterest, onRegisterFailed, flags, wireFormat);
172  }
173 
179  virtual void
180  removeRegisteredPrefix(uint64_t registeredPrefixId);
181 
187  virtual uint64_t
189  (const InterestFilter& filter, const OnInterestCallback& onInterest);
190 
196  virtual uint64_t
197  setInterestFilter(const Name& prefix, const OnInterestCallback& onInterest);
198 
204  virtual void
205  unsetInterestFilter(uint64_t interestFilterId);
206 
211  virtual void
212  send(const uint8_t *encoding, size_t encodingLength);
213 
221  virtual void
222  callLater(Milliseconds delayMilliseconds, const Callback& callback);
223 
224 private:
225  static ptr_lib::shared_ptr<Transport>
226  getDefaultTransport(boost::asio::io_service& ioService);
227 
228  static ptr_lib::shared_ptr<Transport::ConnectionInfo>
229  getDefaultConnectionInfo();
230 
231  boost::asio::io_service& ioService_;
232 };
233 
234 }
235 
236 #endif
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &)> OnTimeout
An OnTimeout function object is used to pass a callback to expressInterest.
Definition: face.hpp:46
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:111
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &, const ptr_lib::shared_ptr< const Interest > &, Transport &, uint64_t)> OnInterest
Definition: face.hpp:58
Copyright (C) 2015-2016 Regents of the University of California.
Definition: threadsafe-face.hpp:27
The Face class provides the main methods for NDN communication.
Definition: face.hpp:86
A ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an in...
Definition: forwarding-flags.hpp:35
virtual void removePendingInterest(uint64_t pendingInterestId)
Override to use the ioService given to the constructor to dispatch removePendingInterest to be called...
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &, uint64_t)> 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
virtual void unsetInterestFilter(uint64_t interestFilterId)
Override to use the ioService given to the constructor to dispatch unsetInterestFilter to be called i...
ThreadsafeFace(boost::asio::io_service &ioService, const ptr_lib::shared_ptr< Transport > &transport, const ptr_lib::shared_ptr< const Transport::ConnectionInfo > &connectionInfo)
Create a new Face for communication with an NDN hub with the given Transport object and connectionInf...
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:41
virtual uint64_t setInterestFilter(const InterestFilter &filter, const OnInterestCallback &onInterest)
Override to use the ioService given to the constructor to dispatch setInterestFilter to be called in ...
func_lib::function< void()> Callback
Face::Callback is used internally in callLater.
Definition: face.hpp:674
virtual void callLater(Milliseconds delayMilliseconds, const Callback &callback)
Override to call callback() after the given delay, using a basic_deadline_timer with the ioService gi...
virtual uint64_t registerPrefix(const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Override to use the ioService given to the constructor to dispatch registerPrefix to be called in a t...
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &, const ptr_lib::shared_ptr< const Interest > &, Face &, uint64_t, const ptr_lib::shared_ptr< const InterestFilter > &)> OnInterestCallback
An OnInterestCallback function object is used to pass a callback to setInterestFilter and optionally ...
Definition: face.hpp:67
virtual void removeRegisteredPrefix(uint64_t registeredPrefixId)
Override to use the ioService given to the constructor to dispatch removeRegisteredPrefix to be calle...
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
Definition: wire-format.hpp:39
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &)> OnRegisterFailed
An OnRegisterFailed function object is used to report when registerPrefix fails.
Definition: face.hpp:72
An InterestFilter holds a Name prefix and optional regex match expression for use in Face::setInteres...
Definition: interest-filter.hpp:33
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
virtual uint64_t expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout, const OnNetworkNack &onNetworkNack, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Override to use the ioService given to the constructor to dispatch expressInterest to be called in a ...
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &, const ptr_lib::shared_ptr< Data > &)> OnData
An OnData function object is used to pass a callback to expressInterest.
Definition: face.hpp:35
A ThreadsafeFace extends Face to use a Boost asio io_service to process events and schedule communica...
Definition: threadsafe-face.hpp:37
virtual void send(const uint8_t *encoding, size_t encodingLength)
Override to use the ioService given to the constructor to dispatch send to be called in a thread-safe...
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &, const ptr_lib::shared_ptr< NetworkNack > &)> OnNetworkNack
An OnNetworkNack function object is used to pass a callback to expressInterest.
Definition: face.hpp:52