Follow ndn::Scheduler API changes
Refs: #4883
Change-Id: I94f9096225a26accbdc9e2dc37462f6d7c6474ef
diff --git a/examples/data-producer.cpp b/examples/data-producer.cpp
index f81ab03..e401603 100644
--- a/examples/data-producer.cpp
+++ b/examples/data-producer.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.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -18,9 +18,10 @@
*/
/**
- * This file demonstrates how to generate data to be stored in repo with repo watch
- * protocol and repo insert protocol.
- * The details of the protocols can be find here
+ * @file This file demonstrates how to generate data to be stored in a repo using
+ * the repo watch protocol and repo insertion protocol.
+ *
+ * The details of the protocols can be found here:
* <https://redmine.named-data.net/projects/repo-ng/wiki/Watched_Prefix_Insertion_Protocol>
* <https://redmine.named-data.net/projects/repo-ng/wiki/Basic_Repo_Insertion_Protocol>
*
@@ -33,10 +34,16 @@
* The description of command parameter can be found in the function usage().
*/
-#include "../src/common.hpp"
-
#include <boost/asio/io_service.hpp>
#include <boost/lexical_cast.hpp>
+
+#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/util/random.hpp>
+#include <ndn-cxx/util/scheduler.hpp>
+#include <ndn-cxx/util/time.hpp>
+
#include <fstream>
#include <iostream>
#include <random>
@@ -46,7 +53,7 @@
using ndn::time::milliseconds;
-static const milliseconds DEFAULT_TIME_INTERVAL(2000);
+const milliseconds DEFAULT_TIME_INTERVAL(2000);
enum Mode {
AUTO,
@@ -59,23 +66,17 @@
class Error : public std::runtime_error
{
public:
- explicit
- Error(const std::string& what)
- : std::runtime_error(what)
- {
- }
+ using std::runtime_error::runtime_error;
};
public:
Publisher()
: mode(AUTO)
- , dataPrefix(Name("/example/data"))
+ , dataPrefix("/example/data")
, timeInterval(DEFAULT_TIME_INTERVAL)
, duration(0)
, m_scheduler(m_face.getIoService())
- , m_randomEngine(std::random_device{}())
, m_randomDist(200, 1000)
- , m_range([this] { return m_randomDist(m_randomEngine); })
{
}
@@ -88,32 +89,30 @@
void
generateFromFile();
- std::shared_ptr<ndn::Data>
+ static std::shared_ptr<ndn::Data>
createData(const ndn::Name& name);
public:
std::ifstream insertStream;
Mode mode;
- Name dataPrefix;
+ ndn::Name dataPrefix;
milliseconds timeInterval;
milliseconds duration;
private:
ndn::Face m_face;
ndn::Scheduler m_scheduler;
- std::mt19937 m_randomEngine;
- std::uniform_int_distribution<unsigned int> m_randomDist;
- std::function<unsigned int(void)> m_range;
+ std::uniform_int_distribution<> m_randomDist;
};
void
Publisher::run()
{
if (mode == AUTO) {
- m_scheduler.scheduleEvent(timeInterval, std::bind(&Publisher::autoGenerate, this));
+ m_scheduler.schedule(timeInterval, [this] { autoGenerate(); });
}
else {
- m_scheduler.scheduleEvent(timeInterval, std::bind(&Publisher::generateFromFile, this));
+ m_scheduler.schedule(timeInterval, [this] { generateFromFile(); });
}
m_face.processEvents(duration);
}
@@ -121,11 +120,12 @@
void
Publisher::autoGenerate()
{
- Name name = dataPrefix;
- name.appendNumber(m_range());
- std::shared_ptr<Data> data = createData(name);
+ ndn::Name name = dataPrefix;
+ name.appendNumber(m_randomDist(ndn::random::getRandomNumberEngine()));
+ auto data = createData(name);
m_face.put(*data);
- m_scheduler.scheduleEvent(timeInterval, std::bind(&Publisher::autoGenerate, this));
+
+ m_scheduler.schedule(timeInterval, [this] { autoGenerate(); });
}
void
@@ -134,23 +134,25 @@
if (insertStream.eof()) {
m_face.getIoService().stop();
return;
- }
+ }
+
std::string name;
getline(insertStream, name);
- std::shared_ptr<Data> data = createData(Name(name));
+ auto data = createData(ndn::Name(name));
m_face.put(*data);
- m_scheduler.scheduleEvent(timeInterval, std::bind(&Publisher::generateFromFile, this));
+
+ m_scheduler.schedule(timeInterval, [this] { generateFromFile(); });
}
-std::shared_ptr<Data>
-Publisher::createData(const Name& name)
+std::shared_ptr<ndn::Data>
+Publisher::createData(const ndn::Name& name)
{
static ndn::KeyChain keyChain;
static std::vector<uint8_t> content(1500, '-');
- std::shared_ptr<ndn::Data> data = std::make_shared<Data>();
+ auto data = std::make_shared<ndn::Data>();
data->setName(name);
- data->setContent(&content[0], content.size());
+ data->setContent(content.data(), content.size());
keyChain.sign(*data);
return data;
}
@@ -169,7 +171,7 @@
}
static int
-main(int argc, char** argv)
+main(int argc, char* argv[])
{
Publisher generator;
bool isAuto = false;
@@ -179,7 +181,7 @@
switch (opt) {
case 'd':
{
- generator.dataPrefix = Name(std::string(optarg));
+ generator.dataPrefix = ndn::Name(std::string(optarg));
generator.mode = AUTO;
isAuto = true;
}
@@ -236,7 +238,7 @@
} // namespace repo
int
-main(int argc, char** argv)
+main(int argc, char* argv[])
{
try {
return repo::main(argc, argv);
diff --git a/src/handles/write-handle.cpp b/src/handles/write-handle.cpp
index 675f286..d971878 100644
--- a/src/handles/write-handle.cpp
+++ b/src/handles/write-handle.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.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -318,23 +318,22 @@
void
WriteHandle::deferredDeleteProcess(ProcessId processId)
{
- scheduler.scheduleEvent(PROCESS_DELETE_TIME,
- std::bind(&WriteHandle::deleteProcess, this, processId));
+ scheduler.schedule(PROCESS_DELETE_TIME, [=] { deleteProcess(processId); });
}
void
WriteHandle::extendNoEndTime(ProcessInfo& process)
{
- ndn::time::steady_clock::TimePoint& noEndTime = process.noEndTime;
- ndn::time::steady_clock::TimePoint now = ndn::time::steady_clock::now();
+ auto& noEndTime = process.noEndTime;
+ auto now = ndn::time::steady_clock::now();
RepoCommandResponse& response = process.response;
if (now > noEndTime) {
response.setCode(405);
return;
}
+
//extends noEndTime
process.noEndTime = ndn::time::steady_clock::now() + m_noEndTimeout;
-
}
RepoCommandResponse
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index e57d71e..cc40734 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -127,7 +127,7 @@
insertEvents.erase(eventIt);
}
// schedule an event 50ms later to check whether insert is Ok
- scheduler.scheduleEvent(500_ms, std::bind(&Fixture<T>::checkInsertOk, this, interest));
+ scheduler.schedule(500_ms, std::bind(&Fixture<T>::checkInsertOk, this, interest));
}
template<class T> void
@@ -160,7 +160,7 @@
BOOST_CHECK_EQUAL(statusCode, 200);
//schedlute an event to check whether delete is Ok.
- scheduler.scheduleEvent(100_ms, std::bind(&Fixture<T>::checkDeleteOk, this, interest));
+ scheduler.schedule(100_ms, std::bind(&Fixture<T>::checkDeleteOk, this, interest));
}
template<class T> void
@@ -230,11 +230,11 @@
insertCommandName.append(insertParameter.wireEncode());
Interest insertInterest = signer.makeCommandInterest(insertCommandName);
// schedule a job to express insertInterest every 50ms
- scheduler.scheduleEvent(milliseconds(timeCount * 50 + 1000),
- std::bind(&Fixture<T>::sendInsertInterest, this, insertInterest));
+ scheduler.schedule(milliseconds(timeCount * 50 + 1000),
+ std::bind(&Fixture<T>::sendInsertInterest, this, insertInterest));
// schedule what to do when interest timeout
- auto delayEventId = scheduler.scheduleEvent(milliseconds(5000 + timeCount * 50),
- std::bind(&Fixture<T>::delayedInterest, this));
+ auto delayEventId = scheduler.schedule(milliseconds(5000 + timeCount * 50),
+ std::bind(&Fixture<T>::delayedInterest, this));
insertEvents[insertParameter.getName()] = delayEventId;
// The delayEvent will be canceled in onInsertInterest
insertFace.setInterestFilter(insertParameter.getName(),
@@ -258,8 +258,8 @@
deleteCommandName.append(deleteParameter.wireEncode());
Interest deleteInterest = signer.makeCommandInterest(deleteCommandName);
deleteNamePairs[deleteInterest.getName()] = (*i)->getName();
- scheduler.scheduleEvent(milliseconds(4000 + timeCount * 50),
- std::bind(&Fixture<T>::sendDeleteInterest, this, deleteInterest));
+ scheduler.schedule(milliseconds(4000 + timeCount * 50),
+ std::bind(&Fixture<T>::sendDeleteInterest, this, deleteInterest));
timeCount++;
}
}
@@ -271,8 +271,8 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertDelete, T, Datasets, Fixture<T>)
{
// schedule events
- this->scheduler.scheduleEvent(0_s, std::bind(&Fixture<T>::scheduleInsertEvent, this));
- this->scheduler.scheduleEvent(10_s, std::bind(&Fixture<T>::scheduleDeleteEvent, this));
+ this->scheduler.schedule(0_s, std::bind(&Fixture<T>::scheduleInsertEvent, this));
+ this->scheduler.schedule(10_s, std::bind(&Fixture<T>::scheduleDeleteEvent, this));
this->repoFace.processEvents(30_s);
}
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index d73b0d1..81ace5b 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.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.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -79,9 +79,8 @@
Interest readInterest((*i)->getName());
readInterest.setMustBeFresh(true);
- scheduler.scheduleEvent(ndn::time::milliseconds(timeCount * 50),
- std::bind(&BasicInterestReadFixture<Dataset>::sendInterest, this,
- readInterest));
+ scheduler.schedule(ndn::time::milliseconds(timeCount * 50),
+ std::bind(&BasicInterestReadFixture<Dataset>::sendInterest, this, readInterest));
timeCount++;
}
}
@@ -133,11 +132,9 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(Read, T, Datasets, BasicInterestReadFixture<T>)
{
this->startListen();
- this->scheduler.scheduleEvent(1_s,
- std::bind(&BasicInterestReadFixture<T>::scheduleReadEvent, this));
+ this->scheduler.schedule(1_s, std::bind(&BasicInterestReadFixture<T>::scheduleReadEvent, this));
this->repoFace.processEvents(20_s);
-
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit/tcp-bulk-insert-handle.cpp b/tests/unit/tcp-bulk-insert-handle.cpp
index ad82c10..48d1ae3 100644
--- a/tests/unit/tcp-bulk-insert-handle.cpp
+++ b/tests/unit/tcp-bulk-insert-handle.cpp
@@ -84,8 +84,7 @@
: scheduler(ioService)
, bulkInserter(ioService, *handle)
{
- guardEvent = scheduler.scheduleEvent(ndn::time::seconds(2),
- std::bind(&TcpBulkInsertFixture::fail, this, "Test timed out"));
+ guardEvent = scheduler.schedule(2_s, std::bind(&TcpBulkInsertFixture::fail, this, "Test timed out"));
}
virtual void
@@ -118,12 +117,10 @@
}
if (isFinal) {
- scheduler.cancelEvent(guardEvent);
+ guardEvent.cancel();
// In case there are some outstanding handlers
- // ioService.post(bind(&TcpBulkInsertFixture::stop, this));
- scheduler.scheduleEvent(ndn::time::seconds(1),
- std::bind(&TcpBulkInsertFixture::stop, this));
+ scheduler.schedule(1_s, [this] { stop(); });
}
}
@@ -171,7 +168,6 @@
}
}
-
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
diff --git a/tools/ndnputfile.cpp b/tools/ndnputfile.cpp
index 2564a60..94fffa2 100644
--- a/tools/ndnputfile.cpp
+++ b/tools/ndnputfile.cpp
@@ -223,7 +223,7 @@
bind(&NdnPutFile::onRegisterFailed, this, _1, _2));
if (hasTimeout)
- m_scheduler.scheduleEvent(timeout, [this] { stopProcess(); });
+ m_scheduler.schedule(timeout, [this] { stopProcess(); });
m_face.processEvents();
}
@@ -261,7 +261,7 @@
}
m_processId = response.getProcessId();
- m_scheduler.scheduleEvent(m_checkPeriod, [this] { startCheckCommand(); });
+ m_scheduler.schedule(m_checkPeriod, [this] { startCheckCommand(); });
}
void
@@ -409,7 +409,7 @@
}
}
- m_scheduler.scheduleEvent(m_checkPeriod, [this] { startCheckCommand(); });
+ m_scheduler.schedule(m_checkPeriod, [this] { startCheckCommand(); });
}
void