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 virtual std::string getChassis(sdbusplus::bus_t& /*bus*/,
36 const std::string& /*invpath*/) const = 0;
37 };
38
39 const UtilBase& getUtils();
40
getPresence(sdbusplus::bus_t & bus,const std::string & invpath)41 inline bool getPresence(sdbusplus::bus_t& bus, const std::string& invpath)
42 {
43 return getUtils().getPresence(bus, invpath);
44 }
45
setPresence(sdbusplus::bus_t & bus,const std::string & invpath,bool present,const std::string & name)46 inline void setPresence(sdbusplus::bus_t& bus, const std::string& invpath,
47 bool present, const std::string& name)
48 {
49 return getUtils().setPresence(bus, invpath, present, name);
50 }
51
setAvailable(sdbusplus::bus_t & bus,const std::string & invpath,bool available)52 inline void setAvailable(sdbusplus::bus_t& bus, const std::string& invpath,
53 bool available)
54 {
55 getUtils().setAvailable(bus, invpath, available);
56 }
57
handleChassisHealthRollup(sdbusplus::bus_t & bus,const std::string & invpath,bool addRollup)58 inline void handleChassisHealthRollup(sdbusplus::bus_t& bus,
59 const std::string& invpath,
60 bool addRollup)
61 {
62 getUtils().handleChassisHealthRollup(bus, invpath, addRollup);
63 }
64
getChassis(sdbusplus::bus_t & bus,const std::string & invpath)65 inline std::string getChassis(sdbusplus::bus_t& bus, const std::string& invpath)
66 {
67 return getUtils().getChassis(bus, invpath);
68 }
69
70 class GPIOInterfaceBase
71 {
72 public:
73 virtual ~GPIOInterfaceBase() = default;
74
75 virtual int read() = 0;
76 virtual void write(int value, std::bitset<32> flags) = 0;
77 virtual void toggleLowHigh(const std::chrono::milliseconds& delay) = 0;
78 virtual std::string getName() const = 0;
79 };
80
81 } // namespace phosphor::power::psu
82