diff options
| author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-19 13:15:31 +0000 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-19 13:15:31 +0000 | 
| commit | 731fe831d99a672dc078d248b953f0ee8a5b202b (patch) | |
| tree | 81203d5eecc36ffd1a5a30b837b1ea7afc97ae57 /hardinfo2 | |
| parent | dc777c0905f102ee8bfa8ea7c752f5f8f0124f96 (diff) | |
SyncManager almost working! :)
Diffstat (limited to 'hardinfo2')
| -rw-r--r-- | hardinfo2/arch/common/blowfish.h | 2 | ||||
| -rw-r--r-- | hardinfo2/arch/common/fib.h | 2 | ||||
| -rw-r--r-- | hardinfo2/arch/common/md5.h | 2 | ||||
| -rw-r--r-- | hardinfo2/arch/common/raytrace.h | 2 | ||||
| -rw-r--r-- | hardinfo2/arch/common/sha1.h | 2 | ||||
| -rw-r--r-- | hardinfo2/arch/common/zlib.h | 2 | ||||
| -rw-r--r-- | hardinfo2/benchmark.c | 70 | ||||
| -rw-r--r-- | hardinfo2/shell.c | 2 | ||||
| -rw-r--r-- | hardinfo2/syncmanager.c | 71 | 
9 files changed, 118 insertions, 37 deletions
| diff --git a/hardinfo2/arch/common/blowfish.h b/hardinfo2/arch/common/blowfish.h index 10165c37..6ece3b23 100644 --- a/hardinfo2/arch/common/blowfish.h +++ b/hardinfo2/arch/common/blowfish.h @@ -61,6 +61,8 @@ benchmark_fish(void)      g_timer_destroy(timer);      g_free(bdata_path); +     +    bench_results[BENCHMARK_BLOWFISH] = elapsed;      gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n"                             "<i>This Machine</i>=%.2f\n", elapsed); diff --git a/hardinfo2/arch/common/fib.h b/hardinfo2/arch/common/fib.h index c8612496..f78ecab8 100644 --- a/hardinfo2/arch/common/fib.h +++ b/hardinfo2/arch/common/fib.h @@ -43,6 +43,8 @@ benchmark_fib(void)      g_timer_stop(timer);      elapsed = g_timer_elapsed(timer, NULL);      g_timer_destroy(timer); +     +    bench_results[BENCHMARK_FIB] = elapsed;      gchar *retval = g_strdup_printf("[Results]\n"                             "<i>This Machine</i>=%.3f s\n", elapsed); diff --git a/hardinfo2/arch/common/md5.h b/hardinfo2/arch/common/md5.h index bd902920..4bfc8e6e 100644 --- a/hardinfo2/arch/common/md5.h +++ b/hardinfo2/arch/common/md5.h @@ -58,6 +58,8 @@ benchmark_md5(void)      g_timer_destroy(timer);      g_free(bdata_path); +     +    bench_results[BENCHMARK_MD5] = 312.0 / elapsed;      gchar *retval = g_strdup_printf("[Results]\n"                             "<i>This Machine</i>=%.2f MiB/s\n", 312.0 / elapsed); diff --git a/hardinfo2/arch/common/raytrace.h b/hardinfo2/arch/common/raytrace.h index f9abcebd..5da34860 100644 --- a/hardinfo2/arch/common/raytrace.h +++ b/hardinfo2/arch/common/raytrace.h @@ -40,6 +40,8 @@ benchmark_raytrace(void)      }      g_timer_destroy(timer); +     +    bench_results[BENCHMARK_RAYTRACE] = elapsed;      gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n"                             "<i>This Machine</i>=%.2f\n", elapsed); diff --git a/hardinfo2/arch/common/sha1.h b/hardinfo2/arch/common/sha1.h index 6e343dfb..cd00b9be 100644 --- a/hardinfo2/arch/common/sha1.h +++ b/hardinfo2/arch/common/sha1.h @@ -57,6 +57,8 @@ benchmark_sha1(void)      g_timer_destroy(timer);      g_free(bdata_path); +     +    bench_results[BENCHMARK_SHA1] = 312.0 / elapsed;      gchar *retval = g_strdup_printf("[Results]\n"                             "<i>This Machine</i>=%.2f MiB/s\n", 312.0 / elapsed); diff --git a/hardinfo2/arch/common/zlib.h b/hardinfo2/arch/common/zlib.h index 74911c0e..7a8d0666 100644 --- a/hardinfo2/arch/common/zlib.h +++ b/hardinfo2/arch/common/zlib.h @@ -80,6 +80,8 @@ benchmark_zlib(void)      g_timer_destroy(timer);      g_free(bdata_path); +     +    bench_results[BENCHMARK_ZLIB] = 65536.0 / elapsed;      gchar *retval = g_strdup_printf("[Results]\n"                                      "<i>This Machine</i>=%.3f KiB/s\n", diff --git a/hardinfo2/benchmark.c b/hardinfo2/benchmark.c index c396bb61..4d4d347c 100644 --- a/hardinfo2/benchmark.c +++ b/hardinfo2/benchmark.c @@ -28,7 +28,8 @@ enum {      BENCHMARK_MD5,      BENCHMARK_SHA1,      BENCHMARK_BLOWFISH, -    BENCHMARK_RAYTRACE +    BENCHMARK_RAYTRACE, +    BENCHMARK_N_ENTRIES  } Entries;  void scan_zlib(gboolean reload); @@ -100,13 +101,7 @@ static gchar *benchmark_include_results(gchar * results,  				       SHELL_ORDER_ASCENDING);  } -#include <arch/common/fib.h> -#include <arch/common/zlib.h> -#include <arch/common/md5.h> -#include <arch/common/sha1.h> -#include <arch/common/blowfish.h> -#include <arch/common/raytrace.h> - +static gdouble bench_results[BENCHMARK_N_ENTRIES];  static gchar *bench_zlib = NULL,      *bench_fib = NULL,      *bench_md5 = NULL, @@ -114,6 +109,13 @@ static gchar *bench_zlib = NULL,      *bench_fish = NULL,      *bench_ray = NULL; +#include <arch/common/fib.h> +#include <arch/common/zlib.h> +#include <arch/common/md5.h> +#include <arch/common/sha1.h> +#include <arch/common/blowfish.h> +#include <arch/common/raytrace.h> +  gchar *callback_zlib()  {      return g_strdup(bench_zlib); @@ -224,22 +226,6 @@ ModuleEntry *hi_module_get_entries(void)      return entries;  } -gchar *get_all_results(void) -{ -    return ""; -} - -ShellModuleMethod* -hi_exported_methods(void) -{ -    static ShellModuleMethod m[] = { -      { "getAllResults", get_all_results }, -      { NULL } -    }; -     -    return m; -} -  ModuleAbout *  hi_module_get_about(void)  { @@ -255,9 +241,37 @@ hi_module_get_about(void)      return ma;  } -static gchar *bla() +static gchar *get_benchmark_results()  { -    return g_strdup("ola mundo!"); +    void (*scan_callback)(gboolean rescan); +     +    gint i = G_N_ELEMENTS(entries) - 1; +    gchar *machine = module_call_method("devices::getProcessorName"); +    gchar *param = g_strdup_printf("[param]\n" +                                   "machine=%s\n" +                                   "nbenchmarks=%d\n", +                                   machine, i); +    gchar *result = param; +     +    for (; i >= 0; i--) { +        if ((scan_callback = entries[i].scan_callback)) { +            scan_callback(FALSE); +         +            result = g_strdup_printf("%s\n" +                                     "[bench%d]\n" +                                     "name=%s\n" +                                     "value=%f\n", +                                     result, +                                     i, +                                     entries[i].name, +                                     bench_results[i]); +        } +    } +     +    g_free(machine); +    g_free(param); +     +    return result;  }  void @@ -267,8 +281,8 @@ hi_module_init(void)        {            .fancy_name = "Benchmark results",            .name       = "BenchmarkResults", -          .save_to    = "/tmp/bla.txt", -          .get_data   = bla +          .save_to    = "benchmarks.conf", +          .get_data   = get_benchmark_results        }      }; diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index 3768d1fd..2f67e3e7 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -264,6 +264,8 @@ void shell_status_set_enabled(gboolean setting)      else {  	gtk_widget_hide(shell->progress);  	shell_view_set_enabled(TRUE); +	 +	shell_status_update("Done.");      }  } diff --git a/hardinfo2/syncmanager.c b/hardinfo2/syncmanager.c index 1993003e..3366fe70 100644 --- a/hardinfo2/syncmanager.c +++ b/hardinfo2/syncmanager.c @@ -60,6 +60,7 @@ struct _SyncDialog {  static GSList		*entries = NULL;  static SoupSession	*session = NULL; +static GMainLoop	*loop;  static GQuark		 err_quark;  #define XMLRPC_SERVER_URI   		"http://condor/xmlrpc/" @@ -105,7 +106,13 @@ void sync_manager_show(void)      err_quark = g_quark_from_static_string("syncmanager");      if (gtk_dialog_run(GTK_DIALOG(sd->dialog)) == GTK_RESPONSE_ACCEPT) { +        shell_view_set_enabled(FALSE); +        shell_status_set_enabled(TRUE); +                  sync_dialog_start_sync(sd); +         +        shell_status_set_enabled(FALSE); +        shell_view_set_enabled(TRUE);      }         sync_dialog_destroy(sd); @@ -134,6 +141,7 @@ static SoupXmlrpcValue *_soup_get_xmlrpc_value(SoupMessage *msg, SyncNetAction *          SNA_ERROR(3, "No response value in XML-RPC response");      } +    /* g_object_unref(response); */  bad:      return value;  } @@ -157,6 +165,25 @@ bad:      return int_value;  } +static gchar* _soup_get_xmlrpc_value_string(SoupMessage *msg, SyncNetAction *sna) +{ +    SoupXmlrpcValue *value; +    gchar *string = NULL; +     +    value = _soup_get_xmlrpc_value(msg, sna); +    if (!value) { +        SNA_ERROR(4, "Could not extract result from XML-RPC response"); +        goto bad; +    } + +    if (!soup_xmlrpc_value_get_string(value, &string)) { +        SNA_ERROR(4, "Could not extract result from XML-RPC response"); +    } + +bad: +    return string; +} +  static gboolean _soup_xmlrpc_call(gchar *method, SyncNetAction *sna,                                    SoupMessageCallbackFn callback)  { @@ -168,6 +195,7 @@ static gboolean _soup_xmlrpc_call(gchar *method, SyncNetAction *sna,      if (!msg)          return FALSE; +    DEBUG("calling xmlrpc method %s", method);      soup_xmlrpc_message_start_call(msg, method);      soup_xmlrpc_message_end_call(msg); @@ -175,7 +203,7 @@ static gboolean _soup_xmlrpc_call(gchar *method, SyncNetAction *sna,      soup_session_queue_message(session, SOUP_MESSAGE(msg),                                 callback, sna); -    gtk_main(); +    g_main_run(loop);      return TRUE;  } @@ -194,6 +222,7 @@ static gboolean _soup_xmlrpc_call_with_parameters(gchar *method, SyncNetAction *      if (!msg)          return FALSE; +    DEBUG("calling xmlrpc method %s", method);      soup_xmlrpc_message_start_call(msg, method);      va_start(ap, callback); @@ -201,6 +230,8 @@ static gboolean _soup_xmlrpc_call_with_parameters(gchar *method, SyncNetAction *          soup_xmlrpc_message_start_param(msg);          soup_xmlrpc_message_write_string(msg, argument);          soup_xmlrpc_message_end_param(msg); +         +        DEBUG("with parameter: %s", argument);      }      va_end(ap); @@ -208,7 +239,7 @@ static gboolean _soup_xmlrpc_call_with_parameters(gchar *method, SyncNetAction *      soup_xmlrpc_message_persist(msg);      soup_session_queue_message(session, SOUP_MESSAGE(msg), callback, sna); -    gtk_main(); +    g_main_run(loop);      return TRUE;  } @@ -224,7 +255,7 @@ static void _action_check_api_version_got_response(SoupMessage *msg, gpointer us                       "version %d.", version, XMLRPC_SERVER_API_VERSION);      } -    gtk_main_quit(); +    g_main_quit(loop);  }  static gboolean _action_check_api_version(SyncDialog *sd, gpointer user_data) @@ -241,11 +272,25 @@ static gboolean _action_check_api_version(SyncDialog *sd, gpointer user_data)  static void _action_send_data_got_response(SoupMessage *msg, gpointer user_data)  {      SyncNetAction *sna = (SyncNetAction *) user_data; +    gchar *string; +     +    string = _soup_get_xmlrpc_value_string(msg, sna); +    DEBUG("received string: %s\n", string); -    /* FIXME: save things if needed */ -    _soup_get_xmlrpc_value_int(msg, sna); +    if (sna->entry->save_to) { +        gchar *filename = g_build_filename(g_get_home_dir(), ".hardinfo", +                                           sna->entry->save_to, NULL); +         +        DEBUG("saving to %s", filename); -    gtk_main_quit(); +        g_file_set_contents(filename, string, -1, NULL); +        g_free(filename); +    } else { +        DEBUG("not saving :("); +    } + +    g_free(string); +    g_main_quit(loop);  }  static gboolean _action_send_data(SyncDialog *sd, gpointer user_data) @@ -280,7 +325,7 @@ static gboolean _cancel_sync(GtkWidget *widget, gpointer data)      }      sd->flag_cancel = TRUE; -    gtk_main_quit(); +    g_main_quit(loop);      return FALSE;  } @@ -321,6 +366,8 @@ static void sync_dialog_start_sync(SyncDialog *sd)      if (!session) {          session = soup_session_async_new_with_options(SOUP_SESSION_TIMEOUT, 10, NULL);      } +     +    loop = g_main_loop_new(NULL, TRUE);      gtk_widget_hide(sd->button_sync);      sync_dialog_netarea_show(sd); @@ -335,7 +382,8 @@ static void sync_dialog_start_sync(SyncDialog *sd)      gtk_widget_show(sd->button_close);      /* wait for the user to close the dialog */     -    gtk_main(); +    g_main_run(loop); +    g_main_loop_unref(loop);  }  static void sync_dialog_netarea_start_actions(SyncDialog *sd, SyncNetAction sna[], gint n) @@ -503,6 +551,11 @@ sel_toggle(GtkCellRendererToggle *cellrenderertoggle,      gtk_tree_path_free(path);  } +static void close_clicked(void) +{ +    g_main_quit(loop); +} +  static SyncDialog *sync_dialog_new(void)  {      SyncDialog *sd; @@ -605,7 +658,7 @@ static SyncDialog *sync_dialog_new(void)      GTK_WIDGET_SET_FLAGS(button7, GTK_CAN_DEFAULT);      button6 = gtk_button_new_from_stock(GTK_STOCK_CLOSE); -    g_signal_connect(G_OBJECT(button6), "clicked", (GCallback)gtk_main_quit, NULL); +    g_signal_connect(G_OBJECT(button6), "clicked", (GCallback)close_clicked, NULL);      gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button6,  				 GTK_RESPONSE_ACCEPT);      GTK_WIDGET_SET_FLAGS(button6, GTK_CAN_DEFAULT); | 
