James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 2 | |
| 3 | #include "VariantVisitors.hpp" |
| 4 | |
Zhikui Ren | da98f09 | 2021-11-01 09:41:08 -0700 | [diff] [blame] | 5 | #include <boost/algorithm/string/replace.hpp> |
James Feist | 8086aba | 2020-08-25 16:00:59 -0700 | [diff] [blame] | 6 | #include <boost/asio/steady_timer.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 7 | #include <boost/container/flat_map.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 8 | #include <sdbusplus/asio/connection.hpp> |
| 9 | #include <sdbusplus/asio/object_server.hpp> |
| 10 | #include <sdbusplus/message/types.hpp> |
| 11 | |
James Feist | 24f02f2 | 2019-04-15 11:05:39 -0700 | [diff] [blame] | 12 | #include <filesystem> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 13 | #include <functional> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 14 | #include <iostream> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 15 | #include <memory> |
Bruce Mitchell | 544e7dc | 2021-07-29 18:05:49 -0500 | [diff] [blame] | 16 | #include <optional> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 17 | #include <regex> |
Zev Weiss | 214d971 | 2022-08-12 12:54:31 -0700 | [diff] [blame] | 18 | #include <span> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <tuple> |
| 21 | #include <utility> |
| 22 | #include <variant> |
| 23 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 24 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 25 | const constexpr char* jsonStore = "/var/configuration/flattened.json"; |
| 26 | const constexpr char* inventoryPath = "/xyz/openbmc_project/inventory"; |
| 27 | const constexpr char* entityManagerName = "xyz.openbmc_project.EntityManager"; |
James Feist | 58295ad | 2019-05-30 15:01:41 -0700 | [diff] [blame] | 28 | |
| 29 | constexpr const char* cpuInventoryPath = |
| 30 | "/xyz/openbmc_project/inventory/system/chassis/motherboard"; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 31 | const std::regex illegalDbusRegex("[^A-Za-z0-9_]"); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 32 | |
| 33 | using BasicVariantType = |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 34 | std::variant<std::vector<std::string>, std::string, int64_t, uint64_t, |
| 35 | double, int32_t, uint32_t, int16_t, uint16_t, uint8_t, bool>; |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 36 | using SensorBaseConfigMap = |
| 37 | boost::container::flat_map<std::string, BasicVariantType>; |
| 38 | using SensorBaseConfiguration = std::pair<std::string, SensorBaseConfigMap>; |
| 39 | using SensorData = boost::container::flat_map<std::string, SensorBaseConfigMap>; |
| 40 | using ManagedObjectType = |
| 41 | boost::container::flat_map<sdbusplus::message::object_path, SensorData>; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 42 | |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 43 | using GetSubTreeType = std::vector< |
| 44 | std::pair<std::string, |
| 45 | std::vector<std::pair<std::string, std::vector<std::string>>>>>; |
James Feist | d8bd562 | 2019-06-26 12:09:05 -0700 | [diff] [blame] | 46 | using Association = std::tuple<std::string, std::string, std::string>; |
| 47 | |
Zhikui Ren | da98f09 | 2021-11-01 09:41:08 -0700 | [diff] [blame] | 48 | inline std::string escapeName(const std::string& sensorName) |
| 49 | { |
| 50 | return boost::replace_all_copy(sensorName, " ", "_"); |
| 51 | } |
| 52 | |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 53 | enum class PowerState |
| 54 | { |
| 55 | on, |
| 56 | biosPost, |
Thu Nguyen | 6db8aae | 2022-10-04 08:12:48 +0700 | [diff] [blame] | 57 | always, |
| 58 | chassisOn |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Jason Ling | 100c20b | 2020-08-11 14:50:33 -0700 | [diff] [blame] | 61 | std::optional<std::string> openAndRead(const std::string& hwmonFile); |
| 62 | std::optional<std::string> |
| 63 | getFullHwmonFilePath(const std::string& directory, |
| 64 | const std::string& hwmonBaseName, |
| 65 | const std::set<std::string>& permitSet); |
| 66 | std::set<std::string> getPermitSet(const SensorBaseConfigMap& config); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 67 | bool findFiles(const std::filesystem::path& dirPath, |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 68 | std::string_view matchString, |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 69 | std::vector<std::filesystem::path>& foundPaths, |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 70 | int symlinkDepth = 1); |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 71 | bool isPowerOn(void); |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 72 | bool hasBiosPost(void); |
Thu Nguyen | 6db8aae | 2022-10-04 08:12:48 +0700 | [diff] [blame] | 73 | bool isChassisOn(void); |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 74 | void setupPowerMatchCallback( |
| 75 | const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 76 | std::function<void(PowerState type, bool state)>&& callback); |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 77 | void setupPowerMatch(const std::shared_ptr<sdbusplus::asio::connection>& conn); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 78 | bool getSensorConfiguration( |
| 79 | const std::string& type, |
| 80 | const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 81 | ManagedObjectType& resp, bool useCache); |
| 82 | |
| 83 | bool getSensorConfiguration( |
| 84 | const std::string& type, |
| 85 | const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 86 | ManagedObjectType& resp); |
James Feist | 87d713a | 2018-12-06 16:06:24 -0800 | [diff] [blame] | 87 | |
James Feist | 82bac4c | 2019-03-11 11:16:53 -0700 | [diff] [blame] | 88 | void createAssociation( |
| 89 | std::shared_ptr<sdbusplus::asio::dbus_interface>& association, |
| 90 | const std::string& path); |
| 91 | |
James Feist | 87d713a | 2018-12-06 16:06:24 -0800 | [diff] [blame] | 92 | // replaces limits if MinReading and MaxReading are found. |
| 93 | void findLimits(std::pair<double, double>& limits, |
James Feist | 40a7214 | 2018-12-21 10:09:53 -0800 | [diff] [blame] | 94 | const SensorBaseConfiguration* data); |
| 95 | |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 96 | bool readingStateGood(const PowerState& powerState); |
| 97 | |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 98 | constexpr const char* configInterfacePrefix = |
| 99 | "xyz.openbmc_project.Configuration."; |
| 100 | |
| 101 | inline std::string configInterfaceName(const std::string& type) |
| 102 | { |
| 103 | return std::string(configInterfacePrefix) + type; |
| 104 | } |
| 105 | |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 106 | namespace mapper |
| 107 | { |
| 108 | constexpr const char* busName = "xyz.openbmc_project.ObjectMapper"; |
| 109 | constexpr const char* path = "/xyz/openbmc_project/object_mapper"; |
| 110 | constexpr const char* interface = "xyz.openbmc_project.ObjectMapper"; |
| 111 | constexpr const char* subtree = "GetSubTree"; |
| 112 | } // namespace mapper |
| 113 | |
| 114 | namespace properties |
| 115 | { |
| 116 | constexpr const char* interface = "org.freedesktop.DBus.Properties"; |
| 117 | constexpr const char* get = "Get"; |
James Feist | 49a8ccd | 2020-09-16 16:09:52 -0700 | [diff] [blame] | 118 | constexpr const char* set = "Set"; |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 119 | } // namespace properties |
| 120 | |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 121 | namespace power |
| 122 | { |
| 123 | const static constexpr char* busname = "xyz.openbmc_project.State.Host"; |
| 124 | const static constexpr char* interface = "xyz.openbmc_project.State.Host"; |
| 125 | const static constexpr char* path = "/xyz/openbmc_project/state/host0"; |
| 126 | const static constexpr char* property = "CurrentHostState"; |
| 127 | } // namespace power |
Thu Nguyen | 6db8aae | 2022-10-04 08:12:48 +0700 | [diff] [blame] | 128 | |
| 129 | namespace chassis |
| 130 | { |
| 131 | const static constexpr char* busname = "xyz.openbmc_project.State.Chassis"; |
| 132 | const static constexpr char* interface = "xyz.openbmc_project.State.Chassis"; |
| 133 | const static constexpr char* path = "/xyz/openbmc_project/state/chassis0"; |
| 134 | const static constexpr char* property = "CurrentPowerState"; |
| 135 | const static constexpr char* sOn = "On"; |
| 136 | } // namespace chassis |
| 137 | |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 138 | namespace post |
| 139 | { |
| 140 | const static constexpr char* busname = |
| 141 | "xyz.openbmc_project.State.OperatingSystem"; |
| 142 | const static constexpr char* interface = |
| 143 | "xyz.openbmc_project.State.OperatingSystem.Status"; |
| 144 | const static constexpr char* path = "/xyz/openbmc_project/state/os"; |
| 145 | const static constexpr char* property = "OperatingSystemState"; |
| 146 | } // namespace post |
| 147 | |
James Feist | 2adc95c | 2019-09-30 14:55:28 -0700 | [diff] [blame] | 148 | namespace association |
| 149 | { |
| 150 | const static constexpr char* interface = |
| 151 | "xyz.openbmc_project.Association.Definitions"; |
| 152 | } // namespace association |
| 153 | |
James Feist | 40a7214 | 2018-12-21 10:09:53 -0800 | [diff] [blame] | 154 | template <typename T> |
Zev Weiss | afd1504 | 2022-07-18 12:28:40 -0700 | [diff] [blame] | 155 | inline T loadVariant(const SensorBaseConfigMap& data, const std::string& key) |
James Feist | 40a7214 | 2018-12-21 10:09:53 -0800 | [diff] [blame] | 156 | { |
| 157 | auto it = data.find(key); |
| 158 | if (it == data.end()) |
| 159 | { |
| 160 | std::cerr << "Configuration missing " << key << "\n"; |
| 161 | throw std::invalid_argument("Key Missing"); |
| 162 | } |
| 163 | if constexpr (std::is_same_v<T, double>) |
| 164 | { |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 165 | return std::visit(VariantToDoubleVisitor(), it->second); |
James Feist | 40a7214 | 2018-12-21 10:09:53 -0800 | [diff] [blame] | 166 | } |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 167 | else if constexpr (std::is_unsigned_v<T>) |
| 168 | { |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 169 | return std::visit(VariantToUnsignedIntVisitor(), it->second); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 170 | } |
James Feist | 40a7214 | 2018-12-21 10:09:53 -0800 | [diff] [blame] | 171 | else if constexpr (std::is_same_v<T, std::string>) |
| 172 | { |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 173 | return std::visit(VariantToStringVisitor(), it->second); |
James Feist | 40a7214 | 2018-12-21 10:09:53 -0800 | [diff] [blame] | 174 | } |
| 175 | else |
| 176 | { |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 177 | static_assert(!std::is_same_v<T, T>, "Type Not Implemented"); |
James Feist | 40a7214 | 2018-12-21 10:09:53 -0800 | [diff] [blame] | 178 | } |
| 179 | } |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 180 | |
| 181 | inline void setReadState(const std::string& str, PowerState& val) |
| 182 | { |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 183 | if (str == "On") |
| 184 | { |
| 185 | val = PowerState::on; |
| 186 | } |
| 187 | else if (str == "BiosPost") |
| 188 | { |
| 189 | val = PowerState::biosPost; |
| 190 | } |
| 191 | else if (str == "Always") |
| 192 | { |
| 193 | val = PowerState::always; |
| 194 | } |
Thu Nguyen | 6db8aae | 2022-10-04 08:12:48 +0700 | [diff] [blame] | 195 | else if (str == "ChassisOn") |
| 196 | { |
| 197 | val = PowerState::chassisOn; |
| 198 | } |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 199 | } |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 200 | |
Zev Weiss | a4d2768 | 2022-07-19 15:30:36 -0700 | [diff] [blame] | 201 | inline PowerState getPowerState(const SensorBaseConfigMap& cfg) |
| 202 | { |
| 203 | PowerState state = PowerState::always; |
| 204 | auto findPowerState = cfg.find("PowerState"); |
| 205 | if (findPowerState != cfg.end()) |
| 206 | { |
Patrick Williams | 779c96a | 2023-05-10 07:50:42 -0500 | [diff] [blame] | 207 | std::string powerState = std::visit(VariantToStringVisitor(), |
| 208 | findPowerState->second); |
Zev Weiss | a4d2768 | 2022-07-19 15:30:36 -0700 | [diff] [blame] | 209 | setReadState(powerState, state); |
| 210 | } |
| 211 | return state; |
| 212 | } |
| 213 | |
Zev Weiss | 8569bf2 | 2022-10-11 15:37:44 -0700 | [diff] [blame] | 214 | inline float getPollRate(const SensorBaseConfigMap& cfg, float dflt) |
| 215 | { |
| 216 | float pollRate = dflt; |
| 217 | auto findPollRate = cfg.find("PollRate"); |
| 218 | if (findPollRate != cfg.end()) |
| 219 | { |
| 220 | pollRate = std::visit(VariantToFloatVisitor(), findPollRate->second); |
| 221 | if (!std::isfinite(pollRate) || pollRate <= 0.0F) |
| 222 | { |
| 223 | pollRate = dflt; // poll time invalid, fall back to default |
| 224 | } |
| 225 | } |
| 226 | return pollRate; |
| 227 | } |
| 228 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 229 | inline void setLed(const std::shared_ptr<sdbusplus::asio::connection>& conn, |
James Feist | 49a8ccd | 2020-09-16 16:09:52 -0700 | [diff] [blame] | 230 | const std::string& name, bool on) |
| 231 | { |
| 232 | conn->async_method_call( |
| 233 | [name](const boost::system::error_code ec) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 234 | if (ec) |
| 235 | { |
| 236 | std::cerr << "Failed to set LED " << name << "\n"; |
| 237 | } |
James Feist | 49a8ccd | 2020-09-16 16:09:52 -0700 | [diff] [blame] | 238 | }, |
| 239 | "xyz.openbmc_project.LED.GroupManager", |
| 240 | "/xyz/openbmc_project/led/groups/" + name, properties::interface, |
| 241 | properties::set, "xyz.openbmc_project.Led.Group", "Asserted", |
| 242 | std::variant<bool>(on)); |
| 243 | } |
| 244 | |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 245 | void createInventoryAssoc( |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 246 | const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 247 | const std::shared_ptr<sdbusplus::asio::dbus_interface>& association, |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 248 | const std::string& path); |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 249 | |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 250 | struct GetSensorConfiguration : |
| 251 | std::enable_shared_from_this<GetSensorConfiguration> |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 252 | { |
| 253 | GetSensorConfiguration( |
| 254 | std::shared_ptr<sdbusplus::asio::connection> connection, |
| 255 | std::function<void(ManagedObjectType& resp)>&& callbackFunc) : |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 256 | dbusConnection(std::move(connection)), |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 257 | callback(std::move(callbackFunc)) |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 258 | {} |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 259 | |
| 260 | void getPath(const std::string& path, const std::string& interface, |
| 261 | const std::string& owner, size_t retries = 5) |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 262 | { |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 263 | if (retries > 5) |
| 264 | { |
| 265 | retries = 5; |
| 266 | } |
| 267 | std::shared_ptr<GetSensorConfiguration> self = shared_from_this(); |
| 268 | |
| 269 | self->dbusConnection->async_method_call( |
Zev Weiss | afd1504 | 2022-07-18 12:28:40 -0700 | [diff] [blame] | 270 | [self, path, interface, owner, retries]( |
| 271 | const boost::system::error_code ec, SensorBaseConfigMap& data) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 272 | if (ec) |
| 273 | { |
| 274 | std::cerr << "Error getting " << path << ": retries left" |
| 275 | << retries - 1 << "\n"; |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 276 | if (retries == 0U) |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 277 | { |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 278 | return; |
| 279 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 280 | auto timer = std::make_shared<boost::asio::steady_timer>( |
| 281 | self->dbusConnection->get_io_context()); |
| 282 | timer->expires_after(std::chrono::seconds(10)); |
| 283 | timer->async_wait([self, timer, path, interface, owner, |
| 284 | retries](boost::system::error_code ec) { |
| 285 | if (ec) |
| 286 | { |
| 287 | std::cerr << "Timer error!\n"; |
| 288 | return; |
| 289 | } |
| 290 | self->getPath(path, interface, owner, retries - 1); |
| 291 | }); |
| 292 | return; |
| 293 | } |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 294 | |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 295 | self->respData[path][interface] = std::move(data); |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 296 | }, |
| 297 | owner, path, "org.freedesktop.DBus.Properties", "GetAll", |
| 298 | interface); |
| 299 | } |
| 300 | |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 301 | void getConfiguration(const std::vector<std::string>& types, |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 302 | size_t retries = 0) |
| 303 | { |
| 304 | if (retries > 5) |
| 305 | { |
| 306 | retries = 5; |
| 307 | } |
| 308 | |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 309 | std::vector<std::string> interfaces(types.size()); |
| 310 | for (const auto& type : types) |
| 311 | { |
| 312 | interfaces.push_back(configInterfaceName(type)); |
| 313 | } |
| 314 | |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 315 | std::shared_ptr<GetSensorConfiguration> self = shared_from_this(); |
| 316 | dbusConnection->async_method_call( |
James Feist | f27a55c | 2020-08-04 14:27:30 -0700 | [diff] [blame] | 317 | [self, interfaces, retries](const boost::system::error_code ec, |
| 318 | const GetSubTreeType& ret) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 319 | if (ec) |
| 320 | { |
| 321 | std::cerr << "Error calling mapper\n"; |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 322 | if (retries == 0U) |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 323 | { |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 324 | return; |
| 325 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 326 | auto timer = std::make_shared<boost::asio::steady_timer>( |
| 327 | self->dbusConnection->get_io_context()); |
| 328 | timer->expires_after(std::chrono::seconds(10)); |
| 329 | timer->async_wait([self, timer, interfaces, |
| 330 | retries](boost::system::error_code ec) { |
| 331 | if (ec) |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 332 | { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 333 | std::cerr << "Timer error!\n"; |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 334 | return; |
| 335 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 336 | self->getConfiguration(interfaces, retries - 1); |
| 337 | }); |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 338 | |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 339 | return; |
| 340 | } |
| 341 | for (const auto& [path, objDict] : ret) |
| 342 | { |
| 343 | if (objDict.empty()) |
| 344 | { |
| 345 | return; |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 346 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 347 | const std::string& owner = objDict.begin()->first; |
| 348 | |
| 349 | for (const std::string& interface : objDict.begin()->second) |
| 350 | { |
| 351 | // anything that starts with a requested configuration |
| 352 | // is good |
| 353 | if (std::find_if(interfaces.begin(), interfaces.end(), |
| 354 | [interface](const std::string& possible) { |
Zev Weiss | 6c106d6 | 2022-08-17 20:50:00 -0700 | [diff] [blame] | 355 | return interface.starts_with(possible); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 356 | }) == interfaces.end()) |
| 357 | { |
| 358 | continue; |
| 359 | } |
| 360 | self->getPath(path, interface, owner); |
| 361 | } |
| 362 | } |
James Feist | c71c119 | 2019-09-18 14:31:33 -0700 | [diff] [blame] | 363 | }, |
| 364 | mapper::busName, mapper::path, mapper::interface, mapper::subtree, |
| 365 | "/", 0, interfaces); |
| 366 | } |
| 367 | |
| 368 | ~GetSensorConfiguration() |
| 369 | { |
| 370 | callback(respData); |
| 371 | } |
| 372 | |
| 373 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; |
| 374 | std::function<void(ManagedObjectType& resp)> callback; |
| 375 | ManagedObjectType respData; |
| 376 | }; |
Zbigniew Kurzynski | 63f3866 | 2020-06-09 13:02:11 +0200 | [diff] [blame] | 377 | |
| 378 | // The common scheme for sysfs files naming is: <type><number>_<item>. |
| 379 | // This function returns optionally these 3 elements as a tuple. |
| 380 | std::optional<std::tuple<std::string, std::string, std::string>> |
| 381 | splitFileName(const std::filesystem::path& filePath); |
| 382 | std::optional<double> readFile(const std::string& thresholdFile, |
James Feist | 8086aba | 2020-08-25 16:00:59 -0700 | [diff] [blame] | 383 | const double& scaleFactor); |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 384 | void setupManufacturingModeMatch(sdbusplus::asio::connection& conn); |
| 385 | bool getManufacturingMode(); |
Zev Weiss | 214d971 | 2022-08-12 12:54:31 -0700 | [diff] [blame] | 386 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> |
| 387 | setupPropertiesChangedMatches( |
| 388 | sdbusplus::asio::connection& bus, std::span<const char* const> types, |
| 389 | const std::function<void(sdbusplus::message_t&)>& handler); |