Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Alexander Afanasyev | 26c24d2 | 2014-03-20 09:31:21 -0700 | [diff] [blame] | 7 | #ifndef NDN_MANAGEMENT_NFD_CONTROLLER_HPP |
| 8 | #define NDN_MANAGEMENT_NFD_CONTROLLER_HPP |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 9 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 10 | #include "controller.hpp" |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 11 | #include "nfd-control-command.hpp" |
| 12 | #include "../face.hpp" |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 13 | |
| 14 | namespace ndn { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 15 | namespace nfd { |
| 16 | |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 17 | /** \brief NFD Management protocol - ControlCommand client |
| 18 | */ |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 19 | class Controller : public ndn::Controller |
| 20 | { |
| 21 | public: |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 22 | /** \brief a callback on command success |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 23 | */ |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 24 | typedef function<void(const ControlParameters&)> CommandSucceedCallback; |
| 25 | |
| 26 | /** \brief a callback on command failure |
| 27 | */ |
| 28 | typedef function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback; |
| 29 | |
| 30 | explicit |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 31 | Controller(Face& face); |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 32 | |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 33 | /** \brief start command execution |
| 34 | */ |
| 35 | template<typename Command> |
| 36 | void |
| 37 | start(const ControlParameters& parameters, |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 38 | const CommandSucceedCallback& onSuccess, |
| 39 | const CommandFailCallback& onFailure); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 40 | |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 41 | public: // selfreg using FIB Management commands |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 42 | virtual void |
| 43 | selfRegisterPrefix(const Name& prefixToRegister, |
| 44 | const SuccessCallback& onSuccess, |
| 45 | const FailCallback& onFail); |
| 46 | |
| 47 | virtual void |
Alexander Afanasyev | 884280c | 2014-03-07 09:40:39 +0000 | [diff] [blame] | 48 | selfDeregisterPrefix(const Name& prefixToDeRegister, |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 49 | const SuccessCallback& onSuccess, |
| 50 | const FailCallback& onFail); |
| 51 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 52 | private: |
| 53 | void |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 54 | processCommandResponse(const Data& data, |
| 55 | const shared_ptr<ControlCommand>& command, |
| 56 | const CommandSucceedCallback& onSuccess, |
| 57 | const CommandFailCallback& onFailure); |
hilata | 7d160f2 | 2014-03-13 19:51:42 -0500 | [diff] [blame] | 58 | |
hilata | a99e37e | 2014-02-15 23:52:46 -0600 | [diff] [blame] | 59 | protected: |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 60 | Face& m_face; |
Alexander Afanasyev | 884280c | 2014-03-07 09:40:39 +0000 | [diff] [blame] | 61 | CommandInterestGenerator m_commandInterestGenerator; |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 64 | |
| 65 | template<typename Command> |
| 66 | void |
| 67 | Controller::start(const ControlParameters& parameters, |
| 68 | const CommandSucceedCallback& onSuccess, |
| 69 | const CommandFailCallback& onFailure) |
| 70 | { |
| 71 | shared_ptr<ControlCommand> command = make_shared<Command>(); |
| 72 | |
| 73 | Interest commandInterest = command->makeCommandInterest(parameters, m_commandInterestGenerator); |
| 74 | |
| 75 | // http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668.aspx |
| 76 | const uint32_t timeoutCode = 10060; |
| 77 | m_face.expressInterest(commandInterest, |
| 78 | bind(&Controller::processCommandResponse, this, _2, |
| 79 | command, onSuccess, onFailure), |
| 80 | bind(onFailure, timeoutCode, "Command Interest timed out")); |
| 81 | } |
| 82 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 83 | } // namespace nfd |
| 84 | } // namespace ndn |
| 85 | |
Alexander Afanasyev | 26c24d2 | 2014-03-20 09:31:21 -0700 | [diff] [blame] | 86 | #endif // NDN_MANAGEMENT_NFD_CONTROLLER_HPP |