Source code for plugin utilities. More...
#include <gio/gio.h>
#include "application-data.h"
#include "plugins.h"
Go to the source code of this file.
Functions | |
GList * | plugin_list_new (const gchar *plugins_dir) |
Creates a list of plugins available in the given directory. | |
void | plugin_list_free (GList *list) |
Frees a list of plugins. | |
plugin_t * | plugin_new (const gchar *plugins_dir, const gchar *name) |
Creates a new plugin. | |
void * | plugin_get_symbol (plugin_t *pt, const char *symbol_name, gboolean display_warnings) |
Gets a symbol in a plugin's library file. | |
void | plugin_free (plugin_t *pt) |
Frees a plugin_t struct. | |
plugin_t * | plugin_list_find_custom_list (GList *list, const gchar *name) |
Find a plugin matching name in a given list of plugins. | |
plugin_t * | plugin_list_find (const gchar *name) |
Searches the Synema instance for a plugin. | |
gboolean | plugin_exists (const gchar *name) |
Checks if a plugin exists. | |
gchar * | plugin_get_display_name (plugin_t *pt) |
Returns the display name of a plugin. | |
GList * | plugin_get_time_periods (plugin_t *pt) |
Returns the time periods available for a plugin. |
Source code for plugin utilities.
This source code file contains plugin related functions.
Definition in file plugins.c.
gboolean plugin_exists | ( | const gchar * | name | ) |
Checks if a plugin exists.
This function checks if a plugin exists by calling plugin_list_find and checking if the result is different from NULL.
[in] | name | the name of the plugin to look for |
Definition at line 160 of file plugins.c.
00161 { 00162 return plugin_list_find (name) != NULL; 00163 }
void plugin_free | ( | plugin_t * | pt | ) |
gchar * plugin_get_display_name | ( | plugin_t * | pt | ) |
Returns the display name of a plugin.
This function returns the display name of a plugin, as a static string. Don't modify or free it.
[in] | pt | the plugin |
Definition at line 167 of file plugins.c.
00168 { 00169 g_return_val_if_fail (pt != NULL, NULL); 00170 00171 gchar *(*func)(frame_t *) = NULL; 00172 00173 *(void **) (&func) = plugin_get_symbol (pt, "get_display_name", TRUE); 00174 if (!func) { 00175 g_warning ("plugin_get_display_name: Failed to get the display name"); 00176 return NULL; 00177 } 00178 00179 return func(NULL); 00180 }
void * plugin_get_symbol | ( | plugin_t * | pt, | |
const char * | symbol_name, | |||
gboolean | display_warnings | |||
) |
Gets a symbol in a plugin's library file.
This function gets a symbol in a plugin. The name of the symbol is given as a parameter.
[in] | pt | the plugin whose symbol to get |
[in] | symbol_name | the name of the symbol |
[in] | display_warnings | whether to display warnings if the symbol isn't found. |
Definition at line 106 of file plugins.c.
00107 { 00108 g_return_val_if_fail (pt != NULL, NULL); 00109 00110 char *err = NULL; 00111 void *symbol = NULL; 00112 00113 * (void **) &symbol = dlsym (pt->handle, symbol_name); 00114 err = dlerror (); 00115 if (err) { 00116 if (display_warnings) 00117 g_warning ("plugin_get_symbol: %s", err); 00118 return NULL; 00119 } 00120 00121 return symbol; 00122 }
GList * plugin_get_time_periods | ( | plugin_t * | pt | ) |
Returns the time periods available for a plugin.
This function returns a GList of pointers to time_period_t available for a given plugin.
[in] | pt | the plugin |
Definition at line 184 of file plugins.c.
00185 { 00186 g_return_val_if_fail (pt != NULL, NULL); 00187 00188 GList *(*func)() = NULL; 00189 00190 *(void **) (&func) = plugin_get_symbol (pt, "build_time_periods", TRUE); 00191 if (!func) { 00192 g_warning ("plugin_get_time_periods: Failed to get the list of time periods"); 00193 return NULL; 00194 } 00195 00196 return func(); 00197 }
plugin_t * plugin_list_find | ( | const gchar * | name | ) |
Searches the Synema instance for a plugin.
This function is a wrapper for plugin_list_find_custom_list which will use the application instance's list of plugins as a list.
[in] | name | the name of the wanted plugin |
Definition at line 152 of file plugins.c.
00153 { 00154 synema_instance_t *inst = synema_instance (); 00155 return (plugin_list_find_custom_list (inst->plugins_list, name)); 00156 }
plugin_t * plugin_list_find_custom_list | ( | GList * | list, | |
const gchar * | name | |||
) |
Find a plugin matching name in a given list of plugins.
This function searches through a list of plugin_t structs given as a parameter for a plugin whose name is also given as a parameter.
[in] | list | the list in which to search |
[in] | name | the name of the plugin to find |
void plugin_list_free | ( | GList * | list | ) |
Frees a list of plugins.
This function frees the plugin_t structs contained in a given list of plugin_t pointers.
[out] | list | the list of plugins to free |
Definition at line 71 of file plugins.c.
00072 { 00073 if (list) { 00074 GList *iter = list; 00075 do { 00076 plugin_free (iter->data); 00077 } while ((iter = g_list_next (iter)) != NULL); 00078 } 00079 00080 g_list_free (list); 00081 }
GList * plugin_list_new | ( | const gchar * | plugins_dir | ) |
Creates a list of plugins available in the given directory.
This function creates a list of plugins based on the .so files available in the directory given as a parameter.
[in] | plugins_dir | the directory to scan for plugins |
Definition at line 31 of file plugins.c.
00032 { 00033 const gchar *filename = NULL; 00034 gchar *pluginname = NULL; 00035 GError *err = NULL; 00036 GFile *file = g_file_new_for_path (plugins_dir); 00037 GFileEnumerator *fileenum = g_file_enumerate_children (file, "standard::name", G_FILE_QUERY_INFO_NONE, NULL, &err); 00038 GFileInfo *current = NULL; 00039 gint len = 0; 00040 GList *list = NULL; 00041 00042 if (err) { 00043 g_warning ("plugin_list_new: Error while trying to read the directory containing plugins (%s)", err->message); 00044 g_clear_error (&err); 00045 return NULL; 00046 } 00047 00048 while ((current = g_file_enumerator_next_file (fileenum, NULL, &err)) != NULL) { 00049 if (err) { 00050 g_warning ("plugin_list_new: Error while reading a file in the plugins directory (%s)", err->message); 00051 g_clear_error (&err); 00052 } else { 00053 filename = g_file_info_get_name (current); 00054 len = g_strrstr (filename, ".so") - filename; 00055 00056 pluginname = g_strndup (filename, len); 00057 list = g_list_prepend (list, plugin_new (plugins_dir, pluginname)); 00058 00059 g_free (pluginname); 00060 g_object_unref (current); 00061 } 00062 } 00063 00064 g_object_unref (fileenum); 00065 g_object_unref (file); 00066 return list; 00067 }
plugin_t * plugin_new | ( | const gchar * | plugins_dir, | |
const gchar * | name | |||
) |
Creates a new plugin.
This function creates a plugin, with a name given as a parameter. It gets the dlhandle from a .so file which should be in plugins_dir.
[in] | plugins_dir | the directory in which to look for the .so file matching name |
[in] | name | the name to give to the plugin |
Definition at line 85 of file plugins.c.
00086 { 00087 plugin_t *pt = g_malloc (sizeof (plugin_t)); 00088 gchar *path = g_strdup_printf ("%s/%s.so", plugins_dir, name); 00089 char *err = NULL; 00090 00091 pt->name = g_strdup (name); 00092 pt->handle = dlopen (path, RTLD_NOW); 00093 g_free (path); 00094 00095 err = dlerror (); 00096 if (err) { 00097 g_warning ("plugin_new: %s", err); 00098 return NULL; 00099 } 00100 00101 return pt; 00102 }