|
@@ -1201,10 +1201,8 @@ json_t* Engine::toJson() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Engine::fromJson(json_t* rootJ) { |
|
|
void Engine::fromJson(json_t* rootJ) { |
|
|
std::lock_guard<SharedMutex> lock(internal->mutex); |
|
|
|
|
|
|
|
|
|
|
|
clear_NoLock(); |
|
|
|
|
|
// modules |
|
|
// modules |
|
|
|
|
|
std::vector<Module*> modules; |
|
|
json_t* modulesJ = json_object_get(rootJ, "modules"); |
|
|
json_t* modulesJ = json_object_get(rootJ, "modules"); |
|
|
if (!modulesJ) |
|
|
if (!modulesJ) |
|
|
return; |
|
|
return; |
|
@@ -1228,15 +1226,12 @@ void Engine::fromJson(json_t* rootJ) { |
|
|
assert(module); |
|
|
assert(module); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
// This doesn't need a lock because the Module is not added to the Engine yet. |
|
|
|
|
|
module->fromJson(moduleJ); |
|
|
module->fromJson(moduleJ); |
|
|
|
|
|
|
|
|
// Before 1.0, the module ID was the index in the "modules" array |
|
|
// Before 1.0, the module ID was the index in the "modules" array |
|
|
if (module->id < 0) { |
|
|
if (module->id < 0) { |
|
|
module->id = moduleIndex; |
|
|
module->id = moduleIndex; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
addModule_NoLock(module); |
|
|
|
|
|
} |
|
|
} |
|
|
catch (Exception& e) { |
|
|
catch (Exception& e) { |
|
|
WARN("Cannot load module: %s", e.what()); |
|
|
WARN("Cannot load module: %s", e.what()); |
|
@@ -1244,6 +1239,17 @@ void Engine::fromJson(json_t* rootJ) { |
|
|
delete module; |
|
|
delete module; |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
modules.push_back(module); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::lock_guard<SharedMutex> lock(internal->mutex); |
|
|
|
|
|
|
|
|
|
|
|
clear_NoLock(); |
|
|
|
|
|
|
|
|
|
|
|
// Add modules |
|
|
|
|
|
for (Module* module : modules) { |
|
|
|
|
|
addModule_NoLock(module); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// cables |
|
|
// cables |
|
@@ -1280,7 +1286,7 @@ void Engine::fromJson(json_t* rootJ) { |
|
|
// masterModule |
|
|
// masterModule |
|
|
json_t* masterModuleIdJ = json_object_get(rootJ, "masterModuleId"); |
|
|
json_t* masterModuleIdJ = json_object_get(rootJ, "masterModuleId"); |
|
|
if (masterModuleIdJ) { |
|
|
if (masterModuleIdJ) { |
|
|
Module* masterModule = getModule(json_integer_value(masterModuleIdJ)); |
|
|
|
|
|
|
|
|
Module* masterModule = getModule_NoLock(json_integer_value(masterModuleIdJ)); |
|
|
setMasterModule_NoLock(masterModule); |
|
|
setMasterModule_NoLock(masterModule); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|