1 #pragma once
2 
3 #include "types.hpp"
4 
5 #include <sdbusplus/bus/match.hpp>
6 
7 #include <bitset>
8 #include <chrono>
9 
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_t& bus,
23                              const std::string& invpath) const = 0;
24 
25     virtual void setPresence(sdbusplus::bus_t& bus, const std::string& invpath,
26                              bool present, const std::string& name) const = 0;
27 
28     virtual void setAvailable(sdbusplus::bus_t& bus, const std::string& invpath,
29                               bool available) const = 0;
30 
31     virtual void handleChassisHealthRollup(sdbusplus::bus_t& bus,
32                                            const std::string& invpath,
33                                            bool addRollup) const = 0;
34 };
35 
36 const UtilBase& getUtils();
37 
38 inline bool getPresence(sdbusplus::bus_t& bus, const std::string& invpath)
39 {
40     return getUtils().getPresence(bus, invpath);
41 }
42 
43 inline void setPresence(sdbusplus::bus_t& bus, const std::string& invpath,
44                         bool present, const std::string& name)
45 {
46     return getUtils().setPresence(bus, invpath, present, name);
47 }
48 
49 inline void setAvailable(sdbusplus::bus_t& bus, const std::string& invpath,
50                          bool available)
51 {
52     getUtils().setAvailable(bus, invpath, available);
53 }
54 
55 inline void handleChassisHealthRollup(sdbusplus::bus_t& bus,
56                                       const std::string& invpath,
57                                       bool addRollup)
58 {
59     getUtils().handleChassisHealthRollup(bus, invpath, addRollup);
60 }
61 
62 class GPIOInterfaceBase
63 {
64   public:
65     virtual ~GPIOInterfaceBase() = default;
66 
67     virtual int read() = 0;
68     virtual void write(int value, std::bitset<32> flags) = 0;
69     virtual void toggleLowHigh(const std::chrono::milliseconds& delay) = 0;
70     virtual std::string getName() const = 0;
71 };
72 
73 } // namespace phosphor::power::psu
74