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