summaryrefslogtreecommitdiffstats
path: root/entity_map_json.hpp
blob: 3ab4ff24dda1ea67fa59f5716657935e9aa0a25d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include <ipmid/types.hpp>
#include <memory>
#include <nlohmann/json.hpp>

namespace ipmi
{
namespace sensor
{

/**
 * @brief Grab a handle to the entity map.
 */
const EntityInfoMap& getIpmiEntityRecords();

/**
 * @brief Open the default entity map json file, and if present and valid json,
 * return a built entity map.
 *
 * @return the map
 */
EntityInfoMap buildEntityMapFromFile();

/**
 * @brief Given json data validate the data matches the expected format for the
 * entity map configuration and parse the data into a map of the entities.
 *
 * If any entry is invalid, the entire contents passed in is disregarded as
 * possibly corrupt.
 *
 * @param[in] data - the json data
 * @return the map
 */
EntityInfoMap buildJsonEntityMap(const nlohmann::json& data);

/**
 * @brief Owner of the EntityInfoMap.
 */
class EntityInfoMapContainer
{
  public:
    /** Get ahold of the owner. */
    static EntityInfoMapContainer* getContainer();
    /** Get ahold of the records. */
    const EntityInfoMap& getIpmiEntityRecords();

  private:
    EntityInfoMapContainer(const EntityInfoMap& entityRecords) :
        entityRecords(entityRecords)
    {
    }
    EntityInfoMap entityRecords;
};

} // namespace sensor
} // namespace ipmi
OpenPOWER on IntegriCloud