diff options
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/plugin_manager.c | 135 |
1 files changed, 59 insertions, 76 deletions
diff --git a/src/plugins/plugin_manager.c b/src/plugins/plugin_manager.c index afca55e..aab98c8 100644 --- a/src/plugins/plugin_manager.c +++ b/src/plugins/plugin_manager.c @@ -6,99 +6,82 @@ #include <string.h> // Linked list node for plugins. -typedef struct PluginNode -{ - ZPlugin *plugin; - void *handle; // dlopen handle (NULL for built-ins). - struct PluginNode *next; +typedef struct PluginNode { + ZPlugin *plugin; + void *handle; // dlopen handle (NULL for built-ins). + struct PluginNode *next; } PluginNode; static PluginNode *head = NULL; -void zptr_plugin_mgr_init(void) -{ - head = NULL; -} +void zptr_plugin_mgr_init(void) { head = NULL; } -void zptr_register_plugin(ZPlugin *plugin) -{ - if (!plugin) - { - return; - } +void zptr_register_plugin(ZPlugin *plugin) { + if (!plugin) { + return; + } - if (zptr_find_plugin(plugin->name)) - { - return; - } + if (zptr_find_plugin(plugin->name)) { + return; + } - PluginNode *node = malloc(sizeof(PluginNode)); - node->plugin = plugin; - node->handle = NULL; - node->next = head; - head = node; + PluginNode *node = malloc(sizeof(PluginNode)); + node->plugin = plugin; + node->handle = NULL; + node->next = head; + head = node; } -ZPlugin *zptr_load_plugin(const char *path) -{ - void *handle = dlopen(path, RTLD_LAZY); - if (!handle) - { - return NULL; - } +ZPlugin *zptr_load_plugin(const char *path) { + void *handle = dlopen(path, RTLD_LAZY); + if (!handle) { + return NULL; + } - ZPluginInitFn init_fn = (ZPluginInitFn)dlsym(handle, "z_plugin_init"); - if (!init_fn) - { - fprintf(stderr, "Plugin '%s' missing 'z_plugin_init' symbol\n", path); - dlclose(handle); - return NULL; - } + ZPluginInitFn init_fn = (ZPluginInitFn)dlsym(handle, "z_plugin_init"); + if (!init_fn) { + fprintf(stderr, "Plugin '%s' missing 'z_plugin_init' symbol\n", path); + dlclose(handle); + return NULL; + } - ZPlugin *plugin = init_fn(); - if (!plugin) - { - fprintf(stderr, "Plugin '%s' init returned NULL\n", path); - dlclose(handle); - return NULL; - } + ZPlugin *plugin = init_fn(); + if (!plugin) { + fprintf(stderr, "Plugin '%s' init returned NULL\n", path); + dlclose(handle); + return NULL; + } - // Register - PluginNode *node = malloc(sizeof(PluginNode)); - node->plugin = plugin; - node->handle = handle; - node->next = head; - head = node; + // Register + PluginNode *node = malloc(sizeof(PluginNode)); + node->plugin = plugin; + node->handle = handle; + node->next = head; + head = node; - return plugin; + return plugin; } -ZPlugin *zptr_find_plugin(const char *name) -{ - PluginNode *curr = head; - while (curr) - { - if (strcmp(curr->plugin->name, name) == 0) - { - return curr->plugin; - } - curr = curr->next; +ZPlugin *zptr_find_plugin(const char *name) { + PluginNode *curr = head; + while (curr) { + if (strcmp(curr->plugin->name, name) == 0) { + return curr->plugin; } - return NULL; + curr = curr->next; + } + return NULL; } -void zptr_plugin_mgr_cleanup(void) -{ - PluginNode *curr = head; - while (curr) - { - PluginNode *next = curr->next; - if (curr->handle) - { - dlclose(curr->handle); - } - free(curr); - curr = next; +void zptr_plugin_mgr_cleanup(void) { + PluginNode *curr = head; + while (curr) { + PluginNode *next = curr->next; + if (curr->handle) { + dlclose(curr->handle); } - head = NULL; + free(curr); + curr = next; + } + head = NULL; } |
