James Feist | c95cb14 | 2018-02-26 10:41:42 -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 | */ |
| 16 | |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 17 | #include <Overlay.hpp> |
| 18 | #include <Utils.hpp> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 19 | #include <boost/algorithm/string/predicate.hpp> |
| 20 | #include <boost/container/flat_map.hpp> |
| 21 | #include <boost/container/flat_set.hpp> |
| 22 | #include <boost/process/child.hpp> |
| 23 | #include <devices.hpp> |
James Feist | 637b3ef | 2019-04-15 16:35:30 -0700 | [diff] [blame^] | 24 | #include <filesystem> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 25 | #include <iomanip> |
| 26 | #include <iostream> |
| 27 | #include <nlohmann/json.hpp> |
| 28 | #include <regex> |
| 29 | #include <string> |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 30 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 31 | constexpr const char* DT_OVERLAY = "/usr/bin/dtoverlay"; |
| 32 | constexpr const char* DTC = "/usr/bin/dtc"; |
| 33 | constexpr const char* OUTPUT_DIR = "/tmp/overlays"; |
| 34 | constexpr const char* TEMPLATE_DIR = PACKAGE_DIR "overlay_templates"; |
| 35 | constexpr const char* TEMPLATE_CHAR = "$"; |
| 36 | constexpr const char* HEX_FORMAT_STR = "0x"; |
| 37 | constexpr const char* PLATFORM = "aspeed,ast2500"; |
| 38 | constexpr const char* I2C_DEVS_DIR = "/sys/bus/i2c/devices"; |
| 39 | constexpr const char* MUX_SYMLINK_DIR = "/dev/i2c-mux"; |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 40 | |
| 41 | // some drivers need to be unbind / bind to load device tree changes |
| 42 | static const boost::container::flat_map<std::string, std::string> FORCE_PROBES = |
| 43 | {{"IntelFanConnector", "/sys/bus/platform/drivers/aspeed_pwm_tacho"}}; |
| 44 | |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 45 | std::regex ILLEGAL_NAME_REGEX("[^A-Za-z0-9_]"); |
| 46 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 47 | void createOverlay(const std::string& templatePath, |
| 48 | const nlohmann::json& configuration); |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 49 | |
| 50 | void unloadAllOverlays(void) |
| 51 | { |
| 52 | boost::process::child c(DT_OVERLAY, "-d", OUTPUT_DIR, "-R"); |
| 53 | c.wait(); |
| 54 | } |
| 55 | |
| 56 | // this is hopefully temporary, but some drivers can't detect changes |
| 57 | // without an unbind and bind so this function must exist for now |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 58 | void forceProbe(const std::string& driver) |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 59 | { |
| 60 | std::ofstream driverUnbind(driver + "/unbind"); |
| 61 | std::ofstream driverBind(driver + "/bind"); |
| 62 | if (!driverUnbind.is_open()) |
| 63 | { |
| 64 | std::cerr << "force probe error opening " << driver << "\n"; |
| 65 | return; |
| 66 | } |
| 67 | if (!driverBind.is_open()) |
| 68 | { |
| 69 | driverUnbind.close(); |
| 70 | std::cerr << "force probe error opening " << driver << "\n"; |
| 71 | return; |
| 72 | } |
| 73 | |
Ed Tanous | 072e25d | 2018-12-16 21:45:20 -0800 | [diff] [blame] | 74 | std::filesystem::path pathObj(driver); |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 75 | for (auto& p : std::filesystem::directory_iterator(pathObj)) |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 76 | { |
| 77 | // symlinks are object names |
| 78 | if (is_symlink(p)) |
| 79 | { |
| 80 | std::string driverName = p.path().filename(); |
| 81 | driverUnbind << driverName; |
| 82 | driverBind << driverName; |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | driverUnbind.close(); |
| 87 | driverBind.close(); |
| 88 | } |
| 89 | |
| 90 | // helper function to make json types into string |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 91 | std::string jsonToString(const nlohmann::json& in) |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 92 | { |
| 93 | if (in.type() == nlohmann::json::value_t::string) |
| 94 | { |
| 95 | return in.get<std::string>(); |
| 96 | } |
| 97 | else if (in.type() == nlohmann::json::value_t::array) |
| 98 | { |
| 99 | // remove brackets and comma from array |
| 100 | std::string array = in.dump(); |
| 101 | array = array.substr(1, array.size() - 2); |
| 102 | boost::replace_all(array, ",", " "); |
| 103 | return array; |
| 104 | } |
| 105 | return in.dump(); |
| 106 | } |
| 107 | |
Ed Tanous | ee3357a | 2019-02-26 12:44:14 -0800 | [diff] [blame] | 108 | void linkMux(const std::string& muxName, size_t busIndex, size_t address, |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 109 | const nlohmann::json::array_t& channelNames) |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 110 | { |
James Feist | 286babc | 2019-02-07 16:48:28 -0800 | [diff] [blame] | 111 | std::error_code ec; |
Ed Tanous | ee3357a | 2019-02-26 12:44:14 -0800 | [diff] [blame] | 112 | std::filesystem::path muxSymlinkDir(MUX_SYMLINK_DIR); |
| 113 | std::filesystem::create_directory(muxSymlinkDir, ec); |
| 114 | // ignore error codes here if the directory already exists |
| 115 | ec.clear(); |
| 116 | std::filesystem::path linkDir = muxSymlinkDir / muxName; |
| 117 | std::filesystem::create_directory(linkDir, ec); |
| 118 | |
| 119 | std::ostringstream hexAddress; |
| 120 | hexAddress << std::hex << std::setfill('0') << std::setw(4) << address; |
James Feist | 286babc | 2019-02-07 16:48:28 -0800 | [diff] [blame] | 121 | |
| 122 | std::filesystem::path devDir(I2C_DEVS_DIR); |
Ed Tanous | ee3357a | 2019-02-26 12:44:14 -0800 | [diff] [blame] | 123 | devDir /= std::to_string(busIndex) + "-" + hexAddress.str(); |
James Feist | 286babc | 2019-02-07 16:48:28 -0800 | [diff] [blame] | 124 | |
James Feist | 286babc | 2019-02-07 16:48:28 -0800 | [diff] [blame] | 125 | std::string channelName; |
James Feist | 9d74626 | 2019-02-13 15:08:10 -0800 | [diff] [blame] | 126 | |
Ed Tanous | ee3357a | 2019-02-26 12:44:14 -0800 | [diff] [blame] | 127 | for (std::size_t channelIndex = 0; channelIndex < channelNames.size(); |
| 128 | channelIndex++) |
James Feist | 286babc | 2019-02-07 16:48:28 -0800 | [diff] [blame] | 129 | { |
Ed Tanous | ee3357a | 2019-02-26 12:44:14 -0800 | [diff] [blame] | 130 | const std::string* channelName = |
| 131 | channelNames[channelIndex].get_ptr<const std::string*>(); |
| 132 | if (channelName == nullptr) |
| 133 | { |
| 134 | continue; |
| 135 | } |
| 136 | if (channelName->empty()) |
| 137 | { |
| 138 | continue; |
| 139 | } |
| 140 | |
| 141 | std::filesystem::path channelPath = |
| 142 | devDir / ("channel-" + std::to_string(channelIndex)); |
| 143 | if (!is_symlink(channelPath)) |
| 144 | { |
| 145 | std::cerr << channelPath << "for mux channel " << *channelName |
| 146 | << " doesn't exist!\n"; |
| 147 | continue; |
| 148 | } |
| 149 | std::filesystem::path bus = std::filesystem::read_symlink(channelPath); |
| 150 | |
| 151 | std::filesystem::path fp("/dev" / bus.filename()); |
| 152 | std::filesystem::path link(linkDir / *channelName); |
| 153 | |
| 154 | std::filesystem::create_symlink(fp, link, ec); |
| 155 | if (ec) |
| 156 | { |
| 157 | std::cerr << "Failure creating symlink for " << fp << " to " << link |
| 158 | << "\n"; |
| 159 | } |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 163 | void exportDevice(const std::string& type, |
| 164 | const devices::ExportTemplate& exportTemplate, |
| 165 | const nlohmann::json& configuration) |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 166 | { |
| 167 | |
| 168 | std::string parameters = exportTemplate.parameters; |
| 169 | std::string device = exportTemplate.device; |
| 170 | std::string name = "unknown"; |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 171 | const uint64_t* bus = nullptr; |
| 172 | const uint64_t* address = nullptr; |
| 173 | const nlohmann::json::array_t* channels = nullptr; |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 174 | |
| 175 | for (auto keyPair = configuration.begin(); keyPair != configuration.end(); |
| 176 | keyPair++) |
| 177 | { |
| 178 | std::string subsituteString; |
| 179 | |
| 180 | if (keyPair.key() == "Name" && |
| 181 | keyPair.value().type() == nlohmann::json::value_t::string) |
| 182 | { |
| 183 | subsituteString = std::regex_replace( |
| 184 | keyPair.value().get<std::string>(), ILLEGAL_NAME_REGEX, "_"); |
| 185 | name = subsituteString; |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | subsituteString = jsonToString(keyPair.value()); |
| 190 | } |
| 191 | |
| 192 | if (keyPair.key() == "Bus") |
| 193 | { |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 194 | bus = keyPair.value().get_ptr<const uint64_t*>(); |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 195 | } |
| 196 | else if (keyPair.key() == "Address") |
| 197 | { |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 198 | address = keyPair.value().get_ptr<const uint64_t*>(); |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 199 | } |
James Feist | 286babc | 2019-02-07 16:48:28 -0800 | [diff] [blame] | 200 | else if (keyPair.key() == "ChannelNames") |
| 201 | { |
| 202 | channels = |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 203 | keyPair.value().get_ptr<const nlohmann::json::array_t*>(); |
James Feist | 286babc | 2019-02-07 16:48:28 -0800 | [diff] [blame] | 204 | } |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 205 | boost::replace_all(parameters, TEMPLATE_CHAR + keyPair.key(), |
| 206 | subsituteString); |
| 207 | boost::replace_all(device, TEMPLATE_CHAR + keyPair.key(), |
| 208 | subsituteString); |
| 209 | } |
| 210 | |
| 211 | // if we found bus and address we can attempt to prevent errors |
| 212 | if (bus != nullptr && address != nullptr) |
| 213 | { |
| 214 | std::ostringstream hex; |
| 215 | hex << std::hex << *address; |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 216 | const std::string& addressHex = hex.str(); |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 217 | std::string busStr = std::to_string(*bus); |
| 218 | |
Ed Tanous | 072e25d | 2018-12-16 21:45:20 -0800 | [diff] [blame] | 219 | std::filesystem::path devicePath(device); |
James Feist | 58b9c26 | 2019-02-12 13:38:45 -0800 | [diff] [blame] | 220 | std::filesystem::path parentPath = devicePath.parent_path(); |
| 221 | if (std::filesystem::is_directory(parentPath)) |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 222 | { |
James Feist | 58b9c26 | 2019-02-12 13:38:45 -0800 | [diff] [blame] | 223 | for (const auto& path : |
| 224 | std::filesystem::directory_iterator(parentPath)) |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 225 | { |
James Feist | 58b9c26 | 2019-02-12 13:38:45 -0800 | [diff] [blame] | 226 | if (!std::filesystem::is_directory(path)) |
| 227 | { |
| 228 | continue; |
| 229 | } |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 230 | |
James Feist | 58b9c26 | 2019-02-12 13:38:45 -0800 | [diff] [blame] | 231 | const std::string& directoryName = path.path().filename(); |
| 232 | if (boost::starts_with(directoryName, busStr) && |
| 233 | boost::ends_with(directoryName, addressHex)) |
| 234 | { |
| 235 | return; // already exported |
| 236 | } |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | std::ofstream deviceFile(device); |
| 242 | if (!deviceFile.good()) |
| 243 | { |
| 244 | std::cerr << "Error writing " << device << "\n"; |
| 245 | return; |
| 246 | } |
| 247 | deviceFile << parameters; |
| 248 | deviceFile.close(); |
James Feist | 286babc | 2019-02-07 16:48:28 -0800 | [diff] [blame] | 249 | if (boost::ends_with(type, "Mux") && bus && address && channels) |
| 250 | { |
| 251 | linkMux(name, *bus, *address, *channels); |
| 252 | } |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | // this is now deprecated |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 256 | void createOverlay(const std::string& templatePath, |
| 257 | const nlohmann::json& configuration) |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 258 | { |
| 259 | std::ifstream templateFile(templatePath); |
| 260 | |
| 261 | if (!templateFile.is_open()) |
| 262 | { |
| 263 | std::cerr << "createOverlay error opening " << templatePath << "\n"; |
| 264 | return; |
| 265 | } |
| 266 | std::stringstream buff; |
| 267 | buff << templateFile.rdbuf(); |
| 268 | std::string templateStr = buff.str(); |
| 269 | std::string name = "unknown"; |
James Feist | d63d18a | 2018-07-19 15:23:45 -0700 | [diff] [blame] | 270 | std::string type = configuration["Type"]; |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 271 | for (auto keyPair = configuration.begin(); keyPair != configuration.end(); |
| 272 | keyPair++) |
| 273 | { |
| 274 | std::string subsituteString; |
| 275 | |
| 276 | // device tree symbols are in decimal |
James Feist | 1e3e698 | 2018-08-03 16:09:28 -0700 | [diff] [blame] | 277 | if (keyPair.key() == "Bus" && |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 278 | keyPair.value().type() == nlohmann::json::value_t::string) |
| 279 | { |
| 280 | unsigned int dec = |
| 281 | std::stoul(keyPair.value().get<std::string>(), nullptr, 16); |
| 282 | subsituteString = std::to_string(dec); |
| 283 | } |
James Feist | d63d18a | 2018-07-19 15:23:45 -0700 | [diff] [blame] | 284 | else if (keyPair.key() == "Name" && |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 285 | keyPair.value().type() == nlohmann::json::value_t::string) |
| 286 | { |
| 287 | subsituteString = std::regex_replace( |
| 288 | keyPair.value().get<std::string>(), ILLEGAL_NAME_REGEX, "_"); |
| 289 | name = subsituteString; |
| 290 | } |
James Feist | 1e3e698 | 2018-08-03 16:09:28 -0700 | [diff] [blame] | 291 | else if (keyPair.key() == "Address") |
Jae Hyun Yoo | 6d1d014 | 2018-07-25 10:07:43 -0700 | [diff] [blame] | 292 | { |
| 293 | if (keyPair.value().type() == nlohmann::json::value_t::string) |
| 294 | { |
| 295 | subsituteString = keyPair.value().get<std::string>(); |
| 296 | subsituteString.erase( |
| 297 | 0, subsituteString.find_first_not_of(HEX_FORMAT_STR)); |
| 298 | } |
| 299 | else |
| 300 | { |
| 301 | std::ostringstream hex; |
| 302 | hex << std::hex << keyPair.value().get<unsigned int>(); |
| 303 | subsituteString = hex.str(); |
| 304 | } |
| 305 | } |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 306 | else |
| 307 | { |
| 308 | subsituteString = jsonToString(keyPair.value()); |
| 309 | } |
| 310 | boost::replace_all(templateStr, TEMPLATE_CHAR + keyPair.key(), |
| 311 | subsituteString); |
| 312 | } |
| 313 | // todo: this is a lame way to fill in platform, but we only |
| 314 | // care about ast2500 right now |
James Feist | 1e3e698 | 2018-08-03 16:09:28 -0700 | [diff] [blame] | 315 | boost::replace_all(templateStr, TEMPLATE_CHAR + std::string("Platform"), |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 316 | PLATFORM); |
| 317 | std::string dtsFilename = |
| 318 | std::string(OUTPUT_DIR) + "/" + name + "_" + type + ".dts"; |
| 319 | std::string dtboFilename = |
| 320 | std::string(OUTPUT_DIR) + "/" + name + "_" + type + ".dtbo"; |
| 321 | |
| 322 | std::ofstream out(dtsFilename); |
| 323 | if (!out.is_open()) |
| 324 | { |
| 325 | std::cerr << "createOverlay error opening " << dtsFilename << "\n"; |
| 326 | return; |
| 327 | } |
| 328 | out << templateStr; |
| 329 | out.close(); |
| 330 | |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 331 | // compile dtbo and load overlay |
| 332 | boost::process::child c1(DTC, "-@", "-q", "-I", "dts", "-O", "dtb", "-o", |
| 333 | dtboFilename, dtsFilename); |
| 334 | c1.wait(); |
| 335 | if (c1.exit_code()) |
| 336 | { |
| 337 | std::cerr << "DTC error with file " << dtsFilename << "\n"; |
| 338 | return; |
| 339 | } |
| 340 | boost::process::child c2(DT_OVERLAY, "-d", OUTPUT_DIR, name + "_" + type); |
| 341 | c2.wait(); |
| 342 | if (c2.exit_code()) |
| 343 | { |
| 344 | std::cerr << "DTOverlay error with file " << dtboFilename << "\n"; |
| 345 | return; |
| 346 | } |
| 347 | auto findForceProbe = FORCE_PROBES.find(type); |
| 348 | if (findForceProbe != FORCE_PROBES.end()) |
| 349 | { |
| 350 | forceProbe(findForceProbe->second); |
| 351 | } |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 352 | } |
| 353 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 354 | bool loadOverlays(const nlohmann::json& systemConfiguration) |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 355 | { |
| 356 | |
Ed Tanous | 072e25d | 2018-12-16 21:45:20 -0800 | [diff] [blame] | 357 | std::vector<std::filesystem::path> paths; |
| 358 | if (!findFiles(std::filesystem::path(TEMPLATE_DIR), |
James Feist | a3c180a | 2018-08-09 16:06:04 -0700 | [diff] [blame] | 359 | R"(.*\.template)", paths)) |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 360 | { |
| 361 | std::cerr << "Unable to find any tempate files in " << TEMPLATE_DIR |
| 362 | << "\n"; |
| 363 | return false; |
| 364 | } |
| 365 | |
Ed Tanous | 072e25d | 2018-12-16 21:45:20 -0800 | [diff] [blame] | 366 | std::filesystem::create_directory(OUTPUT_DIR); |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 367 | for (auto entity = systemConfiguration.begin(); |
| 368 | entity != systemConfiguration.end(); entity++) |
| 369 | { |
James Feist | 1e3e698 | 2018-08-03 16:09:28 -0700 | [diff] [blame] | 370 | auto findExposes = entity.value().find("Exposes"); |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 371 | if (findExposes == entity.value().end() || |
| 372 | findExposes->type() != nlohmann::json::value_t::array) |
| 373 | { |
| 374 | continue; |
| 375 | } |
| 376 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 377 | for (auto& configuration : *findExposes) |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 378 | { |
James Feist | 1e3e698 | 2018-08-03 16:09:28 -0700 | [diff] [blame] | 379 | auto findStatus = configuration.find("Status"); |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 380 | // status missing is assumed to be 'okay' |
| 381 | if (findStatus != configuration.end() && *findStatus == "disabled") |
| 382 | { |
| 383 | continue; |
| 384 | } |
James Feist | d63d18a | 2018-07-19 15:23:45 -0700 | [diff] [blame] | 385 | auto findType = configuration.find("Type"); |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 386 | if (findType == configuration.end() || |
| 387 | findType->type() != nlohmann::json::value_t::string) |
| 388 | { |
| 389 | continue; |
| 390 | } |
| 391 | std::string type = findType.value().get<std::string>(); |
James Feist | ce4367c | 2018-10-16 09:19:57 -0700 | [diff] [blame] | 392 | #if OVERLAYS |
| 393 | |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 394 | std::string typeFile = type + std::string(".template"); |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 395 | for (const auto& path : paths) |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 396 | { |
| 397 | if (path.filename() != typeFile) |
| 398 | { |
| 399 | continue; |
| 400 | } |
| 401 | createOverlay(path.string(), configuration); |
| 402 | break; |
| 403 | } |
James Feist | ce4367c | 2018-10-16 09:19:57 -0700 | [diff] [blame] | 404 | #endif |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 405 | auto device = devices::exportTemplates.find(type.c_str()); |
| 406 | if (device != devices::exportTemplates.end()) |
| 407 | { |
James Feist | 286babc | 2019-02-07 16:48:28 -0800 | [diff] [blame] | 408 | exportDevice(type, device->second, configuration); |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 409 | } |
James Feist | c95cb14 | 2018-02-26 10:41:42 -0800 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
| 413 | return true; |
Jae Hyun Yoo | 6d1d014 | 2018-07-25 10:07:43 -0700 | [diff] [blame] | 414 | } |