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 
27*b69209b4SWilliam A. Kennington III     std::tuple<std::uint8_t, std::string>
28*b69209b4SWilliam A. Kennington III         getEthDetails(std::string intf) const override;
29c87de558SPatrick Venture     std::int64_t getRxPackets(const std::string& name) const override;
30c87de558SPatrick Venture     VersionTuple getCpldVersion(unsigned int id) const override;
31c87de558SPatrick Venture     void psuResetDelay(std::uint32_t delay) const override;
32ac4a16f7SShounak Mitra     void psuResetOnShutdown() const override;
33c87de558SPatrick Venture     std::string getEntityName(std::uint8_t id, std::uint8_t instance) override;
343b1b427cSWilly Tu     uint32_t getFlashSize() override;
3529f35bceSWilliam A. Kennington III     std::string getMachineName() override;
36c87de558SPatrick Venture     void buildI2cPcieMapping() override;
37c87de558SPatrick Venture     size_t getI2cPcieMappingSize() const override;
388cfa4c44Slinyuny     void hostPowerOffDelay(std::uint32_t delay) const override;
39c87de558SPatrick Venture     std::tuple<std::uint32_t, std::string>
40c87de558SPatrick Venture         getI2cEntry(unsigned int entry) const override;
41c87de558SPatrick Venture 
42c87de558SPatrick Venture   private:
43c87de558SPatrick Venture     std::string _configFile;
44c87de558SPatrick Venture 
45c87de558SPatrick Venture     bool _entityConfigParsed = false;
46c87de558SPatrick Venture 
47c87de558SPatrick Venture     const std::map<uint8_t, std::string> _entityIdToName{
48c87de558SPatrick Venture         {0x03, "cpu"},
49c87de558SPatrick Venture         {0x04, "storage_device"},
50c87de558SPatrick Venture         {0x06, "system_management_module"},
51c87de558SPatrick Venture         {0x07, "system_board"},
52c87de558SPatrick Venture         {0x08, "memory_module"},
53c87de558SPatrick Venture         {0x0B, "add_in_card"},
54c87de558SPatrick Venture         {0x0E, "power_system_board"},
55c87de558SPatrick Venture         {0x10, "system_internal_expansion_board"},
56c87de558SPatrick Venture         {0x11, "other_system_board"},
57c87de558SPatrick Venture         {0x17, "system_chassis"},
58c87de558SPatrick Venture         {0x1D, "fan"},
59c87de558SPatrick Venture         {0x1E, "cooling_unit"},
60c87de558SPatrick Venture         {0x20, "memory_device"}};
61c87de558SPatrick Venture 
62c87de558SPatrick Venture     nlohmann::json _entityConfig{};
63c87de558SPatrick Venture 
64c87de558SPatrick Venture     std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map;
65c87de558SPatrick Venture };
66c87de558SPatrick Venture 
67a3f9c2d3SPatrick Venture /**
68a3f9c2d3SPatrick Venture  * Given a type, entity instance, and a configuration, return the name.
69a3f9c2d3SPatrick Venture  *
70a3f9c2d3SPatrick Venture  * @param[in] type - the entity type
71a3f9c2d3SPatrick Venture  * @param[in] instance - the entity instance
72a3f9c2d3SPatrick Venture  * @param[in] config - the json object holding the entity mapping
73a3f9c2d3SPatrick Venture  * @return the name of the entity from the map
74a3f9c2d3SPatrick Venture  */
75a3f9c2d3SPatrick Venture std::string readNameFromConfig(const std::string& type, uint8_t instance,
76a3f9c2d3SPatrick Venture                                const nlohmann::json& config);
77a3f9c2d3SPatrick Venture 
78c87de558SPatrick Venture } // namespace ipmi
79c87de558SPatrick Venture } // namespace google
80