blob: 36a377be6bacb4b1c35836df3451ac698731872d [file] [log] [blame]
Patrick Venturef085d912019-03-15 08:50:00 -07001#pragma once
2
3#include <cstdint>
Patrick Ventureab650002019-03-16 09:08:47 -07004#include <map>
5#include <nlohmann/json.hpp>
Patrick Venturef085d912019-03-15 08:50:00 -07006#include <string>
7#include <tuple>
Patrick Venture49f23ad2019-03-16 11:59:55 -07008#include <vector>
Patrick Venturef085d912019-03-15 08:50:00 -07009
10namespace google
11{
12namespace ipmi
13{
14
Patrick Venturebb90d4f2019-03-15 13:42:06 -070015using VersionTuple =
16 std::tuple<std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t>;
17
Patrick Venturef085d912019-03-15 08:50:00 -070018class HandlerInterface
19{
20 public:
21 virtual ~HandlerInterface() = default;
22
23 /**
24 * Return ethernet details (hard-coded).
25 *
26 * @return tuple of ethernet details (channel, if name).
27 */
28 virtual std::tuple<std::uint8_t, std::string> getEthDetails() const = 0;
Patrick Ventured2037c62019-03-15 10:29:47 -070029
30 /**
31 * Return the value of rx_packets, given a if_name.
32 *
33 * @param[in] name, the interface name.
34 * @return the number of packets received.
35 * @throw IpmiException on failure.
36 */
37 virtual std::int64_t getRxPackets(const std::string& name) const = 0;
Patrick Venturebb90d4f2019-03-15 13:42:06 -070038
39 /**
40 * Return the values from a cpld version file.
41 *
42 * @param[in] id - the cpld id number.
43 * @return the quad of numbers as a tuple (maj,min,pt,subpt)
44 * @throw IpmiException on failure.
45 */
46 virtual VersionTuple getCpldVersion(unsigned int id) const = 0;
Patrick Ventureaa374122019-03-15 15:09:10 -070047
48 /**
49 * Set the PSU Reset delay.
50 *
51 * @param[in] delay - delay in seconds.
52 * @throw IpmiException on failure.
53 */
54 virtual void psuResetDelay(std::uint32_t delay) const = 0;
Patrick Venture07f85152019-03-15 21:36:56 -070055
56 /**
57 * Return the entity name.
58 * On the first call to this method it'll build the list of entities.
59 * @todo Consider moving the list building to construction time (and ignore
60 * failures).
61 *
62 * @param[in] id - the entity id value
63 * @param[in] instance - the entity instance
64 * @return the entity's name
65 * @throw IpmiException on failure.
66 */
67 virtual std::string getEntityName(std::uint8_t id,
68 std::uint8_t instance) = 0;
Patrick Venture49f23ad2019-03-16 11:59:55 -070069
70 /**
71 * Populate the i2c-pcie mapping vector.
72 */
73 virtual void buildI2cPcieMapping() = 0;
74
75 /**
76 * Return the size of the i2c-pcie mapping vector.
77 *
78 * @return the size of the vector holding the i2c-pcie mapping tuples.
79 */
80 virtual size_t getI2cPcieMappingSize() const = 0;
81
82 /**
83 * Return a copy of the entry in the vector.
84 *
85 * @param[in] entry - the index into the vector.
86 * @return the tuple at that index.
87 */
88 virtual std::tuple<std::uint32_t, std::string>
89 getI2cEntry(unsigned int entry) const = 0;
Patrick Venturef085d912019-03-15 08:50:00 -070090};
91
Patrick Ventureab650002019-03-16 09:08:47 -070092/**
93 * Given a type, entity instance, and a configuration, return the name.
94 *
95 * @param[in] type - the entity type
96 * @param[in] instance - the entity instance
97 * @param[in] config - the json object holding the entity mapping
98 * @return the name of the entity from the map
99 */
100std::string readNameFromConfig(const std::string& type, uint8_t instance,
101 const nlohmann::json& config);
102
Patrick Venturef085d912019-03-15 08:50:00 -0700103} // namespace ipmi
104} // namespace google