mgmt: publish Strategy Choice dataset

refs: #1632

Change-Id: I4ed09d191433fd80071367e7b2ffcd2ac81c5c17
diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp
index 261358a..b51badc 100644
--- a/daemon/mgmt/strategy-choice-manager.cpp
+++ b/daemon/mgmt/strategy-choice-manager.cpp
@@ -5,7 +5,8 @@
  *                     Colorado State University,
  *                     University Pierre & Marie Curie, Sorbonne University,
  *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ *                     Beijing Institute of Technology,
+ *                     The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -42,10 +43,13 @@
   StrategyChoiceManager::COMMAND_UNSIGNED_NCOMPS +
   4; // (timestamp, nonce, signed info tlv, signature tlv)
 
+const Name StrategyChoiceManager::LIST_DATASET_PREFIX("/localhost/nfd/strategy-choice/list");
+
 StrategyChoiceManager::StrategyChoiceManager(StrategyChoice& strategyChoice,
                                              shared_ptr<InternalFace> face)
   : ManagerBase(face, STRATEGY_CHOICE_PRIVILEGE)
   , m_strategyChoice(strategyChoice)
+  , m_listPublisher(strategyChoice, m_face, LIST_DATASET_PREFIX)
 {
   face->setInterestFilter("/localhost/nfd/strategy-choice",
                           bind(&StrategyChoiceManager::onStrategyChoiceRequest, this, _2));
@@ -62,6 +66,12 @@
   const Name& command = request.getName();
   const size_t commandNComps = command.size();
 
+  if (command == LIST_DATASET_PREFIX)
+    {
+      listStrategies(request);
+      return;
+    }
+
   if (COMMAND_UNSIGNED_NCOMPS <= commandNComps &&
       commandNComps < COMMAND_SIGNED_NCOMPS)
     {
@@ -84,6 +94,12 @@
 }
 
 void
+StrategyChoiceManager::listStrategies(const Interest& request)
+{
+  m_listPublisher.publish();
+}
+
+void
 StrategyChoiceManager::onValidatedStrategyChoiceRequest(const shared_ptr<const Interest>& request)
 {
   static const Name::Component VERB_SET("set");
diff --git a/daemon/mgmt/strategy-choice-manager.hpp b/daemon/mgmt/strategy-choice-manager.hpp
index cf46e96..f3a0ed5 100644
--- a/daemon/mgmt/strategy-choice-manager.hpp
+++ b/daemon/mgmt/strategy-choice-manager.hpp
@@ -5,7 +5,8 @@
  *                     Colorado State University,
  *                     University Pierre & Marie Curie, Sorbonne University,
  *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ *                     Beijing Institute of Technology,
+ *                     The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -26,6 +27,7 @@
 #define NFD_DAEMON_MGMT_STRATEGY_CHOICE_MANAGER_HPP
 
 #include "mgmt/manager-base.hpp"
+#include "mgmt/strategy-choice-publisher.hpp"
 
 #include <ndn-cxx/management/nfd-control-parameters.hpp>
 
@@ -48,6 +50,10 @@
   onStrategyChoiceRequest(const Interest& request);
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+
+  void
+  listStrategies(const Interest& request);
+
   void
   onValidatedStrategyChoiceRequest(const shared_ptr<const Interest>& request);
 
@@ -63,6 +69,8 @@
 
   StrategyChoice& m_strategyChoice;
 
+  StrategyChoicePublisher m_listPublisher;
+
   static const Name COMMAND_PREFIX; // /localhost/nfd/strategy-choice
 
   // number of components in an invalid, but not malformed, unsigned command.
@@ -73,6 +81,8 @@
   // (see UNSIGNED_NCOMPS), 9 with signed Interest support.
   static const size_t COMMAND_SIGNED_NCOMPS;
 
+  static const Name LIST_DATASET_PREFIX; // /localhost/nfd/strategy-choice/list
+
 };
 
 } // namespace nfd
diff --git a/daemon/mgmt/strategy-choice-publisher.cpp b/daemon/mgmt/strategy-choice-publisher.cpp
new file mode 100644
index 0000000..933cc29
--- /dev/null
+++ b/daemon/mgmt/strategy-choice-publisher.cpp
@@ -0,0 +1,72 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014  Regents of the University of California,
+ *                     Arizona Board of Regents,
+ *                     Colorado State University,
+ *                     University Pierre & Marie Curie, Sorbonne University,
+ *                     Washington University in St. Louis,
+ *                     Beijing Institute of Technology,
+ *                     The University of Memphis
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "strategy-choice-publisher.hpp"
+#include "face-flags.hpp"
+#include "core/logger.hpp"
+#include "table/strategy-choice.hpp"
+
+#include <ndn-cxx/management/nfd-strategy-choice.hpp>
+
+namespace nfd {
+
+NFD_LOG_INIT("StrategyChoicePublisher");
+
+
+StrategyChoicePublisher::StrategyChoicePublisher(const StrategyChoice& strategyChoice,
+                                                 shared_ptr<AppFace> face,
+                                                 const Name& prefix)
+  : SegmentPublisher(face, prefix)
+  , m_strategyChoice(strategyChoice)
+{
+
+}
+
+StrategyChoicePublisher::~StrategyChoicePublisher()
+{
+
+}
+
+size_t
+StrategyChoicePublisher::generate(ndn::EncodingBuffer& outBuffer)
+{
+  size_t totalLength = 0;
+
+  for (StrategyChoice::const_iterator i = m_strategyChoice.begin();
+       i != m_strategyChoice.end();
+       ++i)
+    {
+      ndn::nfd::StrategyChoice entry;
+
+      entry.setName(i->getPrefix())
+           .setStrategy(i->getStrategyName());
+
+      totalLength += entry.wireEncode(outBuffer);
+    }
+
+  return totalLength;
+}
+
+} // namespace nfd
diff --git a/daemon/mgmt/strategy-choice-publisher.hpp b/daemon/mgmt/strategy-choice-publisher.hpp
new file mode 100644
index 0000000..d19a92e
--- /dev/null
+++ b/daemon/mgmt/strategy-choice-publisher.hpp
@@ -0,0 +1,58 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014  Regents of the University of California,
+ *                     Arizona Board of Regents,
+ *                     Colorado State University,
+ *                     University Pierre & Marie Curie, Sorbonne University,
+ *                     Washington University in St. Louis,
+ *                     Beijing Institute of Technology,
+ *                     The University of Memphis
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#ifndef NFD_DAEMON_MGMT_STRATEGY_CHOICE_PUBLISHER_HPP
+#define NFD_DAEMON_MGMT_STRATEGY_CHOICE_PUBLISHER_HPP
+
+#include "mgmt/segment-publisher.hpp"
+
+namespace nfd {
+
+class StrategyChoice;
+
+class StrategyChoicePublisher : public SegmentPublisher
+{
+public:
+  StrategyChoicePublisher(const StrategyChoice& strategyChoice,
+                          shared_ptr<AppFace> face,
+                          const Name& prefix);
+
+  virtual
+  ~StrategyChoicePublisher();
+
+protected:
+
+  virtual size_t
+  generate(ndn::EncodingBuffer& outBuffer);
+
+private:
+
+  const StrategyChoice& m_strategyChoice;
+
+};
+
+} // namespace nfd
+
+#endif // NFD_DAEMON_MGMT_STRATEGY_CHOICE_PUBLISHER_HPP