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