Skip to content

Commit

Permalink
Further reduce the use of std::bind()
Browse files Browse the repository at this point in the history
And also avoid deprecated ndn-cxx type aliases

Change-Id: I87e903b9671a3cf1c1b9ab30d4594d595c3c6da9
  • Loading branch information
Pesa committed May 11, 2023
1 parent 63b3ae8 commit ae43030
Show file tree
Hide file tree
Showing 37 changed files with 156 additions and 169 deletions.
2 changes: 1 addition & 1 deletion core/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ using namespace ndn::tlv;
namespace lp = ndn::lp;
namespace name = ndn::name;
namespace scheduler = ndn::scheduler;
namespace signal = ndn::util::signal;
namespace signal = ndn::signal;
namespace time = ndn::time;
using namespace ndn::time_literals;

Expand Down
6 changes: 1 addition & 5 deletions daemon/fw/unsolicited-data-policy.cpp
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) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -66,7 +66,6 @@ UnsolicitedDataPolicy::getPolicyNames()
return policyNames;
}

const std::string DropAllUnsolicitedDataPolicy::POLICY_NAME("drop-all");
NFD_REGISTER_UNSOLICITED_DATA_POLICY(DropAllUnsolicitedDataPolicy);

UnsolicitedDataDecision
Expand All @@ -75,7 +74,6 @@ DropAllUnsolicitedDataPolicy::decide(const Face&, const Data&) const
return UnsolicitedDataDecision::DROP;
}

const std::string AdmitLocalUnsolicitedDataPolicy::POLICY_NAME("admit-local");
NFD_REGISTER_UNSOLICITED_DATA_POLICY(AdmitLocalUnsolicitedDataPolicy);

UnsolicitedDataDecision
Expand All @@ -87,7 +85,6 @@ AdmitLocalUnsolicitedDataPolicy::decide(const Face& inFace, const Data&) const
return UnsolicitedDataDecision::DROP;
}

const std::string AdmitNetworkUnsolicitedDataPolicy::POLICY_NAME("admit-network");
NFD_REGISTER_UNSOLICITED_DATA_POLICY(AdmitNetworkUnsolicitedDataPolicy);

UnsolicitedDataDecision
Expand All @@ -99,7 +96,6 @@ AdmitNetworkUnsolicitedDataPolicy::decide(const Face& inFace, const Data&) const
return UnsolicitedDataDecision::DROP;
}

const std::string AdmitAllUnsolicitedDataPolicy::POLICY_NAME("admit-all");
NFD_REGISTER_UNSOLICITED_DATA_POLICY(AdmitAllUnsolicitedDataPolicy);

UnsolicitedDataDecision
Expand Down
20 changes: 10 additions & 10 deletions daemon/fw/unsolicited-data-policy.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) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -60,10 +60,10 @@ class UnsolicitedDataPolicy : noncopyable
public: // registry
template<typename P>
static void
registerPolicy(const std::string& policyName = P::POLICY_NAME)
registerPolicy(std::string_view policyName = P::POLICY_NAME)
{
BOOST_ASSERT(!policyName.empty());
auto r = getRegistry().insert_or_assign(policyName, [] { return make_unique<P>(); });
auto r = getRegistry().insert_or_assign(std::string(policyName), [] { return make_unique<P>(); });
BOOST_VERIFY(r.second);
}

Expand Down Expand Up @@ -96,7 +96,7 @@ class DropAllUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
decide(const Face& inFace, const Data& data) const final;

public:
static const std::string POLICY_NAME;
static constexpr std::string_view POLICY_NAME{"drop-all"};
};

/**
Expand All @@ -109,7 +109,7 @@ class AdmitLocalUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
decide(const Face& inFace, const Data& data) const final;

public:
static const std::string POLICY_NAME;
static constexpr std::string_view POLICY_NAME{"admit-local"};
};

/**
Expand All @@ -122,7 +122,7 @@ class AdmitNetworkUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
decide(const Face& inFace, const Data& data) const final;

public:
static const std::string POLICY_NAME;
static constexpr std::string_view POLICY_NAME{"admit-network"};
};

/**
Expand All @@ -135,7 +135,7 @@ class AdmitAllUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
decide(const Face& inFace, const Data& data) const final;

public:
static const std::string POLICY_NAME;
static constexpr std::string_view POLICY_NAME{"admit-all"};
};

/**
Expand All @@ -146,9 +146,9 @@ using DefaultUnsolicitedDataPolicy = DropAllUnsolicitedDataPolicy;
} // namespace nfd::fw

/**
* \brief Registers an unsolicited data policy
* \param P A subclass of nfd::fw::UnsolicitedDataPolicy. \p P must have a static data
* member `POLICY_NAME` convertible to std::string that contains the policy name.
* \brief Registers an unsolicited data policy.
* \param P A subclass of nfd::fw::UnsolicitedDataPolicy. \p P must have a static const data
* member `POLICY_NAME` convertible to std::string_view that contains the policy name.
*/
#define NFD_REGISTER_UNSOLICITED_DATA_POLICY(P) \
static class NfdAuto ## P ## UnsolicitedDataPolicyRegistrationClass \
Expand Down
12 changes: 6 additions & 6 deletions daemon/mgmt/cs-manager.cpp
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) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -38,11 +38,11 @@ CsManager::CsManager(Cs& cs, const ForwarderCounters& fwCounters,
, m_fwCounters(fwCounters)
{
registerCommandHandler<ndn::nfd::CsConfigCommand>("config",
std::bind(&CsManager::changeConfig, this, _4, _5));
[this] (auto&&, auto&&, auto&&, auto&&... args) { changeConfig(std::forward<decltype(args)>(args)...); });
registerCommandHandler<ndn::nfd::CsEraseCommand>("erase",
std::bind(&CsManager::erase, this, _4, _5));

registerStatusDatasetHandler("info", std::bind(&CsManager::serveInfo, this, _1, _2, _3));
[this] (auto&&, auto&&, auto&&, auto&&... args) { erase(std::forward<decltype(args)>(args)...); });
registerStatusDatasetHandler("info",
[this] (auto&&, auto&&, auto&&... args) { serveInfo(std::forward<decltype(args)>(args)...); });
}

