Static members
| 120 | |
| 121 | // Static members |
| 122 | Plugin * |
| 123 | Plugin::make(const char *path) |
| 124 | { |
| 125 | void *handle = nullptr; |
| 126 | Plugin *plugin = nullptr; |
| 127 | const char *name; |
| 128 | const char *desc; |
| 129 | |
| 130 | if ((handle = dlopen(path, RTLD_LAZY)) == nullptr) { |
| 131 | SU_ERROR("Cannot open %s: %s\n", path, dlerror()); |
| 132 | return nullptr; |
| 133 | } |
| 134 | |
| 135 | // Not an error, just not a plugin |
| 136 | if ((name = SCAST( |
| 137 | const char *, |
| 138 | dlsym(handle, SUSCAN_SYM_NAME(plugin_name)))) == nullptr) { |
| 139 | SU_WARNING("%s: not a plugin (no plugin name)\n", path); |
| 140 | goto done; |
| 141 | } |
| 142 | |
| 143 | if ((desc = SCAST( |
| 144 | const char *, |
| 145 | dlsym(handle, SUSCAN_SYM_NAME(plugin_desc)))) == nullptr) { |
| 146 | SU_WARNING("%s: not a plugin (no plugin desc)\n", path); |
| 147 | goto done; |
| 148 | } |
| 149 | |
| 150 | plugin = new Plugin(name, path, desc, handle); |
| 151 | |
| 152 | done: |
| 153 | if (plugin == nullptr && handle != nullptr) |
| 154 | dlclose(handle); |
| 155 | |
| 156 | return plugin; |
| 157 | } |
| 158 | |
| 159 | Plugin * |
| 160 | Plugin::getDefaultPlugin() |