fw: UnsolicitedDataPolicy registry

refs #2181

Change-Id: I39f5dd02a224f9d872bde29f29aab05f64bb6e06
diff --git a/daemon/fw/unsolicited-data-policy.cpp b/daemon/fw/unsolicited-data-policy.cpp
index 67d4d37..dd68e38 100644
--- a/daemon/fw/unsolicited-data-policy.cpp
+++ b/daemon/fw/unsolicited-data-policy.cpp
@@ -40,12 +40,31 @@
   return os << static_cast<int>(d);
 }
 
+UnsolicitedDataPolicy::Registry&
+UnsolicitedDataPolicy::getRegistry()
+{
+  static Registry registry;
+  return registry;
+}
+
+unique_ptr<UnsolicitedDataPolicy>
+UnsolicitedDataPolicy::create(const std::string& key)
+{
+  Registry& registry = getRegistry();
+  auto i = registry.find(key);
+  return i == registry.end() ? nullptr : i->second();
+}
+
+NFD_REGISTER_UNSOLICITED_DATA_POLICY(DropAllUnsolicitedDataPolicy, "drop-all");
+
 UnsolicitedDataDecision
 DropAllUnsolicitedDataPolicy::decide(const Face& inFace, const Data& data) const
 {
   return UnsolicitedDataDecision::DROP;
 }
 
+NFD_REGISTER_UNSOLICITED_DATA_POLICY(AdmitLocalUnsolicitedDataPolicy, "admit-local");
+
 UnsolicitedDataDecision
 AdmitLocalUnsolicitedDataPolicy::decide(const Face& inFace, const Data& data) const
 {
@@ -55,6 +74,8 @@
   return UnsolicitedDataDecision::DROP;
 }
 
+NFD_REGISTER_UNSOLICITED_DATA_POLICY(AdmitNetworkUnsolicitedDataPolicy, "admit-network");
+
 UnsolicitedDataDecision
 AdmitNetworkUnsolicitedDataPolicy::decide(const Face& inFace, const Data& data) const
 {
@@ -64,30 +85,13 @@
   return UnsolicitedDataDecision::DROP;
 }
 
+NFD_REGISTER_UNSOLICITED_DATA_POLICY(AdmitAllUnsolicitedDataPolicy, "admit-all");
+
 UnsolicitedDataDecision
 AdmitAllUnsolicitedDataPolicy::decide(const Face& inFace, const Data& data) const
 {
   return UnsolicitedDataDecision::CACHE;
 }
 
-unique_ptr<UnsolicitedDataPolicy>
-makeUnsolicitedDataPolicy(const std::string& key)
-{
-  /// \todo register policy with a macro
-  if (key == "drop-all") {
-    return make_unique<DropAllUnsolicitedDataPolicy>();
-  }
-  if (key == "admit-local") {
-    return make_unique<AdmitLocalUnsolicitedDataPolicy>();
-  }
-  if (key == "admit-network") {
-    return make_unique<AdmitNetworkUnsolicitedDataPolicy>();
-  }
-  if (key == "admit-all") {
-    return make_unique<AdmitAllUnsolicitedDataPolicy>();
-  }
-  return nullptr;
-}
-
 } // namespace fw
 } // namespace nfd