face.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_FACE_HPP
23 #define NDN_FACE_HPP
24 
25 #include "common.hpp"
26 
27 #include "name.hpp"
28 #include "interest.hpp"
29 #include "interest-filter.hpp"
30 #include "data.hpp"
32 #include "lp/nack.hpp"
34 
35 #define NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
36 
37 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
39 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
40 
41 namespace boost {
42 namespace asio {
43 class io_service;
44 } // namespace asio
45 } // namespace boost
46 
47 namespace ndn {
48 
49 class Transport;
50 
51 class PendingInterestId;
52 class RegisteredPrefixId;
53 class InterestFilterId;
54 
55 namespace security {
56 class KeyChain;
57 } // namespace security
58 using security::KeyChain;
59 
60 namespace nfd {
61 class Controller;
62 } // namespace nfd
63 
67 typedef function<void(const Interest&, const Data&)> DataCallback;
68 
72 typedef function<void(const Interest&, const lp::Nack&)> NackCallback;
73 
77 typedef function<void(const Interest&)> TimeoutCallback;
78 
83 typedef function<void(const Interest&, Data&)> OnData;
84 
89 typedef function<void(const Interest&)> OnTimeout;
90 
94 typedef function<void(const InterestFilter&, const Interest&)> InterestCallback;
95 
100 typedef function<void (const InterestFilter&, const Interest&)> OnInterest;
101 
105 typedef function<void(const Name&)> RegisterPrefixSuccessCallback;
106 
110 typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
111 
115 typedef function<void()> UnregisterPrefixSuccessCallback;
116 
120 typedef function<void(const std::string&)> UnregisterPrefixFailureCallback;
121 
125 class Face : noncopyable
126 {
127 public:
128  class Error : public std::runtime_error
129  {
130  public:
131  explicit
132  Error(const std::string& what)
133  : std::runtime_error(what)
134  {
135  }
136  };
137 
138 public: // constructors
150  explicit
151  Face(shared_ptr<Transport> transport = nullptr);
152 
181  explicit
182  Face(boost::asio::io_service& ioService);
183 
190  explicit
191  Face(const std::string& host, const std::string& port = "6363");
192 
205  Face(shared_ptr<Transport> transport, KeyChain& keyChain);
206 
220  Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService);
221 
236  Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain);
237 
238  ~Face();
239 
240 public: // consumer
250  const PendingInterestId*
251  expressInterest(const Interest& interest,
252  const DataCallback& afterSatisfied,
253  const NackCallback& afterNacked,
254  const TimeoutCallback& afterTimeout);
255 
269  const PendingInterestId*
270  expressInterest(const Interest& interest,
271  const OnData& onData,
272  const OnTimeout& onTimeout = nullptr);
273 
288  const PendingInterestId*
289  expressInterest(const Name& name,
290  const Interest& tmpl,
291  const OnData& onData,
292  const OnTimeout& onTimeout = nullptr);
293 
299  void
300  removePendingInterest(const PendingInterestId* pendingInterestId);
301 
305  void
307 
311  size_t
312  getNPendingInterests() const;
313 
314 public: // producer
335  const RegisteredPrefixId*
336  setInterestFilter(const InterestFilter& interestFilter,
337  const InterestCallback& onInterest,
338  const RegisterPrefixFailureCallback& onFailure,
339  const security::SigningInfo& signingInfo = security::SigningInfo(),
340  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
341 
363  const RegisteredPrefixId*
364  setInterestFilter(const InterestFilter& interestFilter,
365  const InterestCallback& onInterest,
366  const RegisterPrefixSuccessCallback& onSuccess,
367  const RegisterPrefixFailureCallback& onFailure,
368  const security::SigningInfo& signingInfo = security::SigningInfo(),
369  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
370 
383  const InterestFilterId*
384  setInterestFilter(const InterestFilter& interestFilter,
385  const InterestCallback& onInterest);
386 
387 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
388 
411  DEPRECATED(
412  const RegisteredPrefixId*
413  setInterestFilter(const InterestFilter& interestFilter,
414  const OnInterest& onInterest,
415  const RegisterPrefixSuccessCallback& onSuccess,
416  const RegisterPrefixFailureCallback& onFailure,
417  const security::v1::IdentityCertificate& certificate,
418  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
419 
442  DEPRECATED(
443  const RegisteredPrefixId*
444  setInterestFilter(const InterestFilter& interestFilter,
445  const OnInterest& onInterest,
446  const RegisterPrefixFailureCallback& onFailure,
447  const security::v1::IdentityCertificate& certificate,
448  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
449 
471  DEPRECATED(
472  const RegisteredPrefixId*
473  setInterestFilter(const InterestFilter& interestFilter,
474  const OnInterest& onInterest,
475  const RegisterPrefixSuccessCallback& onSuccess,
476  const RegisterPrefixFailureCallback& onFailure,
477  const Name& identity,
478  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
479 
500  DEPRECATED(
501  const RegisteredPrefixId*
502  setInterestFilter(const InterestFilter& interestFilter,
503  const OnInterest& onInterest,
504  const RegisterPrefixFailureCallback& onFailure,
505  const Name& identity,
506  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
507 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
508 
526  const RegisteredPrefixId*
527  registerPrefix(const Name& prefix,
528  const RegisterPrefixSuccessCallback& onSuccess,
529  const RegisterPrefixFailureCallback& onFailure,
530  const security::SigningInfo& signingInfo = security::SigningInfo(),
531  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
532 
533 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
534 
552  DEPRECATED(
553  const RegisteredPrefixId*
554  registerPrefix(const Name& prefix,
555  const RegisterPrefixSuccessCallback& onSuccess,
556  const RegisterPrefixFailureCallback& onFailure,
557  const security::v1::IdentityCertificate& certificate,
558  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
559 
578  DEPRECATED(
579  const RegisteredPrefixId*
580  registerPrefix(const Name& prefix,
581  const RegisterPrefixSuccessCallback& onSuccess,
582  const RegisterPrefixFailureCallback& onFailure,
583  const Name& identity,
584  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
585 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
586 
599  void
600  unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
601 
610  void
611  unsetInterestFilter(const InterestFilterId* interestFilterId);
612 
626  void
627  unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
628  const UnregisterPrefixSuccessCallback& onSuccess,
629  const UnregisterPrefixFailureCallback& onFailure);
630 
644  void
645  put(const Data& data);
646 
652  void
653  put(const lp::Nack& nack);
654 
655 public: // IO routine
677  void
678  processEvents(const time::milliseconds& timeout = time::milliseconds::zero(),
679  bool keepThread = false)
680  {
681  this->doProcessEvents(timeout, keepThread);
682  }
683 
692  void
693  shutdown();
694 
698  boost::asio::io_service&
700  {
701  return m_ioService;
702  }
703 
708  shared_ptr<Transport>
709  getTransport();
710 
711 protected:
712  virtual void
713  doProcessEvents(const time::milliseconds& timeout, bool keepThread);
714 
715 private:
719  shared_ptr<Transport>
720  makeDefaultTransport();
721 
726  void
727  construct(shared_ptr<Transport> transport, KeyChain& keyChain);
728 
729  void
730  onReceiveElement(const Block& blockFromDaemon);
731 
732  void
733  asyncShutdown();
734 
735 private:
737  unique_ptr<boost::asio::io_service> m_internalIoService;
739  boost::asio::io_service& m_ioService;
740 
741  shared_ptr<Transport> m_transport;
742 
750  unique_ptr<KeyChain> m_internalKeyChain;
751 
752  unique_ptr<nfd::Controller> m_nfdController;
753 
754  class Impl;
755  shared_ptr<Impl> m_impl;
756 };
757 
758 } // namespace ndn
759 
760 #endif // NDN_FACE_HPP
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
Error(const std::string &what)
Definition: face.hpp:132
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command fails.
Definition: face.hpp:120
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:98
const RegisteredPrefixId * setInterestFilter(const InterestFilter &interestFilter, const InterestCallback &onInterest, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
Set InterestFilter to dispatch incoming matching interest to onInterest callback and register the fil...
Definition: face.cpp:278
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression
The packet signing interface.
Definition: key-chain.hpp:47
STL namespace.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:42
function< void(const Interest &)> OnTimeout
Callback invoked when expressed Interest times out.
Definition: face.hpp:89
function< void(const InterestFilter &, const Interest &)> OnInterest
Callback invoked when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:100
virtual void doProcessEvents(const time::milliseconds &timeout, bool keepThread)
Definition: face.cpp:442
Signing parameters passed to KeyChain.
void unregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
Unregister prefix from RIB.
Definition: face.cpp:432
represents a Network Nack
Definition: nack.hpp:40
Copyright (c) 2013-2016 Regents of the University of California.
void removeAllPendingInterests()
Cancel all previously expressed Interests.
Definition: face.cpp:225
shared_ptr< Transport > getTransport()
Definition: face.cpp:161
void shutdown()
Shutdown face operations.
Definition: face.cpp:481
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:125
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback invoked when registerPrefix or setInterestFilter command fails.
Definition: face.hpp:110
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback invoked when registerPrefix or setInterestFilter command succeeds.
Definition: face.hpp:105
Name abstraction to represent an absolute name.
Definition: name.hpp:46
void unsetInterestFilter(const RegisteredPrefixId *registeredPrefixId)
Remove the registered prefix entry with the registeredPrefixId.
Definition: face.cpp:416
boost::asio::io_service & getIoService()
Definition: face.hpp:699
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:94
function< void(const Interest &, Data &)> OnData
Callback invoked when expressed Interest gets satisfied with Data packet.
Definition: face.hpp:83
#define DEPRECATED(func)
Definition: common.hpp:71
size_t getNPendingInterests() const
Get number of pending Interests.
Definition: face.cpp:233
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds.
Definition: face.hpp:115
const PendingInterestId * expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
Definition: face.cpp:167
void processEvents(const time::milliseconds &timeout=time::milliseconds::zero(), bool keepThread=false)
Process any data to receive or call timeout callbacks.
Definition: face.hpp:678
function< void(const Interest &)> TimeoutCallback
Callback invoked when expressed Interest times out.
Definition: face.hpp:77
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback invoked when Nack is sent in response to expressed Interest.
Definition: face.hpp:72
represents a Data packet
Definition: data.hpp:37
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:42
const RegisteredPrefixId * registerPrefix(const Name &prefix, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
Register prefix with the connected NDN forwarder.
Definition: face.cpp:376
Face(shared_ptr< Transport > transport=nullptr)
Create Face using given transport (or default transport if omitted)
Definition: face.cpp:48
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when expressed Interest gets satisfied with a Data packet.
Definition: face.hpp:67
void removePendingInterest(const PendingInterestId *pendingInterestId)
Cancel previously expressed Interest.
Definition: face.cpp:217
void put(const Data &data)
Publish data packet.
Definition: face.cpp:239