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 | #include "manager-base.hpp" |
| 8 | #include "mgmt/app-face.hpp" |
| 9 | |
| 10 | #include <ndn-cpp-dev/management/control-response.hpp> |
| 11 | |
| 12 | namespace nfd { |
| 13 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 14 | NFD_LOG_INIT("ManagerBase"); |
| 15 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 16 | ManagerBase::ManagerBase(shared_ptr<AppFace> face) |
| 17 | : m_face(face) |
| 18 | { |
| 19 | |
| 20 | } |
| 21 | |
| 22 | ManagerBase::~ManagerBase() |
| 23 | { |
| 24 | |
| 25 | } |
| 26 | |
| 27 | void |
| 28 | ManagerBase::sendResponse(const Name& name, |
| 29 | uint32_t code, |
| 30 | const std::string& text) |
| 31 | { |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 32 | // Path 1 - runtime exception on receive's wireDecode. |
| 33 | // Set Data response's content payload to the |
| 34 | // encoded Block. |
| 35 | { |
| 36 | ndn::ControlResponse control(code, text); |
| 37 | const Block& encodedControl = control.wireEncode(); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 38 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 39 | NFD_LOG_DEBUG("sending control response (Path 1)" |
| 40 | << " Name: " << name |
| 41 | << " code: " << code |
| 42 | << " text: " << text); |
| 43 | |
| 44 | NFD_LOG_DEBUG("sending raw control block size = " << encodedControl.size()); |
| 45 | |
| 46 | Data response(name); |
| 47 | response.setContent(encodedControl); |
| 48 | |
| 49 | m_face->put(response); |
| 50 | } |
| 51 | |
| 52 | // Path 2 - works, but not conformant to protocol. |
| 53 | // Encode ControlResponse and append Block as |
| 54 | // the last component of the name. |
| 55 | // { |
| 56 | // ndn::ControlResponse control(code, text); |
| 57 | // const Block& encodedControl = control.wireEncode(); |
| 58 | |
| 59 | // NFD_LOG_DEBUG("sending control response (Path 2)" |
| 60 | // << " Name: " << name |
| 61 | // << " code: " << code |
| 62 | // << " text: " << text); |
| 63 | |
| 64 | // NFD_LOG_DEBUG("sending raw control block size = " << encodedControl.size()); |
| 65 | |
| 66 | // Name responseName(name); |
| 67 | // responseName.append(encodedControl); |
| 68 | |
| 69 | // Data response(responseName); |
| 70 | // m_face->put(response); |
| 71 | // } |
| 72 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
| 76 | } // namespace nfd |