blob: bb7dc3caacd4ae2533040e11e4add35c63ead51a [file] [log] [blame]
Brandon Wyman3f1242f2020-01-28 13:11:25 -06001#pragma once
2
3#include "types.hpp"
4
5#include <sdbusplus/bus/match.hpp>
6
Adriana Kobylak52245b62021-09-13 15:46:21 +00007#include <bitset>
8
Brandon Wyman3f1242f2020-01-28 13:11:25 -06009namespace phosphor::power::psu
10{
11
12/**
13 * @class UtilBase
14 * A base class to allow for mocking certain utility functions.
15 */
16class UtilBase
17{
18 public:
19 virtual ~UtilBase() = default;
20
21 virtual bool getPresence(sdbusplus::bus::bus& bus,
22 const std::string& invpath) const = 0;
B. J. Wyman681b2a32021-04-20 22:31:22 +000023
24 virtual void setPresence(sdbusplus::bus::bus& bus,
25 const std::string& invpath, bool present,
26 const std::string& name) const = 0;
Matt Spinler0975eaf2022-02-14 15:38:30 -060027
28 virtual void setAvailable(sdbusplus::bus::bus& bus,
29 const std::string& invpath,
30 bool available) const = 0;
Brandon Wyman3f1242f2020-01-28 13:11:25 -060031};
32
33const UtilBase& getUtils();
34
35inline bool getPresence(sdbusplus::bus::bus& bus, const std::string& invpath)
36{
37 return getUtils().getPresence(bus, invpath);
38}
39
B. J. Wyman681b2a32021-04-20 22:31:22 +000040inline void setPresence(sdbusplus::bus::bus& bus, const std::string& invpath,
41 bool present, const std::string& name)
42{
43 return getUtils().setPresence(bus, invpath, present, name);
44}
45
Matt Spinler0975eaf2022-02-14 15:38:30 -060046inline void setAvailable(sdbusplus::bus::bus& bus, const std::string& invpath,
47 bool available)
48{
49 getUtils().setAvailable(bus, invpath, available);
50}
51
Adriana Kobylak3ca062a2021-10-20 15:27:23 +000052class GPIOInterfaceBase
B. J. Wyman681b2a32021-04-20 22:31:22 +000053{
54 public:
Adriana Kobylak3ca062a2021-10-20 15:27:23 +000055 virtual ~GPIOInterfaceBase() = default;
B. J. Wyman681b2a32021-04-20 22:31:22 +000056
57 virtual int read() = 0;
Adriana Kobylak52245b62021-09-13 15:46:21 +000058 virtual void write(int value, std::bitset<32> flags) = 0;
B. J. Wymand8b8cb12021-07-15 22:03:34 +000059 virtual std::string getName() const = 0;
B. J. Wyman681b2a32021-04-20 22:31:22 +000060};
61
Brandon Wyman3f1242f2020-01-28 13:11:25 -060062} // namespace phosphor::power::psu