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