Zev Weiss | dabd48d | 2022-08-03 15:43:17 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <Utils.hpp> |
| 3 | #include <boost/container/flat_map.hpp> |
| 4 | |
| 5 | #include <functional> |
| 6 | #include <optional> |
| 7 | #include <string_view> |
| 8 | |
| 9 | struct I2CDeviceType |
| 10 | { |
| 11 | const char* name; |
| 12 | bool createsHWMon; |
| 13 | }; |
| 14 | |
| 15 | using I2CDeviceTypeMap = |
| 16 | boost::container::flat_map<std::string, I2CDeviceType, std::less<>>; |
| 17 | |
Zev Weiss | 3ee959a | 2022-09-21 17:16:28 -0700 | [diff] [blame] | 18 | struct I2CDeviceParams |
Zev Weiss | dabd48d | 2022-08-03 15:43:17 -0700 | [diff] [blame] | 19 | { |
Zev Weiss | 3ee959a | 2022-09-21 17:16:28 -0700 | [diff] [blame] | 20 | I2CDeviceParams(const I2CDeviceType& type, uint64_t bus, uint64_t address) : |
Zev Weiss | dabd48d | 2022-08-03 15:43:17 -0700 | [diff] [blame] | 21 | type(&type), bus(bus), address(address){}; |
| 22 | |
| 23 | const I2CDeviceType* type; |
| 24 | uint64_t bus; |
| 25 | uint64_t address; |
| 26 | |
Zev Weiss | 3ee959a | 2022-09-21 17:16:28 -0700 | [diff] [blame] | 27 | bool devicePresent(void) const; |
Zev Weiss | 41f49c0 | 2022-09-21 17:27:18 -0700 | [diff] [blame] | 28 | bool deviceStatic(void) const; |
Zev Weiss | 3ee959a | 2022-09-21 17:16:28 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | std::optional<I2CDeviceParams> |
| 32 | getI2CDeviceParams(const I2CDeviceTypeMap& dtmap, |
| 33 | const SensorBaseConfigMap& cfg); |
| 34 | |
| 35 | class I2CDevice |
| 36 | { |
| 37 | public: |
| 38 | explicit I2CDevice(I2CDeviceParams params); |
| 39 | ~I2CDevice(); |
| 40 | |
| 41 | private: |
| 42 | I2CDeviceParams params; |
| 43 | |
Zev Weiss | dabd48d | 2022-08-03 15:43:17 -0700 | [diff] [blame] | 44 | int create(void) const; |
| 45 | int destroy(void) const; |
| 46 | }; |
| 47 | |
Zev Weiss | dabd48d | 2022-08-03 15:43:17 -0700 | [diff] [blame] | 48 | // HACK: this declaration "should" live in Utils.hpp, but that leads to a |
| 49 | // tangle of header-dependency hell because each header needs types declared |
| 50 | // in the other. |
| 51 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> |
| 52 | setupPropertiesChangedMatches( |
| 53 | sdbusplus::asio::connection& bus, const I2CDeviceTypeMap& typeMap, |
| 54 | const std::function<void(sdbusplus::message_t&)>& handler); |