Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_MGMT_MANAGER_BASE_HPP |
| 8 | #define NFD_MGMT_MANAGER_BASE_HPP |
| 9 | |
| 10 | #include "common.hpp" |
| 11 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 12 | #include "mgmt/command-validator.hpp" |
| 13 | #include "mgmt/internal-face.hpp" |
| 14 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame^] | 15 | #include <ndn-cpp-dev/management/nfd-control-command.hpp> |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 16 | #include <ndn-cpp-dev/management/nfd-control-response.hpp> |
| 17 | #include <ndn-cpp-dev/management/nfd-control-parameters.hpp> |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 18 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 19 | namespace nfd { |
| 20 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame^] | 21 | using ndn::nfd::ControlCommand; |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 22 | using ndn::nfd::ControlResponse; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 23 | using ndn::nfd::ControlParameters; |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 24 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 25 | class InternalFace; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 26 | |
| 27 | class ManagerBase |
| 28 | { |
| 29 | public: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 31 | struct Error : public std::runtime_error |
| 32 | { |
| 33 | Error(const std::string& what) : std::runtime_error(what) {} |
| 34 | }; |
| 35 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 36 | ManagerBase(shared_ptr<InternalFace> face, const std::string& privilege); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 37 | |
| 38 | virtual |
| 39 | ~ManagerBase(); |
| 40 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 41 | void |
| 42 | onCommandValidationFailed(const shared_ptr<const Interest>& command, |
| 43 | const std::string& error); |
| 44 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 45 | protected: |
| 46 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 47 | static bool |
| 48 | extractParameters(const Name::Component& parameterComponent, |
| 49 | ControlParameters& extractedParameters); |
| 50 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 51 | void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 52 | setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 53 | uint32_t code, |
| 54 | const std::string& text); |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 55 | void |
| 56 | setResponse(ControlResponse& response, |
| 57 | uint32_t code, |
| 58 | const std::string& text, |
| 59 | const Block& body); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 60 | |
| 61 | void |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 62 | sendResponse(const Name& name, |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 63 | const ControlResponse& response); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 64 | |
| 65 | void |
| 66 | sendResponse(const Name& name, |
| 67 | uint32_t code, |
| 68 | const std::string& text); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 69 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 70 | void |
| 71 | sendResponse(const Name& name, |
| 72 | uint32_t code, |
| 73 | const std::string& text, |
| 74 | const Block& body); |
| 75 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame^] | 76 | virtual bool |
| 77 | validateParameters(const ControlCommand& command, |
| 78 | ControlParameters& parameters); |
| 79 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 80 | PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 81 | void |
| 82 | addInterestRule(const std::string& regex, |
| 83 | const ndn::IdentityCertificate& certificate); |
| 84 | |
| 85 | void |
| 86 | addInterestRule(const std::string& regex, |
| 87 | const Name& keyName, |
| 88 | const ndn::PublicKey& publicKey); |
| 89 | |
| 90 | void |
| 91 | validate(const Interest& interest, |
| 92 | const ndn::OnInterestValidated& onValidated, |
| 93 | const ndn::OnInterestValidationFailed& onValidationFailed); |
| 94 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 95 | protected: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 96 | shared_ptr<InternalFace> m_face; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 99 | inline void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 100 | ManagerBase::setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 101 | uint32_t code, |
| 102 | const std::string& text) |
| 103 | { |
| 104 | response.setCode(code); |
| 105 | response.setText(text); |
| 106 | } |
| 107 | |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 108 | inline void |
| 109 | ManagerBase::setResponse(ControlResponse& response, |
| 110 | uint32_t code, |
| 111 | const std::string& text, |
| 112 | const Block& body) |
| 113 | { |
| 114 | setResponse(response, code, text); |
| 115 | response.setBody(body); |
| 116 | } |
| 117 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 118 | inline void |
| 119 | ManagerBase::addInterestRule(const std::string& regex, |
| 120 | const ndn::IdentityCertificate& certificate) |
| 121 | { |
| 122 | m_face->getValidator().addInterestRule(regex, certificate); |
| 123 | } |
| 124 | |
| 125 | inline void |
| 126 | ManagerBase::addInterestRule(const std::string& regex, |
| 127 | const Name& keyName, |
| 128 | const ndn::PublicKey& publicKey) |
| 129 | { |
| 130 | m_face->getValidator().addInterestRule(regex, keyName, publicKey); |
| 131 | } |
| 132 | |
| 133 | inline void |
| 134 | ManagerBase::validate(const Interest& interest, |
| 135 | const ndn::OnInterestValidated& onValidated, |
| 136 | const ndn::OnInterestValidationFailed& onValidationFailed) |
| 137 | { |
| 138 | m_face->getValidator().validate(interest, onValidated, onValidationFailed); |
| 139 | } |
| 140 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 141 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 142 | } // namespace nfd |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 143 | |
| 144 | #endif // NFD_MGMT_MANAGER_BASE_HPP |
| 145 | |