core: global io_service and scheduler
Scheduler and time are imported from ndn-cpp-dev.
Forwarder is using the new scheduler API.
Face system is not transitioned yet.
refs #1290
Change-Id: I5679cb50bbf9890a105f663b038f13951403c2b6
diff --git a/tests/core/scheduler.cpp b/tests/core/scheduler.cpp
index 77ca1e9..d6b51fa 100644
--- a/tests/core/scheduler.cpp
+++ b/tests/core/scheduler.cpp
@@ -21,7 +21,7 @@
, count4(0)
{
}
-
+
void
event1()
{
@@ -47,7 +47,7 @@
{
++count4;
}
-
+
int count1;
int count2;
int count3;
@@ -56,23 +56,23 @@
BOOST_FIXTURE_TEST_CASE(Events, SchedulerFixture)
{
- boost::asio::io_service io;
+ resetGlobalIoService();
- Scheduler scheduler(io);
- scheduler.scheduleEvent(time::seconds(0.5), bind(&SchedulerFixture::event1, this));
-
- EventId i = scheduler.scheduleEvent(time::seconds(1.0), bind(&SchedulerFixture::event2, this));
- scheduler.cancelEvent(i);
+ scheduler::schedule(time::seconds(0.5), bind(&SchedulerFixture::event1, this));
- scheduler.scheduleEvent(time::seconds(0.25), bind(&SchedulerFixture::event3, this));
+ EventId i = scheduler::schedule(time::seconds(1.0), bind(&SchedulerFixture::event2, this));
+ scheduler::cancel(i);
- i = scheduler.scheduleEvent(time::seconds(0.05), bind(&SchedulerFixture::event2, this));
- scheduler.cancelEvent(i);
+ scheduler::schedule(time::seconds(0.25), bind(&SchedulerFixture::event3, this));
- i = scheduler.schedulePeriodicEvent(time::seconds(0.3), time::seconds(0.1), bind(&SchedulerFixture::event4, this));
- scheduler.scheduleEvent(time::seconds(1), bind(&Scheduler::cancelEvent, &scheduler, i));
-
- io.run();
+ i = scheduler::schedule(time::seconds(0.05), bind(&SchedulerFixture::event2, this));
+ scheduler::cancel(i);
+
+ // TODO deprecate periodic event
+ i = scheduler::getGlobalScheduler().schedulePeriodicEvent(time::seconds(0.3), time::seconds(0.1), bind(&SchedulerFixture::event4, this));
+ scheduler::schedule(time::seconds(1), bind(&scheduler::cancel, i));
+
+ getGlobalIoService().run();
BOOST_CHECK_EQUAL(count1, 1);
BOOST_CHECK_EQUAL(count2, 0);
@@ -82,37 +82,29 @@
BOOST_AUTO_TEST_CASE(CancelEmptyEvent)
{
- boost::asio::io_service io;
- Scheduler scheduler(io);
-
EventId i;
- scheduler.cancelEvent(i);
+ scheduler::cancel(i);
}
struct SelfCancelFixture
{
- SelfCancelFixture()
- : m_scheduler(m_io)
- {
- }
-
void
cancelSelf()
{
- m_scheduler.cancelEvent(m_selfEventId);
+ scheduler::cancel(m_selfEventId);
}
-
- boost::asio::io_service m_io;
- Scheduler m_scheduler;
+
EventId m_selfEventId;
};
BOOST_FIXTURE_TEST_CASE(SelfCancel, SelfCancelFixture)
{
- m_selfEventId = m_scheduler.scheduleEvent(time::seconds(0.1),
- bind(&SelfCancelFixture::cancelSelf, this));
-
- BOOST_REQUIRE_NO_THROW(m_io.run());
+ resetGlobalIoService();
+
+ m_selfEventId = scheduler::schedule(time::seconds(0.1),
+ bind(&SelfCancelFixture::cancelSelf, this));
+
+ BOOST_REQUIRE_NO_THROW(getGlobalIoService().run());
}
BOOST_AUTO_TEST_SUITE_END()