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