blob: 95228129ee0dba0ec39e11b88e57bcd76cd48bf9 [file] [log] [blame]
Steve DiBenedetto042bfe92014-01-30 15:05:08 -07001/* -*- 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 Afanasyevd482fd32014-02-09 23:40:20 -080011#include <ndn-cpp-dev/management/nfd-control-response.hpp>
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070012
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070013#include "mgmt/command-validator.hpp"
14#include "mgmt/internal-face.hpp"
15
16
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070017namespace nfd {
18
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080019using ndn::nfd::ControlResponse;
20
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070021class InternalFace;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070022
23class ManagerBase
24{
25public:
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070026
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080027 struct Error : public std::runtime_error
28 {
29 Error(const std::string& what) : std::runtime_error(what) {}
30 };
31
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070032 ManagerBase(shared_ptr<InternalFace> face, const std::string& privilege);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070033
34 virtual
35 ~ManagerBase();
36
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070037 void
38 onCommandValidationFailed(const shared_ptr<const Interest>& command,
39 const std::string& error);
40
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070041protected:
42
Steve DiBenedetto3970c892014-01-31 23:31:13 -070043 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080044 setResponse(ControlResponse& response,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070045 uint32_t code,
46 const std::string& text);
Steve DiBenedetto2693db92014-02-10 15:58:36 -070047 void
48 setResponse(ControlResponse& response,
49 uint32_t code,
50 const std::string& text,
51 const Block& body);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070052
53 void
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070054 sendResponse(const Name& name,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080055 const ControlResponse& response);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070056
57 void
58 sendResponse(const Name& name,
59 uint32_t code,
60 const std::string& text);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070061
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070062PUBLIC_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 DiBenedetto042bfe92014-01-30 15:05:08 -070077protected:
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070078 shared_ptr<InternalFace> m_face;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070079};
80
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070081inline void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080082ManagerBase::setResponse(ControlResponse& response,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070083 uint32_t code,
84 const std::string& text)
85{
86 response.setCode(code);
87 response.setText(text);
88}
89
Steve DiBenedetto2693db92014-02-10 15:58:36 -070090inline void
91ManagerBase::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 DiBenedetto2c2b8892014-02-27 11:46:48 -0700100inline void
101ManagerBase::addInterestRule(const std::string& regex,
102 const ndn::IdentityCertificate& certificate)
103{
104 m_face->getValidator().addInterestRule(regex, certificate);
105}
106
107inline void
108ManagerBase::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
115inline void
116ManagerBase::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 DiBenedetto042bfe92014-01-30 15:05:08 -0700123
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700124} // namespace nfd
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700125
126#endif // NFD_MGMT_MANAGER_BASE_HPP
127