diff options
| author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-04-26 18:19:40 -0300 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-04-26 18:19:40 -0300 | 
| commit | 22f840d9ca7fade0ebeeb44c54fad3cc64b07ac7 (patch) | |
| tree | 8dcda7b111d2e2761d197164755f5446c09b7e8c /hardinfo2 | |
| parent | c2367073c9eb18987c6b9278d63f29fb7880283a (diff) | |
Making more room to implement the remote mode :)
Diffstat (limited to 'hardinfo2')
| -rw-r--r-- | hardinfo2/Makefile.in | 3 | ||||
| -rw-r--r-- | hardinfo2/remote.c | 71 | ||||
| -rw-r--r-- | hardinfo2/shell.h | 1 | ||||
| -rw-r--r-- | hardinfo2/util.c | 1 | ||||
| -rw-r--r-- | hardinfo2/xmlrpc-client.c | 227 | ||||
| -rw-r--r-- | hardinfo2/xmlrpc-client.h | 39 | ||||
| -rw-r--r-- | hardinfo2/xmlrpc-server.c | 2 | 
7 files changed, 341 insertions, 3 deletions
| diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in index 3cf83329..aaa76794 100644 --- a/hardinfo2/Makefile.in +++ b/hardinfo2/Makefile.in @@ -8,7 +8,8 @@ CCSLOW = gcc -O0 -g  OBJECTS = hardinfo.o shell.o util.o iconcache.o loadgraph.o  \  		menu.o stock.o callbacks.o expr.o report.o binreloc.o \ -		vendor.o socket.o syncmanager.o remote.o xmlrpc-server.o +		vendor.o socket.o syncmanager.o remote.o xmlrpc-server.o \ +		xmlrpc-client.o  BENCHMARK_OBJECTS = fbench.o sha1.o blowfish.o md5.o nqueens.o fftbench.o  MODULES = computer.so devices.so benchmark.so network.so diff --git a/hardinfo2/remote.c b/hardinfo2/remote.c index de3a9692..556299ca 100644 --- a/hardinfo2/remote.c +++ b/hardinfo2/remote.c @@ -24,6 +24,8 @@  #include <hardinfo.h>  #include <config.h> +#include "xmlrpc-client.h" +  /*   * TODO   * @@ -67,9 +69,75 @@ struct _RemoteDialog {  static RemoteDialog *remote_dialog_new(GtkWidget *parent); -static void remote_connect(RemoteDialog *rd) +static gboolean remote_version_is_supported(void) +{ +    shell_status_update("Obtaining remote server API version..."); + +    switch (xmlrpc_get_integer("http://localhost:4242/xmlrpc", "server.getAPIVersion", NULL)) { +    case -1: +        g_warning("Remote Host didn't respond."); +        break; +    case 1: +        return TRUE; +    default: +        g_warning("Remote Host has an unsupported API version."); +    } + +    return FALSE; +} + +static gboolean load_module_list()  { +    GValueArray *modules; +    int i = 0; +     +    shell_status_update("Obtaining remote server module list..."); +     +    modules = xmlrpc_get_array("http://localhost:4242/xmlrpc", "module.getModuleList", NULL); +    if (!modules) { +        return FALSE; +    } +     +    for (; i < modules->n_values; i++) { +        GValueArray *entries; +        const gchar *module = g_value_get_string(&modules->values[i]); +        int j = 0; +         +        DEBUG("%s", module); +         +        shell_status_pulse(); +        entries = xmlrpc_get_array("http://localhost:4242/xmlrpc", "module.getEntryList", "%s", module); +        if (entries) { +            for (; j < entries->n_values; j++) { +                GValueArray *tuple = g_value_get_boxed(&entries->values[j]); +                 +                DEBUG("--- %s [%s](%d)", +                      g_value_get_string(&tuple->values[0]), +                      g_value_get_string(&tuple->values[1]), +                      j); +            } +             +            g_value_array_free(entries); +        } +    } +     +    g_value_array_free(modules); +     +    return TRUE; +} +static void remote_connect(RemoteDialog *rd) +{ +    xmlrpc_init(); +     +    /* check API version */ +    if (remote_version_is_supported()) { +        if (!load_module_list()) { +            g_warning("Remote module list couldn't be loaded."); +        } +    } +     +    shell_status_update("Done.");  }  void remote_dialog_show(GtkWidget *parent) @@ -83,6 +151,7 @@ void remote_dialog_show(GtkWidget *parent)  	shell_status_set_enabled(TRUE);  	remote_connect(rd); +	  	shell_status_set_enabled(FALSE);      } diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h index 56b7765f..6fe86009 100644 --- a/hardinfo2/shell.h +++ b/hardinfo2/shell.h @@ -134,6 +134,7 @@ struct _ShellModuleMethod {  struct _ShellModuleEntry {      gchar		*name;      GdkPixbuf		*icon; +    gchar		*icon_file;      gboolean		 selected;      gint		 number; diff --git a/hardinfo2/util.c b/hardinfo2/util.c index b1771957..7b99f0ea 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -637,6 +637,7 @@ static ShellModule *module_load(gchar * filename)  	    if (params.gui_running) {  		entry->icon = icon_cache_get_pixbuf(entries[i].icon);  	    } +	    entry->icon_file = entries[i].icon;  	    g_module_symbol(module->dll, "hi_more_info",  			    (gpointer) & (entry->morefunc)); diff --git a/hardinfo2/xmlrpc-client.c b/hardinfo2/xmlrpc-client.c new file mode 100644 index 00000000..81177381 --- /dev/null +++ b/hardinfo2/xmlrpc-client.c @@ -0,0 +1,227 @@ +/* + *    XMLRPC Client + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2009 Leandro A. F. Pereira <leandro@hardinfo.org> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +#include <string.h> +#include "config.h" +#include "xmlrpc-client.h" + +static GMainLoop	*loop = NULL; +static SoupSession	*session = NULL; + +void xmlrpc_init(void) +{ +    if (!loop) { +      loop = g_main_loop_new(FALSE, TRUE); +    } +     +    if (!session) { +      session = soup_session_async_new_with_options(SOUP_SESSION_TIMEOUT, 10, NULL); +    } +}     + +static void xmlrpc_response_get_integer(SoupSession *s, +                                        SoupMessage *m, +                                        gpointer user_data) +{ +    gint *response = user_data; +     +    *response = -1; +     +    if (SOUP_STATUS_IS_SUCCESSFUL(m->status_code)) { +        soup_xmlrpc_extract_method_response(m->response_body->data, +                                            m->response_body->length, +                                            NULL, +                                            G_TYPE_INT, response); +    } +     +    g_main_quit(loop); +}                                 + +gint xmlrpc_get_integer(gchar *addr, +                               gchar *method, +                               const gchar *param_types, +                               ...) +{ +    gint integer; +    GValueArray *params; +    SoupMessage *msg; +    gchar *body; + +    msg = soup_message_new("POST", addr); + +    params = g_value_array_new(1); +     +    if (param_types && *param_types) { +        va_list ap; + +        va_start(ap, param_types); +        while (*param_types) { +            switch (*param_types) { +            case '%': +              break; +            case 'i': +              soup_value_array_append(params, G_TYPE_INT, va_arg(ap, int)); +              break; +            case 's': +            default: +              soup_value_array_append(params, G_TYPE_STRING, va_arg(ap, char *)); +              break; +            } +             +            param_types++; +        } +         +        va_end(ap); +    } + +    body = soup_xmlrpc_build_method_call(method, params->values, params->n_values); +    g_value_array_free(params); + +    soup_message_set_request(msg, "text/xml", +			     SOUP_MEMORY_TAKE, body, strlen(body)); +     +    soup_session_queue_message(session, msg, xmlrpc_response_get_integer, &integer); +    g_main_run(loop); +     +    return integer; +} + +static void xmlrpc_response_get_string(SoupSession *s, +                                       SoupMessage *m, +                                       gpointer user_data) +{ +    if (SOUP_STATUS_IS_SUCCESSFUL(m->status_code)) { +        soup_xmlrpc_extract_method_response(m->response_body->data, +                                            m->response_body->length, +                                            NULL, +                                            G_TYPE_STRING, user_data); +    } +     +    g_main_quit(loop); +}                                 + +gchar *xmlrpc_get_string(gchar *addr, +                                gchar *method, +                                const gchar *param_types, +                                ...) +{ +    GValueArray *params; +    SoupMessage *msg; +    gchar *body, *string = NULL; + +    msg = soup_message_new("POST", addr); + +    params = g_value_array_new(1); +     +    if (param_types && *param_types) { +        va_list ap; + +        va_start(ap, param_types); +        while (*param_types) { +            switch (*param_types) { +            case '%': +              break; +            case 'i': +              soup_value_array_append(params, G_TYPE_INT, va_arg(ap, int)); +              break; +            case 's': +            default: +              soup_value_array_append(params, G_TYPE_STRING, va_arg(ap, char *)); +              break; +            } +             +            param_types++; +        } +         +        va_end(ap); +    } + +    body = soup_xmlrpc_build_method_call(method, params->values, params->n_values); +    g_value_array_free(params); + +    soup_message_set_request(msg, "text/xml", +			     SOUP_MEMORY_TAKE, body, strlen(body)); +     +    soup_session_queue_message(session, msg, xmlrpc_response_get_string, &string); +    g_main_run(loop); +     +    return string; +} + +static void xmlrpc_response_get_array(SoupSession *s, +                                      SoupMessage *m, +                                      gpointer user_data) +{ +    if (SOUP_STATUS_IS_SUCCESSFUL(m->status_code)) { +        soup_xmlrpc_extract_method_response(m->response_body->data, +                                            m->response_body->length, +                                            NULL, +                                            G_TYPE_VALUE_ARRAY, user_data); +    } +     +    g_main_quit(loop); +}                                 + +GValueArray *xmlrpc_get_array(gchar *addr, +                                     gchar *method, +                                     const gchar *param_types, +                                     ...) +{ +    GValueArray *params, *answer = NULL; +    SoupMessage *msg; +    gchar *body; + +    msg = soup_message_new("POST", addr); + +    params = g_value_array_new(1); +     +    if (param_types && *param_types) { +        va_list ap; + +        va_start(ap, param_types); +        while (*param_types) { +            switch (*param_types) { +            case '%': +              break; +            case 'i': +              soup_value_array_append(params, G_TYPE_INT, va_arg(ap, int)); +              break; +            case 's': +            default: +              soup_value_array_append(params, G_TYPE_STRING, va_arg(ap, char *)); +              break; +            } +             +            param_types++; +        } +         +        va_end(ap); +    } + +    body = soup_xmlrpc_build_method_call(method, params->values, params->n_values); +    g_value_array_free(params); + +    soup_message_set_request(msg, "text/xml", +			     SOUP_MEMORY_TAKE, body, strlen(body)); +     +    soup_session_queue_message(session, msg, xmlrpc_response_get_array, &answer); +    g_main_run(loop); +     +    return answer; +} diff --git a/hardinfo2/xmlrpc-client.h b/hardinfo2/xmlrpc-client.h new file mode 100644 index 00000000..98afd63b --- /dev/null +++ b/hardinfo2/xmlrpc-client.h @@ -0,0 +1,39 @@ +/* + *    XMLRPC Client + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2009 Leandro A. F. Pereira <leandro@hardinfo.org> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +#ifndef __XMLRPC_CLIENT_H__ +#define __XMLRPC_CLIENT_H__ + +#include <libsoup/soup.h> + +void xmlrpc_init(void); +gint xmlrpc_get_integer(gchar *addr, +                        gchar *method, +                        const gchar *param_types, +                        ...); +gchar *xmlrpc_get_string(gchar *addr, +                         gchar *method, +                         const gchar *param_types, +                         ...); +GValueArray *xmlrpc_get_array(gchar *addr, +                              gchar *method, +                              const gchar *param_types, +                              ...); + +#endif	/* __XMLRPC_CLIENT_H__ */ diff --git a/hardinfo2/xmlrpc-server.c b/hardinfo2/xmlrpc-server.c index f66d646c..e0643e2a 100644 --- a/hardinfo2/xmlrpc-server.c +++ b/hardinfo2/xmlrpc-server.c @@ -180,7 +180,7 @@ static void method_get_entry_list(SoupMessage * msg, GValueArray * params)            tuple = soup_value_array_new();            soup_value_array_append(tuple, G_TYPE_STRING, module_entry->name); -          soup_value_array_append(tuple, G_TYPE_INT, module_entry->number); +          soup_value_array_append(tuple, G_TYPE_STRING, module_entry->icon_file);            soup_value_array_append(out, G_TYPE_VALUE_ARRAY, tuple);            g_value_array_free(tuple); | 
