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