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::bus& bus,
23                              const std::string& invpath) const = 0;
24 
25     virtual void setPresence(sdbusplus::bus::bus& bus,
26                              const std::string& invpath, bool present,
27                              const std::string& name) const = 0;
28 
29     virtual void setAvailable(sdbusplus::bus::bus& bus,
30                               const std::string& invpath,
31                               bool available) const = 0;
32 
33     virtual void handleChassisHealthRollup(sdbusplus::bus::bus& bus,
34                                            const std::string& invpath,
35                                            bool addRollup) const = 0;
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 
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 
51 inline void setAvailable(sdbusplus::bus::bus& bus, const std::string& invpath,
52                          bool available)
53 {
54     getUtils().setAvailable(bus, invpath, available);
55 }
56 
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 
64 class GPIOInterfaceBase
65 {
66   public:
67     virtual ~GPIOInterfaceBase() = default;
68 
69     virtual int read() = 0;
70     virtual void write(int value, std::bitset<32> flags) = 0;
71     virtual void toggleLowHigh(const std::chrono::milliseconds& delay) = 0;
72     virtual std::string getName() const = 0;
73 };
74 
75 } // namespace phosphor::power::psu
76