Allow plugins to provide an error message. Useful for reporting problems
when registering the plugins.
This commit is contained in:
@@ -826,22 +826,12 @@ void hub_plugins_load(struct hub_info* hub)
|
||||
|
||||
void hub_plugins_unload(struct hub_info* hub)
|
||||
{
|
||||
if (!hub->plugins || !hub->plugins->loaded)
|
||||
if (hub->plugins)
|
||||
{
|
||||
return;
|
||||
plugin_shutdown(hub->plugins);
|
||||
hub_free(hub->plugins);
|
||||
hub->plugins = 0;
|
||||
}
|
||||
|
||||
struct uhub_plugin_handle* plugin = (struct uhub_plugin_handle*) list_get_first(hub->plugins->loaded);
|
||||
while (plugin)
|
||||
{
|
||||
plugin_unload(plugin);
|
||||
plugin = (struct uhub_plugin_handle*) list_get_next(hub->plugins->loaded);
|
||||
}
|
||||
|
||||
list_destroy(hub->plugins->loaded);
|
||||
hub_free(hub->plugins->plugin_dir);
|
||||
hub_free(hub->plugins);
|
||||
hub->plugins = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ struct uhub_plugin_handle* plugin_load(const char* filename, const char* config)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Unable to load plugin: %s - Failed to initialize", filename);
|
||||
LOG_ERROR("Unable to load plugin: %s - Failed to initialize: %s", filename, handle->error_msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,10 +127,16 @@ static int plugin_parse_line(char* line, int line_count, void* ptr_data)
|
||||
char *directive, *soname, *params;
|
||||
|
||||
if (cfg_token_count(tokens) == 0)
|
||||
{
|
||||
cfg_tokens_free(tokens);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cfg_token_count(tokens) < 2)
|
||||
{
|
||||
cfg_tokens_free(tokens);
|
||||
return -1;
|
||||
}
|
||||
|
||||
directive = cfg_token_get_first(tokens);
|
||||
soname = cfg_token_get_next(tokens);
|
||||
@@ -141,12 +147,12 @@ static int plugin_parse_line(char* line, int line_count, void* ptr_data)
|
||||
if (!params)
|
||||
params = "";
|
||||
|
||||
|
||||
LOG_TRACE("Load plugin: \"%s\", params=\"%s\"", soname, params);
|
||||
struct uhub_plugin_handle* plugin = plugin_load(soname, params);
|
||||
if (plugin)
|
||||
{
|
||||
list_append(handle->loaded, plugin);
|
||||
cfg_tokens_free(tokens);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -175,5 +181,17 @@ int plugin_initialize(struct hub_config* config, struct uhub_plugins* handle)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void plugin_shutdown(struct uhub_plugins* handle)
|
||||
{
|
||||
struct uhub_plugin_handle* plugin = (struct uhub_plugin_handle*) list_get_first(handle->loaded);
|
||||
while (plugin)
|
||||
{
|
||||
list_remove(handle->loaded, plugin);
|
||||
plugin_unload(plugin);
|
||||
plugin = (struct uhub_plugin_handle*) list_get_first(handle->loaded);
|
||||
}
|
||||
|
||||
list_destroy(handle->loaded);
|
||||
}
|
||||
|
||||
#endif /* PLUGIN_SUPPORT */
|
||||
|
||||
@@ -39,7 +39,6 @@ struct uhub_plugin
|
||||
struct uhub_plugins
|
||||
{
|
||||
struct linked_list* loaded;
|
||||
char* plugin_dir;
|
||||
};
|
||||
|
||||
// High level plugin loader ode
|
||||
@@ -48,6 +47,7 @@ extern void plugin_unload(struct uhub_plugin_handle* plugin);
|
||||
|
||||
// extern void plugin_unload(struct uhub_plugin_handle*);
|
||||
extern int plugin_initialize(struct hub_config* config, struct uhub_plugins* handle);
|
||||
extern void plugin_shutdown(struct uhub_plugins* handle);
|
||||
|
||||
// Low level plugin loader code (used internally)
|
||||
extern struct uhub_plugin* plugin_open(const char* filename);
|
||||
|
||||
Reference in New Issue
Block a user