diff options
Diffstat (limited to 'hardinfo2')
-rw-r--r-- | hardinfo2/Makefile.in | 2 | ||||
-rw-r--r-- | hardinfo2/arch/common/fib.h | 3 | ||||
-rw-r--r-- | hardinfo2/arch/linux/common/sensors.h | 89 | ||||
-rw-r--r-- | hardinfo2/computer.c | 4 | ||||
-rw-r--r-- | hardinfo2/loadgraph.c | 21 | ||||
-rw-r--r-- | hardinfo2/loadgraph.h | 4 | ||||
-rw-r--r-- | hardinfo2/shell.c | 8 | ||||
-rw-r--r-- | hardinfo2/socket.c | 81 | ||||
-rw-r--r-- | hardinfo2/socket.h | 35 |
9 files changed, 229 insertions, 18 deletions
diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in index 1eaf0727..554f42ba 100644 --- a/hardinfo2/Makefile.in +++ b/hardinfo2/Makefile.in @@ -7,7 +7,7 @@ CFLAGS = -fPIC -pipe -Wall -g $(GTK_CFLAGS) $(GLADE_CFLAGS) -I. OBJECTS = hardinfo.o shell.o util.o iconcache.o loadgraph.o sha1.o md5.o \ menu.o stock.o callbacks.o expr.o report.o blowfish.o binreloc.o \ - vendor.o + vendor.o socket.o MODULES = computer.so devices.so benchmark.so all: $(OBJECTS) $(MODULES) diff --git a/hardinfo2/arch/common/fib.h b/hardinfo2/arch/common/fib.h index 493cfd0f..9f2d4e77 100644 --- a/hardinfo2/arch/common/fib.h +++ b/hardinfo2/arch/common/fib.h @@ -33,7 +33,7 @@ benchmark_fib(void) gdouble elapsed = 0; shell_view_set_enabled(FALSE); - shell_status_update("Calculating the 42<sup>th</sup> Fibonacci number..."); + shell_status_update("Calculating the 42nd Fibonacci number..."); g_timer_start(timer); fib(42); /* the answer? :) */ @@ -47,4 +47,3 @@ benchmark_fib(void) "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); return benchmark_include_results(retval, "Fibonacci"); } - diff --git a/hardinfo2/arch/linux/common/sensors.h b/hardinfo2/arch/linux/common/sensors.h index af707076..44e2260d 100644 --- a/hardinfo2/arch/linux/common/sensors.h +++ b/hardinfo2/arch/linux/common/sensors.h @@ -131,17 +131,13 @@ adjust_sensor(gchar *name, float value) return math_postfix_eval(postfix, value); } + static void -read_sensors(void) +read_sensors_hwmon(void) { - gchar *path_hwmon, *path_sensor, *tmp, *driver, *name, *mon; int hwmon, count; - - if (sensors) - g_free(sensors); - + gchar *path_hwmon, *path_sensor, *tmp, *driver, *name, *mon; hwmon = 0; - sensors = g_strdup(""); path_hwmon = g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", hwmon); while (g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) { @@ -233,17 +229,24 @@ read_sensors(void) } g_free(path_hwmon); + +} + +static void +read_sensors_acpi(void) +{ + const gchar *path_tz = "/proc/acpi/thermal_zone"; - path_hwmon = g_strdup("/proc/acpi/thermal_zone"); - if (g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) { + if (g_file_test(path_tz, G_FILE_TEST_EXISTS)) { GDir *tz; - if ((tz = g_dir_open(path_hwmon, 0, NULL))) { + if ((tz = g_dir_open(path_tz, 0, NULL))) { const gchar *entry; sensors = g_strdup_printf("%s\n[ACPI Thermal Zone]\n", sensors); + while ((entry = g_dir_read_name(tz))) { - gchar *path = g_strdup_printf("%s/%s/temperature", path_hwmon, entry); + gchar *path = g_strdup_printf("%s/%s/temperature", path_tz, entry); gchar *contents; if (g_file_get_contents(path, &contents, NULL, NULL)) { @@ -261,7 +264,69 @@ read_sensors(void) g_dir_close(tz); } } + +} + +static void +read_sensors_hddtemp(void) +{ + Socket *s = sock_connect("127.0.0.1", 7634); + static gchar *old = NULL; + gchar buffer[1024]; + gint len; - g_free(path_hwmon); + if (!s) + return; + + len = sock_read(s, buffer, sizeof(buffer)); + sock_close(s); + + if (len > 2 && buffer[0] == '|' && buffer[1] == '/') { + gchar **disks; + int i; + + if (old) + g_free(old); + + old = g_strdup("[Hard Disk Temperature]\n"); + + disks = g_strsplit(buffer, "\n", 0); + for (i = 0; disks[i]; i++) { + gchar **fields = g_strsplit(disks[i] + 1, "|", 5); + + /* + * 0 -> /dev/hda + * 1 -> FUJITSU MHV2080AH + * 2 -> 41 + * 3 -> C + */ + old = g_strdup_printf("%s\n" + "%s (%s)=%s\302\260%s\n", + old, + fields[1], fields[0], + fields[2], fields[3]); + + g_strfreev(fields); + } + + g_strfreev(disks); + } + + if (old) { + sensors = g_strconcat(sensors, "\n", old, NULL); + } +} + +static void +read_sensors(void) +{ + if (sensors) + g_free(sensors); + + sensors = g_strdup(""); + + read_sensors_hwmon(); + read_sensors_acpi(); + read_sensors_hddtemp(); } diff --git a/hardinfo2/computer.c b/hardinfo2/computer.c index ecc36d16..ee430d77 100644 --- a/hardinfo2/computer.c +++ b/hardinfo2/computer.c @@ -32,6 +32,8 @@ #include <vendor.h> #include <expr.h> +#include "socket.h" + enum { COMPUTER_SUMMARY, COMPUTER_PROCESSORS, @@ -213,7 +215,7 @@ hi_info(gint entry) "%s\n", human_users, sys_users); case COMPUTER_SENSORS: return g_strdup_printf("[$ShellParam$]\n" - "ReloadInterval=3000\n" + "ReloadInterval=5000\n" "%s", sensors); case COMPUTER_SHARES: return g_strdup_printf("[SAMBA]\n" diff --git a/hardinfo2/loadgraph.c b/hardinfo2/loadgraph.c index 53fb54f7..18ae08c8 100644 --- a/hardinfo2/loadgraph.c +++ b/hardinfo2/loadgraph.c @@ -42,12 +42,24 @@ LoadGraph *load_graph_new(gint size) lg->width = size * 4; lg->height = size * 2; + lg->max_value = -1; + gtk_widget_set_size_request(lg->area, lg->width, lg->height); gtk_widget_show(lg->area); return lg; } +int load_graph_get_max(LoadGraph *lg) +{ + return lg->max_value; +} + +void load_graph_set_max(LoadGraph *lg, gint value) +{ + lg->max_value = value; +} + GtkWidget *load_graph_get_framed(LoadGraph *lg) { GtkWidget *align, *frame; @@ -73,6 +85,7 @@ void load_graph_clear(LoadGraph *lg) lg->data[i] = 0; lg->scale = 1.0; +// lg->max_value = -1; _draw(lg); } @@ -196,7 +209,13 @@ load_graph_update(LoadGraph *lg, gint value) if (value < 0) return; - lg->scale = (gfloat)lg->height / (gfloat)_max(lg); + if (lg->max_value > 0) { + lg->scale = (gfloat)lg->height / (gfloat)_max(lg); + } else { + lg->scale = (gfloat)lg->height / (gfloat)lg->max_value; + + g_print("using max value %d; scale is %f\n", lg->max_value, lg->scale); + } /* shift-right our data */ for (i = 0; i < lg->size; i++) { diff --git a/hardinfo2/loadgraph.h b/hardinfo2/loadgraph.h index fdd967f0..93185af0 100644 --- a/hardinfo2/loadgraph.h +++ b/hardinfo2/loadgraph.h @@ -46,6 +46,8 @@ struct _LoadGraph { gint size; gint width, height; LoadGraphColor color; + + gint max_value; }; LoadGraph *load_graph_new(gint size); @@ -54,6 +56,8 @@ void load_graph_configure_expose(LoadGraph *lg); GtkWidget *load_graph_get_framed(LoadGraph *lg); void load_graph_update(LoadGraph *lg, gint value); +void load_graph_set_max(LoadGraph *lg, gint value); +int load_graph_get_max(LoadGraph *lg); void load_graph_set_color(LoadGraph *lg, LoadGraphColor color); void load_graph_clear(LoadGraph *lg); diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index 66d83cf9..8f051241 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -546,7 +546,7 @@ static gboolean update_field(gpointer data) { ShellFieldUpdate *fu = (ShellFieldUpdate *) data; - + /* if the entry is still selected, update it */ if (fu->entry->selected && fu->entry->fieldfunc) { gchar *value = fu->entry->fieldfunc(fu->field_name); @@ -556,6 +556,7 @@ update_field(gpointer data) SHELL_VIEW_LOAD_GRAPH */ if (fu->loadgraph && shell->view_type == SHELL_VIEW_LOAD_GRAPH) { GtkTreeSelection *ts; + ts = gtk_tree_view_get_selection(GTK_TREE_VIEW (shell->info->view)); @@ -686,6 +687,11 @@ group_handle_special(GKeyFile * key_file, ShellModuleEntry * entry, fu->loadgraph = TRUE; g_timeout_add(ms, update_field, fu); + } else if (g_str_equal(key, "LoadGraphMaxValue")) { + gint max_value; + + max_value = g_key_file_get_integer(key_file, group, key, NULL); + load_graph_set_max(shell->loadgraph, max_value); } else if (g_str_equal(key, "ReloadInterval")) { gint ms; diff --git a/hardinfo2/socket.c b/hardinfo2/socket.c new file mode 100644 index 00000000..4212c547 --- /dev/null +++ b/hardinfo2/socket.c @@ -0,0 +1,81 @@ +/* + * HardInfo - Displays System Information + * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + * 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 <stdio.h> +#include <string.h> +#include <arpa/inet.h> +#include <errno.h> +#include <netdb.h> +#include <netinet/in.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <unistd.h> + +#include <glib.h> + +#include "socket.h" + +Socket *sock_connect(gchar * host, gint port) +{ + struct sockaddr_in server; + Socket *s; + int sock; + + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock > 0) { + memset(&server, 0, sizeof(server)); + server.sin_family = AF_INET; + server.sin_addr.s_addr = inet_addr(host); + server.sin_port = htons(port); + + if (connect(sock, (struct sockaddr *) (void *) &server, sizeof(server)) < 0) { + return NULL; + } + + s = g_new0(Socket, 1); + s->host = g_strdup(host); + s->port = port; + s->sock = sock; + + return s; + } + + return NULL; +} + +int sock_write(Socket * s, gchar * str) +{ + return write(s->sock, str, strlen(str)); +} + +int sock_read(Socket * s, gchar * buffer, gint size) +{ + gint n; + + n = read(s->sock, buffer, size); + buffer[n] = '\0'; + + return n; +} + +void sock_close(Socket * s) +{ + close(s->sock); + g_free(s->host); + g_free(s); +} diff --git a/hardinfo2/socket.h b/hardinfo2/socket.h new file mode 100644 index 00000000..4c8fddb2 --- /dev/null +++ b/hardinfo2/socket.h @@ -0,0 +1,35 @@ +/* + * HardInfo - Displays System Information + * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + * 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 __HI_SOCKET_H__ +#define __HI_SOCKET_H__ + +typedef struct _Socket Socket; + +struct _Socket { + gchar *host; + gint port; + gint sock; +}; + +Socket *sock_connect(gchar * host, gint port); +int sock_write(Socket * s, gchar * str); +int sock_read(Socket * s, gchar * buffer, gint size); +void sock_close(Socket * s); + +#endif /* __HI_SOCKET_H__ */ |