logic: use ScopedEventId

refs #4698

Change-Id: Ic5b4cd3327a690693eb416be31c25ed95516ab99
diff --git a/src/logic.cpp b/src/logic.cpp
index 2cc6268..db6f691 100644
--- a/src/logic.cpp
+++ b/src/logic.cpp
@@ -170,12 +170,8 @@
 
   sendSyncInterest();
 
-  if (static_cast<bool>(m_delayedInterestProcessingId))
-    m_scheduler.cancelEvent(m_delayedInterestProcessingId);
-
-  m_delayedInterestProcessingId =
-    m_scheduler.scheduleEvent(m_cancelResetTimer,
-                              bind(&Logic::cancelReset, this));
+  m_delayedInterestProcessingId = m_scheduler.scheduleEvent(m_cancelResetTimer,
+                                  bind(&Logic::cancelReset, this));
 }
 
 void
@@ -432,14 +428,10 @@
       _LOG_DEBUG_ID("Non timed processing in reset");
       // Still in reset, our own seq has not been put into state yet
       // Do not hurry, some others may be also resetting and may send their reply
-      if (static_cast<bool>(m_delayedInterestProcessingId))
-        m_scheduler.cancelEvent(m_delayedInterestProcessingId);
-
       time::milliseconds after(m_rangeUniformRandom(m_rng));
       _LOG_DEBUG_ID("After: " << after);
-      m_delayedInterestProcessingId =
-        m_scheduler.scheduleEvent(after,
-                                  bind(&Logic::processSyncInterest, this, interest, true));
+      m_delayedInterestProcessingId = m_scheduler.scheduleEvent(after,
+                                      bind(&Logic::processSyncInterest, this, interest, true));
     }
     else {
       _LOG_DEBUG_ID("Timed processing in reset");
@@ -468,12 +460,7 @@
   if (!isTimedProcessing) {
     _LOG_DEBUG_ID("Let's wait, just wait for a while");
     // Do not hurry, some incoming SyncReplies may help us to recognize the digest
-    bool doesExist = m_interestTable.has(digest);
     m_interestTable.insert(interest, digest, true);
-    if (doesExist)
-      // Original comment (not sure): somebody else replied, so restart random-game timer
-      // YY: Get the same SyncInterest again, refresh the timer
-      m_scheduler.cancelEvent(m_delayedInterestProcessingId);
 
     m_delayedInterestProcessingId =
       m_scheduler.scheduleEvent(time::milliseconds(m_rangeUniformRandom(m_rng)),
@@ -551,13 +538,10 @@
 
   if (static_cast<bool>(commit) && !commit->getLeaves().empty()) {
     // state changed and it is safe to express a new interest
-    time::steady_clock::Duration after = time::milliseconds(m_reexpressionJitter(m_rng));
+    auto after = time::milliseconds(m_reexpressionJitter(m_rng));
     _LOG_DEBUG_ID("Reschedule sync interest after: " << after);
-    EventId eventId = m_scheduler.scheduleEvent(after,
-                                                bind(&Logic::sendSyncInterest, this));
-
-    m_scheduler.cancelEvent(m_reexpressingInterestId);
-    m_reexpressingInterestId = eventId;
+    m_reexpressingInterestId = m_scheduler.scheduleEvent(after,
+                               bind(&Logic::sendSyncInterest, this));
   }
 }
 
@@ -607,11 +591,9 @@
     _LOG_DEBUG_ID("Need Period Reset");
     _LOG_DEBUG_ID("ResetTimer: " << m_resetTimer);
 
-    EventId eventId =
-      m_scheduler.scheduleEvent(m_resetTimer + ndn::time::milliseconds(m_reexpressionJitter(m_rng)),
-                                bind(&Logic::sendResetInterest, this));
-    m_scheduler.cancelEvent(m_resetInterestId);
-    m_resetInterestId = eventId;
+    m_resetInterestId = m_scheduler.scheduleEvent(
+                        m_resetTimer + ndn::time::milliseconds(m_reexpressionJitter(m_rng)),
+                        bind(&Logic::sendResetInterest, this));
   }
 
   Interest interest(m_syncReset);
@@ -643,12 +625,9 @@
   printDigest(m_state.getRootDigest());
 #endif
 
-  EventId eventId =
-    m_scheduler.scheduleEvent(m_syncInterestLifetime / 2 +
-                              ndn::time::milliseconds(m_reexpressionJitter(m_rng)),
-                              bind(&Logic::sendSyncInterest, this));
-  m_scheduler.cancelEvent(m_reexpressingInterestId);
-  m_reexpressingInterestId = eventId;
+  m_reexpressingInterestId = m_scheduler.scheduleEvent(m_syncInterestLifetime / 2 +
+                             ndn::time::milliseconds(m_reexpressionJitter(m_rng)),
+                             bind(&Logic::sendSyncInterest, this));
 
   Interest interest(interestName);
   interest.setMustBeFresh(true);
@@ -740,9 +719,7 @@
     time::milliseconds after(m_reexpressionJitter(m_rng));
     _LOG_DEBUG_ID("Satisfy our own interest");
     _LOG_DEBUG_ID("Reschedule sync interest after " << after);
-    EventId eventId = m_scheduler.scheduleEvent(after, bind(&Logic::sendSyncInterest, this));
-    m_scheduler.cancelEvent(m_reexpressingInterestId);
-    m_reexpressingInterestId = eventId;
+    m_reexpressingInterestId = m_scheduler.scheduleEvent(after, bind(&Logic::sendSyncInterest, this));
   }
   _LOG_DEBUG_ID("<< Logic::sendSyncData");
 }
diff --git a/src/logic.hpp b/src/logic.hpp
index 9e5ea71..1110cdb 100644
--- a/src/logic.hpp
+++ b/src/logic.hpp
@@ -505,10 +505,10 @@
   UpdateCallback m_onUpdate;
 
   // Event
-  ndn::Scheduler m_scheduler;
-  ndn::EventId m_delayedInterestProcessingId;
-  ndn::EventId m_reexpressingInterestId;
-  ndn::EventId m_resetInterestId;
+  ndn::util::scheduler::Scheduler m_scheduler;
+  ndn::util::scheduler::ScopedEventId m_delayedInterestProcessingId;
+  ndn::util::scheduler::ScopedEventId m_reexpressingInterestId;
+  ndn::util::scheduler::ScopedEventId m_resetInterestId;
 
   // Timer
   ndn::random::RandomNumberEngine& m_rng;