core+daemon: eliminate scheduler::{schedule,cancel} wrappers
Also move core/global-io.hpp to daemon/global.hpp
Refs: #4528, #4883
Change-Id: I0b99029f1a19d7451aab57099cd3303b7eb42ff3
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index e7e0904..eec5a63 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -26,6 +26,7 @@
#include "access-strategy.hpp"
#include "algorithm.hpp"
#include "core/logger.hpp"
+#include "daemon/global.hpp"
namespace nfd {
namespace fw {
@@ -42,8 +43,7 @@
NDN_THROW(std::invalid_argument("AccessStrategy does not accept parameters"));
}
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
- NDN_THROW(std::invalid_argument(
- "AccessStrategy does not support version " + to_string(*parsed.version)));
+ NDN_THROW(std::invalid_argument("AccessStrategy does not support version " + to_string(*parsed.version)));
}
this->setInstanceName(makeInstanceName(name, getStrategyName()));
}
@@ -153,7 +153,7 @@
// schedule RTO timeout
PitInfo* pi = pitEntry->insertStrategyInfo<PitInfo>().first;
- pi->rtoTimer = scheduler::schedule(rto,
+ pi->rtoTimer = getScheduler().schedule(rto,
bind(&AccessStrategy::afterRtoTimeout, this, weak_ptr<pit::Entry>(pitEntry),
inFace.getId(), mi.lastNexthop));
diff --git a/daemon/fw/asf-measurements.cpp b/daemon/fw/asf-measurements.cpp
index 17771e0..dde6866 100644
--- a/daemon/fw/asf-measurements.cpp
+++ b/daemon/fw/asf-measurements.cpp
@@ -24,6 +24,7 @@
*/
#include "asf-measurements.hpp"
+#include "daemon/global.hpp"
namespace nfd {
namespace fw {
@@ -73,7 +74,7 @@
FaceInfo::~FaceInfo()
{
cancelTimeoutEvent();
- scheduler::cancel(m_measurementExpirationId);
+ m_measurementExpirationId.cancel();
}
void
@@ -92,7 +93,7 @@
void
FaceInfo::cancelTimeoutEvent()
{
- scheduler::cancel(m_timeoutEventId);
+ m_timeoutEventId.cancel();
m_isTimeoutScheduled = false;
}
@@ -114,7 +115,7 @@
FaceInfo::recordRtt(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace)
{
// Calculate RTT
- pit::OutRecordCollection::const_iterator outRecord = pitEntry->getOutRecord(inFace, 0);
+ auto outRecord = pitEntry->getOutRecord(inFace, 0);
if (outRecord == pitEntry->out_end()) { // no out-record
NFD_LOG_TRACE(pitEntry->getInterest() << " dataFrom inFace=" << inFace.getId() << " no-out-record");
@@ -122,7 +123,7 @@
}
time::steady_clock::Duration steadyRtt = time::steady_clock::now() - outRecord->getLastRenewed();
- RttEstimator::Duration durationRtt = time::duration_cast<RttEstimator::Duration>(steadyRtt);
+ auto durationRtt = time::duration_cast<RttEstimator::Duration>(steadyRtt);
m_rttStats.addRttMeasurement(durationRtt);
@@ -148,10 +149,9 @@
}
FaceInfo*
-NamespaceInfo::getFaceInfo(const fib::Entry& fibEntry, FaceId faceId)
+NamespaceInfo::getFaceInfo(const fib::Entry&, FaceId faceId)
{
- FaceInfoTable::iterator it = m_fit.find(faceId);
-
+ auto it = m_fit.find(faceId);
if (it != m_fit.end()) {
return &it->second;
}
@@ -161,10 +161,9 @@
}
FaceInfo&
-NamespaceInfo::getOrCreateFaceInfo(const fib::Entry& fibEntry, FaceId faceId)
+NamespaceInfo::getOrCreateFaceInfo(const fib::Entry&, FaceId faceId)
{
- FaceInfoTable::iterator it = m_fit.find(faceId);
-
+ auto it = m_fit.find(faceId);
FaceInfo* info = nullptr;
if (it == m_fit.end()) {
@@ -190,10 +189,11 @@
NamespaceInfo::extendFaceInfoLifetime(FaceInfo& info, FaceId faceId)
{
// Cancel previous expiration
- scheduler::cancel(info.getMeasurementExpirationEventId());
+ info.getMeasurementExpirationEventId().cancel();
// Refresh measurement
- auto id = scheduler::schedule(AsfMeasurements::MEASUREMENTS_LIFETIME, [=] { expireFaceInfo(faceId); });
+ auto id = getScheduler().schedule(AsfMeasurements::MEASUREMENTS_LIFETIME,
+ [=] { expireFaceInfo(faceId); });
info.setMeasurementExpirationEventId(id);
}
diff --git a/daemon/fw/asf-probing-module.cpp b/daemon/fw/asf-probing-module.cpp
index dd2b537..84055f1 100644
--- a/daemon/fw/asf-probing-module.cpp
+++ b/daemon/fw/asf-probing-module.cpp
@@ -25,6 +25,7 @@
#include "asf-probing-module.hpp"
#include "algorithm.hpp"
+#include "daemon/global.hpp"
#include <ndn-cxx/util/random.hpp>
@@ -50,7 +51,7 @@
Name prefix = fibEntry.getPrefix();
// Set the probing flag for the namespace to true after passed interval of time
- scheduler::schedule(interval, [this, prefix] {
+ getScheduler().schedule(interval, [this, prefix] {
NamespaceInfo* info = m_measurements.getNamespaceInfo(prefix);
if (info == nullptr) {
@@ -65,10 +66,8 @@
}
Face*
-ProbingModule::getFaceToProbe(const Face& inFace,
- const Interest& interest,
- const fib::Entry& fibEntry,
- const Face& faceUsed)
+ProbingModule::getFaceToProbe(const Face& inFace, const Interest& interest,
+ const fib::Entry& fibEntry, const Face& faceUsed)
{
FaceInfoFacePairSet rankedFaces(
[] (const auto& pairLhs, const auto& pairRhs) -> bool {
@@ -83,7 +82,7 @@
// Put eligible faces into rankedFaces. If a face does not have an RTT measurement,
// immediately pick the face for probing
- for (const fib::NextHop& hop : fibEntry.getNextHops()) {
+ for (const auto& hop : fibEntry.getNextHops()) {
Face& hopFace = hop.getFace();
// Don't send probe Interest back to the incoming face or use the same face
diff --git a/daemon/fw/asf-strategy.cpp b/daemon/fw/asf-strategy.cpp
index 779daee..46acaf4 100644
--- a/daemon/fw/asf-strategy.cpp
+++ b/daemon/fw/asf-strategy.cpp
@@ -26,6 +26,7 @@
#include "asf-strategy.hpp"
#include "algorithm.hpp"
#include "core/logger.hpp"
+#include "daemon/global.hpp"
namespace nfd {
namespace fw {
@@ -226,9 +227,8 @@
NFD_LOG_TRACE("Scheduling timeout for " << fibEntry.getPrefix() << " to: " << egress
<< " in " << time::duration_cast<time::milliseconds>(timeout) << " ms");
- scheduler::EventId id = scheduler::schedule(timeout,
- bind(&AsfStrategy::onTimeout, this, interest.getName(), egress.face.getId()));
-
+ auto id = getScheduler().schedule(timeout, bind(&AsfStrategy::onTimeout, this,
+ interest.getName(), egress.face.getId()));
faceInfo.setTimeoutEvent(id, interest.getName());
}
}
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index 7e1880f..a25e107 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,8 +24,8 @@
*/
#include "face-table.hpp"
-#include "core/global-io.hpp"
#include "core/logger.hpp"
+#include "daemon/global.hpp"
#include "face/channel.hpp"
#include <ndn-cxx/util/concepts.hpp>
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 508a890..328ff31 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -29,6 +29,7 @@
#include "best-route-strategy2.hpp"
#include "strategy.hpp"
#include "core/logger.hpp"
+#include "daemon/global.hpp"
#include "table/cleanup.hpp"
#include <ndn-cxx/lp/tags.hpp>
@@ -44,7 +45,7 @@
}
Forwarder::Forwarder()
- : m_unsolicitedDataPolicy(new fw::DefaultUnsolicitedDataPolicy())
+ : m_unsolicitedDataPolicy(make_unique<fw::DefaultUnsolicitedDataPolicy>())
, m_fib(m_nameTree)
, m_pit(m_nameTree)
, m_measurements(m_nameTree)
@@ -241,7 +242,7 @@
<< (pitEntry->isSatisfied ? " satisfied" : " unsatisfied"));
// Dead Nonce List insert if necessary
- this->insertDeadNonceList(*pitEntry, 0);
+ this->insertDeadNonceList(*pitEntry, nullptr);
// Increment satisfied/unsatisfied Interests counter
if (pitEntry->isSatisfied) {
@@ -252,7 +253,7 @@
}
// PIT delete
- scheduler::cancel(pitEntry->expiryTimer);
+ pitEntry->expiryTimer.cancel();
m_pit.erase(pitEntry.get());
}
@@ -507,9 +508,8 @@
BOOST_ASSERT(pitEntry);
BOOST_ASSERT(duration >= 0_ms);
- scheduler::cancel(pitEntry->expiryTimer);
-
- pitEntry->expiryTimer = scheduler::schedule(duration, [=] { onInterestFinalize(pitEntry); });
+ pitEntry->expiryTimer.cancel();
+ pitEntry->expiryTimer = getScheduler().schedule(duration, [=] { onInterestFinalize(pitEntry); });
}
void
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index ecc4d72..18ca483 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -26,11 +26,9 @@
#ifndef NFD_DAEMON_FW_FORWARDER_HPP
#define NFD_DAEMON_FW_FORWARDER_HPP
-#include "core/common.hpp"
-#include "core/scheduler.hpp"
-#include "forwarder-counters.hpp"
-#include "face-table.hpp"
#include "face-endpoint.hpp"
+#include "face-table.hpp"
+#include "forwarder-counters.hpp"
#include "unsolicited-data-policy.hpp"
#include "table/fib.hpp"
#include "table/pit.hpp"
@@ -46,9 +44,9 @@
class Strategy;
} // namespace fw
-/** \brief main class of NFD
+/** \brief Main class of NFD forwarding engine.
*
- * Forwarder owns all faces and tables, and implements forwarding pipelines.
+ * Forwarder owns all faces and tables, and implements the forwarding pipelines.
*/
class Forwarder
{
diff --git a/daemon/fw/ncc-strategy.cpp b/daemon/fw/ncc-strategy.cpp
index a6c1e99..5063200 100644
--- a/daemon/fw/ncc-strategy.cpp
+++ b/daemon/fw/ncc-strategy.cpp
@@ -25,6 +25,7 @@
#include "ncc-strategy.hpp"
#include "algorithm.hpp"
+#include "daemon/global.hpp"
#include <ndn-cxx/util/random.hpp>
@@ -90,8 +91,7 @@
deferRange = time::microseconds((deferFirst.count() + 1) / 2);
--nUpstreams;
this->sendInterest(pitEntry, FaceEndpoint(*bestFace, 0), interest);
- pitEntryInfo->bestFaceTimeout = scheduler::schedule(
- meInfo.prediction,
+ pitEntryInfo->bestFaceTimeout = getScheduler().schedule(meInfo.prediction,
bind(&NccStrategy::timeoutOnBestFace, this, weak_ptr<pit::Entry>(pitEntry)));
}
else {
@@ -128,7 +128,7 @@
// this maxInterval would be used to determine when the next doPropagate would happen.
pitEntryInfo->maxInterval = deferFirst;
}
- pitEntryInfo->propagateTimer = scheduler::schedule(deferFirst,
+ pitEntryInfo->propagateTimer = getScheduler().schedule(deferFirst,
bind(&NccStrategy::doPropagate, this, ingress.face.getId(), weak_ptr<pit::Entry>(pitEntry)));
}
@@ -178,7 +178,7 @@
if (isForwarded) {
std::uniform_int_distribution<time::nanoseconds::rep> dist(0, pitEntryInfo->maxInterval.count() - 1);
time::nanoseconds deferNext(dist(ndn::random::getRandomNumberEngine()));
- pitEntryInfo->propagateTimer = scheduler::schedule(deferNext,
+ pitEntryInfo->propagateTimer = getScheduler().schedule(deferNext,
bind(&NccStrategy::doPropagate, this, inFaceId, weak_ptr<pit::Entry>(pitEntry)));
}
}
@@ -233,14 +233,14 @@
PitEntryInfo* pitEntryInfo = pitEntry->getStrategyInfo<PitEntryInfo>();
if (pitEntryInfo != nullptr) {
- scheduler::cancel(pitEntryInfo->propagateTimer);
+ pitEntryInfo->propagateTimer.cancel();
// Verify that the best face satisfied the interest before canceling the timeout call
MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(pitEntry);
shared_ptr<Face> bestFace = meInfo.getBestFace();
if (bestFace.get() == &ingress.face)
- scheduler::cancel(pitEntryInfo->bestFaceTimeout);
+ pitEntryInfo->bestFaceTimeout.cancel();
}
}
@@ -337,8 +337,8 @@
NccStrategy::PitEntryInfo::~PitEntryInfo()
{
- scheduler::cancel(this->bestFaceTimeout);
- scheduler::cancel(this->propagateTimer);
+ bestFaceTimeout.cancel();
+ propagateTimer.cancel();
}
} // namespace fw
diff --git a/daemon/fw/self-learning-strategy.cpp b/daemon/fw/self-learning-strategy.cpp
index 12e6176..f0eab59 100644
--- a/daemon/fw/self-learning-strategy.cpp
+++ b/daemon/fw/self-learning-strategy.cpp
@@ -27,7 +27,7 @@
#include "algorithm.hpp"
#include "core/logger.hpp"
-#include "core/global-io.hpp"
+#include "daemon/global.hpp"
#include "rib/service.hpp"
#include <ndn-cxx/lp/empty-value.hpp>
diff --git a/daemon/fw/strategy.hpp b/daemon/fw/strategy.hpp
index bb50556..cc1b2b8 100644
--- a/daemon/fw/strategy.hpp
+++ b/daemon/fw/strategy.hpp
@@ -51,7 +51,9 @@
BOOST_ASSERT(strategyName.at(-1).isVersion());
Registry& registry = getRegistry();
BOOST_ASSERT(registry.count(strategyName) == 0);
- registry[strategyName] = &make_unique<S, Forwarder&, const Name&>;
+ registry[strategyName] = [] (auto&&... args) {
+ return make_unique<S>(std::forward<decltype(args)>(args)...);
+ };
}
/** \return whether a strategy instance can be created from \p instanceName
@@ -81,9 +83,9 @@
listRegistered();
public: // constructor, destructor, strategy name
- /** \brief construct a strategy instance
+ /** \brief Construct a strategy instance.
* \param forwarder a reference to the forwarder, used to enable actions and accessors.
- * \note Strategy subclass constructor should not retain a reference to the forwarder.
+ * \note Strategy subclass constructor must not retain a reference to \p forwarder.
*/
explicit
Strategy(Forwarder& forwarder);