| 19 | |
| 20 | |
| 21 | void Cable::fromJson(json_t* rootJ) { |
| 22 | // Only set ID if unset |
| 23 | if (id < 0) { |
| 24 | // id |
| 25 | json_t* idJ = json_object_get(rootJ, "id"); |
| 26 | // Before 1.0, cables IDs were not used, so just leave it as default and Engine will assign one automatically. |
| 27 | if (idJ) |
| 28 | id = json_integer_value(idJ); |
| 29 | } |
| 30 | |
| 31 | // inputModuleId |
| 32 | json_t* inputModuleIdJ = json_object_get(rootJ, "inputModuleId"); |
| 33 | if (!inputModuleIdJ) |
| 34 | throw Exception("Input module ID not found for cable %lld", (long long) id); |
| 35 | int64_t inputModuleId = json_integer_value(inputModuleIdJ); |
| 36 | inputModule = APP->engine->getModule_NoLock(inputModuleId); |
| 37 | if (!inputModule) |
| 38 | throw Exception("Input module %lld not found for cable %lld", (long long) inputModuleId, (long long) id); |
| 39 | |
| 40 | // inputId |
| 41 | json_t* inputIdJ = json_object_get(rootJ, "inputId"); |
| 42 | if (!inputIdJ) |
| 43 | throw Exception("Input ID not found for cable %lld", (long long) id); |
| 44 | inputId = json_integer_value(inputIdJ); |
| 45 | |
| 46 | // outputModuleId |
| 47 | json_t* outputModuleIdJ = json_object_get(rootJ, "outputModuleId"); |
| 48 | if (!outputModuleIdJ) |
| 49 | throw Exception("Output module ID not found for cable %lld", (long long) id); |
| 50 | int64_t outputModuleId = json_integer_value(outputModuleIdJ); |
| 51 | outputModule = APP->engine->getModule_NoLock(outputModuleId); |
| 52 | if (!outputModule) |
| 53 | throw Exception("Output module %lld not found for cable %lld", (long long) outputModuleId, (long long) id); |
| 54 | |
| 55 | // outputId |
| 56 | json_t* outputIdJ = json_object_get(rootJ, "outputId"); |
| 57 | if (!outputIdJ) |
| 58 | throw Exception("Output ID not found for cable %lld", (long long) id); |
| 59 | outputId = json_integer_value(outputIdJ); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | void Cable::jsonStripIds(json_t* rootJ) { |
nothing calls this directly
no test coverage detected