diff options
author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-02 15:32:50 +0000 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-02 15:32:50 +0000 |
commit | 4e082dd27545c503e6ee1440e45032f93216631a (patch) | |
tree | 3b0b64937a40e9b7256647455cada96b99fed96c /hardinfo2/util.c | |
parent | 2ac586a621e9d20667838df367ce5c3b4b428500 (diff) |
Cleanups, reorganization. Implemented foreign module calls.
Diffstat (limited to 'hardinfo2/util.c')
-rw-r--r-- | hardinfo2/util.c | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 86ba47a3..d95770ff 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -368,7 +368,52 @@ gchar *strreplace(gchar * string, gchar * replace, gchar new_char) return string; } -static ShellModule *module_load(gchar *filename) { +static GHashTable *__modules = NULL; + +void module_register(ShellModule *module) +{ + ShellModuleMethod *(*get_methods) (void); + gchar *method_name; + + if (__modules == NULL) { + __modules = g_hash_table_new(g_str_hash, g_str_equal); + } + + if (g_module_symbol(module->dll, "hi_exported_methods", (gpointer) &get_methods)) { + ShellModuleMethod *methods = get_methods(); + + while (TRUE) { + ShellModuleMethod method = *methods; + gchar *name = g_path_get_basename(g_module_name(module->dll)); + + strend(name, '.'); + + method_name = g_strdup_printf("%s::%s", name, method.name); + g_hash_table_insert(__modules, method_name, method.function); + g_free(name); + + if (!(*(++methods)).name) + break; + } + } + +} + +gchar *module_call_method(gchar *method) +{ + gchar *(*function) (void); + + if (__modules == NULL) { + return NULL; + } + + function = g_hash_table_lookup(__modules, method); + return function ? g_strdup(function()) : + g_strdup_printf("{Unknown method: \"%s\"}", method); +} + +static ShellModule *module_load(gchar *filename) +{ ShellModule *module; gchar *tmp; @@ -441,6 +486,8 @@ static ShellModule *module_load(gchar *filename) { module = NULL; } + module_register(module); + return module; } @@ -541,6 +588,9 @@ void tree_view_save_image(gchar *filename) { /* this is ridiculously complicated :/ why in the hell gtk+ makes this kind of thing so difficult? */ + + /* FIXME: this does not work if the window (or part of it) isn't visible. does + anyone know how to fix this? :/ */ Shell *shell = shell_get_main_shell(); GtkWidget *widget = shell->info->view; @@ -631,3 +681,16 @@ void tree_view_save_image(gchar *filename) gtk_widget_set_sensitive(widget, tv_enabled); } + + +static gboolean __schedule_free_do(gpointer ptr) +{ + g_free(ptr); + + return FALSE; +} + +void schedule_free(gpointer ptr) +{ + g_timeout_add(5000, __schedule_free_do, ptr); +} |