rib: ReadvertiseDestination availability

refs: #3818

Change-Id: Ifc2875ba38025595f3d6a8f8207f5ec126f93c90
diff --git a/rib/readvertise/nfd-rib-readvertise-destination.cpp b/rib/readvertise/nfd-rib-readvertise-destination.cpp
index 849f6cb..dcf3d93 100644
--- a/rib/readvertise/nfd-rib-readvertise-destination.cpp
+++ b/rib/readvertise/nfd-rib-readvertise-destination.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -32,11 +32,15 @@
 using ndn::nfd::ControlResponse;
 
 NfdRibReadvertiseDestination::NfdRibReadvertiseDestination(ndn::nfd::Controller& controller,
-                                                           //ndn::KeyChain& keyChain,
-                                                           const ndn::Name& commandPrefix)
+                                                           const ndn::Name& commandPrefix,
+                                                           Rib& rib)
   : m_controller(controller)
   , m_commandPrefix(commandPrefix)
 {
+  m_ribAddConn = rib.afterInsertEntry.connect(
+    std::bind(&NfdRibReadvertiseDestination::handleRibAdd, this, _1));
+  m_ribRemoveConn = rib.afterEraseEntry.connect(
+    std::bind(&NfdRibReadvertiseDestination::handleRibRemove, this, _1));
 }
 
 void
@@ -63,5 +67,21 @@
     [=] (const ControlResponse& cr) { failureCb(cr.getText()); });
 }
 
+void
+NfdRibReadvertiseDestination::handleRibAdd(const ndn::Name& name)
+{
+  if (name == m_commandPrefix) {
+    setAvailability(true);
+  }
+}
+
+void
+NfdRibReadvertiseDestination::handleRibRemove(const ndn::Name& name)
+{
+  if (name == m_commandPrefix) {
+    setAvailability(false);
+  }
+}
+
 } // namespace rib
 } // namespace nfd