diff options
author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-13 17:51:53 +0000 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-13 17:51:53 +0000 |
commit | 77cc3adfb63d9ba837da2d81f87eb4fdc38fc340 (patch) | |
tree | d0fbd51d4560c8383b739cfc9a517f57055c3135 | |
parent | f70403b0a5f74e13907262e668653eef29803754 (diff) |
Talking with remote server is working; still does nothing useful :)
-rw-r--r-- | hardinfo2/Makefile.in | 4 | ||||
-rwxr-xr-x | hardinfo2/configure | 2 | ||||
-rw-r--r-- | hardinfo2/hardinfo.c | 4 | ||||
-rw-r--r-- | hardinfo2/pixmaps/status-done.png | bin | 1019 -> 870 bytes | |||
-rw-r--r-- | hardinfo2/syncmanager.c | 205 | ||||
-rw-r--r-- | hardinfo2/util.c | 20 |
6 files changed, 191 insertions, 44 deletions
diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in index 3c122d4f..40b4f29f 100644 --- a/hardinfo2/Makefile.in +++ b/hardinfo2/Makefile.in @@ -1,7 +1,7 @@ CC = gcc -O3 $(ARCHOPTS) CCSLOW = gcc -O0 -CFLAGS = -fPIC -pipe -Wall -g $(GTK_CFLAGS) $(GLADE_CFLAGS) -I. +CFLAGS = -fPIC -pipe -Wall -g $(GTK_CFLAGS) $(GLADE_CFLAGS) $(SOUP_CFLAGS) -I. # ---------------------------------------------------------------------------- @@ -12,7 +12,7 @@ MODULES = computer.so devices.so benchmark.so all: $(OBJECTS) $(MODULES) $(CC) $(CFLAGS) -o hardinfo -Wl,-export-dynamic $(OBJECTS) $(GTK_LIBS) $(GTK_FLAGS) \ - $(GLADE_LIBS) $(GLADE_FLAGS) + $(GLADE_LIBS) $(GLADE_FLAGS) $(SOUP_LIBS) $(SOUP_FLAGS) md5.o: $(CCSLOW) $(CFLAGS) -c md5.c -o $@ diff --git a/hardinfo2/configure b/hardinfo2/configure index a5ac23db..56847e02 100755 --- a/hardinfo2/configure +++ b/hardinfo2/configure @@ -210,7 +210,7 @@ rm -f Makefile echo "GTK_LIBS = ${GTK_LIBS}" > Makefile echo "GTK_CFLAGS = ${GTK_FLAGS}" >> Makefile echo "SOUP_LIBS = ${SOUP_LIBS}" >> Makefile -echo "SOUP_CFLAGS = ${SOUP_CFLAGS}" >> Makefile +echo "SOUP_CFLAGS = ${SOUP_FLAGS}" >> Makefile echo "PACKAGE = `basename ${PWD}`" >> Makefile echo "ARCHOPTS = " >> Makefile diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index 3c01529c..77557cdc 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -116,6 +116,10 @@ main(int argc, char **argv) stock_icons_init(); shell_init(modules); + + DEBUG("initializing GLib thread"); + if (!g_thread_supported()) + g_thread_init (NULL); DEBUG("entering gtk+ main loop"); gtk_main(); diff --git a/hardinfo2/pixmaps/status-done.png b/hardinfo2/pixmaps/status-done.png Binary files differindex 896eb720..fa39fd70 100644 --- a/hardinfo2/pixmaps/status-done.png +++ b/hardinfo2/pixmaps/status-done.png diff --git a/hardinfo2/syncmanager.c b/hardinfo2/syncmanager.c index 0767f926..e514847c 100644 --- a/hardinfo2/syncmanager.c +++ b/hardinfo2/syncmanager.c @@ -1,6 +1,11 @@ #include "syncmanager.h" #include "iconcache.h" #include "hardinfo.h" +#include "config.h" + +#include <libsoup/soup.h> +#include <libsoup/soup-xmlrpc-message.h> +#include <libsoup/soup-xmlrpc-response.h> typedef struct _SyncDialog SyncDialog; typedef struct _SyncNetArea SyncNetArea; @@ -12,7 +17,9 @@ struct _SyncNetArea { struct _SyncNetAction { gchar *name; - gboolean (*do_action)(SyncDialog *sd); + gboolean (*do_action)(SyncDialog *sd, gpointer sna); + + GError *error; }; struct _SyncDialog { @@ -26,9 +33,16 @@ struct _SyncDialog { GtkWidget *scroll_box; SyncNetArea *sna; + + gboolean flag_cancel : 1; }; static GSList *entries = NULL; +static SoupSession *session = NULL; +static GQuark err_quark; + +#define XMLRPC_SERVER_URI "http://hardinfo.berlios.de/xmlrpc/" +#define XMLRPC_SERVER_API_VERSION 1 #define LABEL_SYNC_DEFAULT "<big><b>Synchronize with Central Database</b></big>\n" \ "The following information may be synchronized " \ @@ -57,6 +71,8 @@ void sync_manager_add_entry(SyncEntry *entry) void sync_manager_show(void) { SyncDialog *sd = sync_dialog_new(); + + err_quark = g_quark_from_static_string("syncmanager"); if (gtk_dialog_run(GTK_DIALOG(sd->dialog)) == GTK_RESPONSE_ACCEPT) { sync_dialog_start_sync(sd); @@ -65,33 +81,159 @@ void sync_manager_show(void) sync_dialog_destroy(sd); } -static gboolean _action_wait(SyncDialog *sd) +static SoupXmlrpcValue *_soup_get_xmlrpc_value(SoupMessage *msg, SyncNetAction *sna) { - nonblock_sleep(1000); + SoupXmlrpcResponse *response = NULL; + SoupXmlrpcValue *value = NULL; + + sna->error = NULL; + + if (!SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) { + sna->error = g_error_new(err_quark, 1, "%s (error #%d)", + msg->reason_phrase, msg->status_code); + goto bad; + } + + response = soup_xmlrpc_message_parse_response(SOUP_XMLRPC_MESSAGE(msg)); + if (!response) { + sna->error = g_error_new(err_quark, 2, "Could not parse XMLRPC response"); + goto bad; + } + + value = soup_xmlrpc_response_get_value(response); + if (!value) { + sna->error = g_error_new(err_quark, 3, "No response value in XMLRPC response"); + } + +bad: + return value; +} + +static long _soup_get_xmlrpc_value_int(SoupMessage *msg, SyncNetAction *sna) +{ + SoupXmlrpcValue *value; + long int_value = -1; + + value = _soup_get_xmlrpc_value(msg, sna); + if (!value) { + if (!sna->error) + sna->error = GINT_TO_POINTER(1); + goto very_bad; + } + + if (!soup_xmlrpc_value_get_int(value, &int_value)) { + if (!sna->error) + sna->error = g_error_new(err_quark, 4, + "Could not extract result from XMLRPC response"); + + goto bad; + } + +bad: + /* FIXME: free value? */ +very_bad: + return int_value; +} + +static gboolean _soup_xmlrpc_call(gchar *method, SyncNetAction *sna, + SoupMessageCallbackFn callback) +{ + SoupXmlrpcMessage *msg; + + sna->error = NULL; + + msg = soup_xmlrpc_message_new(XMLRPC_SERVER_URI); + if (!msg) + return FALSE; + + soup_xmlrpc_message_start_call(msg, method); + soup_xmlrpc_message_end_call(msg); + + soup_xmlrpc_message_persist(msg); + + soup_session_queue_message(session, SOUP_MESSAGE(msg), + callback, sna); + gtk_main(); + return TRUE; } -static gboolean _action_wait_fail(SyncDialog *sd) +static void _action_check_api_version_got_response(SoupMessage *msg, gpointer user_data) { - nonblock_sleep(2000); + SyncNetAction *sna = (SyncNetAction *) user_data; + long version = _soup_get_xmlrpc_value_int(msg, sna); + + if (version != XMLRPC_SERVER_API_VERSION) { + if (!sna->error) + sna->error = g_error_new(err_quark, 5, "Server says it supports API version %ld, but " \ + "this version of HardInfo only supports API " \ + "version %d.", version, XMLRPC_SERVER_API_VERSION); + } + + gtk_main_quit(); +} + +static gboolean _action_check_api_version(SyncDialog *sd, gpointer user_data) +{ + SyncNetAction *sna = (SyncNetAction *) user_data; + + if (!_soup_xmlrpc_call("server.getAPIVersion", sna, + _action_check_api_version_got_response)) + return FALSE; + + return sna->error ? FALSE : TRUE; +} + +static void _action_get_benchmarks_got_response(SoupMessage *msg, gpointer user_data) +{ + SyncNetAction *sna = (SyncNetAction *) user_data; + + _soup_get_xmlrpc_value_int(msg, sna); + + gtk_main_quit(); +} + +static gboolean _action_get_benchmarks(SyncDialog *sd, gpointer user_data) +{ + SyncNetAction *sna = (SyncNetAction *) user_data; + + if (!_soup_xmlrpc_call("benchmark.getResults", sna, + _action_get_benchmarks_got_response)) + return FALSE; + + return sna->error ? FALSE : TRUE; +} + +static gboolean _cancel_sync(GtkWidget *widget, gpointer data) +{ + SyncDialog *sd = (SyncDialog *) data; + + if (session) { + soup_session_abort(session); + } + + sd->flag_cancel = TRUE; + gtk_main_quit(); + return FALSE; } static void sync_dialog_start_sync(SyncDialog *sd) { SyncNetAction actions[] = { - { "Contacting HardInfo central database", _action_wait }, - { "Sending benchmark results (1/3)", _action_wait }, - { "Sending benchmark results (2/3)", _action_wait }, - { "Sending benchmark results (3/3)", _action_wait }, - { "Receiving benchmark results", _action_wait }, - { "This should fail!", _action_wait_fail }, + { "Contacting HardInfo Central Database", _action_check_api_version }, + { "Receiving benchmark results", _action_get_benchmarks }, { "Sync finished", NULL }, }; + + if (!session) { + session = soup_session_async_new_with_options(SOUP_SESSION_TIMEOUT, 5, NULL); + } gtk_widget_hide(sd->button_sync); - gtk_widget_set_sensitive(sd->button_cancel, FALSE); sync_dialog_netarea_show(sd); + g_signal_connect(G_OBJECT(sd->button_cancel), "clicked", + (GCallback)_cancel_sync, sd); sync_dialog_netarea_start_actions(sd, actions, G_N_ELEMENTS(actions)); @@ -139,20 +281,42 @@ static void sync_dialog_netarea_start_actions(SyncDialog *sd, SyncNetAction sna[ gtk_main_iteration(); for (i = 0; i < n; i++) { - gchar *bold; + gchar *markup; + + if (sd->flag_cancel) { + markup = g_strdup_printf("<s>%s</s> <i>(canceled)</i>", sna[i].name); + gtk_label_set_markup(GTK_LABEL(labels[i]), markup); + g_free(markup); + + gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), + icon_cache_get_pixbuf("dialog-error.png")); + break; + } - bold = g_strdup_printf("<b>%s</b>", sna[i].name); - gtk_label_set_markup(GTK_LABEL(labels[i]), bold); - g_free(bold); + markup = g_strdup_printf("<b>%s</b>", sna[i].name); + gtk_label_set_markup(GTK_LABEL(labels[i]), markup); + g_free(markup); gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), curr_icon); - if (sna[i].do_action && !sna[i].do_action(sd)) { + if (sna[i].do_action && !sna[i].do_action(sd, &sna[i])) { + markup = g_strdup_printf("<b><s>%s</s></b> <i>(failed)</i>", sna[i].name); + gtk_label_set_markup(GTK_LABEL(labels[i]), markup); + g_free(markup); + gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), icon_cache_get_pixbuf("dialog-error.png")); - g_warning("Failed while performing \"%s\". Please file a bug report " \ - "if this problem persists. (Use the Help\342\206\222Report" \ - " bug option.)", sna[i].name); + if (sna[i].error) { + g_warning("Failed while performing \"%s\". Please file a bug report " \ + "if this problem persists. (Use the Help\342\206\222Report" \ + " bug option.)\n\nDetails: %s", + sna[i].name, sna[i].error->message); + g_error_free(sna[i].error); + } else { + g_warning("Failed while performing \"%s\". Please file a bug report " \ + "if this problem persists. (Use the Help\342\206\222Report" \ + " bug option.)", sna[i].name); + } break; } @@ -182,7 +346,6 @@ static void sync_dialog_netarea_destroy(SyncNetArea *sna) { g_return_if_fail(sna != NULL); - gtk_widget_destroy(sna->vbox); g_free(sna); } diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 7267758b..e526d125 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -422,8 +422,6 @@ static void module_register_methods(ShellModule *module) g_hash_table_insert(__module_methods, method_name, method.function); g_free(name); - DEBUG("Registered method: %s", method_name); - if (!(*(++methods)).name) break; } @@ -439,8 +437,6 @@ gchar *module_call_method(gchar *method) return NULL; } - DEBUG("Calling method: %s", method); - function = g_hash_table_lookup(__module_methods, method); return function ? g_strdup(function()) : g_strdup_printf("{Unknown method: \"%s\"}", method); @@ -494,8 +490,6 @@ static ShellModule *module_load(gchar *filename) module->weight = weight_func ? weight_func() : 0; module->name = name_func(); - DEBUG("%p", module->name); - entries = get_module_entries(); while (entries[i].name) { ShellModuleEntry *entry = g_new0(ShellModuleEntry, 1); @@ -605,8 +599,6 @@ static GSList *modules_check_deps(GSList *modules) module = (ShellModule *) mm->data; - DEBUG("check deps: %s", module->name); - if (g_module_symbol(module->dll, "hi_module_get_dependencies", (gpointer) & get_deps)) { for (i = 0, deps = get_deps(); deps[i]; i++) { @@ -614,8 +606,6 @@ static GSList *modules_check_deps(GSList *modules) ShellModule *m; gboolean found = FALSE; - DEBUG(" %s depends on %s", module->name, deps[i]); - for (l = modules; l; l = l->next) { m = (ShellModule *)l->data; gchar *name = g_path_get_basename(g_module_name(m->dll)); @@ -628,8 +618,6 @@ static GSList *modules_check_deps(GSList *modules) g_free(name); } - DEBUG(" dependency %s", found ? "found" : "not found"); - if (!found) { if (params.autoload_deps) { ShellModule *mod = module_load(deps[i]); @@ -672,8 +660,6 @@ static GSList *modules_check_deps(GSList *modules) } } } - } else { - DEBUG(" no dependencies needed"); } } @@ -859,10 +845,6 @@ void tree_view_save_image(gchar *filename) static gboolean __idle_free_do(gpointer ptr) { if (ptr) { - DEBUG("Freeing mem @ %p: %s", ptr, - g_utf8_validate((gchar*)ptr, 3, NULL) ? - (gchar*)ptr : "[non string data]"); - g_free(ptr); } @@ -872,8 +854,6 @@ static gboolean __idle_free_do(gpointer ptr) gpointer idle_free(gpointer ptr) { if (ptr) { - DEBUG("Will free mem @ %p in 10000ms", ptr); - g_timeout_add(10000, __idle_free_do, ptr); } |