void
Expand Down Expand Up @@ -99,7 +99,7 @@ CsManager::erase(const ControlParameters& parameters,
}

void
CsManager::serveInfo(const Name&, const Interest&, ndn::mgmt::StatusDatasetContext& context) const
CsManager::serveInfo(ndn::mgmt::StatusDatasetContext& context) const
{
ndn::nfd::CsInfo info;
info.setCapacity(m_cs.getLimit());
Expand Down
5 changes: 2 additions & 3 deletions daemon/mgmt/cs-manager.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) 2014-2021, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -62,8 +62,7 @@ class CsManager final : public ManagerBase
/** \brief Serve CS information dataset.
*/
void
serveInfo(const Name& topPrefix, const Interest& interest,
ndn::mgmt::StatusDatasetContext& context) const;
serveInfo(ndn::mgmt::StatusDatasetContext& context) const;

public:
static constexpr size_t ERASE_LIMIT = 256;
Expand Down
17 changes: 10 additions & 7 deletions daemon/mgmt/face-manager.cpp
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) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -48,16 +48,19 @@ FaceManager::FaceManager(FaceSystem& faceSystem,
{
// register handlers for ControlCommand
registerCommandHandler<ndn::nfd::FaceCreateCommand>("create",
std::bind(&FaceManager::createFace, this, _4, _5));
[this] (auto&&, auto&&, auto&&, auto&&... args) { createFace(std::forward<decltype(args)>(args)...); });
registerCommandHandler<ndn::nfd::FaceUpdateCommand>("update",
std::bind(&FaceManager::updateFace, this, _3, _4, _5));
[this] (auto&&, auto&&, auto&&... args) { updateFace(std::forward<decltype(args)>(args)...); });
registerCommandHandler<ndn::nfd::FaceDestroyCommand>("destroy",
std::bind(&FaceManager::destroyFace, this, _4, _5));
[this] (auto&&, auto&&, auto&&, auto&&... args) { destroyFace(std::forward<decltype(args)>(args)...); });

// register handlers for StatusDataset
registerStatusDatasetHandler("list", std::bind(&FaceManager::listFaces, this, _3));
registerStatusDatasetHandler("channels", std::bind(&FaceManager::listChannels, this, _3));
registerStatusDatasetHandler("query", std::bind(&FaceManager::queryFaces, this, _2, _3));
registerStatusDatasetHandler("list",
[this] (auto&&, auto&&, auto&&... args) { listFaces(std::forward<decltype(args)>(args)...); });
registerStatusDatasetHandler("channels",
[this] (auto&&, auto&&, auto&&... args) { listChannels(std::forward<decltype(args)>(args)...); });
registerStatusDatasetHandler("query",
[this] (auto&&, auto&&... args) { queryFaces(std::forward<decltype(args)>(args)...); });

// register notification stream
m_postNotification = registerNotificationStream("events");
Expand Down
19 changes: 8 additions & 11 deletions daemon/mgmt/fib-manager.cpp
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) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -45,16 +45,15 @@ FibManager::FibManager(Fib& fib, const FaceTable& faceTable,
, m_faceTable(faceTable)
{
registerCommandHandler<ndn::nfd::FibAddNextHopCommand>("add-nexthop",
std::bind(&FibManager::addNextHop, this, _2, _3, _4, _5));
[this] (auto&&, auto&&, auto&&... args) { addNextHop(std::forward<decltype(args)>(args)...); });
registerCommandHandler<ndn::nfd::FibRemoveNextHopCommand>("remove-nexthop",
std::bind(&FibManager::removeNextHop, this, _2, _3, _4, _5));

registerStatusDatasetHandler("list", std::bind(&FibManager::listEntries, this, _1, _2, _3));
[this] (auto&&, auto&&, auto&&... args) { removeNextHop(std::forward<decltype(args)>(args)...); });
registerStatusDatasetHandler("list",
[this] (auto&&, auto&&, auto&&... args) { listEntries(std::forward<decltype(args)>(args)...); });
}

