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 
165  virtual void
166  removeRegisteredPrefix(uint64_t registeredPrefixId);
167 
173  virtual uint64_t
175  (const InterestFilter& filter, const OnInterestCallback& onInterest);
176 
182  virtual uint64_t
183  setInterestFilter(const Name& prefix, const OnInterestCallback& onInterest);
184 
190  virtual void
191  unsetInterestFilter(uint64_t interestFilterId);
192 
197  virtual void
198  send(const uint8_t *encoding, size_t encodingLength);
199 
204  virtual void
205  shutdown();
206 
214  virtual void
215  callLater(Milliseconds delayMilliseconds, const Callback& callback);
216 
217 private:
218  static ptr_lib::shared_ptr<Transport>
219  getDefaultTransport(boost::asio::io_service& ioService);
220 
221  static ptr_lib::shared_ptr<Transport::ConnectionInfo>
222  getDefaultConnectionInfo();
223 
224  boost::asio::io_service& ioService_;
225 };
226 
227 }
228 
229 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:112
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
Copyright (C) 2015-2016 Regents of the University of California.
Definition: threadsafe-face.hpp:27
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
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 > &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
virtual void unsetInterestFilter(uint64_t interestFilterId)
Override to use the ioService given to the constructor to dispatch unsetInterestFilter to be called i...
virtual void shutdown()
Override to use the ioService given to the constructor to dispatch shutdown to be called in a thread-...
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
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
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:42
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:662
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 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
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
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 ...
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...