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" |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 11 | #include <ndn-cpp-dev/management/nfd-control-response.hpp> |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 12 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 13 | #include "mgmt/command-validator.hpp" |
| 14 | #include "mgmt/internal-face.hpp" |
| 15 | |
| 16 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 17 | namespace nfd { |
| 18 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 19 | using ndn::nfd::ControlResponse; |
| 20 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 21 | class InternalFace; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 22 | |
| 23 | class ManagerBase |
| 24 | { |
| 25 | public: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 27 | struct Error : public std::runtime_error |
| 28 | { |
| 29 | Error(const std::string& what) : std::runtime_error(what) {} |
| 30 | }; |
| 31 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 32 | ManagerBase(shared_ptr<InternalFace> face, const std::string& privilege); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 33 | |
| 34 | virtual |
| 35 | ~ManagerBase(); |
| 36 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 37 | void |
| 38 | onCommandValidationFailed(const shared_ptr<const Interest>& command, |
| 39 | const std::string& error); |
| 40 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 41 | protected: |
| 42 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 43 | void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 44 | setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 45 | uint32_t code, |
| 46 | const std::string& text); |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 47 | void |
| 48 | setResponse(ControlResponse& response, |
| 49 | uint32_t code, |
| 50 | const std::string& text, |
| 51 | const Block& body); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 52 | |
| 53 | void |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 54 | sendResponse(const Name& name, |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 55 | const ControlResponse& response); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 56 | |
| 57 | void |
| 58 | sendResponse(const Name& name, |
| 59 | uint32_t code, |
| 60 | const std::string& text); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 61 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 62 | PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 63 | void |
| 64 | addInterestRule(const std::string& regex, |
| 65 | const ndn::IdentityCertificate& certificate); |
| 66 | |
| 67 | void |
| 68 | addInterestRule(const std::string& regex, |
| 69 | const Name& keyName, |
| 70 | const ndn::PublicKey& publicKey); |
| 71 | |
| 72 | void |
| 73 | validate(const Interest& interest, |
| 74 | const ndn::OnInterestValidated& onValidated, |
| 75 | const ndn::OnInterestValidationFailed& onValidationFailed); |
| 76 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 77 | protected: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 78 | shared_ptr<InternalFace> m_face; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 81 | inline void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 82 | ManagerBase::setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 83 | uint32_t code, |
| 84 | const std::string& text) |
| 85 | { |
| 86 | response.setCode(code); |
| 87 | response.setText(text); |
| 88 | } |
| 89 | |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 90 | inline void |
| 91 | ManagerBase::setResponse(ControlResponse& response, |
| 92 | uint32_t code, |
| 93 | const std::string& text, |
| 94 | const Block& body) |
| 95 | { |
| 96 | setResponse(response, code, text); |
| 97 | response.setBody(body); |
| 98 | } |
| 99 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 100 | inline void |
| 101 | ManagerBase::addInterestRule(const std::string& regex, |
| 102 | const ndn::IdentityCertificate& certificate) |
| 103 | { |
| 104 | m_face->getValidator().addInterestRule(regex, certificate); |
| 105 | } |
| 106 | |
| 107 | inline void |
| 108 | ManagerBase::addInterestRule(const std::string& regex, |
| 109 | const Name& keyName, |
| 110 | const ndn::PublicKey& publicKey) |
| 111 | { |
| 112 | m_face->getValidator().addInterestRule(regex, keyName, publicKey); |
| 113 | } |
| 114 | |
| 115 | inline void |
| 116 | ManagerBase::validate(const Interest& interest, |
| 117 | const ndn::OnInterestValidated& onValidated, |
| 118 | const ndn::OnInterestValidationFailed& onValidationFailed) |
| 119 | { |
| 120 | m_face->getValidator().validate(interest, onValidated, onValidationFailed); |
| 121 | } |
| 122 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 123 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 124 | } // namespace nfd |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 125 | |
| 126 | #endif // NFD_MGMT_MANAGER_BASE_HPP |
| 127 | |