James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
Brad Bishop | e45d8c7 | 2022-05-25 15:12:53 -0400 | [diff] [blame] | 16 | /// \file entity_manager.cpp |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 17 | |
Brad Bishop | e45d8c7 | 2022-05-25 15:12:53 -0400 | [diff] [blame] | 18 | #include "entity_manager.hpp" |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 19 | |
Brad Bishop | e45d8c7 | 2022-05-25 15:12:53 -0400 | [diff] [blame] | 20 | #include "overlay.hpp" |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 21 | #include "topology.hpp" |
Brad Bishop | e45d8c7 | 2022-05-25 15:12:53 -0400 | [diff] [blame] | 22 | #include "utils.hpp" |
| 23 | #include "variant_visitors.hpp" |
James Feist | 481c5d5 | 2019-08-13 14:40:40 -0700 | [diff] [blame] | 24 | |
James Feist | 11be667 | 2018-04-06 14:05:32 -0700 | [diff] [blame] | 25 | #include <boost/algorithm/string/case_conv.hpp> |
James Feist | f5125b0 | 2019-06-06 11:27:43 -0700 | [diff] [blame] | 26 | #include <boost/algorithm/string/classification.hpp> |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 27 | #include <boost/algorithm/string/predicate.hpp> |
| 28 | #include <boost/algorithm/string/replace.hpp> |
James Feist | f5125b0 | 2019-06-06 11:27:43 -0700 | [diff] [blame] | 29 | #include <boost/algorithm/string/split.hpp> |
James Feist | 02d2b93 | 2020-02-06 16:28:48 -0800 | [diff] [blame] | 30 | #include <boost/asio/io_context.hpp> |
Ed Tanous | 49a888c | 2023-03-06 13:44:51 -0800 | [diff] [blame] | 31 | #include <boost/asio/post.hpp> |
James Feist | b1728ca | 2020-04-30 15:40:55 -0700 | [diff] [blame] | 32 | #include <boost/asio/steady_timer.hpp> |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 33 | #include <boost/container/flat_map.hpp> |
| 34 | #include <boost/container/flat_set.hpp> |
James Feist | f5125b0 | 2019-06-06 11:27:43 -0700 | [diff] [blame] | 35 | #include <boost/range/iterator_range.hpp> |
James Feist | 8c505da | 2020-05-28 10:06:33 -0700 | [diff] [blame] | 36 | #include <nlohmann/json.hpp> |
| 37 | #include <sdbusplus/asio/connection.hpp> |
| 38 | #include <sdbusplus/asio/object_server.hpp> |
| 39 | |
Igor Kononenko | 9fd87e5 | 2020-10-06 01:18:17 +0300 | [diff] [blame] | 40 | #include <charconv> |
James Feist | 637b3ef | 2019-04-15 16:35:30 -0700 | [diff] [blame] | 41 | #include <filesystem> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 42 | #include <fstream> |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 43 | #include <functional> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 44 | #include <iostream> |
Andrew Jeffery | 666583b | 2021-12-01 15:50:12 +1030 | [diff] [blame] | 45 | #include <map> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 46 | #include <regex> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 47 | #include <variant> |
Andrew Jeffery | a9c5892 | 2021-06-01 09:28:59 +0930 | [diff] [blame] | 48 | constexpr const char* hostConfigurationDirectory = SYSCONF_DIR "configurations"; |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 49 | constexpr const char* configurationDirectory = PACKAGE_DIR "configurations"; |
| 50 | constexpr const char* schemaDirectory = PACKAGE_DIR "configurations/schemas"; |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 51 | constexpr const char* tempConfigDir = "/tmp/configuration/"; |
| 52 | constexpr const char* lastConfiguration = "/tmp/configuration/last.json"; |
| 53 | constexpr const char* currentConfiguration = "/var/configuration/system.json"; |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 54 | constexpr const char* globalSchema = "global.json"; |
James Feist | f1b1414 | 2019-04-10 15:22:09 -0700 | [diff] [blame] | 55 | |
Andrew Jeffery | 666583b | 2021-12-01 15:50:12 +1030 | [diff] [blame] | 56 | const boost::container::flat_map<const char*, probe_type_codes, CmpStr> |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 57 | probeTypes{{{"FALSE", probe_type_codes::FALSE_T}, |
| 58 | {"TRUE", probe_type_codes::TRUE_T}, |
| 59 | {"AND", probe_type_codes::AND}, |
| 60 | {"OR", probe_type_codes::OR}, |
| 61 | {"FOUND", probe_type_codes::FOUND}, |
| 62 | {"MATCH_ONE", probe_type_codes::MATCH_ONE}}}; |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 63 | |
Adrian Ambrożewicz | c789fca | 2020-05-14 15:50:05 +0200 | [diff] [blame] | 64 | static constexpr std::array<const char*, 6> settableInterfaces = { |
| 65 | "FanProfile", "Pid", "Pid.Zone", "Stepwise", "Thresholds", "Polling"}; |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 66 | using JsonVariantType = |
James Feist | 338b8a7 | 2019-03-01 10:16:45 -0800 | [diff] [blame] | 67 | std::variant<std::vector<std::string>, std::vector<double>, std::string, |
| 68 | int64_t, uint64_t, double, int32_t, uint32_t, int16_t, |
| 69 | uint16_t, uint8_t, bool>; |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 70 | |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 71 | // store reference to all interfaces so we can destroy them later |
| 72 | boost::container::flat_map< |
James Feist | 02d2b93 | 2020-02-06 16:28:48 -0800 | [diff] [blame] | 73 | std::string, std::vector<std::weak_ptr<sdbusplus::asio::dbus_interface>>> |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 74 | inventory; |
| 75 | |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 76 | // todo: pass this through nicer |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 77 | std::shared_ptr<sdbusplus::asio::connection> systemBus; |
Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 78 | nlohmann::json lastJson; |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 79 | |
James Feist | 02d2b93 | 2020-02-06 16:28:48 -0800 | [diff] [blame] | 80 | boost::asio::io_context io; |
| 81 | |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 82 | const std::regex illegalDbusPathRegex("[^A-Za-z0-9_.]"); |
| 83 | const std::regex illegalDbusMemberRegex("[^A-Za-z0-9_]"); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 84 | |
Andrew Jeffery | 666583b | 2021-12-01 15:50:12 +1030 | [diff] [blame] | 85 | FoundProbeTypeT findProbeType(const std::string& probe) |
| 86 | { |
| 87 | boost::container::flat_map<const char*, probe_type_codes, |
| 88 | CmpStr>::const_iterator probeType; |
| 89 | for (probeType = probeTypes.begin(); probeType != probeTypes.end(); |
| 90 | ++probeType) |
| 91 | { |
| 92 | if (probe.find(probeType->first) != std::string::npos) |
| 93 | { |
| 94 | return probeType; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return std::nullopt; |
| 99 | } |
| 100 | |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 101 | static std::shared_ptr<sdbusplus::asio::dbus_interface> |
| 102 | createInterface(sdbusplus::asio::object_server& objServer, |
| 103 | const std::string& path, const std::string& interface, |
James Feist | 02d2b93 | 2020-02-06 16:28:48 -0800 | [diff] [blame] | 104 | const std::string& parent, bool checkNull = false) |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 105 | { |
James Feist | 02d2b93 | 2020-02-06 16:28:48 -0800 | [diff] [blame] | 106 | // on first add we have no reason to check for null before add, as there |
| 107 | // won't be any. For dynamically added interfaces, we check for null so that |
| 108 | // a constant delete/add will not create a memory leak |
| 109 | |
| 110 | auto ptr = objServer.add_interface(path, interface); |
| 111 | auto& dataVector = inventory[parent]; |
| 112 | if (checkNull) |
| 113 | { |
| 114 | auto it = std::find_if(dataVector.begin(), dataVector.end(), |
| 115 | [](const auto& p) { return p.expired(); }); |
| 116 | if (it != dataVector.end()) |
| 117 | { |
| 118 | *it = ptr; |
| 119 | return ptr; |
| 120 | } |
| 121 | } |
| 122 | dataVector.emplace_back(ptr); |
| 123 | return ptr; |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 124 | } |
| 125 | |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 126 | // writes output files to persist data |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 127 | bool writeJsonFiles(const nlohmann::json& systemConfiguration) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 128 | { |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 129 | std::filesystem::create_directory(configurationOutDir); |
| 130 | std::ofstream output(currentConfiguration); |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 131 | if (!output.good()) |
| 132 | { |
| 133 | return false; |
| 134 | } |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 135 | output << systemConfiguration.dump(4); |
| 136 | output.close(); |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 137 | return true; |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 138 | } |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 139 | |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 140 | template <typename JsonType> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 141 | bool setJsonFromPointer(const std::string& ptrStr, const JsonType& value, |
| 142 | nlohmann::json& systemConfiguration) |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 143 | { |
| 144 | try |
| 145 | { |
| 146 | nlohmann::json::json_pointer ptr(ptrStr); |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 147 | nlohmann::json& ref = systemConfiguration[ptr]; |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 148 | ref = value; |
| 149 | return true; |
| 150 | } |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 151 | catch (const std::out_of_range&) |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 152 | { |
| 153 | return false; |
| 154 | } |
| 155 | } |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 156 | |
James Feist | ebcc26b | 2019-03-22 12:30:43 -0700 | [diff] [blame] | 157 | // template function to add array as dbus property |
| 158 | template <typename PropertyType> |
| 159 | void addArrayToDbus(const std::string& name, const nlohmann::json& array, |
| 160 | sdbusplus::asio::dbus_interface* iface, |
| 161 | sdbusplus::asio::PropertyPermission permission, |
| 162 | nlohmann::json& systemConfiguration, |
| 163 | const std::string& jsonPointerString) |
| 164 | { |
| 165 | std::vector<PropertyType> values; |
| 166 | for (const auto& property : array) |
| 167 | { |
| 168 | auto ptr = property.get_ptr<const PropertyType*>(); |
| 169 | if (ptr != nullptr) |
| 170 | { |
| 171 | values.emplace_back(*ptr); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if (permission == sdbusplus::asio::PropertyPermission::readOnly) |
| 176 | { |
| 177 | iface->register_property(name, values); |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | iface->register_property( |
| 182 | name, values, |
| 183 | [&systemConfiguration, |
| 184 | jsonPointerString{std::string(jsonPointerString)}]( |
| 185 | const std::vector<PropertyType>& newVal, |
| 186 | std::vector<PropertyType>& val) { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 187 | val = newVal; |
| 188 | if (!setJsonFromPointer(jsonPointerString, val, |
| 189 | systemConfiguration)) |
| 190 | { |
| 191 | std::cerr << "error setting json field\n"; |
| 192 | return -1; |
| 193 | } |
| 194 | if (!writeJsonFiles(systemConfiguration)) |
| 195 | { |
| 196 | std::cerr << "error setting json file\n"; |
| 197 | return -1; |
| 198 | } |
| 199 | return 1; |
James Feist | ebcc26b | 2019-03-22 12:30:43 -0700 | [diff] [blame] | 200 | }); |
| 201 | } |
| 202 | } |
| 203 | |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 204 | template <typename PropertyType> |
Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 205 | void addProperty(const std::string& name, const PropertyType& value, |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 206 | sdbusplus::asio::dbus_interface* iface, |
| 207 | nlohmann::json& systemConfiguration, |
| 208 | const std::string& jsonPointerString, |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 209 | sdbusplus::asio::PropertyPermission permission) |
| 210 | { |
| 211 | if (permission == sdbusplus::asio::PropertyPermission::readOnly) |
| 212 | { |
Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 213 | iface->register_property(name, value); |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 214 | return; |
| 215 | } |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 216 | iface->register_property( |
Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 217 | name, value, |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 218 | [&systemConfiguration, |
| 219 | jsonPointerString{std::string(jsonPointerString)}]( |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 220 | const PropertyType& newVal, PropertyType& val) { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 221 | val = newVal; |
| 222 | if (!setJsonFromPointer(jsonPointerString, val, systemConfiguration)) |
| 223 | { |
| 224 | std::cerr << "error setting json field\n"; |
| 225 | return -1; |
| 226 | } |
| 227 | if (!writeJsonFiles(systemConfiguration)) |
| 228 | { |
| 229 | std::cerr << "error setting json file\n"; |
| 230 | return -1; |
| 231 | } |
| 232 | return 1; |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 233 | }); |
| 234 | } |
| 235 | |
| 236 | void createDeleteObjectMethod( |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 237 | const std::string& jsonPointerPath, |
| 238 | const std::shared_ptr<sdbusplus::asio::dbus_interface>& iface, |
| 239 | sdbusplus::asio::object_server& objServer, |
| 240 | nlohmann::json& systemConfiguration) |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 241 | { |
| 242 | std::weak_ptr<sdbusplus::asio::dbus_interface> interface = iface; |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 243 | iface->register_method("Delete", |
| 244 | [&objServer, &systemConfiguration, interface, |
| 245 | jsonPointerPath{std::string(jsonPointerPath)}]() { |
| 246 | std::shared_ptr<sdbusplus::asio::dbus_interface> dbusInterface = |
| 247 | interface.lock(); |
| 248 | if (!dbusInterface) |
| 249 | { |
| 250 | // this technically can't happen as the pointer is pointing to |
| 251 | // us |
| 252 | throw DBusInternalError(); |
| 253 | } |
| 254 | nlohmann::json::json_pointer ptr(jsonPointerPath); |
| 255 | systemConfiguration[ptr] = nullptr; |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 256 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 257 | // todo(james): dig through sdbusplus to find out why we can't |
| 258 | // delete it in a method call |
| 259 | boost::asio::post(io, [&objServer, dbusInterface]() mutable { |
| 260 | objServer.remove_interface(dbusInterface); |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 261 | }); |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 262 | |
| 263 | if (!writeJsonFiles(systemConfiguration)) |
| 264 | { |
| 265 | std::cerr << "error setting json file\n"; |
| 266 | throw DBusInternalError(); |
| 267 | } |
| 268 | }); |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 269 | } |
| 270 | |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 271 | // adds simple json types to interface's properties |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 272 | void populateInterfaceFromJson( |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 273 | nlohmann::json& systemConfiguration, const std::string& jsonPointerPath, |
| 274 | std::shared_ptr<sdbusplus::asio::dbus_interface>& iface, |
| 275 | nlohmann::json& dict, sdbusplus::asio::object_server& objServer, |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 276 | sdbusplus::asio::PropertyPermission permission = |
| 277 | sdbusplus::asio::PropertyPermission::readOnly) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 278 | { |
Patrick Williams | 2594d36 | 2022-09-28 06:46:24 -0500 | [diff] [blame] | 279 | for (const auto& [key, value] : dict.items()) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 280 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 281 | auto type = value.type(); |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 282 | bool array = false; |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 283 | if (value.type() == nlohmann::json::value_t::array) |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 284 | { |
| 285 | array = true; |
Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 286 | if (value.empty()) |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 287 | { |
| 288 | continue; |
| 289 | } |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 290 | type = value[0].type(); |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 291 | bool isLegal = true; |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 292 | for (const auto& arrayItem : value) |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 293 | { |
| 294 | if (arrayItem.type() != type) |
| 295 | { |
| 296 | isLegal = false; |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | if (!isLegal) |
| 301 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 302 | std::cerr << "dbus format error" << value << "\n"; |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 303 | continue; |
| 304 | } |
James Feist | a218ddb | 2019-04-11 14:01:31 -0700 | [diff] [blame] | 305 | } |
| 306 | if (type == nlohmann::json::value_t::object) |
| 307 | { |
| 308 | continue; // handled elsewhere |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 309 | } |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 310 | |
| 311 | std::string path = jsonPointerPath; |
| 312 | path.append("/").append(key); |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 313 | if (permission == sdbusplus::asio::PropertyPermission::readWrite) |
| 314 | { |
| 315 | // all setable numbers are doubles as it is difficult to always |
| 316 | // create a configuration file with all whole numbers as decimals |
| 317 | // i.e. 1.0 |
James Feist | ebcc26b | 2019-03-22 12:30:43 -0700 | [diff] [blame] | 318 | if (array) |
| 319 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 320 | if (value[0].is_number()) |
James Feist | ebcc26b | 2019-03-22 12:30:43 -0700 | [diff] [blame] | 321 | { |
| 322 | type = nlohmann::json::value_t::number_float; |
| 323 | } |
| 324 | } |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 325 | else if (value.is_number()) |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 326 | { |
| 327 | type = nlohmann::json::value_t::number_float; |
| 328 | } |
| 329 | } |
| 330 | |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 331 | switch (type) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 332 | { |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 333 | case (nlohmann::json::value_t::boolean): |
| 334 | { |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 335 | if (array) |
| 336 | { |
| 337 | // todo: array of bool isn't detected correctly by |
| 338 | // sdbusplus, change it to numbers |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 339 | addArrayToDbus<uint64_t>(key, value, iface.get(), |
| 340 | permission, systemConfiguration, |
| 341 | path); |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 342 | } |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 343 | |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 344 | else |
| 345 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 346 | addProperty(key, value.get<bool>(), iface.get(), |
| 347 | systemConfiguration, path, permission); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 348 | } |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 349 | break; |
| 350 | } |
| 351 | case (nlohmann::json::value_t::number_integer): |
| 352 | { |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 353 | if (array) |
| 354 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 355 | addArrayToDbus<int64_t>(key, value, iface.get(), permission, |
Andrew Jeffery | 029ee28 | 2022-03-25 13:11:36 +1030 | [diff] [blame] | 356 | systemConfiguration, path); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 357 | } |
| 358 | else |
| 359 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 360 | addProperty(key, value.get<int64_t>(), iface.get(), |
| 361 | systemConfiguration, path, |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 362 | sdbusplus::asio::PropertyPermission::readOnly); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 363 | } |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 364 | break; |
| 365 | } |
| 366 | case (nlohmann::json::value_t::number_unsigned): |
| 367 | { |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 368 | if (array) |
| 369 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 370 | addArrayToDbus<uint64_t>(key, value, iface.get(), |
| 371 | permission, systemConfiguration, |
| 372 | path); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 373 | } |
| 374 | else |
| 375 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 376 | addProperty(key, value.get<uint64_t>(), iface.get(), |
Andrew Jeffery | 029ee28 | 2022-03-25 13:11:36 +1030 | [diff] [blame] | 377 | systemConfiguration, path, |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 378 | sdbusplus::asio::PropertyPermission::readOnly); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 379 | } |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 380 | break; |
| 381 | } |
| 382 | case (nlohmann::json::value_t::number_float): |
| 383 | { |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 384 | if (array) |
| 385 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 386 | addArrayToDbus<double>(key, value, iface.get(), permission, |
Andrew Jeffery | 029ee28 | 2022-03-25 13:11:36 +1030 | [diff] [blame] | 387 | systemConfiguration, path); |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 388 | } |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 389 | |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 390 | else |
| 391 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 392 | addProperty(key, value.get<double>(), iface.get(), |
| 393 | systemConfiguration, path, permission); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 394 | } |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 395 | break; |
| 396 | } |
| 397 | case (nlohmann::json::value_t::string): |
| 398 | { |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 399 | if (array) |
| 400 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 401 | addArrayToDbus<std::string>(key, value, iface.get(), |
| 402 | permission, systemConfiguration, |
| 403 | path); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 404 | } |
| 405 | else |
| 406 | { |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 407 | addProperty(key, value.get<std::string>(), iface.get(), |
| 408 | systemConfiguration, path, permission); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 409 | } |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 410 | break; |
| 411 | } |
James Feist | 0eb4035 | 2019-04-09 14:44:04 -0700 | [diff] [blame] | 412 | default: |
| 413 | { |
James Feist | a218ddb | 2019-04-11 14:01:31 -0700 | [diff] [blame] | 414 | std::cerr << "Unexpected json type in system configuration " |
Andrew Jeffery | 65ea450 | 2022-03-25 13:15:34 +1030 | [diff] [blame] | 415 | << key << ": " << value.type_name() << "\n"; |
James Feist | 0eb4035 | 2019-04-09 14:44:04 -0700 | [diff] [blame] | 416 | break; |
| 417 | } |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 418 | } |
| 419 | } |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 420 | if (permission == sdbusplus::asio::PropertyPermission::readWrite) |
| 421 | { |
| 422 | createDeleteObjectMethod(jsonPointerPath, iface, objServer, |
| 423 | systemConfiguration); |
| 424 | } |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 425 | iface->initialize(); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 426 | } |
| 427 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 428 | sdbusplus::asio::PropertyPermission getPermission(const std::string& interface) |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 429 | { |
| 430 | return std::find(settableInterfaces.begin(), settableInterfaces.end(), |
| 431 | interface) != settableInterfaces.end() |
| 432 | ? sdbusplus::asio::PropertyPermission::readWrite |
| 433 | : sdbusplus::asio::PropertyPermission::readOnly; |
| 434 | } |
| 435 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 436 | void createAddObjectMethod(const std::string& jsonPointerPath, |
| 437 | const std::string& path, |
| 438 | nlohmann::json& systemConfiguration, |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 439 | sdbusplus::asio::object_server& objServer, |
| 440 | const std::string& board) |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 441 | { |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 442 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface = createInterface( |
| 443 | objServer, path, "xyz.openbmc_project.AddObject", board); |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 444 | |
| 445 | iface->register_method( |
| 446 | "AddObject", |
| 447 | [&systemConfiguration, &objServer, |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 448 | jsonPointerPath{std::string(jsonPointerPath)}, path{std::string(path)}, |
| 449 | board](const boost::container::flat_map<std::string, JsonVariantType>& |
| 450 | data) { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 451 | nlohmann::json::json_pointer ptr(jsonPointerPath); |
| 452 | nlohmann::json& base = systemConfiguration[ptr]; |
| 453 | auto findExposes = base.find("Exposes"); |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 454 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 455 | if (findExposes == base.end()) |
| 456 | { |
| 457 | throw std::invalid_argument("Entity must have children."); |
| 458 | } |
| 459 | |
| 460 | // this will throw invalid-argument to sdbusplus if invalid json |
| 461 | nlohmann::json newData{}; |
| 462 | for (const auto& item : data) |
| 463 | { |
| 464 | nlohmann::json& newJson = newData[item.first]; |
| 465 | std::visit( |
| 466 | [&newJson](auto&& val) { |
| 467 | newJson = std::forward<decltype(val)>(val); |
| 468 | }, |
| 469 | item.second); |
| 470 | } |
| 471 | |
| 472 | auto findName = newData.find("Name"); |
| 473 | auto findType = newData.find("Type"); |
| 474 | if (findName == newData.end() || findType == newData.end()) |
| 475 | { |
| 476 | throw std::invalid_argument("AddObject missing Name or Type"); |
| 477 | } |
| 478 | const std::string* type = findType->get_ptr<const std::string*>(); |
| 479 | const std::string* name = findName->get_ptr<const std::string*>(); |
| 480 | if (type == nullptr || name == nullptr) |
| 481 | { |
| 482 | throw std::invalid_argument("Type and Name must be a string."); |
| 483 | } |
| 484 | |
| 485 | bool foundNull = false; |
| 486 | size_t lastIndex = 0; |
| 487 | // we add in the "exposes" |
| 488 | for (const auto& expose : *findExposes) |
| 489 | { |
| 490 | if (expose.is_null()) |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 491 | { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 492 | foundNull = true; |
| 493 | continue; |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 496 | if (expose["Name"] == *name && expose["Type"] == *type) |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 497 | { |
| 498 | throw std::invalid_argument( |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 499 | "Field already in JSON, not adding"); |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 500 | } |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 501 | |
James Feist | 02d2b93 | 2020-02-06 16:28:48 -0800 | [diff] [blame] | 502 | if (foundNull) |
| 503 | { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 504 | continue; |
James Feist | 02d2b93 | 2020-02-06 16:28:48 -0800 | [diff] [blame] | 505 | } |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 506 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 507 | lastIndex++; |
| 508 | } |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 509 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 510 | std::ifstream schemaFile(std::string(schemaDirectory) + "/" + |
| 511 | boost::to_lower_copy(*type) + ".json"); |
| 512 | // todo(james) we might want to also make a list of 'can add' |
| 513 | // interfaces but for now I think the assumption if there is a |
| 514 | // schema avaliable that it is allowed to update is fine |
| 515 | if (!schemaFile.good()) |
| 516 | { |
| 517 | throw std::invalid_argument( |
| 518 | "No schema avaliable, cannot validate."); |
| 519 | } |
| 520 | nlohmann::json schema = nlohmann::json::parse(schemaFile, nullptr, |
| 521 | false); |
| 522 | if (schema.is_discarded()) |
| 523 | { |
| 524 | std::cerr << "Schema not legal" << *type << ".json\n"; |
| 525 | throw DBusInternalError(); |
| 526 | } |
| 527 | if (!validateJson(schema, newData)) |
| 528 | { |
| 529 | throw std::invalid_argument("Data does not match schema"); |
| 530 | } |
| 531 | if (foundNull) |
| 532 | { |
| 533 | findExposes->at(lastIndex) = newData; |
| 534 | } |
| 535 | else |
| 536 | { |
| 537 | findExposes->push_back(newData); |
| 538 | } |
| 539 | if (!writeJsonFiles(systemConfiguration)) |
| 540 | { |
| 541 | std::cerr << "Error writing json files\n"; |
| 542 | throw DBusInternalError(); |
| 543 | } |
| 544 | std::string dbusName = *name; |
| 545 | |
| 546 | std::regex_replace(dbusName.begin(), dbusName.begin(), dbusName.end(), |
| 547 | illegalDbusMemberRegex, "_"); |
| 548 | |
| 549 | std::shared_ptr<sdbusplus::asio::dbus_interface> interface = |
| 550 | createInterface(objServer, path + "/" + dbusName, |
| 551 | "xyz.openbmc_project.Configuration." + *type, board, |
| 552 | true); |
| 553 | // permission is read-write, as since we just created it, must be |
| 554 | // runtime modifiable |
| 555 | populateInterfaceFromJson( |
| 556 | systemConfiguration, |
| 557 | jsonPointerPath + "/Exposes/" + std::to_string(lastIndex), |
| 558 | interface, newData, objServer, |
| 559 | sdbusplus::asio::PropertyPermission::readWrite); |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 560 | }); |
| 561 | iface->initialize(); |
| 562 | } |
| 563 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 564 | void postToDbus(const nlohmann::json& newConfiguration, |
| 565 | nlohmann::json& systemConfiguration, |
| 566 | sdbusplus::asio::object_server& objServer) |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 567 | |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 568 | { |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 569 | Topology topology; |
| 570 | |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 571 | // iterate through boards |
Patrick Williams | 2594d36 | 2022-09-28 06:46:24 -0500 | [diff] [blame] | 572 | for (const auto& [boardId, boardConfig] : newConfiguration.items()) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 573 | { |
Andrew Jeffery | 13132df | 2022-03-25 13:29:41 +1030 | [diff] [blame] | 574 | std::string boardKey = boardConfig["Name"]; |
| 575 | std::string boardKeyOrig = boardConfig["Name"]; |
| 576 | std::string jsonPointerPath = "/" + boardId; |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 577 | // loop through newConfiguration, but use values from system |
| 578 | // configuration to be able to modify via dbus later |
Andrew Jeffery | 13132df | 2022-03-25 13:29:41 +1030 | [diff] [blame] | 579 | auto boardValues = systemConfiguration[boardId]; |
James Feist | d63d18a | 2018-07-19 15:23:45 -0700 | [diff] [blame] | 580 | auto findBoardType = boardValues.find("Type"); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 581 | std::string boardType; |
| 582 | if (findBoardType != boardValues.end() && |
| 583 | findBoardType->type() == nlohmann::json::value_t::string) |
| 584 | { |
| 585 | boardType = findBoardType->get<std::string>(); |
| 586 | std::regex_replace(boardType.begin(), boardType.begin(), |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 587 | boardType.end(), illegalDbusMemberRegex, "_"); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 588 | } |
| 589 | else |
| 590 | { |
| 591 | std::cerr << "Unable to find type for " << boardKey |
| 592 | << " reverting to Chassis.\n"; |
| 593 | boardType = "Chassis"; |
| 594 | } |
James Feist | 11be667 | 2018-04-06 14:05:32 -0700 | [diff] [blame] | 595 | std::string boardtypeLower = boost::algorithm::to_lower_copy(boardType); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 596 | |
| 597 | std::regex_replace(boardKey.begin(), boardKey.begin(), boardKey.end(), |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 598 | illegalDbusMemberRegex, "_"); |
| 599 | std::string boardName = "/xyz/openbmc_project/inventory/system/"; |
| 600 | boardName += boardtypeLower; |
| 601 | boardName += "/"; |
| 602 | boardName += boardKey; |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 603 | |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 604 | std::shared_ptr<sdbusplus::asio::dbus_interface> inventoryIface = |
| 605 | createInterface(objServer, boardName, |
| 606 | "xyz.openbmc_project.Inventory.Item", boardKey); |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 607 | |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 608 | std::shared_ptr<sdbusplus::asio::dbus_interface> boardIface = |
| 609 | createInterface(objServer, boardName, |
| 610 | "xyz.openbmc_project.Inventory.Item." + boardType, |
| 611 | boardKeyOrig); |
James Feist | 11be667 | 2018-04-06 14:05:32 -0700 | [diff] [blame] | 612 | |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 613 | createAddObjectMethod(jsonPointerPath, boardName, systemConfiguration, |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 614 | objServer, boardKeyOrig); |
James Feist | 68500ff | 2018-08-08 15:40:42 -0700 | [diff] [blame] | 615 | |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 616 | populateInterfaceFromJson(systemConfiguration, jsonPointerPath, |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 617 | boardIface, boardValues, objServer); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 618 | jsonPointerPath += "/"; |
| 619 | // iterate through board properties |
Patrick Williams | 2594d36 | 2022-09-28 06:46:24 -0500 | [diff] [blame] | 620 | for (const auto& [propName, propValue] : boardValues.items()) |
James Feist | 11be667 | 2018-04-06 14:05:32 -0700 | [diff] [blame] | 621 | { |
Andrew Jeffery | a96950d | 2022-03-25 13:32:46 +1030 | [diff] [blame] | 622 | if (propValue.type() == nlohmann::json::value_t::object) |
James Feist | 11be667 | 2018-04-06 14:05:32 -0700 | [diff] [blame] | 623 | { |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 624 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface = |
Andrew Jeffery | a96950d | 2022-03-25 13:32:46 +1030 | [diff] [blame] | 625 | createInterface(objServer, boardName, propName, |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 626 | boardKeyOrig); |
| 627 | |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 628 | populateInterfaceFromJson(systemConfiguration, |
Andrew Jeffery | a96950d | 2022-03-25 13:32:46 +1030 | [diff] [blame] | 629 | jsonPointerPath + propName, iface, |
| 630 | propValue, objServer); |
James Feist | 11be667 | 2018-04-06 14:05:32 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 633 | |
James Feist | 1e3e698 | 2018-08-03 16:09:28 -0700 | [diff] [blame] | 634 | auto exposes = boardValues.find("Exposes"); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 635 | if (exposes == boardValues.end()) |
| 636 | { |
| 637 | continue; |
| 638 | } |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 639 | // iterate through exposes |
James Feist | 1e3e698 | 2018-08-03 16:09:28 -0700 | [diff] [blame] | 640 | jsonPointerPath += "Exposes/"; |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 641 | |
| 642 | // store the board level pointer so we can modify it on the way down |
| 643 | std::string jsonPointerPathBoard = jsonPointerPath; |
| 644 | size_t exposesIndex = -1; |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 645 | for (auto& item : *exposes) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 646 | { |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 647 | exposesIndex++; |
| 648 | jsonPointerPath = jsonPointerPathBoard; |
| 649 | jsonPointerPath += std::to_string(exposesIndex); |
| 650 | |
James Feist | d63d18a | 2018-07-19 15:23:45 -0700 | [diff] [blame] | 651 | auto findName = item.find("Name"); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 652 | if (findName == item.end()) |
| 653 | { |
| 654 | std::cerr << "cannot find name in field " << item << "\n"; |
| 655 | continue; |
| 656 | } |
James Feist | 1e3e698 | 2018-08-03 16:09:28 -0700 | [diff] [blame] | 657 | auto findStatus = item.find("Status"); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 658 | // if status is not found it is assumed to be status = 'okay' |
| 659 | if (findStatus != item.end()) |
| 660 | { |
| 661 | if (*findStatus == "disabled") |
| 662 | { |
| 663 | continue; |
| 664 | } |
| 665 | } |
James Feist | d63d18a | 2018-07-19 15:23:45 -0700 | [diff] [blame] | 666 | auto findType = item.find("Type"); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 667 | std::string itemType; |
| 668 | if (findType != item.end()) |
| 669 | { |
| 670 | itemType = findType->get<std::string>(); |
| 671 | std::regex_replace(itemType.begin(), itemType.begin(), |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 672 | itemType.end(), illegalDbusPathRegex, "_"); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 673 | } |
| 674 | else |
| 675 | { |
| 676 | itemType = "unknown"; |
| 677 | } |
| 678 | std::string itemName = findName->get<std::string>(); |
| 679 | std::regex_replace(itemName.begin(), itemName.begin(), |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 680 | itemName.end(), illegalDbusMemberRegex, "_"); |
| 681 | std::string ifacePath = boardName; |
| 682 | ifacePath += "/"; |
| 683 | ifacePath += itemName; |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 684 | |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 685 | std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface = |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 686 | createInterface(objServer, ifacePath, |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 687 | "xyz.openbmc_project.Configuration." + itemType, |
| 688 | boardKeyOrig); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 689 | |
Sui Chen | 74ebe59 | 2022-09-13 10:22:03 -0700 | [diff] [blame] | 690 | if (itemType == "BMC") |
| 691 | { |
| 692 | std::shared_ptr<sdbusplus::asio::dbus_interface> bmcIface = |
| 693 | createInterface(objServer, ifacePath, |
| 694 | "xyz.openbmc_project.Inventory.Item.Bmc", |
| 695 | boardKeyOrig); |
| 696 | populateInterfaceFromJson(systemConfiguration, jsonPointerPath, |
| 697 | bmcIface, item, objServer, |
| 698 | getPermission(itemType)); |
| 699 | } |
| 700 | |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 701 | populateInterfaceFromJson(systemConfiguration, jsonPointerPath, |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 702 | itemIface, item, objServer, |
| 703 | getPermission(itemType)); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 704 | |
Patrick Williams | 2594d36 | 2022-09-28 06:46:24 -0500 | [diff] [blame] | 705 | for (const auto& [name, config] : item.items()) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 706 | { |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 707 | jsonPointerPath = jsonPointerPathBoard; |
| 708 | jsonPointerPath.append(std::to_string(exposesIndex)) |
| 709 | .append("/") |
| 710 | .append(name); |
| 711 | if (config.type() == nlohmann::json::value_t::object) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 712 | { |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 713 | std::string ifaceName = |
| 714 | "xyz.openbmc_project.Configuration."; |
| 715 | ifaceName.append(itemType).append(".").append(name); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 716 | |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 717 | std::shared_ptr<sdbusplus::asio::dbus_interface> |
| 718 | objectIface = createInterface(objServer, ifacePath, |
| 719 | ifaceName, boardKeyOrig); |
| 720 | |
| 721 | populateInterfaceFromJson( |
| 722 | systemConfiguration, jsonPointerPath, objectIface, |
| 723 | config, objServer, getPermission(name)); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 724 | } |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 725 | else if (config.type() == nlohmann::json::value_t::array) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 726 | { |
| 727 | size_t index = 0; |
Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 728 | if (config.empty()) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 729 | { |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 730 | continue; |
| 731 | } |
| 732 | bool isLegal = true; |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 733 | auto type = config[0].type(); |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 734 | if (type != nlohmann::json::value_t::object) |
| 735 | { |
| 736 | continue; |
| 737 | } |
| 738 | |
| 739 | // verify legal json |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 740 | for (const auto& arrayItem : config) |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 741 | { |
| 742 | if (arrayItem.type() != type) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 743 | { |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 744 | isLegal = false; |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 745 | break; |
| 746 | } |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 747 | } |
| 748 | if (!isLegal) |
| 749 | { |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 750 | std::cerr << "dbus format error" << config << "\n"; |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 751 | break; |
| 752 | } |
| 753 | |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 754 | for (auto& arrayItem : config) |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 755 | { |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 756 | std::string ifaceName = |
| 757 | "xyz.openbmc_project.Configuration."; |
| 758 | ifaceName.append(itemType).append(".").append(name); |
| 759 | ifaceName.append(std::to_string(index)); |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 760 | |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 761 | std::shared_ptr<sdbusplus::asio::dbus_interface> |
| 762 | objectIface = createInterface( |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 763 | objServer, ifacePath, ifaceName, boardKeyOrig); |
James Feist | d58879a | 2019-09-11 11:26:07 -0700 | [diff] [blame] | 764 | |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 765 | populateInterfaceFromJson( |
| 766 | systemConfiguration, |
| 767 | jsonPointerPath + "/" + std::to_string(index), |
| 768 | objectIface, arrayItem, objServer, |
Andrew Jeffery | 5a6379c | 2022-03-25 13:25:31 +1030 | [diff] [blame] | 769 | getPermission(name)); |
James Feist | bb43d02 | 2018-06-12 15:44:33 -0700 | [diff] [blame] | 770 | index++; |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | } |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 774 | |
| 775 | topology.addBoard(boardName, boardType, item); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 776 | } |
| 777 | } |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 778 | |
| 779 | for (const auto& boardAssoc : topology.getAssocs()) |
| 780 | { |
| 781 | auto ifacePtr = objServer.add_interface( |
| 782 | boardAssoc.first, "xyz.openbmc_project.Association.Definitions"); |
| 783 | |
| 784 | ifacePtr->register_property("Associations", boardAssoc.second); |
| 785 | ifacePtr->initialize(); |
| 786 | } |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 787 | } |
| 788 | |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 789 | // reads json files out of the filesystem |
Andrew Jeffery | f331179 | 2022-03-29 22:09:00 +1030 | [diff] [blame] | 790 | bool loadConfigurations(std::list<nlohmann::json>& configurations) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 791 | { |
| 792 | // find configuration files |
Ed Tanous | 072e25d | 2018-12-16 21:45:20 -0800 | [diff] [blame] | 793 | std::vector<std::filesystem::path> jsonPaths; |
Andrew Jeffery | a9c5892 | 2021-06-01 09:28:59 +0930 | [diff] [blame] | 794 | if (!findFiles( |
| 795 | std::vector<std::filesystem::path>{configurationDirectory, |
| 796 | hostConfigurationDirectory}, |
| 797 | R"(.*\.json)", jsonPaths)) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 798 | { |
| 799 | std::cerr << "Unable to find any configuration files in " |
James Feist | b4383f4 | 2018-08-06 16:54:10 -0700 | [diff] [blame] | 800 | << configurationDirectory << "\n"; |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 801 | return false; |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 802 | } |
James Feist | b4383f4 | 2018-08-06 16:54:10 -0700 | [diff] [blame] | 803 | |
| 804 | std::ifstream schemaStream(std::string(schemaDirectory) + "/" + |
| 805 | globalSchema); |
| 806 | if (!schemaStream.good()) |
| 807 | { |
| 808 | std::cerr |
| 809 | << "Cannot open schema file, cannot validate JSON, exiting\n\n"; |
| 810 | std::exit(EXIT_FAILURE); |
Ed Tanous | 072e25d | 2018-12-16 21:45:20 -0800 | [diff] [blame] | 811 | return false; |
James Feist | b4383f4 | 2018-08-06 16:54:10 -0700 | [diff] [blame] | 812 | } |
| 813 | nlohmann::json schema = nlohmann::json::parse(schemaStream, nullptr, false); |
| 814 | if (schema.is_discarded()) |
| 815 | { |
| 816 | std::cerr |
| 817 | << "Illegal schema file detected, cannot validate JSON, exiting\n"; |
| 818 | std::exit(EXIT_FAILURE); |
Ed Tanous | 072e25d | 2018-12-16 21:45:20 -0800 | [diff] [blame] | 819 | return false; |
James Feist | b4383f4 | 2018-08-06 16:54:10 -0700 | [diff] [blame] | 820 | } |
| 821 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 822 | for (auto& jsonPath : jsonPaths) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 823 | { |
| 824 | std::ifstream jsonStream(jsonPath.c_str()); |
| 825 | if (!jsonStream.good()) |
| 826 | { |
| 827 | std::cerr << "unable to open " << jsonPath.string() << "\n"; |
| 828 | continue; |
| 829 | } |
| 830 | auto data = nlohmann::json::parse(jsonStream, nullptr, false); |
| 831 | if (data.is_discarded()) |
| 832 | { |
| 833 | std::cerr << "syntax error in " << jsonPath.string() << "\n"; |
| 834 | continue; |
| 835 | } |
James Feist | 8da9919 | 2019-01-24 08:20:16 -0800 | [diff] [blame] | 836 | /* |
| 837 | * todo(james): reenable this once less things are in flight |
| 838 | * |
James Feist | b4383f4 | 2018-08-06 16:54:10 -0700 | [diff] [blame] | 839 | if (!validateJson(schema, data)) |
| 840 | { |
| 841 | std::cerr << "Error validating " << jsonPath.string() << "\n"; |
| 842 | continue; |
| 843 | } |
James Feist | 8da9919 | 2019-01-24 08:20:16 -0800 | [diff] [blame] | 844 | */ |
James Feist | b4383f4 | 2018-08-06 16:54:10 -0700 | [diff] [blame] | 845 | |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 846 | if (data.type() == nlohmann::json::value_t::array) |
| 847 | { |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 848 | for (auto& d : data) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 849 | { |
| 850 | configurations.emplace_back(d); |
| 851 | } |
| 852 | } |
| 853 | else |
| 854 | { |
| 855 | configurations.emplace_back(data); |
| 856 | } |
| 857 | } |
Ed Tanous | 072e25d | 2018-12-16 21:45:20 -0800 | [diff] [blame] | 858 | return true; |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 859 | } |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 860 | |
Andrew Jeffery | 5519293 | 2022-03-24 12:29:27 +1030 | [diff] [blame] | 861 | static bool deviceRequiresPowerOn(const nlohmann::json& entity) |
| 862 | { |
| 863 | auto powerState = entity.find("PowerState"); |
Andrew Jeffery | b620944 | 2022-03-24 12:36:20 +1030 | [diff] [blame] | 864 | if (powerState == entity.end()) |
Andrew Jeffery | 5519293 | 2022-03-24 12:29:27 +1030 | [diff] [blame] | 865 | { |
Andrew Jeffery | b620944 | 2022-03-24 12:36:20 +1030 | [diff] [blame] | 866 | return false; |
Andrew Jeffery | 5519293 | 2022-03-24 12:29:27 +1030 | [diff] [blame] | 867 | } |
| 868 | |
Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 869 | const auto* ptr = powerState->get_ptr<const std::string*>(); |
| 870 | if (ptr == nullptr) |
Andrew Jeffery | b620944 | 2022-03-24 12:36:20 +1030 | [diff] [blame] | 871 | { |
| 872 | return false; |
| 873 | } |
| 874 | |
| 875 | return *ptr == "On" || *ptr == "BiosPost"; |
Andrew Jeffery | 5519293 | 2022-03-24 12:29:27 +1030 | [diff] [blame] | 876 | } |
| 877 | |
Andrew Jeffery | 89ec352 | 2022-03-24 13:30:41 +1030 | [diff] [blame] | 878 | static void pruneDevice(const nlohmann::json& systemConfiguration, |
| 879 | const bool powerOff, const bool scannedPowerOff, |
| 880 | const std::string& name, const nlohmann::json& device) |
| 881 | { |
| 882 | if (systemConfiguration.contains(name)) |
| 883 | { |
| 884 | return; |
| 885 | } |
| 886 | |
Andrew Jeffery | 4db38bc | 2022-03-24 13:42:41 +1030 | [diff] [blame] | 887 | if (deviceRequiresPowerOn(device) && (powerOff || scannedPowerOff)) |
Andrew Jeffery | 89ec352 | 2022-03-24 13:30:41 +1030 | [diff] [blame] | 888 | { |
Andrew Jeffery | 89ec352 | 2022-03-24 13:30:41 +1030 | [diff] [blame] | 889 | return; |
| 890 | } |
| 891 | |
| 892 | logDeviceRemoved(device); |
| 893 | } |
| 894 | |
James Feist | b1728ca | 2020-04-30 15:40:55 -0700 | [diff] [blame] | 895 | void startRemovedTimer(boost::asio::steady_timer& timer, |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 896 | nlohmann::json& systemConfiguration) |
| 897 | { |
| 898 | static bool scannedPowerOff = false; |
| 899 | static bool scannedPowerOn = false; |
| 900 | |
James Feist | fb00f39 | 2019-06-25 14:16:48 -0700 | [diff] [blame] | 901 | if (systemConfiguration.empty() || lastJson.empty()) |
| 902 | { |
| 903 | return; // not ready yet |
| 904 | } |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 905 | if (scannedPowerOn) |
| 906 | { |
| 907 | return; |
| 908 | } |
| 909 | |
| 910 | if (!isPowerOn() && scannedPowerOff) |
| 911 | { |
| 912 | return; |
| 913 | } |
| 914 | |
James Feist | b1728ca | 2020-04-30 15:40:55 -0700 | [diff] [blame] | 915 | timer.expires_after(std::chrono::seconds(10)); |
Andrew Jeffery | 27a1cfb | 2022-03-24 12:31:53 +1030 | [diff] [blame] | 916 | timer.async_wait( |
| 917 | [&systemConfiguration](const boost::system::error_code& ec) { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 918 | if (ec == boost::asio::error::operation_aborted) |
| 919 | { |
| 920 | return; |
| 921 | } |
Andrew Jeffery | 27a1cfb | 2022-03-24 12:31:53 +1030 | [diff] [blame] | 922 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 923 | bool powerOff = !isPowerOn(); |
| 924 | for (const auto& [name, device] : lastJson.items()) |
| 925 | { |
| 926 | pruneDevice(systemConfiguration, powerOff, scannedPowerOff, name, |
| 927 | device); |
| 928 | } |
Andrew Jeffery | 89ec352 | 2022-03-24 13:30:41 +1030 | [diff] [blame] | 929 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 930 | scannedPowerOff = true; |
| 931 | if (!powerOff) |
| 932 | { |
| 933 | scannedPowerOn = true; |
| 934 | } |
| 935 | }); |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Andrew Jeffery | 2f750d2 | 2022-03-24 14:32:57 +1030 | [diff] [blame] | 938 | static std::vector<std::weak_ptr<sdbusplus::asio::dbus_interface>>& |
| 939 | getDeviceInterfaces(const nlohmann::json& device) |
| 940 | { |
| 941 | return inventory[device["Name"].get<std::string>()]; |
| 942 | } |
| 943 | |
Andrew Jeffery | 0d0c146 | 2022-03-24 15:26:39 +1030 | [diff] [blame] | 944 | static void pruneConfiguration(nlohmann::json& systemConfiguration, |
| 945 | sdbusplus::asio::object_server& objServer, |
| 946 | bool powerOff, const std::string& name, |
| 947 | const nlohmann::json& device) |
| 948 | { |
| 949 | if (powerOff && deviceRequiresPowerOn(device)) |
| 950 | { |
| 951 | // power not on yet, don't know if it's there or not |
| 952 | return; |
| 953 | } |
| 954 | |
| 955 | auto& ifaces = getDeviceInterfaces(device); |
| 956 | for (auto& iface : ifaces) |
| 957 | { |
| 958 | auto sharedPtr = iface.lock(); |
| 959 | if (!!sharedPtr) |
| 960 | { |
| 961 | objServer.remove_interface(sharedPtr); |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | ifaces.clear(); |
| 966 | systemConfiguration.erase(name); |
| 967 | logDeviceRemoved(device); |
| 968 | } |
| 969 | |
Andrew Jeffery | 7c4cbbe | 2022-03-24 15:27:10 +1030 | [diff] [blame] | 970 | static void deriveNewConfiguration(const nlohmann::json& oldConfiguration, |
| 971 | nlohmann::json& newConfiguration) |
| 972 | { |
| 973 | for (auto it = newConfiguration.begin(); it != newConfiguration.end();) |
| 974 | { |
| 975 | auto findKey = oldConfiguration.find(it.key()); |
| 976 | if (findKey != oldConfiguration.end()) |
| 977 | { |
| 978 | it = newConfiguration.erase(it); |
| 979 | } |
| 980 | else |
| 981 | { |
| 982 | it++; |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 987 | static void publishNewConfiguration( |
| 988 | const size_t& instance, const size_t count, |
| 989 | boost::asio::steady_timer& timer, nlohmann::json& systemConfiguration, |
| 990 | // Gerrit discussion: |
| 991 | // https://gerrit.openbmc-project.xyz/c/openbmc/entity-manager/+/52316/6 |
| 992 | // |
| 993 | // Discord discussion: |
| 994 | // https://discord.com/channels/775381525260664832/867820390406422538/958048437729910854 |
| 995 | // |
| 996 | // NOLINTNEXTLINE(performance-unnecessary-value-param) |
| 997 | const nlohmann::json newConfiguration, |
| 998 | sdbusplus::asio::object_server& objServer) |
| 999 | { |
| 1000 | loadOverlays(newConfiguration); |
| 1001 | |
Ed Tanous | 49a888c | 2023-03-06 13:44:51 -0800 | [diff] [blame] | 1002 | boost::asio::post(io, [systemConfiguration]() { |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 1003 | if (!writeJsonFiles(systemConfiguration)) |
| 1004 | { |
| 1005 | std::cerr << "Error writing json files\n"; |
| 1006 | } |
| 1007 | }); |
| 1008 | |
Ed Tanous | 49a888c | 2023-03-06 13:44:51 -0800 | [diff] [blame] | 1009 | boost::asio::post(io, [&instance, count, &timer, newConfiguration, |
| 1010 | &systemConfiguration, &objServer]() { |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 1011 | postToDbus(newConfiguration, systemConfiguration, objServer); |
| 1012 | if (count == instance) |
| 1013 | { |
| 1014 | startRemovedTimer(timer, systemConfiguration); |
| 1015 | } |
| 1016 | }); |
| 1017 | } |
| 1018 | |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1019 | // main properties changed entry |
James Feist | 4dc617b | 2020-05-01 09:54:47 -0700 | [diff] [blame] | 1020 | void propertiesChangedCallback(nlohmann::json& systemConfiguration, |
| 1021 | sdbusplus::asio::object_server& objServer) |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1022 | { |
James Feist | 2539ccd | 2020-05-01 16:15:08 -0700 | [diff] [blame] | 1023 | static bool inProgress = false; |
James Feist | b1728ca | 2020-04-30 15:40:55 -0700 | [diff] [blame] | 1024 | static boost::asio::steady_timer timer(io); |
James Feist | 899e17f | 2019-09-13 11:46:29 -0700 | [diff] [blame] | 1025 | static size_t instance = 0; |
| 1026 | instance++; |
| 1027 | size_t count = instance; |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 1028 | |
James Feist | b1728ca | 2020-04-30 15:40:55 -0700 | [diff] [blame] | 1029 | timer.expires_after(std::chrono::seconds(5)); |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1030 | |
| 1031 | // setup an async wait as we normally get flooded with new requests |
James Feist | 4dc617b | 2020-05-01 09:54:47 -0700 | [diff] [blame] | 1032 | timer.async_wait([&systemConfiguration, &objServer, |
James Feist | 899e17f | 2019-09-13 11:46:29 -0700 | [diff] [blame] | 1033 | count](const boost::system::error_code& ec) { |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1034 | if (ec == boost::asio::error::operation_aborted) |
| 1035 | { |
| 1036 | // we were cancelled |
| 1037 | return; |
| 1038 | } |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 1039 | if (ec) |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1040 | { |
| 1041 | std::cerr << "async wait error " << ec << "\n"; |
| 1042 | return; |
| 1043 | } |
| 1044 | |
James Feist | 2539ccd | 2020-05-01 16:15:08 -0700 | [diff] [blame] | 1045 | if (inProgress) |
| 1046 | { |
| 1047 | propertiesChangedCallback(systemConfiguration, objServer); |
| 1048 | return; |
| 1049 | } |
| 1050 | inProgress = true; |
| 1051 | |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1052 | nlohmann::json oldConfiguration = systemConfiguration; |
James Feist | 899e17f | 2019-09-13 11:46:29 -0700 | [diff] [blame] | 1053 | auto missingConfigurations = std::make_shared<nlohmann::json>(); |
| 1054 | *missingConfigurations = systemConfiguration; |
| 1055 | |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1056 | std::list<nlohmann::json> configurations; |
Andrew Jeffery | f331179 | 2022-03-29 22:09:00 +1030 | [diff] [blame] | 1057 | if (!loadConfigurations(configurations)) |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1058 | { |
Andrew Jeffery | f331179 | 2022-03-29 22:09:00 +1030 | [diff] [blame] | 1059 | std::cerr << "Could not load configurations\n"; |
James Feist | 2539ccd | 2020-05-01 16:15:08 -0700 | [diff] [blame] | 1060 | inProgress = false; |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1061 | return; |
| 1062 | } |
| 1063 | |
| 1064 | auto perfScan = std::make_shared<PerformScan>( |
James Feist | 899e17f | 2019-09-13 11:46:29 -0700 | [diff] [blame] | 1065 | systemConfiguration, *missingConfigurations, configurations, |
James Feist | 4dc617b | 2020-05-01 09:54:47 -0700 | [diff] [blame] | 1066 | objServer, |
| 1067 | [&systemConfiguration, &objServer, count, oldConfiguration, |
| 1068 | missingConfigurations]() { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1069 | // this is something that since ac has been applied to the bmc |
| 1070 | // we saw, and we no longer see it |
| 1071 | bool powerOff = !isPowerOn(); |
| 1072 | for (const auto& [name, device] : missingConfigurations->items()) |
| 1073 | { |
| 1074 | pruneConfiguration(systemConfiguration, objServer, powerOff, |
| 1075 | name, device); |
| 1076 | } |
James Feist | 899e17f | 2019-09-13 11:46:29 -0700 | [diff] [blame] | 1077 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1078 | nlohmann::json newConfiguration = systemConfiguration; |
Andrew Jeffery | 7c4cbbe | 2022-03-24 15:27:10 +1030 | [diff] [blame] | 1079 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1080 | deriveNewConfiguration(oldConfiguration, newConfiguration); |
Andrew Jeffery | 7c4cbbe | 2022-03-24 15:27:10 +1030 | [diff] [blame] | 1081 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1082 | for (const auto& [_, device] : newConfiguration.items()) |
| 1083 | { |
| 1084 | logDeviceAdded(device); |
| 1085 | } |
James Feist | 899e17f | 2019-09-13 11:46:29 -0700 | [diff] [blame] | 1086 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1087 | inProgress = false; |
James Feist | 2539ccd | 2020-05-01 16:15:08 -0700 | [diff] [blame] | 1088 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1089 | boost::asio::post( |
| 1090 | io, std::bind_front(publishNewConfiguration, std::ref(instance), |
| 1091 | count, std::ref(timer), |
| 1092 | std::ref(systemConfiguration), |
| 1093 | newConfiguration, std::ref(objServer))); |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1094 | }); |
| 1095 | perfScan->run(); |
| 1096 | }); |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 1097 | } |
| 1098 | |
Matt Spinler | 8d1ac3a | 2023-02-02 09:48:04 -0600 | [diff] [blame] | 1099 | // Extract the D-Bus interfaces to probe from the JSON config files. |
| 1100 | static std::set<std::string> getProbeInterfaces() |
| 1101 | { |
| 1102 | std::set<std::string> interfaces; |
| 1103 | std::list<nlohmann::json> configurations; |
| 1104 | if (!loadConfigurations(configurations)) |
| 1105 | { |
| 1106 | return interfaces; |
| 1107 | } |
| 1108 | |
| 1109 | for (auto it = configurations.begin(); it != configurations.end();) |
| 1110 | { |
| 1111 | auto findProbe = it->find("Probe"); |
| 1112 | if (findProbe == it->end()) |
| 1113 | { |
| 1114 | std::cerr << "configuration file missing probe:\n " << *it << "\n"; |
| 1115 | it++; |
| 1116 | continue; |
| 1117 | } |
| 1118 | |
| 1119 | nlohmann::json probeCommand; |
| 1120 | if ((*findProbe).type() != nlohmann::json::value_t::array) |
| 1121 | { |
| 1122 | probeCommand = nlohmann::json::array(); |
| 1123 | probeCommand.push_back(*findProbe); |
| 1124 | } |
| 1125 | else |
| 1126 | { |
| 1127 | probeCommand = *findProbe; |
| 1128 | } |
| 1129 | |
| 1130 | for (const nlohmann::json& probeJson : probeCommand) |
| 1131 | { |
| 1132 | const std::string* probe = probeJson.get_ptr<const std::string*>(); |
| 1133 | if (probe == nullptr) |
| 1134 | { |
| 1135 | std::cerr << "Probe statement wasn't a string, can't parse"; |
| 1136 | continue; |
| 1137 | } |
| 1138 | // Skip it if the probe cmd doesn't contain an interface. |
| 1139 | if (findProbeType(*probe)) |
| 1140 | { |
| 1141 | continue; |
| 1142 | } |
| 1143 | |
| 1144 | // syntax requires probe before first open brace |
| 1145 | auto findStart = probe->find('('); |
| 1146 | if (findStart != std::string::npos) |
| 1147 | { |
| 1148 | std::string interface = probe->substr(0, findStart); |
| 1149 | interfaces.emplace(interface); |
| 1150 | } |
| 1151 | } |
| 1152 | it++; |
| 1153 | } |
| 1154 | |
| 1155 | return interfaces; |
| 1156 | } |
| 1157 | |
| 1158 | // Check if InterfacesAdded payload contains an iface that needs probing. |
| 1159 | static bool |
| 1160 | iaContainsProbeInterface(sdbusplus::message_t& msg, |
| 1161 | const std::set<std::string>& probeInterfaces) |
| 1162 | { |
| 1163 | sdbusplus::message::object_path path; |
| 1164 | DBusObject interfaces; |
| 1165 | std::set<std::string> interfaceSet; |
| 1166 | std::set<std::string> intersect; |
| 1167 | |
| 1168 | msg.read(path, interfaces); |
| 1169 | |
| 1170 | std::for_each(interfaces.begin(), interfaces.end(), |
| 1171 | [&interfaceSet](const auto& iface) { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1172 | interfaceSet.insert(iface.first); |
| 1173 | }); |
Matt Spinler | 8d1ac3a | 2023-02-02 09:48:04 -0600 | [diff] [blame] | 1174 | |
| 1175 | std::set_intersection(interfaceSet.begin(), interfaceSet.end(), |
| 1176 | probeInterfaces.begin(), probeInterfaces.end(), |
| 1177 | std::inserter(intersect, intersect.end())); |
| 1178 | return !intersect.empty(); |
| 1179 | } |
| 1180 | |
| 1181 | // Check if InterfacesRemoved payload contains an iface that needs probing. |
| 1182 | static bool |
| 1183 | irContainsProbeInterface(sdbusplus::message_t& msg, |
| 1184 | const std::set<std::string>& probeInterfaces) |
| 1185 | { |
| 1186 | sdbusplus::message::object_path path; |
| 1187 | std::set<std::string> interfaces; |
| 1188 | std::set<std::string> intersect; |
| 1189 | |
| 1190 | msg.read(path, interfaces); |
| 1191 | |
| 1192 | std::set_intersection(interfaces.begin(), interfaces.end(), |
| 1193 | probeInterfaces.begin(), probeInterfaces.end(), |
| 1194 | std::inserter(intersect, intersect.end())); |
| 1195 | return !intersect.empty(); |
| 1196 | } |
| 1197 | |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 1198 | int main() |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 1199 | { |
| 1200 | // setup connection to dbus |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 1201 | systemBus = std::make_shared<sdbusplus::asio::connection>(io); |
| 1202 | systemBus->request_name("xyz.openbmc_project.EntityManager"); |
James Feist | 4131aea | 2018-03-09 09:47:30 -0800 | [diff] [blame] | 1203 | |
Nan Zhou | a331567 | 2022-09-20 19:48:14 +0000 | [diff] [blame] | 1204 | // The EntityManager object itself doesn't expose any properties. |
| 1205 | // No need to set up ObjectManager for the |EntityManager| object. |
| 1206 | sdbusplus::asio::object_server objServer(systemBus, /*skipManager=*/true); |
| 1207 | |
| 1208 | // All other objects that EntityManager currently support are under the |
| 1209 | // inventory subtree. |
| 1210 | // See the discussion at |
| 1211 | // https://discord.com/channels/775381525260664832/1018929092009144380 |
| 1212 | objServer.add_manager("/xyz/openbmc_project/inventory"); |
James Feist | fd1264a | 2018-05-03 12:10:00 -0700 | [diff] [blame] | 1213 | |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1214 | std::shared_ptr<sdbusplus::asio::dbus_interface> entityIface = |
| 1215 | objServer.add_interface("/xyz/openbmc_project/EntityManager", |
| 1216 | "xyz.openbmc_project.EntityManager"); |
James Feist | fd1264a | 2018-05-03 12:10:00 -0700 | [diff] [blame] | 1217 | |
James Feist | 4131aea | 2018-03-09 09:47:30 -0800 | [diff] [blame] | 1218 | // to keep reference to the match / filter objects so they don't get |
| 1219 | // destroyed |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1220 | |
| 1221 | nlohmann::json systemConfiguration = nlohmann::json::object(); |
| 1222 | |
Matt Spinler | 8d1ac3a | 2023-02-02 09:48:04 -0600 | [diff] [blame] | 1223 | std::set<std::string> probeInterfaces = getProbeInterfaces(); |
| 1224 | |
Brad Bishop | c76af0f | 2020-12-04 13:50:23 -0500 | [diff] [blame] | 1225 | // We need a poke from DBus for static providers that create all their |
| 1226 | // objects prior to claiming a well-known name, and thus don't emit any |
| 1227 | // org.freedesktop.DBus.Properties signals. Similarly if a process exits |
| 1228 | // for any reason, expected or otherwise, we'll need a poke to remove |
| 1229 | // entities from DBus. |
Patrick Williams | 2af3922 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 1230 | sdbusplus::bus::match_t nameOwnerChangedMatch( |
| 1231 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Brad Bishop | c76af0f | 2020-12-04 13:50:23 -0500 | [diff] [blame] | 1232 | sdbusplus::bus::match::rules::nameOwnerChanged(), |
Patrick Williams | 7b8786f | 2022-10-10 10:23:37 -0500 | [diff] [blame] | 1233 | [&](sdbusplus::message_t& m) { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1234 | auto [name, oldOwner, |
| 1235 | newOwner] = m.unpack<std::string, std::string, std::string>(); |
Patrick Williams | 7b8786f | 2022-10-10 10:23:37 -0500 | [diff] [blame] | 1236 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1237 | if (name.starts_with(':')) |
| 1238 | { |
| 1239 | // We should do nothing with unique-name connections. |
| 1240 | return; |
| 1241 | } |
Patrick Williams | 7b8786f | 2022-10-10 10:23:37 -0500 | [diff] [blame] | 1242 | |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1243 | propertiesChangedCallback(systemConfiguration, objServer); |
Brad Bishop | c76af0f | 2020-12-04 13:50:23 -0500 | [diff] [blame] | 1244 | }); |
Brad Bishop | 10a8c5f | 2020-12-07 21:40:07 -0500 | [diff] [blame] | 1245 | // We also need a poke from DBus when new interfaces are created or |
| 1246 | // destroyed. |
Patrick Williams | 2af3922 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 1247 | sdbusplus::bus::match_t interfacesAddedMatch( |
| 1248 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Brad Bishop | 10a8c5f | 2020-12-07 21:40:07 -0500 | [diff] [blame] | 1249 | sdbusplus::bus::match::rules::interfacesAdded(), |
Matt Spinler | 8d1ac3a | 2023-02-02 09:48:04 -0600 | [diff] [blame] | 1250 | [&](sdbusplus::message_t& msg) { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1251 | if (iaContainsProbeInterface(msg, probeInterfaces)) |
| 1252 | { |
| 1253 | propertiesChangedCallback(systemConfiguration, objServer); |
| 1254 | } |
Brad Bishop | 10a8c5f | 2020-12-07 21:40:07 -0500 | [diff] [blame] | 1255 | }); |
Patrick Williams | 2af3922 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 1256 | sdbusplus::bus::match_t interfacesRemovedMatch( |
| 1257 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Brad Bishop | 10a8c5f | 2020-12-07 21:40:07 -0500 | [diff] [blame] | 1258 | sdbusplus::bus::match::rules::interfacesRemoved(), |
Matt Spinler | 8d1ac3a | 2023-02-02 09:48:04 -0600 | [diff] [blame] | 1259 | [&](sdbusplus::message_t& msg) { |
Patrick Williams | df19061 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1260 | if (irContainsProbeInterface(msg, probeInterfaces)) |
| 1261 | { |
| 1262 | propertiesChangedCallback(systemConfiguration, objServer); |
| 1263 | } |
Brad Bishop | 10a8c5f | 2020-12-07 21:40:07 -0500 | [diff] [blame] | 1264 | }); |
Brad Bishop | c76af0f | 2020-12-04 13:50:23 -0500 | [diff] [blame] | 1265 | |
Ed Tanous | 49a888c | 2023-03-06 13:44:51 -0800 | [diff] [blame] | 1266 | boost::asio::post(io, [&]() { |
| 1267 | propertiesChangedCallback(systemConfiguration, objServer); |
| 1268 | }); |
James Feist | 4131aea | 2018-03-09 09:47:30 -0800 | [diff] [blame] | 1269 | |
James Feist | fd1264a | 2018-05-03 12:10:00 -0700 | [diff] [blame] | 1270 | entityIface->register_method("ReScan", [&]() { |
James Feist | 4dc617b | 2020-05-01 09:54:47 -0700 | [diff] [blame] | 1271 | propertiesChangedCallback(systemConfiguration, objServer); |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 1272 | }); |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 1273 | entityIface->initialize(); |
| 1274 | |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 1275 | if (fwVersionIsSame()) |
| 1276 | { |
| 1277 | if (std::filesystem::is_regular_file(currentConfiguration)) |
| 1278 | { |
| 1279 | // this file could just be deleted, but it's nice for debug |
| 1280 | std::filesystem::create_directory(tempConfigDir); |
| 1281 | std::filesystem::remove(lastConfiguration); |
| 1282 | std::filesystem::copy(currentConfiguration, lastConfiguration); |
| 1283 | std::filesystem::remove(currentConfiguration); |
| 1284 | |
| 1285 | std::ifstream jsonStream(lastConfiguration); |
| 1286 | if (jsonStream.good()) |
| 1287 | { |
| 1288 | auto data = nlohmann::json::parse(jsonStream, nullptr, false); |
| 1289 | if (data.is_discarded()) |
| 1290 | { |
| 1291 | std::cerr << "syntax error in " << lastConfiguration |
| 1292 | << "\n"; |
| 1293 | } |
| 1294 | else |
| 1295 | { |
| 1296 | lastJson = std::move(data); |
| 1297 | } |
| 1298 | } |
| 1299 | else |
| 1300 | { |
| 1301 | std::cerr << "unable to open " << lastConfiguration << "\n"; |
| 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | else |
| 1306 | { |
| 1307 | // not an error, just logging at this level to make it in the journal |
| 1308 | std::cerr << "Clearing previous configuration\n"; |
| 1309 | std::filesystem::remove(currentConfiguration); |
| 1310 | } |
| 1311 | |
| 1312 | // some boards only show up after power is on, we want to not say they are |
| 1313 | // removed until the same state happens |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 1314 | setupPowerMatch(systemBus); |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 1315 | |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 1316 | io.run(); |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 1317 | |
| 1318 | return 0; |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 1319 | } |