blob: 4fbfa3e563f5c4224e39da4d46f58fe257477195 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyeve289b532014-02-09 22:14:44 -08002/**
Alexander Afanasyev73e30042015-09-17 17:09:51 -07003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyeve289b532014-02-09 22:14:44 -080020 */
21
Alexander Afanasyev26c24d22014-03-20 09:31:21 -070022#ifndef NDN_MANAGEMENT_NFD_CONTROLLER_HPP
23#define NDN_MANAGEMENT_NFD_CONTROLLER_HPP
Alexander Afanasyeve289b532014-02-09 22:14:44 -080024
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070025#include "nfd-control-command.hpp"
26#include "../face.hpp"
Junxiao Shi70911652014-08-12 10:14:24 -070027#include "../security/key-chain.hpp"
Junxiao Shi5de006b2014-10-26 20:20:52 -070028#include "nfd-command-options.hpp"
Alexander Afanasyeve289b532014-02-09 22:14:44 -080029
30namespace ndn {
Alexander Afanasyeve289b532014-02-09 22:14:44 -080031namespace nfd {
32
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040033/**
Alexander Afanasyev197e5652014-06-13 16:56:31 -070034 * \defgroup management Management
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040035 * \brief Classes and data structures to manage NDN forwarder
36 */
Davide Pesavento18cf81b2015-09-12 23:36:43 +020037
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040038/**
39 * \ingroup management
40 * \brief NFD Management protocol - ControlCommand client
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070041 */
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070042class Controller : noncopyable
Alexander Afanasyeve289b532014-02-09 22:14:44 -080043{
44public:
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070045 /** \brief a callback on command success
Alexander Afanasyeve289b532014-02-09 22:14:44 -080046 */
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070047 typedef function<void(const ControlParameters&)> CommandSucceedCallback;
48
49 /** \brief a callback on command failure
50 */
51 typedef function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback;
52
Junxiao Shi70911652014-08-12 10:14:24 -070053 /** \brief construct a Controller that uses face for transport,
54 * and uses the passed KeyChain to sign commands
55 */
56 Controller(Face& face, KeyChain& keyChain);
57
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070058 /** \brief start command execution
59 */
60 template<typename Command>
61 void
62 start(const ControlParameters& parameters,
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070063 const CommandSucceedCallback& onSuccess,
Junxiao Shi5c785d62014-04-20 18:10:20 -070064 const CommandFailCallback& onFailure,
Junxiao Shi5de006b2014-10-26 20:20:52 -070065 const CommandOptions& options = CommandOptions())
Yingdi Yue66bf2a2014-04-28 17:07:36 -070066 {
Junxiao Shi5de006b2014-10-26 20:20:52 -070067 shared_ptr<ControlCommand> command = make_shared<Command>();
68 this->startCommand(command, parameters, onSuccess, onFailure, options);
69 }
70
Alexander Afanasyeve289b532014-02-09 22:14:44 -080071private:
72 void
Junxiao Shi70911652014-08-12 10:14:24 -070073 startCommand(const shared_ptr<ControlCommand>& command,
74 const ControlParameters& parameters,
75 const CommandSucceedCallback& onSuccess,
76 const CommandFailCallback& onFailure,
Junxiao Shi5de006b2014-10-26 20:20:52 -070077 const CommandOptions& options);
78
Junxiao Shi70911652014-08-12 10:14:24 -070079 void
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070080 processCommandResponse(const Data& data,
81 const shared_ptr<ControlCommand>& command,
82 const CommandSucceedCallback& onSuccess,
83 const CommandFailCallback& onFailure);
hilata7d160f22014-03-13 19:51:42 -050084
Junxiao Shi5c785d62014-04-20 18:10:20 -070085public:
Junxiao Shi5de006b2014-10-26 20:20:52 -070086 /** \brief error code for timeout
Junxiao Shi5de006b2014-10-26 20:20:52 -070087 */
88 static const uint32_t ERROR_TIMEOUT;
89
Junxiao Shib1990df2015-11-05 00:14:44 +000090 /** \brief error code for network Nack
91 */
92 static const uint32_t ERROR_NACK;
93
Junxiao Shi5de006b2014-10-26 20:20:52 -070094 /** \brief error code for server error
95 */
96 static const uint32_t ERROR_SERVER;
97
98 /** \brief inclusive lower bound of error codes
99 */
100 static const uint32_t ERROR_LBOUND;
101
hilataa99e37e2014-02-15 23:52:46 -0600102protected:
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800103 Face& m_face;
Junxiao Shi70911652014-08-12 10:14:24 -0700104 KeyChain& m_keyChain;
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800105};
106
107} // namespace nfd
108} // namespace ndn
109
Alexander Afanasyev26c24d22014-03-20 09:31:21 -0700110#endif // NDN_MANAGEMENT_NFD_CONTROLLER_HPP