Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "types.hpp" |
| 4 | |
| 5 | #include <sdbusplus/bus/match.hpp> |
| 6 | |
Adriana Kobylak | 52245b6 | 2021-09-13 15:46:21 +0000 | [diff] [blame] | 7 | #include <bitset> |
| 8 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 9 | namespace phosphor::power::psu |
| 10 | { |
| 11 | |
| 12 | /** |
| 13 | * @class UtilBase |
| 14 | * A base class to allow for mocking certain utility functions. |
| 15 | */ |
| 16 | class UtilBase |
| 17 | { |
| 18 | public: |
| 19 | virtual ~UtilBase() = default; |
| 20 | |
| 21 | virtual bool getPresence(sdbusplus::bus::bus& bus, |
| 22 | const std::string& invpath) const = 0; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 23 | |
| 24 | virtual void setPresence(sdbusplus::bus::bus& bus, |
| 25 | const std::string& invpath, bool present, |
| 26 | const std::string& name) const = 0; |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 27 | |
| 28 | virtual void setAvailable(sdbusplus::bus::bus& bus, |
| 29 | const std::string& invpath, |
| 30 | bool available) const = 0; |
Matt Spinler | ca1e9ea | 2022-02-18 14:03:08 -0600 | [diff] [blame] | 31 | |
| 32 | virtual void handleChassisHealthRollup(sdbusplus::bus::bus& bus, |
| 33 | const std::string& invpath, |
| 34 | bool addRollup) const = 0; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | const UtilBase& getUtils(); |
| 38 | |
| 39 | inline bool getPresence(sdbusplus::bus::bus& bus, const std::string& invpath) |
| 40 | { |
| 41 | return getUtils().getPresence(bus, invpath); |
| 42 | } |
| 43 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 44 | inline void setPresence(sdbusplus::bus::bus& bus, const std::string& invpath, |
| 45 | bool present, const std::string& name) |
| 46 | { |
| 47 | return getUtils().setPresence(bus, invpath, present, name); |
| 48 | } |
| 49 | |
Matt Spinler | 0975eaf | 2022-02-14 15:38:30 -0600 | [diff] [blame] | 50 | inline void setAvailable(sdbusplus::bus::bus& bus, const std::string& invpath, |
| 51 | bool available) |
| 52 | { |
| 53 | getUtils().setAvailable(bus, invpath, available); |
| 54 | } |
| 55 | |
Matt Spinler | ca1e9ea | 2022-02-18 14:03:08 -0600 | [diff] [blame] | 56 | inline void handleChassisHealthRollup(sdbusplus::bus::bus& bus, |
| 57 | const std::string& invpath, |
| 58 | bool addRollup) |
| 59 | { |
| 60 | getUtils().handleChassisHealthRollup(bus, invpath, addRollup); |
| 61 | } |
| 62 | |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 63 | class GPIOInterfaceBase |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 64 | { |
| 65 | public: |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 66 | virtual ~GPIOInterfaceBase() = default; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 67 | |
| 68 | virtual int read() = 0; |
Adriana Kobylak | 52245b6 | 2021-09-13 15:46:21 +0000 | [diff] [blame] | 69 | virtual void write(int value, std::bitset<32> flags) = 0; |
B. J. Wyman | d8b8cb1 | 2021-07-15 22:03:34 +0000 | [diff] [blame] | 70 | virtual std::string getName() const = 0; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 73 | } // namespace phosphor::power::psu |