All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nfd-controller.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
7 #ifndef NDN_MANAGEMENT_NFD_CONTROLLER_HPP
8 #define NDN_MANAGEMENT_NFD_CONTROLLER_HPP
9 
10 #include "controller.hpp"
11 #include "nfd-control-command.hpp"
12 #include "../face.hpp"
13 
14 namespace ndn {
15 namespace nfd {
16 
20 {
21 public:
24  typedef function<void(const ControlParameters&)> CommandSucceedCallback;
25 
28  typedef function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback;
29 
30  explicit
31  Controller(Face& face);
32 
35  template<typename Command>
36  void
37  start(const ControlParameters& parameters,
38  const CommandSucceedCallback& onSuccess,
39  const CommandFailCallback& onFailure,
40  time::milliseconds timeout = getDefaultCommandTimeout());
41 
42 public: // selfreg using FIB Management commands
43  virtual void
44  selfRegisterPrefix(const Name& prefixToRegister,
45  const SuccessCallback& onSuccess,
46  const FailCallback& onFail);
47 
48  virtual void
49  selfDeregisterPrefix(const Name& prefixToDeRegister,
50  const SuccessCallback& onSuccess,
51  const FailCallback& onFail);
52 
53 private:
54  void
55  processCommandResponse(const Data& data,
56  const shared_ptr<ControlCommand>& command,
57  const CommandSucceedCallback& onSuccess,
58  const CommandFailCallback& onFailure);
59 
60 public:
61  static time::milliseconds
63  {
64  return time::milliseconds(10000);
65  }
66 
67 protected:
70 };
71 
72 
73 template<typename Command>
74 void
76  const CommandSucceedCallback& onSuccess,
77  const CommandFailCallback& onFailure,
78  time::milliseconds timeout)
79 {
80  BOOST_ASSERT(timeout > time::milliseconds::zero());
81 
82  shared_ptr<ControlCommand> command = make_shared<Command>();
83 
84  Interest commandInterest = command->makeCommandInterest(parameters, m_commandInterestGenerator);
85  commandInterest.setInterestLifetime(timeout);
86 
87  // http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668.aspx
88  const uint32_t timeoutCode = 10060;
89  m_face.expressInterest(commandInterest,
90  bind(&Controller::processCommandResponse, this, _2,
91  command, onSuccess, onFailure),
92  bind(onFailure, timeoutCode, "Command Interest timed out"));
93 }
94 
95 } // namespace nfd
96 } // namespace ndn
97 
98 #endif // NDN_MANAGEMENT_NFD_CONTROLLER_HPP
CommandInterestGenerator m_commandInterestGenerator
represents parameters in a ControlCommand request or response
Helper class to generate CommandInterests.
function< void()> SuccessCallback
Definition: controller.hpp:23
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:24
function< void(const ControlParameters &)> CommandSucceedCallback
a callback on command success
function< void(const std::string &)> FailCallback
Definition: controller.hpp:24
Abstraction to communicate with local or remote NDN forwarder.
Definition: face.hpp:54
NFD Management protocol - ControlCommand client.
static time::milliseconds getDefaultCommandTimeout()
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:26
const PendingInterestId * expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout=OnTimeout())
Express Interest.
Definition: face.cpp:125
function< void(uint32_t, const std::string &)> CommandFailCallback
a callback on command failure
virtual void selfRegisterPrefix(const Name &prefixToRegister, const SuccessCallback &onSuccess, const FailCallback &onFail)
Interest & setInterestLifetime(const time::milliseconds &interestLifetime)
Definition: interest.hpp:236
virtual void selfDeregisterPrefix(const Name &prefixToDeRegister, const SuccessCallback &onSuccess, const FailCallback &onFail)
void start(const ControlParameters &parameters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, time::milliseconds timeout=getDefaultCommandTimeout())
start command execution