blob: b9d5e2e6015cafbc254676f68b6355adc3cd06bc [file] [log] [blame]
Brandon Wyman3f1242f2020-01-28 13:11:25 -06001#pragma once
2
3#include "types.hpp"
4
5#include <sdbusplus/bus/match.hpp>
6
Adriana Kobylak52245b62021-09-13 15:46:21 +00007#include <bitset>
Brandon Wyman18a24d92022-04-19 22:48:34 +00008#include <chrono>
Adriana Kobylak52245b62021-09-13 15:46:21 +00009
Brandon Wyman3f1242f2020-01-28 13:11:25 -060010namespace phosphor::power::psu
11{
12
13/**
14 * @class UtilBase
15 * A base class to allow for mocking certain utility functions.
16 */
17class UtilBase
18{
19 public:
20 virtual ~UtilBase() = default;
21
Patrick Williams7354ce62022-07-22 19:26:56 -050022 virtual bool getPresence(sdbusplus::bus_t& bus,
Brandon Wyman3f1242f2020-01-28 13:11:25 -060023 const std::string& invpath) const = 0;
B. J. Wyman681b2a32021-04-20 22:31:22 +000024
Patrick Williams7354ce62022-07-22 19:26:56 -050025 virtual void setPresence(sdbusplus::bus_t& bus, const std::string& invpath,
26 bool present, const std::string& name) const = 0;
Matt Spinler0975eaf2022-02-14 15:38:30 -060027
Patrick Williams7354ce62022-07-22 19:26:56 -050028 virtual void setAvailable(sdbusplus::bus_t& bus, const std::string& invpath,
Matt Spinler0975eaf2022-02-14 15:38:30 -060029 bool available) const = 0;
Matt Spinlerca1e9ea2022-02-18 14:03:08 -060030
Patrick Williams7354ce62022-07-22 19:26:56 -050031 virtual void handleChassisHealthRollup(sdbusplus::bus_t& bus,
Matt Spinlerca1e9ea2022-02-18 14:03:08 -060032 const std::string& invpath,
33 bool addRollup) const = 0;
Matt Spinler592bd272023-08-30 11:00:01 -050034
35 virtual std::string getChassis(sdbusplus::bus_t& /*bus*/,
36 const std::string& /*invpath*/) const = 0;
Brandon Wyman3f1242f2020-01-28 13:11:25 -060037};
38
39const UtilBase& getUtils();
40
Patrick Williams7354ce62022-07-22 19:26:56 -050041inline bool getPresence(sdbusplus::bus_t& bus, const std::string& invpath)
Brandon Wyman3f1242f2020-01-28 13:11:25 -060042{
43 return getUtils().getPresence(bus, invpath);
44}
45
Patrick Williams7354ce62022-07-22 19:26:56 -050046inline void setPresence(sdbusplus::bus_t& bus, const std::string& invpath,
B. J. Wyman681b2a32021-04-20 22:31:22 +000047 bool present, const std::string& name)
48{
49 return getUtils().setPresence(bus, invpath, present, name);
50}
51
Patrick Williams7354ce62022-07-22 19:26:56 -050052inline void setAvailable(sdbusplus::bus_t& bus, const std::string& invpath,
Matt Spinler0975eaf2022-02-14 15:38:30 -060053 bool available)
54{
55 getUtils().setAvailable(bus, invpath, available);
56}
57
Patrick Williams7354ce62022-07-22 19:26:56 -050058inline void handleChassisHealthRollup(sdbusplus::bus_t& bus,
Matt Spinlerca1e9ea2022-02-18 14:03:08 -060059 const std::string& invpath,
60 bool addRollup)
61{
62 getUtils().handleChassisHealthRollup(bus, invpath, addRollup);
63}
64
Matt Spinler592bd272023-08-30 11:00:01 -050065inline std::string getChassis(sdbusplus::bus_t& bus, const std::string& invpath)
66{
67 return getUtils().getChassis(bus, invpath);
68}
69
Adriana Kobylak3ca062a2021-10-20 15:27:23 +000070class GPIOInterfaceBase
B. J. Wyman681b2a32021-04-20 22:31:22 +000071{
72 public:
Adriana Kobylak3ca062a2021-10-20 15:27:23 +000073 virtual ~GPIOInterfaceBase() = default;
B. J. Wyman681b2a32021-04-20 22:31:22 +000074
75 virtual int read() = 0;
Adriana Kobylak52245b62021-09-13 15:46:21 +000076 virtual void write(int value, std::bitset<32> flags) = 0;
Brandon Wyman18a24d92022-04-19 22:48:34 +000077 virtual void toggleLowHigh(const std::chrono::milliseconds& delay) = 0;
B. J. Wymand8b8cb12021-07-15 22:03:34 +000078 virtual std::string getName() const = 0;
B. J. Wyman681b2a32021-04-20 22:31:22 +000079};
80
Brandon Wyman3f1242f2020-01-28 13:11:25 -060081} // namespace phosphor::power::psu