base.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_TOOLS_NDN_AUTOCONFIG_BASE_HPP
27 #define NFD_TOOLS_NDN_AUTOCONFIG_BASE_HPP
28 
29 #include "core/common.hpp"
30 
31 #include <ndn-cxx/face.hpp>
32 #include <ndn-cxx/mgmt/nfd/controller.hpp>
33 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
34 #include <ndn-cxx/security/key-chain.hpp>
35 #include <ndn-cxx/util/face-uri.hpp>
36 
37 namespace ndn {
38 namespace tools {
39 namespace autoconfig {
40 
41 using ndn::nfd::ControlParameters;
42 using ndn::nfd::ControlResponse;
43 using ndn::util::FaceUri;
44 
48 class Base : boost::noncopyable
49 {
50 public:
51  class Error : public std::runtime_error
52  {
53  public:
54  explicit
55  Error(const std::string& what)
56  : std::runtime_error(what)
57  {
58  }
59  };
60 
64  typedef std::function<void(const std::string&)> NextStageCallback;
65 
69  virtual void
70  start() = 0;
71 
72 protected:
79  Base(Face& face, KeyChain& keyChain, const NextStageCallback& nextStageOnFailure);
80 
85  void
86  connectToHub(const std::string& uri);
87 
88 private:
89  void
90  onCanonizeSuccess(const FaceUri& canonicalUri);
91 
92  void
93  onCanonizeFailure(const std::string& reason);
94 
95  void
96  onHubConnectSuccess(const ControlParameters& resp);
97 
98  void
99  onHubConnectError(const ControlResponse& response);
100 
101  void
102  registerPrefix(const Name& prefix, uint64_t faceId);
103 
104  void
105  onPrefixRegistrationSuccess(const ControlParameters& commandSuccessResult);
106 
107  void
108  onPrefixRegistrationError(const ControlResponse& response);
109 
110 protected:
111  Face& m_face;
112  KeyChain& m_keyChain;
113  ndn::nfd::Controller m_controller;
114  NextStageCallback m_nextStageOnFailure;
115 };
116 
117 } // namespace autoconfig
118 } // namespace tools
119 } // namespace ndn
120 
121 #endif // NFD_TOOLS_NDN_AUTOCONFIG_BASE_HPP
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Definition: nfd.hpp:35
Base(Face &face, KeyChain &keyChain, const NextStageCallback &nextStageOnFailure)
Initialize variables and create Controller instance.
Definition: base.cpp:32
STL namespace.
NextStageCallback m_nextStageOnFailure
Definition: base.hpp:114
virtual void start()=0
Start the stage.
void connectToHub(const std::string &uri)
Attempt to connect to local hub using the uri FaceUri.
Definition: base.cpp:41
ndn::nfd::Controller m_controller
Definition: base.hpp:113
std::function< void(const std::string &)> NextStageCallback
Callback to be called when the stage fails.
Definition: base.hpp:64
Base class for discovery stages.
Definition: base.hpp:48
Error(const std::string &what)
Definition: base.hpp:55