Remove circular dependencies in regulator includes

Remove the circular dependencies that currently exist among regulator
include files.  Add forward declarations in two key includes that cause
the issue.

This requires the creation of a new source (.cpp) file and as a result a
new static library.

Change-Id: Ib136adf0a0cf6b30781b64cfecede0fbd50e13f7
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/phosphor-regulators/src/actions/action_environment.hpp b/phosphor-regulators/src/actions/action_environment.hpp
index e519fa5..eb66981 100644
--- a/phosphor-regulators/src/actions/action_environment.hpp
+++ b/phosphor-regulators/src/actions/action_environment.hpp
@@ -15,9 +15,7 @@
  */
 #pragma once
 
-#include "device.hpp"
 #include "id_map.hpp"
-#include "rule.hpp"
 
 #include <cstddef> // for size_t
 #include <stdexcept>
@@ -26,6 +24,10 @@
 namespace phosphor::power::regulators
 {
 
+// Forward declarations to avoid circular dependencies
+class Device;
+class Rule;
+
 /**
  * @class ActionEnvironment
  *
@@ -198,7 +200,7 @@
     /**
      * Mapping from string IDs to the associated Device and Rule objects.
      */
-    const IDMap& idMap{};
+    const IDMap& idMap;
 
     /**
      * Current device ID.
diff --git a/phosphor-regulators/src/id_map.cpp b/phosphor-regulators/src/id_map.cpp
new file mode 100644
index 0000000..d39fa4f
--- /dev/null
+++ b/phosphor-regulators/src/id_map.cpp
@@ -0,0 +1,41 @@
+/**
+ * Copyright © 2019 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "id_map.hpp"
+
+#include "device.hpp"
+#include "rail.hpp"
+#include "rule.hpp"
+
+namespace phosphor::power::regulators
+{
+
+void IDMap::addDevice(Device& device)
+{
+    deviceMap[device.getID()] = &device;
+}
+
+void IDMap::addRail(Rail& rail)
+{
+    railMap[rail.getID()] = &rail;
+}
+
+void IDMap::addRule(Rule& rule)
+{
+    ruleMap[rule.getID()] = &rule;
+}
+
+} // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/src/id_map.hpp b/phosphor-regulators/src/id_map.hpp
index 2fbaa93..289c7a9 100644
--- a/phosphor-regulators/src/id_map.hpp
+++ b/phosphor-regulators/src/id_map.hpp
@@ -15,10 +15,6 @@
  */
 #pragma once
 
-#include "device.hpp"
-#include "rail.hpp"
-#include "rule.hpp"
-
 #include <map>
 #include <stdexcept>
 #include <string>
@@ -26,6 +22,11 @@
 namespace phosphor::power::regulators
 {
 
+// Forward declarations to avoid circular dependencies
+class Device;
+class Rail;
+class Rule;
+
 /**
  * @class IDMap
  *
@@ -48,30 +49,21 @@
      *
      * @param device device to add
      */
-    void addDevice(Device& device)
-    {
-        deviceMap[device.getID()] = &device;
-    }
+    void addDevice(Device& device);
 
     /**
      * Adds the specified rail to this IDMap.
      *
      * @param rail rail to add
      */
-    void addRail(Rail& rail)
-    {
-        railMap[rail.getID()] = &rail;
-    }
+    void addRail(Rail& rail);
 
     /**
      * Adds the specified rule to this IDMap.
      *
      * @param rule rule to add
      */
-    void addRule(Rule& rule)
-    {
-        ruleMap[rule.getID()] = &rule;
-    }
+    void addRule(Rule& rule);
 
     /**
      * Returns the device with the specified ID.
diff --git a/phosphor-regulators/src/meson.build b/phosphor-regulators/src/meson.build
index 23266b0..76551ae 100644
--- a/phosphor-regulators/src/meson.build
+++ b/phosphor-regulators/src/meson.build
@@ -2,3 +2,14 @@
     '.',
     'actions'
 )
+
+phosphor_regulators_source_files = [
+    'id_map.cpp'
+]
+
+phosphor_regulators_library = static_library(
+    'phosphor-regulators',
+    phosphor_regulators_source_files,
+    implicit_include_directories: false,
+    include_directories: phosphor_regulators_include_directories
+)
diff --git a/phosphor-regulators/test/id_map_tests.cpp b/phosphor-regulators/test/id_map_tests.cpp
index 7a1307a..5d47d7d 100644
--- a/phosphor-regulators/test/id_map_tests.cpp
+++ b/phosphor-regulators/test/id_map_tests.cpp
@@ -13,7 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "device.hpp"
 #include "id_map.hpp"
+#include "rail.hpp"
+#include "rule.hpp"
 
 #include <exception>
 #include <stdexcept>
diff --git a/phosphor-regulators/test/meson.build b/phosphor-regulators/test/meson.build
index a60249f..a246150 100644
--- a/phosphor-regulators/test/meson.build
+++ b/phosphor-regulators/test/meson.build
@@ -21,6 +21,7 @@
                     gmock,
                     gtest,
                 ],
+                link_with: phosphor_regulators_library,
                 implicit_include_directories: false,
                 include_directories: [
                     phosphor_regulators_include_directories,