blob: 684abdfcb1254d91b280caff611bb8eb0f3105a7 [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>
Brandon Wyman18a24d92022-04-19 22:48:34 +00008#include <chrono>
Adriana Kobylak52245b62021-09-13 15:46:21 +00009
Brandon Wyman3f1242f2020-01-28 13:11:25 -060010namespace phosphor::power::psu
11{
12
13/**
14 * @class UtilBase
15 * A base class to allow for mocking certain utility functions.
16 */
17class UtilBase
18{
19 public:
20 virtual ~UtilBase() = default;
21
22 virtual bool getPresence(sdbusplus::bus::bus& bus,
23 const std::string& invpath) const = 0;
B. J. Wyman681b2a32021-04-20 22:31:22 +000024
25 virtual void setPresence(sdbusplus::bus::bus& bus,
26 const std::string& invpath, bool present,
27 const std::string& name) const = 0;
Matt Spinler0975eaf2022-02-14 15:38:30 -060028
29 virtual void setAvailable(sdbusplus::bus::bus& bus,
30 const std::string& invpath,
31 bool available) const = 0;
Matt Spinlerca1e9ea2022-02-18 14:03:08 -060032
33 virtual void handleChassisHealthRollup(sdbusplus::bus::bus& bus,
34 const std::string& invpath,
35 bool addRollup) const = 0;
Brandon Wyman3f1242f2020-01-28 13:11:25 -060036};
37
38const UtilBase& getUtils();
39
40inline bool getPresence(sdbusplus::bus::bus& bus, const std::string& invpath)
41{
42 return getUtils().getPresence(bus, invpath);
43}
44
B. J. Wyman681b2a32021-04-20 22:31:22 +000045inline 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
Matt Spinler0975eaf2022-02-14 15:38:30 -060051inline void setAvailable(sdbusplus::bus::bus& bus, const std::string& invpath,
52 bool available)
53{
54 getUtils().setAvailable(bus, invpath, available);
55}
56
Matt Spinlerca1e9ea2022-02-18 14:03:08 -060057inline void handleChassisHealthRollup(sdbusplus::bus::bus& bus,
58 const std::string& invpath,
59 bool addRollup)
60{
61 getUtils().handleChassisHealthRollup(bus, invpath, addRollup);
62}
63
Adriana Kobylak3ca062a2021-10-20 15:27:23 +000064class GPIOInterfaceBase
B. J. Wyman681b2a32021-04-20 22:31:22 +000065{
66 public:
Adriana Kobylak3ca062a2021-10-20 15:27:23 +000067 virtual ~GPIOInterfaceBase() = default;
B. J. Wyman681b2a32021-04-20 22:31:22 +000068
69 virtual int read() = 0;
Adriana Kobylak52245b62021-09-13 15:46:21 +000070 virtual void write(int value, std::bitset<32> flags) = 0;
Brandon Wyman18a24d92022-04-19 22:48:34 +000071 virtual void toggleLowHigh(const std::chrono::milliseconds& delay) = 0;
B. J. Wymand8b8cb12021-07-15 22:03:34 +000072 virtual std::string getName() const = 0;
B. J. Wyman681b2a32021-04-20 22:31:22 +000073};
74
Brandon Wyman3f1242f2020-01-28 13:11:25 -060075} // namespace phosphor::power::psu