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/security/key-chain.hpp>
33 #include <ndn-cxx/mgmt/nfd/controller.hpp>
34 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
35 #include <ndn-cxx/encoding/buffer-stream.hpp>
36 #include <ndn-cxx/util/face-uri.hpp>
37 
38 namespace ndn {
39 namespace tools {
40 namespace autoconfig {
41 
45 class Base : boost::noncopyable
46 {
47 public:
48  class Error : public std::runtime_error
49  {
50  public:
51  explicit
52  Error(const std::string& what)
53  : std::runtime_error(what)
54  {
55  }
56  };
57 
61  typedef std::function<void(const std::string&)> NextStageCallback;
62 
66  virtual void
67  start() = 0;
68 
69 protected:
76  Base(Face& face, KeyChain& keyChain, const NextStageCallback& nextStageOnFailure);
77 
82  void
83  connectToHub(const std::string& uri);
84 
85 private:
86  void
87  onCanonizeSuccess(const util::FaceUri& canonicalUri);
88 
89  void
90  onCanonizeFailure(const std::string& reason);
91 
92  void
93  onHubConnectSuccess(const nfd::ControlParameters& resp);
94 
95  void
96  onHubConnectError(const nfd::ControlResponse& response);
97 
98  void
99  registerPrefix(const Name& prefix, uint64_t faceId);
100 
101  void
102  onPrefixRegistrationSuccess(const nfd::ControlParameters& commandSuccessResult);
103 
104  void
105  onPrefixRegistrationError(const nfd::ControlResponse& response);
106 
107 protected:
108  Face& m_face;
109  KeyChain& m_keyChain;
110  nfd::Controller m_controller;
111  NextStageCallback m_nextStageOnFailure;
112 };
113 
114 } // namespace autoconfig
115 } // namespace tools
116 } // namespace ndn
117 
118 #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 nfd::Controller instance.
Definition: base.cpp:32
STL namespace.
NextStageCallback m_nextStageOnFailure
Definition: base.hpp:111
nfd::Controller m_controller
Definition: base.hpp:110
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
std::function< void(const std::string &)> NextStageCallback
Callback to be called when the stage fails.
Definition: base.hpp:61
Base class for discovery stages.
Definition: base.hpp:45
Error(const std::string &what)
Definition: base.hpp:52