summaryrefslogtreecommitdiffstats
path: root/entity_map_json.cpp
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2019-08-19 11:53:22 -0700
committerPatrick Venture <venture@google.com>2019-08-23 18:11:12 +0000
commitc2b7fc1fc67cc18f8e602eb6bd232b65c991a6e2 (patch)
treed4f279b222db3198a5d604f350389f4a1ae0fc0a /entity_map_json.cpp
parent02e32376817529e960bb918417bb6a55d646a3a3 (diff)
downloadphosphor-host-ipmid-c2b7fc1fc67cc18f8e602eb6bd232b65c991a6e2.tar.gz
phosphor-host-ipmid-c2b7fc1fc67cc18f8e602eb6bd232b65c991a6e2.zip
entitymap: add json file loading if present
Step 3 to handle the entity-map transition from YAML to JSON. This patchset adds a method that will process the json file, if present to build the map. Tested: This patchset has not been tested. Signed-off-by: Patrick Venture <venture@google.com> Change-Id: I79297aef59844a21f20c0a77de7a21264e2ed96a
Diffstat (limited to 'entity_map_json.cpp')
-rw-r--r--entity_map_json.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/entity_map_json.cpp b/entity_map_json.cpp
index db45b05..b6fc6d6 100644
--- a/entity_map_json.cpp
+++ b/entity_map_json.cpp
@@ -1,6 +1,7 @@
#include "entity_map_json.hpp"
#include <exception>
+#include <fstream>
#include <ipmid/types.hpp>
#include <nlohmann/json.hpp>
#include <string>
@@ -11,6 +12,27 @@ namespace ipmi
namespace sensor
{
+EntityInfoMap buildEntityMapFromFile()
+{
+ const char* entityMapJsonFilename =
+ "/usr/share/ipmi-providers/entity-map.json";
+ EntityInfoMap builtMap;
+
+ std::ifstream mapFile(entityMapJsonFilename);
+ if (!mapFile.is_open())
+ {
+ return builtMap;
+ }
+
+ auto data = nlohmann::json::parse(mapFile, nullptr, false);
+ if (data.is_discarded())
+ {
+ return builtMap;
+ }
+
+ return buildJsonEntityMap(data);
+}
+
EntityInfoMap buildJsonEntityMap(const nlohmann::json& data)
{
EntityInfoMap builtMap;
OpenPOWER on IntegriCloud