| 103 | json_t* rootJ; |
| 104 | |
| 105 | StaticPluginLoader(Plugin* const p, const char* const name) |
| 106 | : plugin(p), |
| 107 | file(nullptr), |
| 108 | rootJ(nullptr) |
| 109 | { |
| 110 | #ifdef DEBUG |
| 111 | DEBUG("Loading plugin module %s", name); |
| 112 | #endif |
| 113 | |
| 114 | p->path = asset::pluginPath(name); |
| 115 | |
| 116 | const std::string manifestFilename = asset::pluginManifest(name); |
| 117 | |
| 118 | if ((file = std::fopen(manifestFilename.c_str(), "r")) == nullptr) |
| 119 | { |
| 120 | d_stderr2("Manifest file %s does not exist", manifestFilename.c_str()); |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | json_error_t error; |
| 125 | if ((rootJ = json_loadf(file, 0, &error)) == nullptr) |
| 126 | { |
| 127 | d_stderr2("JSON parsing error at %s %d:%d %s", manifestFilename.c_str(), error.line, error.column, error.text); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | // force ABI, we use static plugins so this doesnt matter as long as it builds |
| 132 | json_t* const version = json_string((APP_VERSION_MAJOR + ".0").c_str()); |
| 133 | json_object_set(rootJ, "version", version); |
| 134 | json_decref(version); |
| 135 | |
| 136 | // Load manifest |
| 137 | p->fromJson(rootJ); |
| 138 | |
| 139 | // Reject plugin if slug already exists |
| 140 | if (Plugin* const existingPlugin = getPlugin(p->slug)) |
| 141 | throw Exception("Plugin %s is already loaded, not attempting to load it again", p->slug.c_str()); |
| 142 | } |
| 143 | |
| 144 | ~StaticPluginLoader() |
| 145 | { |
nothing calls this directly
no test coverage detected