mgmt: Dispatcher
Change-Id: I92b3dc9daae75abac9d791632b6a0bec111b4573
refs: #2107
diff --git a/src/management/nfd-control-command.hpp b/src/management/nfd-control-command.hpp
index a7b8bc6..9d3cbb3 100644
--- a/src/management/nfd-control-command.hpp
+++ b/src/management/nfd-control-command.hpp
@@ -307,7 +307,6 @@
validateResponse(const ControlParameters& parameters) const;
};
-
} // namespace nfd
} // namespace ndn
diff --git a/src/management/nfd-control-parameters.cpp b/src/management/nfd-control-parameters.cpp
index f8ce363..d777843 100644
--- a/src/management/nfd-control-parameters.cpp
+++ b/src/management/nfd-control-parameters.cpp
@@ -95,7 +95,7 @@
template size_t
ControlParameters::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>&) const;
-const Block&
+Block
ControlParameters::wireEncode() const
{
if (m_wire.hasWire())
diff --git a/src/management/nfd-control-parameters.hpp b/src/management/nfd-control-parameters.hpp
index 29434fc..3a099cc 100644
--- a/src/management/nfd-control-parameters.hpp
+++ b/src/management/nfd-control-parameters.hpp
@@ -25,6 +25,7 @@
#include "../encoding/nfd-constants.hpp"
#include "../name.hpp"
#include "../util/time.hpp"
+#include "../mgmt/control-parameters.hpp"
namespace ndn {
namespace nfd {
@@ -71,7 +72,7 @@
* @sa http://redmine.named-data.net/projects/nfd/wiki/ControlCommand#ControlParameters
* @detail This type is copyable because it's an abstraction of a TLV type.
*/
-class ControlParameters
+class ControlParameters : public ndn::mgmt::ControlParameters
{
public:
class Error : public tlv::Error
@@ -93,11 +94,11 @@
size_t
wireEncode(EncodingImpl<TAG>& encoder) const;
- const Block&
- wireEncode() const;
+ virtual Block
+ wireEncode() const NDN_CXX_DECL_FINAL;
- void
- wireDecode(const Block& wire);
+ virtual void
+ wireDecode(const Block& wire) NDN_CXX_DECL_FINAL;
public: // getters & setters
diff --git a/src/management/nfd-control-response.cpp b/src/management/nfd-control-response.cpp
deleted file mode 100644
index 7056162..0000000
--- a/src/management/nfd-control-response.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "nfd-control-response.hpp"
-#include "encoding/tlv-nfd.hpp"
-#include "encoding/block-helpers.hpp"
-
-namespace ndn {
-namespace nfd {
-
-//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ControlResponse>));
-BOOST_CONCEPT_ASSERT((WireEncodable<ControlResponse>));
-BOOST_CONCEPT_ASSERT((WireDecodable<ControlResponse>));
-static_assert(std::is_base_of<tlv::Error, ControlResponse::Error>::value,
- "ControlResponse::Error must inherit from tlv::Error");
-
-ControlResponse::ControlResponse()
- : m_code(200)
-{
-}
-
-ControlResponse::ControlResponse(uint32_t code, const std::string& text)
- : m_code(code)
- , m_text(text)
-{
-}
-
-ControlResponse::ControlResponse(const Block& block)
-{
- wireDecode(block);
-}
-
-const Block&
-ControlResponse::wireEncode() const
-{
- if (m_wire.hasWire())
- return m_wire;
-
- m_wire = Block(tlv::nfd::ControlResponse);
- m_wire.push_back(makeNonNegativeIntegerBlock(tlv::nfd::StatusCode, m_code));
-
- m_wire.push_back(makeBinaryBlock(tlv::nfd::StatusText, m_text.c_str(), m_text.size()));
-
- if (m_body.hasWire()) {
- m_wire.push_back(m_body);
- }
-
- m_wire.encode();
- return m_wire;
-}
-
-void
-ControlResponse::wireDecode(const Block& wire)
-{
- m_wire = wire;
- m_wire.parse();
-
- if (m_wire.type() != tlv::nfd::ControlResponse)
- BOOST_THROW_EXCEPTION(Error("Requested decoding of ControlResponse, but Block is of different "
- "type"));
-
- Block::element_const_iterator val = m_wire.elements_begin();
- if (val == m_wire.elements_end() ||
- val->type() != tlv::nfd::StatusCode)
- {
- BOOST_THROW_EXCEPTION(Error("Incorrect ControlResponse format (StatusCode missing or not the "
- "first item)"));
- }
-
- m_code = readNonNegativeInteger(*val);
- ++val;
-
- if (val == m_wire.elements_end() ||
- val->type() != tlv::nfd::StatusText)
- {
- BOOST_THROW_EXCEPTION(Error("Incorrect ControlResponse format (StatusText missing or not the "
- "second item)"));
- }
- m_text.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
- ++val;
-
- if (val != m_wire.elements_end())
- m_body = *val;
- else
- m_body = Block();
-}
-
-std::ostream&
-operator<<(std::ostream& os, const ControlResponse& response)
-{
- os << response.getCode() << " " << response.getText();
- return os;
-}
-
-} // namespace nfd
-} // namespace ndn
diff --git a/src/management/nfd-control-response.hpp b/src/management/nfd-control-response.hpp
index 42ffd3d..83ba11d 100644
--- a/src/management/nfd-control-response.hpp
+++ b/src/management/nfd-control-response.hpp
@@ -22,112 +22,12 @@
#ifndef NDN_MANAGEMENT_CONTROL_RESPONSE_HPP
#define NDN_MANAGEMENT_CONTROL_RESPONSE_HPP
-#include "../encoding/block.hpp"
+#include "../mgmt/dispatcher.hpp"
namespace ndn {
namespace nfd {
-/**
- * @ingroup management
- * @brief Class defining abstraction of ControlResponse for NFD Control Protocol
- *
- * @see http://redmine.named-data.net/projects/nfd/wiki/ControlCommand#Response-format
- * @detail This type is copyable because it's an abstraction of a TLV type.
- */
-class ControlResponse
-{
-public:
- class Error : public tlv::Error
- {
- public:
- explicit
- Error(const std::string& what)
- : tlv::Error(what)
- {
- }
- };
-
- ControlResponse();
-
- ControlResponse(uint32_t code, const std::string& text);
-
- explicit
- ControlResponse(const Block& block);
-
- uint32_t
- getCode() const;
-
- void
- setCode(uint32_t code);
-
- const std::string&
- getText() const;
-
- void
- setText(const std::string& text);
-
- const Block&
- getBody() const;
-
- void
- setBody(const Block& body);
-
- const Block&
- wireEncode() const;
-
- void
- wireDecode(const Block& block);
-
-protected:
- uint32_t m_code;
- std::string m_text;
- Block m_body;
-
- mutable Block m_wire;
-};
-
-inline uint32_t
-ControlResponse::getCode() const
-{
- return m_code;
-}
-
-inline void
-ControlResponse::setCode(uint32_t code)
-{
- m_code = code;
- m_wire.reset();
-}
-
-inline const std::string&
-ControlResponse::getText() const
-{
- return m_text;
-}
-
-inline void
-ControlResponse::setText(const std::string& text)
-{
- m_text = text;
- m_wire.reset();
-}
-
-inline const Block&
-ControlResponse::getBody() const
-{
- return m_body;
-}
-
-inline void
-ControlResponse::setBody(const Block& body)
-{
- m_body = body;
- m_body.encode(); // will do nothing if already encoded
- m_wire.reset();
-}
-
-std::ostream&
-operator<<(std::ostream& os, const ControlResponse& response);
+typedef ndn::mgmt::ControlResponse ControlResponse;
} // namespace nfd
} // namespace ndn