face+management: Removing ndnd::Controller and re-designing controllers

As of this commit, there is only one controller: nfd::Controller.
Legacy ndnd-tlv is no longer supported, but it is still possible to use
NFD FIB Management directly (RIB Management commands are used by
default).  To request direct FIB management, one needs to call
Face::setDirectFibManagement(true) or configure protocol variable in the
config file.

Instead of using virtual methods of the controllers, a special
setInterestFilterImpl method will select proper prefix registration
method.  In addition to that, setInterestFilterImpl will also remember
how exactly the prefix should be de-registered, including security
parameters.

Change-Id: If9d4c7e87f6d80b6cb766a4116e04e846a51272d
Refs: #1576, #1577
diff --git a/src/detail/interest-filter-record.hpp b/src/detail/interest-filter-record.hpp
new file mode 100644
index 0000000..cf5f253
--- /dev/null
+++ b/src/detail/interest-filter-record.hpp
@@ -0,0 +1,89 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (c) 2013-2014,  Regents of the University of California.
+ * All rights reserved.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * This file licensed under New BSD License.  See COPYING for detailed information about
+ * ndn-cxx library copyright, permissions, and redistribution restrictions.
+ */
+
+#ifndef NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
+#define NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
+
+#include "../common.hpp"
+#include "../name.hpp"
+#include "../interest.hpp"
+
+namespace ndn {
+
+class InterestFilterRecord : noncopyable
+{
+public:
+  typedef function<void (const InterestFilter&, const Interest&)> OnInterest;
+
+  InterestFilterRecord(const InterestFilter& filter, const OnInterest& onInterest)
+    : m_filter(filter)
+    , m_onInterest(onInterest)
+  {
+  }
+
+  /**
+   * @brief Check if Interest name matches the filter
+   * @param name Interest Name
+   */
+  bool
+  doesMatch(const Name& name) const
+  {
+    return m_filter.doesMatch(name);
+  }
+
+  void
+  operator()(const Interest& interest) const
+  {
+    m_onInterest(m_filter, interest);
+  }
+
+  const InterestFilter&
+  getFilter() const
+  {
+    return m_filter;
+  }
+
+private:
+  InterestFilter m_filter;
+  OnInterest m_onInterest;
+};
+
+
+/**
+ * @brief Opaque class representing ID of the Interest filter
+ */
+class InterestFilterId;
+
+/**
+ * @brief Functor to match InterestFilterId
+ */
+class MatchInterestFilterId
+{
+public:
+  explicit
+  MatchInterestFilterId(const InterestFilterId* interestFilterId)
+    : m_id(interestFilterId)
+  {
+  }
+
+  bool
+  operator()(const shared_ptr<InterestFilter>& interestFilterId) const
+  {
+    return (reinterpret_cast<const InterestFilterId*>(interestFilterId.get()) == m_id);
+  }
+private:
+  const InterestFilterId* m_id;
+};
+
+} // namespace ndn
+
+#endif // NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
diff --git a/src/detail/pending-interest.hpp b/src/detail/pending-interest.hpp
index 32cdd66..ad03746 100644
--- a/src/detail/pending-interest.hpp
+++ b/src/detail/pending-interest.hpp
@@ -20,7 +20,7 @@
 
 namespace ndn {
 
-class PendingInterest
+class PendingInterest : noncopyable
 {
 public:
   typedef function<void(const Interest&, Data&)> OnData;
diff --git a/src/detail/registered-prefix.hpp b/src/detail/registered-prefix.hpp
index 8957d5e..1646c64 100644
--- a/src/detail/registered-prefix.hpp
+++ b/src/detail/registered-prefix.hpp
@@ -17,59 +17,42 @@
 #include "../name.hpp"
 #include "../interest.hpp"
 
+#include "interest-filter-record.hpp"
+
 namespace ndn {
 
-class InterestFilterRecord
+namespace nfd {
+class ControlParameters;
+}
+
+class RegisteredPrefix : noncopyable
 {
 public:
-  typedef function<void (const InterestFilter&, const Interest&)> OnInterest;
-
-  InterestFilterRecord(const InterestFilter& filter, const OnInterest& onInterest)
-    : m_filter(filter)
-    , m_onInterest(onInterest)
-  {
-  }
-
-  /**
-   * @brief Check if Interest name matches the filter
-   * @param name Interest Name
+  /** \brief a callback on command success
    */
-  bool
-  doesMatch(const Name& name) const
-  {
-    return m_filter.doesMatch(name);
-  }
+  typedef function<void(const nfd::ControlParameters&)> SuccessCallback;
 
-  void
-  operator()(const Interest& interest) const
-  {
-    m_onInterest(m_filter, interest);
-  }
+  /** \brief a callback on command failure
+   */
+  typedef function<void(uint32_t/*code*/,const std::string&/*reason*/)> FailureCallback;
 
-  const InterestFilter&
-  getFilter() const
-  {
-    return m_filter;
-  }
+  /// @brief Function that should be called to unregister prefix
+  typedef function<void(const SuccessCallback& onSuccess,
+                        const FailureCallback& onFailure)> Unregistrator;
 
-private:
-  InterestFilter m_filter;
-  OnInterest m_onInterest;
-};
-
-
-class RegisteredPrefix
-{
-public:
-  explicit
-  RegisteredPrefix(const Name& prefix)
+  RegisteredPrefix(const Name& prefix,
+                   const Unregistrator& unregistrator)
     : m_prefix(prefix)
+    , m_unregistrator(unregistrator)
   {
   }
 
-  RegisteredPrefix(const Name& prefix, shared_ptr<InterestFilterRecord> filter)
+  RegisteredPrefix(const Name& prefix,
+                   const shared_ptr<InterestFilterRecord>& filter,
+                   const Unregistrator& unregistrator)
     : m_prefix(prefix)
     , m_filter(filter)
+    , m_unregistrator(unregistrator)
   {
   }
 
@@ -85,11 +68,19 @@
     return m_filter;
   }
 
+  void
+  unregister(const SuccessCallback& onSuccess,
+             const FailureCallback& onFailure)
+  {
+    if (static_cast<bool>(m_unregistrator)) {
+      m_unregistrator(onSuccess, onFailure);
+    }
+  }
+
 private:
   Name m_prefix;
-
-  // to support old interface of combined (un)setInterestFilter
   shared_ptr<InterestFilterRecord> m_filter;
+  Unregistrator m_unregistrator;
 };
 
 /**
@@ -119,32 +110,6 @@
 };
 
 
-/**
- * @brief Opaque class representing ID of the Interest filter
- */
-class InterestFilterId;
-
-/**
- * @brief Functor to match InterestFilterId
- */
-class MatchInterestFilterId
-{
-public:
-  explicit
-  MatchInterestFilterId(const InterestFilterId* interestFilterId)
-    : m_id(interestFilterId)
-  {
-  }
-
-  bool
-  operator()(const shared_ptr<InterestFilter>& interestFilterId) const
-  {
-    return (reinterpret_cast<const InterestFilterId*>(interestFilterId.get()) == m_id);
-  }
-private:
-  const InterestFilterId* m_id;
-};
-
 } // namespace ndn
 
 #endif // NDN_DETAIL_REGISTERED_PREFIX_HPP