void
FibManager::addNextHop(const Name&, const Interest& interest,
ControlParameters parameters,
FibManager::addNextHop(const Interest& interest, ControlParameters parameters,
const ndn::mgmt::CommandContinuation& done)
{
setFaceForSelfRegistration(interest, parameters);
Expand Down Expand Up @@ -84,8 +83,7 @@ FibManager::addNextHop(const Name&, const Interest& interest,
}

void
FibManager::removeNextHop(const Name&, const Interest& interest,
ControlParameters parameters,
FibManager::removeNextHop(const Interest& interest, ControlParameters parameters,
const ndn::mgmt::CommandContinuation& done)
{
setFaceForSelfRegistration(interest, parameters);
Expand Down Expand Up @@ -121,8 +119,7 @@ FibManager::removeNextHop(const Name&, const Interest& interest,
}

void
FibManager::listEntries(const Name&, const Interest&,
ndn::mgmt::StatusDatasetContext& context)
FibManager::listEntries(ndn::mgmt::StatusDatasetContext& context)
{
for (const auto& entry : m_fib) {
const auto& nexthops = entry.getNextHops() |
Expand Down
11 changes: 4 additions & 7 deletions daemon/mgmt/fib-manager.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) 2014-2021, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -48,18 +48,15 @@ class FibManager final : public ManagerBase

private:
void
addNextHop(const Name& topPrefix, const Interest& interest,
ControlParameters parameters,
addNextHop(const Interest& interest, ControlParameters parameters,
const ndn::mgmt::CommandContinuation& done);

void
removeNextHop(const Name& topPrefix, const Interest& interest,
ControlParameters parameters,
removeNextHop(const Interest& interest, ControlParameters parameters,
const ndn::mgmt::CommandContinuation& done);

void
listEntries(const Name& topPrefix, const Interest& interest,
ndn::mgmt::StatusDatasetContext& context);
listEntries(ndn::mgmt::StatusDatasetContext& context);

private:
void
Expand Down
7 changes: 3 additions & 4 deletions daemon/mgmt/forwarder-status-manager.cpp
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) 2014-2021, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -35,7 +35,7 @@ ForwarderStatusManager::ForwarderStatusManager(Forwarder& forwarder, Dispatcher&
, m_startTimestamp(time::system_clock::now())
{
m_dispatcher.addStatusDataset("status/general", ndn::mgmt::makeAcceptAllAuthorization(),
std::bind(&ForwarderStatusManager::listGeneralStatus, this, _1, _2, _3));
[this] (auto&&, auto&&, auto&& ctx) { listGeneralStatus(std::forward<decltype(ctx)>(ctx)); });
}

ndn::nfd::ForwarderStatus
Expand Down Expand Up @@ -67,8 +67,7 @@ ForwarderStatusManager::collectGeneralStatus()
}

void
ForwarderStatusManager::listGeneralStatus(const Name&, const Interest&,
ndn::mgmt::StatusDatasetContext& context)
ForwarderStatusManager::listGeneralStatus(ndn::mgmt::StatusDatasetContext& context)
{
auto status = this->collectGeneralStatus();
const auto& wire = status.wireEncode();
Expand Down
5 changes: 2 additions & 3 deletions daemon/mgmt/forwarder-status-manager.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) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -51,8 +51,7 @@ class ForwarderStatusManager : noncopyable
* \brief Provides the general status dataset.
*/
void
listGeneralStatus(const Name& topPrefix, const Interest& interest,
ndn::mgmt::StatusDatasetContext& context);
listGeneralStatus(ndn::mgmt::StatusDatasetContext& context);

private:
Forwarder& m_forwarder;
Expand Down
6 changes: 3 additions & 3 deletions daemon/mgmt/manager-base.cpp
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) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -27,13 +27,13 @@

namespace nfd {

ManagerBase::ManagerBase(const std::string& module, Dispatcher& dispatcher)
ManagerBase::ManagerBase(std::string_view module, Dispatcher& dispatcher)
: m_module(module)
, m_dispatcher(dispatcher)
{
}

ManagerBase::ManagerBase(const std::string& module, Dispatcher& dispatcher,
ManagerBase::ManagerBase(std::string_view module, Dispatcher& dispatcher,
CommandAuthenticator& authenticator)
: m_module(module)
, m_dispatcher(dispatcher)
Expand Down
8 changes: 4 additions & 4 deletions daemon/mgmt/manager-base.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) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -64,11 +64,11 @@ class ManagerBase : noncopyable

protected:
/**
* @warning if you use this constructor, you MUST override makeAuthorization()
* @warning If you use this constructor, you MUST override makeAuthorization().
*/
ManagerBase(const std::string& module, Dispatcher& dispatcher);
ManagerBase(std::string_view module, Dispatcher& dispatcher);

ManagerBase(const std::string& module, Dispatcher& dispatcher,
ManagerBase(std::string_view module, Dispatcher& dispatcher,
CommandAuthenticator& authenticator);

NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
Expand Down
Loading

0 comments on commit ae43030

Please sign in to comment.