1 #pragma once
2 
3 #include "handler.hpp"
4 
5 #include <cstdint>
6 #include <map>
7 #include <nlohmann/json.hpp>
8 #include <string>
9 #include <tuple>
10 #include <vector>
11 
12 namespace google
13 {
14 namespace ipmi
15 {
16 
17 constexpr char defaultConfigFile[] =
18     "/usr/share/ipmi-entity-association/entity_association_map.json";
19 
20 class Handler : public HandlerInterface
21 {
22   public:
23     explicit Handler(const std::string& entityConfigPath = defaultConfigFile) :
24         _configFile(entityConfigPath){};
25     ~Handler() = default;
26 
27     std::tuple<std::uint8_t, std::string> getEthDetails() const override;
28     std::int64_t getRxPackets(const std::string& name) const override;
29     VersionTuple getCpldVersion(unsigned int id) const override;
30     void psuResetDelay(std::uint32_t delay) const override;
31     void psuResetOnShutdown() const override;
32     std::string getEntityName(std::uint8_t id, std::uint8_t instance) override;
33     std::string getMachineName() override;
34     void buildI2cPcieMapping() override;
35     size_t getI2cPcieMappingSize() const override;
36     std::tuple<std::uint32_t, std::string>
37         getI2cEntry(unsigned int entry) const override;
38 
39   private:
40     std::string _configFile;
41 
42     bool _entityConfigParsed = false;
43 
44     const std::map<uint8_t, std::string> _entityIdToName{
45         {0x03, "cpu"},
46         {0x04, "storage_device"},
47         {0x06, "system_management_module"},
48         {0x07, "system_board"},
49         {0x08, "memory_module"},
50         {0x0B, "add_in_card"},
51         {0x0E, "power_system_board"},
52         {0x10, "system_internal_expansion_board"},
53         {0x11, "other_system_board"},
54         {0x17, "system_chassis"},
55         {0x1D, "fan"},
56         {0x1E, "cooling_unit"},
57         {0x20, "memory_device"}};
58 
59     nlohmann::json _entityConfig{};
60 
61     std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map;
62 };
63 
64 /**
65  * Given a type, entity instance, and a configuration, return the name.
66  *
67  * @param[in] type - the entity type
68  * @param[in] instance - the entity instance
69  * @param[in] config - the json object holding the entity mapping
70  * @return the name of the entity from the map
71  */
72 std::string readNameFromConfig(const std::string& type, uint8_t instance,
73                                const nlohmann::json& config);
74 
75 } // namespace ipmi
76 } // namespace google
77