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