| 1246 | |
| 1247 | |
| 1248 | json_t* Engine::toJson() { |
| 1249 | SharedLock<SharedMutex> lock(internal->mutex); |
| 1250 | json_t* rootJ = json_object(); |
| 1251 | |
| 1252 | // modules |
| 1253 | json_t* modulesJ = json_array(); |
| 1254 | for (Module* module : internal->modules) { |
| 1255 | json_t* moduleJ = module->toJson(); |
| 1256 | json_array_append_new(modulesJ, moduleJ); |
| 1257 | } |
| 1258 | json_object_set_new(rootJ, "modules", modulesJ); |
| 1259 | |
| 1260 | // cables |
| 1261 | json_t* cablesJ = json_array(); |
| 1262 | for (Cable* cable : internal->cables) { |
| 1263 | json_t* cableJ = cable->toJson(); |
| 1264 | json_array_append_new(cablesJ, cableJ); |
| 1265 | } |
| 1266 | json_object_set_new(rootJ, "cables", cablesJ); |
| 1267 | |
| 1268 | // masterModule |
| 1269 | if (internal->masterModule) { |
| 1270 | json_object_set_new(rootJ, "masterModuleId", json_integer(internal->masterModule->id)); |
| 1271 | } |
| 1272 | |
| 1273 | return rootJ; |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | void Engine::fromJson(json_t* rootJ) { |