blob: 78c6efee6e0de629d706cf75082599982ac7ab14 [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
13namespace nfd {
14
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080015using ndn::nfd::ControlResponse;
16
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070017class AppFace;
18
19class ManagerBase
20{
21public:
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080022 struct Error : public std::runtime_error
23 {
24 Error(const std::string& what) : std::runtime_error(what) {}
25 };
26
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070027 ManagerBase(shared_ptr<AppFace> face);
28
29 virtual
30 ~ManagerBase();
31
32protected:
33
Steve DiBenedetto3970c892014-01-31 23:31:13 -070034 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080035 setResponse(ControlResponse& response,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070036 uint32_t code,
37 const std::string& text);
Steve DiBenedetto2693db92014-02-10 15:58:36 -070038 void
39 setResponse(ControlResponse& response,
40 uint32_t code,
41 const std::string& text,
42 const Block& body);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070043
44 void
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070045 sendResponse(const Name& name,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080046 const ControlResponse& response);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070047
48 void
49 sendResponse(const Name& name,
50 uint32_t code,
51 const std::string& text);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070052
53protected:
54 shared_ptr<AppFace> m_face;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070055};
56
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070057inline void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080058ManagerBase::setResponse(ControlResponse& response,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070059 uint32_t code,
60 const std::string& text)
61{
62 response.setCode(code);
63 response.setText(text);
64}
65
Steve DiBenedetto2693db92014-02-10 15:58:36 -070066inline void
67ManagerBase::setResponse(ControlResponse& response,
68 uint32_t code,
69 const std::string& text,
70 const Block& body)
71{
72 setResponse(response, code, text);
73 response.setBody(body);
74}
75
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070076
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070077} // namespace nfd
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070078
79#endif // NFD_MGMT_MANAGER_BASE_HPP
80