| 1275 | |
| 1276 | |
| 1277 | void Engine::fromJson(json_t* rootJ) { |
| 1278 | clear(); |
| 1279 | |
| 1280 | // modules |
| 1281 | // We can't instantiate modules before clearing because some modules add ParamHandles upon construction. |
| 1282 | // We also can't lock while instantiating modules because they call addParamHandle() which locks. |
| 1283 | std::vector<Module*> modules; |
| 1284 | json_t* modulesJ = json_object_get(rootJ, "modules"); |
| 1285 | if (!modulesJ) |
| 1286 | return; |
| 1287 | size_t moduleIndex; |
| 1288 | json_t* moduleJ; |
| 1289 | json_array_foreach(modulesJ, moduleIndex, moduleJ) { |
| 1290 | // Get model |
| 1291 | plugin::Model* model; |
| 1292 | try { |
| 1293 | model = plugin::modelFromJson(moduleJ); |
| 1294 | } |
| 1295 | catch (Exception& e) { |
| 1296 | WARN("Cannot load model: %s", e.what()); |
| 1297 | continue; |
| 1298 | } |
| 1299 | |
| 1300 | // Create module |
| 1301 | INFO("Creating module %s", model->getFullName().c_str()); |
| 1302 | Module* module = model->createModule(); |
| 1303 | assert(module); |
| 1304 | |
| 1305 | try { |
| 1306 | module->fromJson(moduleJ); |
| 1307 | |
| 1308 | // Before 1.0, the module ID was the index in the "modules" array |
| 1309 | if (module->id < 0) { |
| 1310 | module->id = moduleIndex; |
| 1311 | } |
| 1312 | } |
| 1313 | catch (Exception& e) { |
| 1314 | WARN("Cannot load module: %s", e.what()); |
| 1315 | delete module; |
| 1316 | continue; |
| 1317 | } |
| 1318 | |
| 1319 | modules.push_back(module); |
| 1320 | } |
| 1321 | |
| 1322 | std::lock_guard<SharedMutex> lock(internal->mutex); |
| 1323 | |
| 1324 | // Add modules |
| 1325 | for (Module* module : modules) { |
| 1326 | addModule_NoLock(module); |
| 1327 | } |
| 1328 | |
| 1329 | // cables |
| 1330 | json_t* cablesJ = json_object_get(rootJ, "cables"); |
| 1331 | // Before 1.0, cables were called wires |
| 1332 | if (!cablesJ) |
| 1333 | cablesJ = json_object_get(rootJ, "wires"); |
| 1334 | if (!cablesJ) |
no outgoing calls
no test coverage detected