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 | |
| 13 | namespace nfd { |
| 14 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 15 | using ndn::nfd::ControlResponse; |
| 16 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 17 | class AppFace; |
| 18 | |
| 19 | class ManagerBase |
| 20 | { |
| 21 | public: |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame^] | 22 | struct Error : public std::runtime_error |
| 23 | { |
| 24 | Error(const std::string& what) : std::runtime_error(what) {} |
| 25 | }; |
| 26 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 27 | ManagerBase(shared_ptr<AppFace> face); |
| 28 | |
| 29 | virtual |
| 30 | ~ManagerBase(); |
| 31 | |
| 32 | protected: |
| 33 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 34 | void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 35 | setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 36 | uint32_t code, |
| 37 | const std::string& text); |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 38 | void |
| 39 | setResponse(ControlResponse& response, |
| 40 | uint32_t code, |
| 41 | const std::string& text, |
| 42 | const Block& body); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 43 | |
| 44 | void |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 45 | sendResponse(const Name& name, |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 46 | const ControlResponse& response); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 47 | |
| 48 | void |
| 49 | sendResponse(const Name& name, |
| 50 | uint32_t code, |
| 51 | const std::string& text); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 52 | |
| 53 | protected: |
| 54 | shared_ptr<AppFace> m_face; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 57 | inline void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 58 | ManagerBase::setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 59 | uint32_t code, |
| 60 | const std::string& text) |
| 61 | { |
| 62 | response.setCode(code); |
| 63 | response.setText(text); |
| 64 | } |
| 65 | |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 66 | inline void |
| 67 | ManagerBase::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 DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 76 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 77 | } // namespace nfd |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 78 | |
| 79 | #endif // NFD_MGMT_MANAGER_BASE_HPP |
| 80 | |