diff options
author | Patrick Venture <venture@google.com> | 2019-08-19 12:07:18 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-09-19 10:20:31 -0700 |
commit | 87fd2cd13314a2b0b8cbc6441e724a4fea57e20c (patch) | |
tree | 4b8278bedc9035659d16d8734bac2218e437e131 /entity_map_json.cpp | |
parent | 99bf1c410f4521e1df05c41cd377e9d1232dbdba (diff) | |
download | phosphor-host-ipmid-87fd2cd13314a2b0b8cbc6441e724a4fea57e20c.tar.gz phosphor-host-ipmid-87fd2cd13314a2b0b8cbc6441e724a4fea57e20c.zip |
sensorhandler: use entity-map from json if filled
Step 4 of the transition from YAML to JSON will return the data from the
JSON file if present and valid, otherwise it'll fallback and return the
default example YAML present in the repository.
Tested: This was not tested.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I33c773fc53660a9eb5e27a8c8c3e231c64fe079d
Diffstat (limited to 'entity_map_json.cpp')
-rw-r--r-- | entity_map_json.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/entity_map_json.cpp b/entity_map_json.cpp index 96ef61c..c0b836c 100644 --- a/entity_map_json.cpp +++ b/entity_map_json.cpp @@ -3,6 +3,7 @@ #include <exception> #include <fstream> #include <ipmid/types.hpp> +#include <memory> #include <nlohmann/json.hpp> #include <string> #include <utility> @@ -14,9 +15,34 @@ namespace sensor extern const EntityInfoMap entities; -const EntityInfoMap& getIpmiEntityRecords() +EntityInfoMapContainer* EntityInfoMapContainer::getContainer() { - return entities; + static std::unique_ptr<EntityInfoMapContainer> instance; + + if (!instance) + { + /* TODO: With multi-threading this would all need to be locked so + * the first thread to hit it would set it up. + */ + EntityInfoMap builtEntityMap = buildEntityMapFromFile(); + if (!builtEntityMap.empty()) + { + instance = std::unique_ptr<EntityInfoMapContainer>( + new EntityInfoMapContainer(builtEntityMap)); + } + else + { + instance = std::unique_ptr<EntityInfoMapContainer>( + new EntityInfoMapContainer(entities)); + } + } + + return instance.get(); +} + +const EntityInfoMap& EntityInfoMapContainer::getIpmiEntityRecords() +{ + return entityRecords; } EntityInfoMap buildEntityMapFromFile() |