producer: use ScopedRegisteredPrefixHandle

Also, don't pass Scheduler to ScopedEventId because it's no
longer necessary.

refs #3919, #4698

Change-Id: I8af3ece977a6ab3a623c0ed7c63a424449df6a82
diff --git a/PSync/full-producer.cpp b/PSync/full-producer.cpp
index 968154a..4390a26 100644
--- a/PSync/full-producer.cpp
+++ b/PSync/full-producer.cpp
@@ -41,15 +41,14 @@
   : ProducerBase(expectedNumEntries, face, syncPrefix, userPrefix, syncReplyFreshness)
   , m_syncInterestLifetime(syncInterestLifetime)
   , m_onUpdate(onUpdateCallBack)
-  , m_scheduledSyncInterestId(m_scheduler)
 {
   int jitter = m_syncInterestLifetime.count() * .20;
   m_jitter = std::uniform_int_distribution<>(-jitter, jitter);
 
-  m_registerPrefixId =
-    m_face.setInterestFilter(ndn::InterestFilter(m_syncPrefix).allowLoopback(false),
-                             std::bind(&FullProducer::onSyncInterest, this, _1, _2),
-                             std::bind(&FullProducer::onRegisterFailed, this, _1, _2));
+  m_registeredPrefix = m_face.setInterestFilter(
+                         ndn::InterestFilter(m_syncPrefix).allowLoopback(false),
+                         std::bind(&FullProducer::onSyncInterest, this, _1, _2),
+                         std::bind(&FullProducer::onRegisterFailed, this, _1, _2));
 
   // Should we do this after setInterestFilter success call back
   // (Currently following ChronoSync's way)
@@ -61,8 +60,6 @@
   if (m_fetcher) {
     m_fetcher->stop();
   }
-
-  m_face.unsetInterestFilter(m_registerPrefixId);
 }
 
 void
@@ -209,16 +206,12 @@
     return;
   }
 
-  ndn::util::scheduler::ScopedEventId scopedEventId(m_scheduler);
-  auto it = m_pendingEntries.emplace(interestName,
-                                     PendingEntryInfoFull{iblt, std::move(scopedEventId)});
-
-  it.first->second.expirationEvent =
-    m_scheduler.scheduleEvent(interest.getInterestLifetime(),
-                              [this, interest] {
-                                NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce());
-                                m_pendingEntries.erase(interest.getName());
-                              });
+  auto& entry = m_pendingEntries.emplace(interestName, PendingEntryInfoFull{iblt, {}}).first->second;
+  entry.expirationEvent = m_scheduler.scheduleEvent(interest.getInterestLifetime(),
+                          [this, interest] {
+                            NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce());
+                            m_pendingEntries.erase(interest.getName());
+                          });
 }
 
 void
diff --git a/PSync/full-producer.hpp b/PSync/full-producer.hpp
index ec0ba4a..b5eb55f 100644
--- a/PSync/full-producer.hpp
+++ b/PSync/full-producer.hpp
@@ -28,11 +28,10 @@
 #include <random>
 
 #include <ndn-cxx/face.hpp>
-#include <ndn-cxx/util/scheduler.hpp>
-#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
-#include <ndn-cxx/util/time.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/util/scheduler.hpp>
 #include <ndn-cxx/util/segment-fetcher.hpp>
+#include <ndn-cxx/util/time.hpp>
 
 namespace psync {
 
@@ -171,7 +170,6 @@
 
   /**
    * @brief Delete pending sync interests that match given name
-   *
    */
   void
   deletePendingInterests(const ndn::Name& interestName);
@@ -186,20 +184,13 @@
   isFutureHash(const ndn::Name& prefix, const std::set<uint32_t>& negative);
 
 private:
-  std::map <ndn::Name, PendingEntryInfoFull> m_pendingEntries;
-
+  std::map<ndn::Name, PendingEntryInfoFull> m_pendingEntries;
   ndn::time::milliseconds m_syncInterestLifetime;
-
   UpdateCallback m_onUpdate;
-
   ndn::util::scheduler::ScopedEventId m_scheduledSyncInterestId;
-
   std::uniform_int_distribution<> m_jitter;
-
   ndn::Name m_outstandingInterestName;
-
-  const ndn::RegisteredPrefixId* m_registerPrefixId;
-
+  ndn::ScopedRegisteredPrefixHandle m_registeredPrefix;
   std::shared_ptr<ndn::util::SegmentFetcher> m_fetcher;
 };
 
