From: <enl...@li...> - 2002-01-04 18:40:23
|
Enlightenment CVS committal Author : rbdpngn Project : e17 Module : libs/ewd Dir : e17/libs/ewd/src Modified Files: Ewd.h Makefile.am ewd_plugin.c ewd_plugin.h ewd_value.c Added Files: ewd_path.c ewd_path.h ewd_sheap.c ewd_sheap.h Log Message: Split up the path handling into a separate file, and added a static sized heap data type (allows for the usual heap access of removing the item at the top of the heap as well as random access within the array). Still need to add destructor callbacks for this data type, but I'm going to make some core changes to ewd soon, so it will have to wait until that point. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewd/src/Ewd.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- Ewd.h 2001/11/04 22:21:40 1.8 +++ Ewd.h 2002/01/04 18:40:22 1.9 @@ -26,6 +26,8 @@ #include <ewd_list.h> #include <ewd_tree.h> #include <ewd_hash.h> +#include <ewd_sheap.h> +#include <ewd_path.h> #include <ewd_plugin.h> #endif =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewd/src/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- Makefile.am 2001/11/04 21:35:25 1.10 +++ Makefile.am 2002/01/04 18:40:22 1.11 @@ -5,22 +5,26 @@ lib_LTLIBRARIES = libewd.la installed_headers_DATA = \ Ewd.h \ + ewd_config.h \ ewd_hash.h \ + ewd_sheap.h \ ewd_list.h \ ewd_macros.h \ + ewd_path.h \ + ewd_plugin.h \ ewd_threads.h \ ewd_tree.h \ - ewd_value.h \ - ewd_config.h \ - ewd_plugin.h + ewd_value.h -libewd_la_CFLAGS = -O6 +libewd_la_CFLAGS = -O2 libewd_la_SOURCES = \ ewd_hash.c \ + ewd_sheap.c \ ewd_list.c \ ewd_tree.c \ ewd_value.c \ + ewd_path.c \ ewd_plugin.c libewd_la_LIBADD = -lm =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewd/src/ewd_plugin.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewd_plugin.c 2001/11/08 22:47:26 1.2 +++ ewd_plugin.c 2002/01/04 18:40:22 1.3 @@ -1,135 +1,10 @@ #include <Ewd.h> -static Ewd_List *group_list = NULL; +static Ewd_List *loaded_plugins = NULL; - -Ewd_Plugin_Group *__ewd_plugin_group_find(char *name); -Ewd_Plugin_Group *__ewd_plugin_group_find_id(int id); - -/** - * ewd_plugin_group_new - create a new plugin group - * @group_name: the name of the new group - * - * Returns 0 on error, the integer id of the new group on success. - */ -int -ewd_plugin_group_new(char *group_name) -{ - Ewd_Plugin_Group *group; - - CHECK_PARAM_POINTER_RETURN("group_name", group_name, -1); - - if (!group_list) { - group_list = ewd_list_new(); - } - else { - group = __ewd_plugin_group_find(group_name); - if (group) - return -1; - } - - group = (Ewd_Plugin_Group *) malloc(sizeof(Ewd_Plugin_Group)); - memset(group, 0, sizeof(Ewd_Plugin_Group)); - - group->name = strdup(group_name); - - ewd_list_append(group_list, group); - - group->id = ewd_list_nodes(group_list); - - return group->id; -} - -/** - * ewd_plugin_group_del - destroy a previously created plugin group - * @group_id: the unique identifier for the group - * - * Returns no value. - */ -void -ewd_plugin_group_del(int group_id) -{ - Ewd_Plugin_Group *group; - - group = __ewd_plugin_group_find_id(group_id); - - if (!group) - return; - - ewd_list_for_each(group->loaded_plugins, - EWD_FOR_EACH(ewd_plugin_unload)); - ewd_list_destroy(group->loaded_plugins); - - ewd_list_for_each(group->paths, - EWD_FOR_EACH(free)); - ewd_list_destroy(group->paths); - - free(group->name); - free(group); -} - /** - * ewd_plugin_path_add - add a directory to be searched for plugins - * @group_id: the unique identifier for the group to add the path - * @path: the new path to be added to the group - * - * Returns no value. - */ -void -ewd_plugin_path_add(int group_id, char *path) -{ - Ewd_Plugin_Group *group; - - CHECK_PARAM_POINTER("path", path); - - group = __ewd_plugin_group_find_id(group_id); - - if (!group) - return; - - if (!group->paths) - group->paths = ewd_list_new(); - - ewd_list_append(group->paths, strdup(path)); -} - -/* - * Remove a directory to be searched for plugins - */ -void -ewd_plugin_path_del(int group_id, char *path) -{ - char *found; - Ewd_Plugin_Group *group; - - CHECK_PARAM_POINTER("path", path); - - group = __ewd_plugin_group_find_id(group_id); - - if (!group || !group->paths) - return; - - /* - * Find the path in the list of available paths - */ - ewd_list_goto_first(group->paths); - - while ((found = ewd_list_current(group->paths)) - && strcmp(found, path)) - ewd_list_next(group->paths); - - /* - * If the path is found, remove and free it - */ - if (found) { - ewd_list_remove(group->paths); - free(found); - } -} - -/** - * ewd_plugin_load - load the specified plugin from the specified group - * @group_id: the group to search for the plugin to load + * ewd_plugin_load - load the specified plugin from the specified path group + * @group_id: the path group to search for the plugin to load * @plugin_name: the name of the plugin to load * * Returns a pointer to the newly loaded plugin on success, NULL on failure. @@ -137,41 +12,22 @@ Ewd_Plugin * ewd_plugin_load(int group_id, char *plugin_name) { - char *p; - char path[1024]; - struct stat st; + char *path; + char temp[PATH_MAX]; - Ewd_Plugin_Group *group; Ewd_Plugin *plugin; void *handle = NULL; CHECK_PARAM_POINTER_RETURN("plugin_name", plugin_name, NULL); - /* - * Make sure we have a plugin group that matches the specified id - */ - group = __ewd_plugin_group_find_id(group_id); - - if (!group || !group->paths) + snprintf(temp, PATH_MAX, "%s.so", plugin_name); + path = ewd_path_group_find(group_id, temp); + if (!path) return NULL; - - /* - * Search the paths of the plugin group for the specified plugin name - */ - ewd_list_goto_first(group->paths); - while ((p = ewd_list_next(group->paths)) != NULL) { - snprintf(path, 1024, "%s/%s.so", p, plugin_name); - stat(path, &st); - - /* - * If we've found a valid plugin, open it and stop searching - */ - if (S_ISREG(st.st_mode)) { - handle = dlopen(path, RTLD_LAZY); - break; - } - } + handle = dlopen(path, RTLD_LAZY); + if (!handle) + return NULL; /* * Allocate the new plugin and initialize it's fields @@ -186,10 +42,10 @@ /* * Now add it to the list of the groups loaded plugins */ - if (!group->loaded_plugins) - group->loaded_plugins = ewd_list_new(); + if (!loaded_plugins) + loaded_plugins = ewd_list_new(); - ewd_list_append(group->loaded_plugins, plugin); + ewd_list_append(loaded_plugins, plugin); return plugin; } @@ -203,17 +59,13 @@ void ewd_plugin_unload(Ewd_Plugin * plugin) { - Ewd_Plugin_Group *group; - CHECK_PARAM_POINTER("plugin", plugin); if (!plugin->handle) return; - - group = __ewd_plugin_group_find_id(plugin->group); - if (ewd_list_goto(group->loaded_plugins, plugin)) - ewd_list_remove(group->loaded_plugins); + if (ewd_list_goto(loaded_plugins, plugin)) + ewd_list_remove(loaded_plugins); dlclose(plugin->handle); @@ -238,106 +90,4 @@ ret = dlsym(plugin->handle, symbol_name); return ret; -} - -Ewd_List * -ewd_plugin_get_available(int group_id) -{ - Ewd_List *avail = NULL; - Ewd_Plugin_Group *group; - char *path; - - group = __ewd_plugin_group_find_id(group_id); - - if (!group || !group->paths || ewd_list_is_empty(group->paths)) - return NULL; - - ewd_list_goto_first(group->paths); - - while ((path = ewd_list_next(group->paths)) != NULL) - { - DIR *dir; - struct stat st; - struct dirent *d; - - stat(path, &st); - - if (!S_ISDIR(st.st_mode)) - continue; - - dir = opendir(path); - - if (!dir) - continue; - - while ((d = readdir(dir)) != NULL) - { - char ppath[1024]; - char *ext; - char n[1024]; - int l; - - if (!strncmp(d->d_name, ".", 1)) - continue; - - ext = strrchr(d->d_name, '.'); - - if (!ext || strncmp(ext, ".so", 3)) - continue; - - snprintf(ppath, 1024, "%s/%s", path, d->d_name); - - stat(ppath, &st); - - if (!S_ISREG(st.st_mode)) - continue; - - l = strlen(d->d_name); - - snprintf(n, l - 2, "%s", d->d_name); - - if (!avail) - avail = ewd_list_new(); - - ewd_list_append(avail, strdup(n)); - } - } - - return avail; -} - -/* - * Find the specified group name - */ -Ewd_Plugin_Group * -__ewd_plugin_group_find(char *name) -{ - Ewd_Plugin_Group *group; - - CHECK_PARAM_POINTER_RETURN("name", name, NULL); - - ewd_list_goto_first(group_list); - - while ((group = ewd_list_next(group_list)) != NULL) - if (!strcmp(group->name, name)) - return group; - - return NULL; -} - -/* - * Find the specified group id - */ -Ewd_Plugin_Group * -__ewd_plugin_group_find_id(int id) -{ - Ewd_Plugin_Group *group; - - ewd_list_goto_first(group_list); - - while ((group = ewd_list_next(group_list)) != NULL) - if (group->id == id) - return group; - - return NULL; } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewd/src/ewd_plugin.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- ewd_plugin.h 2001/11/04 21:35:25 1.1 +++ ewd_plugin.h 2002/01/04 18:40:22 1.2 @@ -1,15 +1,6 @@ #ifndef __EWD_PLUGINS_H__ #define __EWD_PLUGINS_H__ -typedef struct _ewd_plugin_group Ewd_Plugin_Group; -struct _ewd_plugin_group -{ - int id; - char *name; - Ewd_List *paths; - Ewd_List *loaded_plugins; -}; - typedef struct _ewd_plugin Ewd_Plugin; struct _ewd_plugin { @@ -17,26 +8,6 @@ char *name; void *handle; }; - -/* - * Create a new plugin group - */ -int ewd_plugin_group_new(char *group_name); - -/* - * Destroy a previous plugin group - */ -void ewd_plugin_group_del(int group_id); - -/* - * Add a directory to be searched for plugins - */ -void ewd_plugin_path_add(int group_id, char *path); - -/* - * Remove a directory to be searched for plugins - */ -void ewd_plugin_path_del(int group_id, char *path); /* * Load the specified plugin =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewd/src/ewd_value.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- ewd_value.c 2001/11/08 22:47:26 1.5 +++ ewd_value.c 2002/01/04 18:40:22 1.6 @@ -83,10 +83,10 @@ k2 = (unsigned int) key2; if (k1 > k2) - return -1; + return 1; if (k1 < k2) - return 1; + return -1; return 0; } |