Skip to content

Commit

Permalink
mgmt: rename mgmt::ControlParameters to ControlParametersBase
Browse files Browse the repository at this point in the history
It's extremely confusing to have two classes with the same name,
particularly when one is a base class of the other.

Change-Id: Ifdb347cd02cd116aa3e17f8e7ab95e870d8c8920
  • Loading branch information
Pesa committed Jan 2, 2025
1 parent cb385e3 commit 0e13ed3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2023 Regents of the University of California.
* Copyright (c) 2013-2025 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
Expand All @@ -19,21 +19,21 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/

#ifndef NDN_CXX_MGMT_CONTROL_PARAMETERS_HPP
#define NDN_CXX_MGMT_CONTROL_PARAMETERS_HPP
#ifndef NDN_CXX_MGMT_CONTROL_PARAMETERS_BASE_HPP
#define NDN_CXX_MGMT_CONTROL_PARAMETERS_BASE_HPP

#include "ndn-cxx/encoding/block.hpp"

namespace ndn::mgmt {

/**
* \brief Base class for a struct that contains ControlCommand parameters.
* \brief Base class for a struct that contains the parameters for a ControlCommand.
*/
class ControlParameters
class ControlParametersBase
{
public:
virtual
~ControlParameters() = default;
~ControlParametersBase() = default;

virtual void
wireDecode(const Block& wire) = 0;
Expand All @@ -44,4 +44,4 @@ class ControlParameters

} // namespace ndn::mgmt

#endif // NDN_CXX_MGMT_CONTROL_PARAMETERS_HPP
#endif // NDN_CXX_MGMT_CONTROL_PARAMETERS_BASE_HPP
9 changes: 4 additions & 5 deletions ndn-cxx/mgmt/dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ makeAcceptAllAuthorization()
{
return [] (const Name& prefix,
const Interest& interest,
const ControlParameters* params,
const ControlParametersBase* params,
const AcceptContinuation& accept,
const RejectContinuation& reject) {
accept("");
};
}

Dispatcher::Dispatcher(Face& face, KeyChain& keyChain,
const security::SigningInfo& signingInfo,
Dispatcher::Dispatcher(Face& face, KeyChain& keyChain, const security::SigningInfo& signingInfo,
size_t imsCapacity)
: m_face(face)
, m_keyChain(keyChain)
Expand Down Expand Up @@ -168,7 +167,7 @@ Dispatcher::processCommand(const Name& prefix,
ValidateParameters validate,
ControlCommandHandler handler)
{
shared_ptr<ControlParameters> parameters;
ControlParametersPtr parameters;
try {
parameters = parse(prefix, interest);
}
Expand All @@ -189,7 +188,7 @@ Dispatcher::processCommand(const Name& prefix,
void
Dispatcher::processAuthorizedCommand(const Name& prefix,
const Interest& interest,
const shared_ptr<ControlParameters>& parameters,
const ControlParametersPtr& parameters,
const ValidateParameters& validate,
const ControlCommandHandler& handler)
{
Expand Down
39 changes: 20 additions & 19 deletions ndn-cxx/mgmt/dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
#define NDN_CXX_MGMT_DISPATCHER_HPP

#include "ndn-cxx/face.hpp"
#include "ndn-cxx/encoding/block.hpp"
#include "ndn-cxx/ims/in-memory-storage-fifo.hpp"
#include "ndn-cxx/mgmt/control-parameters-base.hpp"
#include "ndn-cxx/mgmt/control-response.hpp"
#include "ndn-cxx/mgmt/control-parameters.hpp"
#include "ndn-cxx/mgmt/status-dataset-context.hpp"
#include "ndn-cxx/security/key-chain.hpp"

Expand Down Expand Up @@ -75,7 +74,7 @@ using RejectContinuation = std::function<void(RejectReply)>;
* Either \p accept or \p reject must be called after authorization completes.
*/
using Authorization = std::function<void(const Name& prefix, const Interest& interest,
const ControlParameters* params,
const ControlParametersBase* params,
const AcceptContinuation& accept,
const RejectContinuation& reject)>;

Expand All @@ -92,23 +91,24 @@ makeAcceptAllAuthorization();
* \param params The parsed ControlParameters; guaranteed to be of the correct (sub-)type
* for the command.
*/
using ValidateParameters = std::function<bool(ControlParameters& params)>;
using ValidateParameters = std::function<bool(ControlParametersBase& params)>;

/**
* \brief A function to be called after a ControlCommandHandler completes.
* \param resp The response that should be sent back to the requester.
*/
using CommandContinuation = std::function<void(const ControlResponse& resp)>;

/** \brief A function to handle an authorized ControlCommand.
* \param prefix top-level prefix, e.g., "/localhost/nfd";
* \param interest incoming Interest
* \param params parsed ControlParameters;
* This is guaranteed to have correct type for the command,
* and is valid (e.g., has all required fields).
/**
* \brief A function to handle an authorized ControlCommand.
* \param prefix Top-level prefix, e.g., `/localhost/nfd`.
* \param interest Incoming Interest carrying the request.
* \param params The parsed ControlParameters; guaranteed to be of the correct (sub-)type
* and to be valid for the command (e.g., has all the required fields).
* \param done Function that must be called after command processing is complete.
*/
using ControlCommandHandler = std::function<void(const Name& prefix, const Interest& interest,
const ControlParameters& params,
const ControlParametersBase& params,
const CommandContinuation& done)>;

// ---- STATUS DATASET ----
Expand Down Expand Up @@ -211,7 +211,7 @@ class Dispatcher : noncopyable
* 8. Send the signed Data packet.
*/
template<typename ParametersType,
std::enable_if_t<std::is_convertible_v<ParametersType*, ControlParameters*>, int> = 0>
std::enable_if_t<std::is_convertible_v<ParametersType*, ControlParametersBase*>, int> = 0>
void
addControlCommand(const PartialName& relPrefix,
Authorization authorize,
Expand All @@ -222,7 +222,7 @@ class Dispatcher : noncopyable

auto relPrefixLen = relPrefix.size();
ParametersParser parse = [relPrefixLen] (const Name& prefix,
const auto& interest) -> shared_ptr<ControlParameters> {
const auto& interest) -> ControlParametersPtr {
const name::Component& comp = interest.getName().get(prefix.size() + relPrefixLen);
return make_shared<ParametersType>(comp.blockFromValue());
};
Expand Down Expand Up @@ -349,14 +349,15 @@ class Dispatcher : noncopyable
addNotificationStream(const PartialName& relPrefix);

private:
using ControlParametersPtr = shared_ptr<ControlParametersBase>;
using InterestHandler = std::function<void(const Name& prefix, const Interest&)>;

/**
* @brief The parser for extracting the parameters from a command request.
* @return A shared pointer to the extracted ControlParameters.
* @throw tlv::Error The request parameters cannot be parsed.
*/
using ParametersParser = std::function<shared_ptr<ControlParameters>(const Name& prefix, const Interest&)>;
using ParametersParser = std::function<ControlParametersPtr(const Name& prefix, const Interest&)>;

void
checkPrefix(const PartialName& relPrefix) const;
Expand Down Expand Up @@ -443,7 +444,7 @@ class Dispatcher : noncopyable
void
processAuthorizedCommand(const Name& prefix,
const Interest& interest,
const shared_ptr<ControlParameters>& parameters,
const ControlParametersPtr& parameters,
const ValidateParameters& validate,
const ControlCommandHandler& handler);

Expand Down Expand Up @@ -490,17 +491,17 @@ class Dispatcher : noncopyable
postNotification(const Block& notification, const PartialName& relPrefix);

private:
Face& m_face;
KeyChain& m_keyChain;
security::SigningInfo m_signingInfo;

struct TopPrefixEntry
{
ScopedRegisteredPrefixHandle registeredPrefix;
std::vector<ScopedInterestFilterHandle> interestFilters;
};
std::unordered_map<Name, TopPrefixEntry> m_topLevelPrefixes;

Face& m_face;
KeyChain& m_keyChain;
security::SigningInfo m_signingInfo;

std::unordered_map<PartialName, InterestHandler> m_handlers;

// NotificationStream name => next sequence number
Expand Down
2 changes: 1 addition & 1 deletion ndn-cxx/mgmt/nfd/control-command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ControlCommand : noncopyable
/**
* \brief Extract parameters from request Interest.
*/
static shared_ptr<mgmt::ControlParameters>
static shared_ptr<mgmt::ControlParametersBase>
parseRequest(const Interest& interest, size_t prefixLen)
{
// /<prefix>/<module>/<verb>
Expand Down
6 changes: 3 additions & 3 deletions ndn-cxx/mgmt/nfd/control-parameters.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2023 Regents of the University of California.
* Copyright (c) 2013-2025 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
Expand All @@ -24,7 +24,7 @@

#include "ndn-cxx/name.hpp"
#include "ndn-cxx/encoding/nfd-constants.hpp"
#include "ndn-cxx/mgmt/control-parameters.hpp"
#include "ndn-cxx/mgmt/control-parameters-base.hpp"
#include "ndn-cxx/util/time.hpp"

namespace ndn::nfd {
Expand Down Expand Up @@ -77,7 +77,7 @@ inline constexpr std::string_view CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOU
* \sa https://redmine.named-data.net/projects/nfd/wiki/ControlCommand#ControlParameters
* \details This type is copyable because it's an abstraction of a TLV type.
*/
class ControlParameters : public mgmt::ControlParameters
class ControlParameters : public mgmt::ControlParametersBase
{
public:
class Error : public tlv::Error
Expand Down
4 changes: 2 additions & 2 deletions ndn-cxx/net/network-monitor-stub.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2023 Regents of the University of California.
* Copyright (c) 2013-2025 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
Expand Down Expand Up @@ -72,7 +72,7 @@ class NetworkMonitorStub : public NetworkMonitor
* interface, it emits the #onInterfaceAdded signal. When the initial enumerating completes,
* it emits the onEnumerationCompleted signal.
*
* To simulate this procedure on a newly constructed MockNetworkMonitor, the caller should
* To simulate this procedure on a newly constructed NetworkMonitorStub, the caller should
* invoke addInterface() once for each network interface that already exists, and then invoke
* emitEnumerationCompleted().
*/
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/mgmt/dispatcher.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DispatcherFixture : public IoKeyChainFixture
InMemoryStorageFifo& storage{dispatcher.m_storage};
};

class VoidParameters : public mgmt::ControlParameters
class VoidParameters : public ControlParametersBase
{
public:
explicit
Expand All @@ -64,7 +64,7 @@ class VoidParameters : public mgmt::ControlParameters
static Authorization
makeTestAuthorization()
{
return [] (const Name&, const Interest& interest, const ControlParameters*,
return [] (const Name&, const Interest& interest, const ControlParametersBase*,
AcceptContinuation accept, RejectContinuation reject) {
if (interest.getName()[-1] == name::Component("valid")) {
accept("");
Expand Down Expand Up @@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(ControlCommandNew,
BOOST_AUTO_TEST_CASE(ControlCommandResponse)
{
auto handler = [] (const Name& prefix, const Interest& interest,
const ControlParameters&, const CommandContinuation& done) {
const ControlParametersBase&, const CommandContinuation& done) {
BOOST_CHECK_EQUAL(prefix, "/root");
BOOST_CHECK_EQUAL(interest.getName().getPrefix(3),
Name("/root").append(nfd::CsConfigCommand::getName()));
Expand All @@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE(ControlCommandResponse)
BOOST_CHECK_EQUAL(resp.getText(), "the answer");
}

class StatefulParameters : public mgmt::ControlParameters
class StatefulParameters : public ControlParametersBase
{
public:
explicit
Expand Down Expand Up @@ -340,12 +340,12 @@ BOOST_AUTO_TEST_CASE(ControlCommandAsyncAuthorization,
* ut::description("test for bug #4059"))
{
AcceptContinuation authorizationAccept;
auto authorization = [&authorizationAccept] (const Name&, const Interest&, const ControlParameters*,
auto authorization = [&authorizationAccept] (const Name&, const Interest&, const ControlParametersBase*,
AcceptContinuation accept, RejectContinuation) {
authorizationAccept = std::move(accept);
};

auto validateParameters = [] (const ControlParameters& params) {
auto validateParameters = [] (const ControlParametersBase& params) {
return dynamic_cast<const StatefulParameters&>(params).check();
};

Expand Down

0 comments on commit 0e13ed3

Please sign in to comment.