diff --git a/PSync/partial-producer.cpp b/PSync/partial-producer.cpp
index ed54175..87f648d 100644
--- a/PSync/partial-producer.cpp
+++ b/PSync/partial-producer.cpp
@@ -38,21 +38,14 @@
  : ProducerBase(expectedNumEntries, face, syncPrefix,
                 userPrefix, syncReplyFreshness, helloReplyFreshness)
 {
-  m_registerPrefixId =
-    m_face.registerPrefix(m_syncPrefix,
-      [this] (const ndn::Name& syncPrefix) {
-        m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("hello"),
-                                 std::bind(&PartialProducer::onHelloInterest, this, _1, _2));
-
-        m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("sync"),
-                                 std::bind(&PartialProducer::onSyncInterest, this, _1, _2));
-      },
-      std::bind(&PartialProducer::onRegisterFailed, this, _1, _2));
-}
-
-PartialProducer::~PartialProducer()
-{
-  m_face.unregisterPrefix(m_registerPrefixId, nullptr, nullptr);
+  m_registeredPrefix = m_face.registerPrefix(m_syncPrefix,
+    [this] (const ndn::Name& syncPrefix) {
+      m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("hello"),
+                               std::bind(&PartialProducer::onHelloInterest, this, _1, _2));
+      m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("sync"),
+                               std::bind(&PartialProducer::onSyncInterest, this, _1, _2));
+    },
+    std::bind(&PartialProducer::onRegisterFailed, this, _1, _2));
 }
 
 void
@@ -199,16 +192,12 @@
     return;
   }
 
-  ndn::util::scheduler::ScopedEventId scopedEventId(m_scheduler);
-  auto it = m_pendingEntries.emplace(interestName,
-                                     PendingEntryInfo{bf, iblt, std::move(scopedEventId)});
-
-  it.first->second.expirationEvent =
-    m_scheduler.scheduleEvent(interest.getInterestLifetime(),
-                              [this, interest] {
-                                NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce());
-                                m_pendingEntries.erase(interest.getName());
-                              });
+  auto& entry = m_pendingEntries.emplace(interestName, PendingEntryInfo{bf, iblt, {}}).first->second;
+  entry.expirationEvent = m_scheduler.scheduleEvent(interest.getInterestLifetime(),
+                          [this, interest] {
+                            NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce());
+                            m_pendingEntries.erase(interest.getName());
+                          });
 }
 
 void
diff --git a/PSync/partial-producer.hpp b/PSync/partial-producer.hpp
index cec1079..94f5672 100644
--- a/PSync/partial-producer.hpp
+++ b/PSync/partial-producer.hpp
@@ -27,10 +27,9 @@
 #include <unordered_set>
 
 #include <ndn-cxx/face.hpp>
-#include <ndn-cxx/util/scheduler.hpp>
-#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
-#include <ndn-cxx/util/time.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/util/scheduler.hpp>
+#include <ndn-cxx/util/time.hpp>
 
 namespace psync {
 
@@ -72,8 +71,6 @@
                   ndn::time::milliseconds helloReplyFreshness = HELLO_REPLY_FRESHNESS,
                   ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS);
 
-  ~PartialProducer();
-
   /**
    * @brief Publish name to let subscribed consumers know
    *
@@ -122,9 +119,8 @@
   onSyncInterest(const ndn::Name& prefix, const ndn::Interest& interest);
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  std::map <ndn::Name, PendingEntryInfo> m_pendingEntries;
-
-  const ndn::RegisteredPrefixId* m_registerPrefixId;
+  std::map<ndn::Name, PendingEntryInfo> m_pendingEntries;
+  ndn::ScopedRegisteredPrefixHandle m_registeredPrefix;
 };
 
 } // namespace psync
diff --git a/PSync/segment-publisher.hpp b/PSync/segment-publisher.hpp
index f28e31d..f00acff 100644
--- a/PSync/segment-publisher.hpp
+++ b/PSync/segment-publisher.hpp
@@ -24,11 +24,10 @@
 
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/name.hpp>
+#include <ndn-cxx/ims/in-memory-storage-fifo.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
-#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
 #include <ndn-cxx/util/scheduler.hpp>
 #include <ndn-cxx/util/time.hpp>
-#include <ndn-cxx/ims/in-memory-storage-fifo.hpp>
 
 namespace psync {