blob: b9946a1afd023497b91a1840e58d1d4038fde756 [file] [log] [blame]
Patrick Venturec87de552020-05-20 20:25:39 -07001#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
12namespace google
13{
14namespace ipmi
15{
16
17extern const std::string defaultConfigFile;
18
19class Handler : public HandlerInterface
20{
21 public:
22 explicit Handler(const std::string& entityConfigPath = defaultConfigFile) :
23 _configFile(entityConfigPath){};
24 ~Handler() = default;
25
26 std::tuple<std::uint8_t, std::string> getEthDetails() const override;
27 std::int64_t getRxPackets(const std::string& name) const override;
28 VersionTuple getCpldVersion(unsigned int id) const override;
29 void psuResetDelay(std::uint32_t delay) const override;
30 std::string getEntityName(std::uint8_t id, std::uint8_t instance) override;
31 void buildI2cPcieMapping() override;
32 size_t getI2cPcieMappingSize() const override;
33 std::tuple<std::uint32_t, std::string>
34 getI2cEntry(unsigned int entry) const override;
35
36 private:
37 std::string _configFile;
38
39 bool _entityConfigParsed = false;
40
41 const std::map<uint8_t, std::string> _entityIdToName{
42 {0x03, "cpu"},
43 {0x04, "storage_device"},
44 {0x06, "system_management_module"},
45 {0x07, "system_board"},
46 {0x08, "memory_module"},
47 {0x0B, "add_in_card"},
48 {0x0E, "power_system_board"},
49 {0x10, "system_internal_expansion_board"},
50 {0x11, "other_system_board"},
51 {0x17, "system_chassis"},
52 {0x1D, "fan"},
53 {0x1E, "cooling_unit"},
54 {0x20, "memory_device"}};
55
56 nlohmann::json _entityConfig{};
57
58 std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map;
59};
60
Patrick Venturea3f9c2d2020-05-29 14:36:25 -070061/**
62 * Given a type, entity instance, and a configuration, return the name.
63 *
64 * @param[in] type - the entity type
65 * @param[in] instance - the entity instance
66 * @param[in] config - the json object holding the entity mapping
67 * @return the name of the entity from the map
68 */
69std::string readNameFromConfig(const std::string& type, uint8_t instance,
70 const nlohmann::json& config);
71
Patrick Venturec87de552020-05-20 20:25:39 -070072} // namespace ipmi
73} // namespace google