regulators: Add VPD service

The regulators application needs to obtain VPD (Vital Product Data)
keyword values.

Sometimes regulator configuration and monitoring varies depending on
hardware type or version.  VPD keyword values can provide this
information about the hardware.

Add a new class to obtain hardware VPD from the D-Bus
xyz.openbmc_project.Inventory.Decorator.Asset interface.

Also define an abstract base class and a mock implementation to
enable use of gmock in test cases related to VPD.

Tested:
* Verified VPD values were successfully obtained from D-Bus.
* Verified VPD values were cached.
* Tested where object path was invalid.
* Tested where keyword was invalid.
* Verified cached VPD values were cleared when machine powered on.
* For the complete test plan, see
  https://gist.github.com/smccarney/519a54353361e28b1d25f5783c15f471

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: Id08e8bca8db6421d46669c495e8a9432e45a1fd6
diff --git a/phosphor-regulators/src/vpd.cpp b/phosphor-regulators/src/vpd.cpp
new file mode 100644
index 0000000..fc99904
--- /dev/null
+++ b/phosphor-regulators/src/vpd.cpp
@@ -0,0 +1,55 @@
+/**
+ * Copyright © 2021 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 "vpd.hpp"
+
+#include "types.hpp"
+#include "utility.hpp"
+
+namespace phosphor::power::regulators
+{
+
+std::string DBusVPD::getValue(const std::string& inventoryPath,
+                              const std::string& keyword)
+{
+    std::string value{};
+
+    // Get cached keywords for the inventory path
+    KeywordMap& cachedKeywords = cache[inventoryPath];
+
+    // Check if the keyword value is already cached
+    auto it = cachedKeywords.find(keyword);
+    if (it != cachedKeywords.end())
+    {
+        value = it->second;
+    }
+    else
+    {
+        // Get keyword value from D-Bus interface/property.  The property name
+        // is normally the same as the VPD keyword name.  However, the CCIN
+        // keyword is stored in the Model property.
+        std::string property{(keyword == "CCIN") ? "Model" : keyword};
+        util::getProperty(ASSET_IFACE, property, inventoryPath,
+                          INVENTORY_MGR_IFACE, bus, value);
+
+        // Cache keyword value
+        cachedKeywords[keyword] = value;
+    }
+
+    return value;
+}
+
+} // namespace phosphor::power::regulators