blob: 5d38a518b5357aa26ee47f48db8f4b47fd6d663c [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;
Brandon Wyman3f1242f2020-01-28 13:11:25 -060034};
35
36const UtilBase& getUtils();
37
Patrick Williams7354ce62022-07-22 19:26:56 -050038inline bool getPresence(sdbusplus::bus_t& bus, const std::string& invpath)
Brandon Wyman3f1242f2020-01-28 13:11:25 -060039{
40 return getUtils().getPresence(bus, invpath);
41}
42
Patrick Williams7354ce62022-07-22 19:26:56 -050043inline void setPresence(sdbusplus::bus_t& bus, const std::string& invpath,
B. J. Wyman681b2a32021-04-20 22:31:22 +000044 bool present, const std::string& name)
45{
46 return getUtils().setPresence(bus, invpath, present, name);
47}
48
Patrick Williams7354ce62022-07-22 19:26:56 -050049inline void setAvailable(sdbusplus::bus_t& bus, const std::string& invpath,
Matt Spinler0975eaf2022-02-14 15:38:30 -060050 bool available)
51{
52 getUtils().setAvailable(bus, invpath, available);
53}
54
Patrick Williams7354ce62022-07-22 19:26:56 -050055inline void handleChassisHealthRollup(sdbusplus::bus_t& bus,
Matt Spinlerca1e9ea2022-02-18 14:03:08 -060056 const std::string& invpath,
57 bool addRollup)
58{
59 getUtils().handleChassisHealthRollup(bus, invpath, addRollup);
60}
61
Adriana Kobylak3ca062a2021-10-20 15:27:23 +000062class GPIOInterfaceBase
B. J. Wyman681b2a32021-04-20 22:31:22 +000063{
64 public:
Adriana Kobylak3ca062a2021-10-20 15:27:23 +000065 virtual ~GPIOInterfaceBase() = default;
B. J. Wyman681b2a32021-04-20 22:31:22 +000066
67 virtual int read() = 0;
Adriana Kobylak52245b62021-09-13 15:46:21 +000068 virtual void write(int value, std::bitset<32> flags) = 0;
Brandon Wyman18a24d92022-04-19 22:48:34 +000069 virtual void toggleLowHigh(const std::chrono::milliseconds& delay) = 0;
B. J. Wymand8b8cb12021-07-15 22:03:34 +000070 virtual std::string getName() const = 0;
B. J. Wyman681b2a32021-04-20 22:31:22 +000071};
72
Brandon Wyman3f1242f2020-01-28 13:11:25 -060073} // namespace phosphor::power::psu