All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
prefix-discovery.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_PREFIX_DISCOVERY_HPP
23 #define NDN_PREFIX_DISCOVERY_HPP
24 
25 #include <ndn-cpp/face.hpp>
26 
27 namespace ndntools {
28 
38 public:
39  typedef ndn::func_lib::function<void
40  (const ndn::ptr_lib::shared_ptr<std::vector<ndn::Name> >& prefixes)> OnPrefixes;
41 
55  (OnPrefixes onPrefixes, ndn::Face* face,
56  ndn::Milliseconds periodMilliseconds = 60000.0)
57  : impl_(new Impl(onPrefixes, face, periodMilliseconds))
58  {
59  }
60 
68  void
69  start() { impl_->start(); }
70 
74  void
75  stop() { impl_->stop(); }
76 
77 private:
83  class Impl : public ndn::ptr_lib::enable_shared_from_this<Impl> {
84  public:
85  Impl(OnPrefixes onPrefixes, ndn::Face* face,
86  ndn::Milliseconds periodMilliseconds)
87  : onPrefixes_(onPrefixes), face_(face),
88  periodMilliseconds_(periodMilliseconds), isEnabled_(false)
89  {
90  }
91 
92  void
93  start()
94  {
95  if (isEnabled_)
96  // Already started.
97  return;
98 
99  isEnabled_ = true;
100  express();
101  }
102 
103  void stop() { isEnabled_ = false; }
104 
105  private:
106  void
107  express();
108 
109  void
110  onData
111  (const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
112  const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
113 
114  void
115  onTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
116 
117  OnPrefixes onPrefixes_;
118  ndn::Face* face_;
119  ndn::Milliseconds periodMilliseconds_;
120  std::vector<ndn::Name> prefixes_;
121  bool isEnabled_;
122  };
123 
124  ndn::ptr_lib::shared_ptr<Impl> impl_;
125 };
126 
127 }
128 
129 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:114
The Face class provides the main methods for NDN communication.
Definition: face.hpp:86
void stop()
Stop the process.
Definition: prefix-discovery.hpp:75
void start()
Start the process by sending the first interest to the Face given to the constructor, then automatically repeat indefinitely with the period specified in the constructor.
Definition: prefix-discovery.hpp:69
PrefixDiscovery(OnPrefixes onPrefixes, ndn::Face *face, ndn::Milliseconds periodMilliseconds=60000.0)
Create a PrefixDiscovery to use the given OnPrefixes callback and face.
Definition: prefix-discovery.hpp:55
PrefixDiscovery repeatedly sends an interest for the routable prefix to the connected NFD...
Definition: prefix-discovery.hpp:37