aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hardinfo2/arch/linux/common/inputdevices.h4
-rw-r--r--hardinfo2/arch/linux/common/modules.h11
-rw-r--r--hardinfo2/arch/linux/common/pci.h4
-rw-r--r--hardinfo2/arch/linux/common/storage.h8
-rw-r--r--hardinfo2/arch/linux/common/usb.h4
-rw-r--r--hardinfo2/computer.c63
-rw-r--r--hardinfo2/computer.h2
-rw-r--r--hardinfo2/devices.c110
-rw-r--r--hardinfo2/hardinfo.h6
-rw-r--r--hardinfo2/shell.h6
-rw-r--r--hardinfo2/util.c65
11 files changed, 218 insertions, 65 deletions
diff --git a/hardinfo2/arch/linux/common/inputdevices.h b/hardinfo2/arch/linux/common/inputdevices.h
index a3fb3e4a..e9deffa7 100644
--- a/hardinfo2/arch/linux/common/inputdevices.h
+++ b/hardinfo2/arch/linux/common/inputdevices.h
@@ -55,7 +55,7 @@ scan_inputdevices(void)
return;
if (input_list) {
- g_hash_table_foreach_remove(devices, remove_input_devices, NULL);
+ g_hash_table_foreach_remove(moreinfo, remove_input_devices, NULL);
g_free(input_list);
g_free(input_icons);
}
@@ -127,7 +127,7 @@ scan_inputdevices(void)
"Version=0x%x\n"
"Connected to=%s\n",
strhash, product, version, phys);
- g_hash_table_insert(devices, tmp, strhash);
+ g_hash_table_insert(moreinfo, tmp, strhash);
g_free(phys);
g_free(name);
diff --git a/hardinfo2/arch/linux/common/modules.h b/hardinfo2/arch/linux/common/modules.h
index 933823d7..3acf4aba 100644
--- a/hardinfo2/arch/linux/common/modules.h
+++ b/hardinfo2/arch/linux/common/modules.h
@@ -16,6 +16,13 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#define GET_STR(field_name,ptr) \
+ if (!ptr && strstr(tmp[0], field_name)) { \
+ ptr = g_markup_escape_text(g_strstrip(tmp[1]), strlen(tmp[1])); \
+ g_strfreev(tmp); \
+ continue; \
+ }
+
static gboolean
remove_module_devices(gpointer key, gpointer value, gpointer data)
{
@@ -40,7 +47,7 @@ scan_modules(void)
module_list = NULL;
}
- g_hash_table_foreach_remove(devices, remove_module_devices, NULL);
+ g_hash_table_foreach_remove(moreinfo, remove_module_devices, NULL);
lsmod = popen("/sbin/lsmod", "r");
if (!lsmod)
@@ -137,7 +144,7 @@ scan_modules(void)
g_free(deps);
}
- g_hash_table_insert(devices, hashkey, strmodule);
+ g_hash_table_insert(moreinfo, hashkey, strmodule);
g_free(license);
g_free(description);
diff --git a/hardinfo2/arch/linux/common/pci.h b/hardinfo2/arch/linux/common/pci.h
index e7c940bb..5f48ba44 100644
--- a/hardinfo2/arch/linux/common/pci.h
+++ b/hardinfo2/arch/linux/common/pci.h
@@ -126,7 +126,7 @@ scan_pci(void)
gpointer start, end;
if (strdevice != NULL && strhash != NULL) {
- g_hash_table_insert(devices, strhash, strdevice);
+ g_hash_table_insert(moreinfo, strhash, strdevice);
g_free(category);
g_free(name);
}
@@ -194,7 +194,7 @@ scan_pci(void)
pci_list = g_strconcat(pci_list, "No PCI devices found=\n", NULL);
} else if (strhash) {
/* insert the last device */
- g_hash_table_insert(devices, strhash, strdevice);
+ g_hash_table_insert(moreinfo, strhash, strdevice);
g_free(category);
g_free(name);
}
diff --git a/hardinfo2/arch/linux/common/storage.h b/hardinfo2/arch/linux/common/storage.h
index 4c9b5633..3397570d 100644
--- a/hardinfo2/arch/linux/common/storage.h
+++ b/hardinfo2/arch/linux/common/storage.h
@@ -43,7 +43,7 @@ scan_scsi(void)
gchar *vendor = NULL, *revision = NULL, *model = NULL;
/* remove old devices from global device table */
- g_hash_table_foreach_remove(devices, remove_scsi_devices, NULL);
+ g_hash_table_foreach_remove(moreinfo, remove_scsi_devices, NULL);
if (!g_file_test("/proc/scsi/scsi", G_FILE_TEST_EXISTS))
return;
@@ -136,7 +136,7 @@ scan_scsi(void)
scsi_channel,
scsi_id,
scsi_lun);
- g_hash_table_insert(devices, devid, strhash);
+ g_hash_table_insert(moreinfo, devid, strhash);
g_free(model);
g_free(revision);
@@ -169,7 +169,7 @@ scan_ide(void)
gchar *capab = NULL, *speed = NULL, *driver = NULL;
/* remove old devices from global device table */
- g_hash_table_foreach_remove(devices, remove_ide_devices, NULL);
+ g_hash_table_foreach_remove(moreinfo, remove_ide_devices, NULL);
storage_list = g_strdup_printf("%s\n[IDE Disks]\n", storage_list);
@@ -345,7 +345,7 @@ scan_ide(void)
speed = NULL;
}
- g_hash_table_insert(devices, devid, strhash);
+ g_hash_table_insert(moreinfo, devid, strhash);
g_free(model);
model = "";
diff --git a/hardinfo2/arch/linux/common/usb.h b/hardinfo2/arch/linux/common/usb.h
index 4fd6ee21..286d9380 100644
--- a/hardinfo2/arch/linux/common/usb.h
+++ b/hardinfo2/arch/linux/common/usb.h
@@ -47,7 +47,7 @@ scan_usb(void)
return;
if (usb_list) {
- g_hash_table_foreach_remove(devices, remove_usb_devices, NULL);
+ g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL);
g_free(usb_list);
}
usb_list = g_strdup("");
@@ -125,7 +125,7 @@ scan_usb(void)
ver, rev, classid,
vendor, prodid, bus, level);
- g_hash_table_insert(devices, tmp, strhash);
+ g_hash_table_insert(moreinfo, tmp, strhash);
}
g_free(manuf);
diff --git a/hardinfo2/computer.c b/hardinfo2/computer.c
index 1d8e0b70..8499bb20 100644
--- a/hardinfo2/computer.c
+++ b/hardinfo2/computer.c
@@ -30,16 +30,12 @@
#include <shell.h>
#include <vendor.h>
-#include <expr.h>
-
-#include "socket.h"
enum {
COMPUTER_SUMMARY,
- COMPUTER_PROCESSORS,
COMPUTER_OPERATING_SYSTEM,
+ COMPUTER_KERNEL_MODULES,
COMPUTER_LANGUAGE,
- COMPUTER_SENSORS,
COMPUTER_FILESYSTEMS,
COMPUTER_SHARES,
COMPUTER_DISPLAY,
@@ -49,10 +45,9 @@ enum {
static ModuleEntry hi_entries[] = {
{"Summary", "summary.png"},
- {"Processor", "processor.png"},
{"Operating System", "os.png"},
+ {"Kernel Modules", "module.png"},
{"Languages", "language.png"},
- {"Sensors", "therm.png"},
{"Filesystems", "dev_removable.png"},
{"Shared Directories", "shares.png"},
{"Display", "monitor.png"},
@@ -63,19 +58,19 @@ static ModuleEntry hi_entries[] = {
#include "computer.h"
static GHashTable *moreinfo = NULL;
+static gchar *module_list = NULL;
+#include <arch/this/modules.h>
#include <arch/common/languages.h>
#include <arch/this/alsa.h>
#include <arch/common/display.h>
#include <arch/this/loadavg.h>
#include <arch/this/memory.h>
#include <arch/this/uptime.h>
-#include <arch/this/processor.h>
#include <arch/this/os.h>
#include <arch/this/filesystem.h>
#include <arch/this/samba.h>
#include <arch/this/nfs.h>
-#include <arch/this/sensors.h>
#include <arch/this/net.h>
#include <arch/common/users.h>
@@ -96,9 +91,6 @@ computer_get_info(void)
moreinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
- shell_status_update("Getting processor information...");
- computer->processors = computer_get_processors();
-
shell_status_update("Getting memory information...");
computer->memory = computer_get_memory();
@@ -118,9 +110,6 @@ computer_get_info(void)
scan_samba_shared_directories();
scan_nfs_shared_directories();
- shell_status_update("Reading sensors...");
- read_sensors();
-
shell_status_update("Obtaining network information...");
scan_net_interfaces();
@@ -135,15 +124,15 @@ void
hi_reload(gint entry)
{
switch (entry) {
+ case COMPUTER_KERNEL_MODULES:
+ scan_modules();
+ break;
case COMPUTER_FILESYSTEMS:
scan_filesystems();
break;
case COMPUTER_NETWORK:
scan_net_interfaces();
break;
- case COMPUTER_SENSORS:
- read_sensors();
- break;
case COMPUTER_USERS:
scan_users();
break;
@@ -193,13 +182,23 @@ gchar *
hi_info(gint entry)
{
static Computer *computer = NULL;
- static gchar *tmp = NULL;
+ static gchar *tmp1, *tmp2;
if (!computer) {
computer = computer_get_info();
}
switch (entry) {
+ case COMPUTER_KERNEL_MODULES:
+ if (!module_list) {
+ shell_status_update("Getting loaded module information...");
+ scan_modules();
+ }
+ return g_strdup_printf("[Loaded Modules]\n"
+ "%s"
+ "[$ShellParam$]\n"
+ "ViewType=1",
+ module_list);
case COMPUTER_NETWORK:
return g_strdup_printf("[$ShellParam$]\n"
"ReloadInterval=3000\n"
@@ -213,10 +212,6 @@ hi_info(gint entry)
"%s\n"
"[System Users]\n"
"%s\n", human_users, sys_users);
- case COMPUTER_SENSORS:
- return g_strdup_printf("[$ShellParam$]\n"
- "ReloadInterval=5000\n"
- "%s", sensors);
case COMPUTER_SHARES:
return g_strdup_printf("[SAMBA]\n"
"%s\n"
@@ -228,11 +223,11 @@ hi_info(gint entry)
"ReloadInterval=5000\n"
"[Mounted File Systems]\n%s\n", fs_list);
case COMPUTER_SUMMARY:
- if (tmp) g_free(tmp);
- tmp = computer_get_alsacards(computer);
+ tmp1 = computer_get_alsacards(computer);
+ tmp2 = module_call_method("devices::getProcessorName");
- /* FIXME: We assume all processors have the same name */
- Processor *processor = (Processor*) computer->processors->data;
+ schedule_free(tmp1);
+ schedule_free(tmp2);
return g_strdup_printf("[$ShellParam$]\n"
"UpdateInterval$Memory=1000\n"
@@ -249,7 +244,7 @@ hi_info(gint entry)
"X11 Vendor=%s\n"
"[Multimedia]\n"
"%s\n",
- processor->model_name,
+ tmp2,
computer->os->distro,
computer->os->username,
computer->date_time,
@@ -257,7 +252,7 @@ hi_info(gint entry)
computer->display->height,
computer->display->ogl_renderer,
computer->display->vendor,
- tmp);
+ tmp1);
case COMPUTER_DISPLAY:
return g_strdup_printf("[Display]\n"
"Resolution=%dx%d pixels\n"
@@ -314,8 +309,6 @@ hi_info(gint entry)
"ViewType=1\n"
"[Available Languages]\n"
"%s", computer->os->languages);
- case COMPUTER_PROCESSORS:
- return processor_get_info(computer->processors);
default:
return g_strdup("[Empty]\nNo info available=");
}
@@ -350,3 +343,11 @@ hi_module_weight(void)
{
return 80;
}
+
+gchar **
+hi_module_depends_on(void)
+{
+ static gchar *deps[] = { "devices.so", NULL };
+
+ return deps;
+}
diff --git a/hardinfo2/computer.h b/hardinfo2/computer.h
index 4fa771f8..d721df64 100644
--- a/hardinfo2/computer.h
+++ b/hardinfo2/computer.h
@@ -44,7 +44,6 @@ static struct {
};
typedef struct _Computer Computer;
-typedef struct _Processor Processor;
typedef struct _OperatingSystem OperatingSystem;
typedef struct _MemoryInfo MemoryInfo;
typedef struct _UptimeInfo UptimeInfo;
@@ -100,7 +99,6 @@ struct _UptimeInfo {
};
struct _Computer {
- GSList *processors;
MemoryInfo *memory;
OperatingSystem *os;
DisplayInfo *display;
diff --git a/hardinfo2/devices.c b/hardinfo2/devices.c
index 4eced276..a88f8e2b 100644
--- a/hardinfo2/devices.c
+++ b/hardinfo2/devices.c
@@ -24,28 +24,35 @@
#include <shell.h>
#include <iconcache.h>
+#include <expr.h>
+#include <socket.h>
+
enum {
- DEVICES_KERNEL_MODULES,
+ DEVICES_PROCESSORS,
+ DEVICES_MEMORY,
DEVICES_PCI,
DEVICES_USB,
DEVICES_PRINTERS,
DEVICES_BATTERY,
+ DEVICES_SENSORS,
DEVICES_INPUT,
DEVICES_STORAGE,
} Entries;
static ModuleEntry hi_entries[] = {
- {"Kernel Modules", "module.png"},
+ {"Processor", "processor.png"},
+ {"Memory", "memory.png"},
{"PCI Devices", "devices.png"},
{"USB Devices", "usb.png"},
{"Printers", "printer.png"},
{"Battery", "battery.png"},
+ {"Sensors", "therm.png"},
{"Input Devices", "keyboard.png"},
{"Storage", "hdd.png"},
};
-static GHashTable *devices = NULL;
-static gchar *module_list = NULL;
+static GHashTable *moreinfo = NULL;
+static GSList *processors = NULL;
static gchar *printer_list = NULL;
static gchar *pci_list = "";
static gchar *input_list = NULL;
@@ -61,23 +68,62 @@ static gchar *battery_list = NULL;
continue; \
}
+#define get_str(field_name,ptr) \
+ if (g_str_has_prefix(tmp[0], field_name)) { \
+ ptr = g_strdup(tmp[1]); \
+ g_strfreev(tmp); \
+ continue; \
+ }
+#define get_int(field_name,ptr) \
+ if (g_str_has_prefix(tmp[0], field_name)) { \
+ ptr = atoi(tmp[1]); \
+ g_strfreev(tmp); \
+ continue; \
+ }
+#define get_float(field_name,ptr) \
+ if (g_str_has_prefix(tmp[0], field_name)) { \
+ ptr = atof(tmp[1]); \
+ g_strfreev(tmp); \
+ continue; \
+ }
+
#include <vendor.h>
+typedef struct _Processor Processor;
+struct _Processor {
+ gchar *model_name;
+ gchar *vendor_id;
+ gchar *flags;
+ gint cache_size;
+ gfloat bogomips, cpu_mhz;
+
+ gchar *has_fpu;
+ gchar *bug_fdiv, *bug_hlt, *bug_f00f, *bug_coma;
+
+ gint model, family, stepping;
+ gchar *strmodel;
+
+ gint id;
+};
+
+#include <arch/this/processor.h>
+
#include <arch/this/pci.h>
-#include <arch/this/modules.h>
#include <arch/common/printers.h>
#include <arch/this/inputdevices.h>
#include <arch/this/usb.h>
#include <arch/this/storage.h>
#include <arch/this/battery.h>
+#include <arch/this/sensors.h>
static void
detect_devices(void)
{
- devices = g_hash_table_new(g_str_hash, g_str_equal);
+ moreinfo = g_hash_table_new(g_str_hash, g_str_equal);
- shell_status_update("Getting loaded modules information...");
- scan_modules();
+ shell_status_update("Getting processor information...");
+ if (!processors)
+ processors = computer_get_processors();
shell_status_update("Scanning PCI devices...");
scan_pci();
@@ -99,12 +145,36 @@ detect_devices(void)
shell_status_update("Scanning batteries...");
scan_battery();
+
+ shell_status_update("Reading sensors...");
+ read_sensors();
+}
+
+gchar *
+get_processor_name(void)
+{
+ if (!processors) {
+ processors = computer_get_processors();
+ }
+
+ Processor *p = (Processor *) processors->data;
+ return p->model_name;
+}
+
+ShellModuleMethod *hi_exported_methods(void)
+{
+ static ShellModuleMethod m[] = {
+ { "getProcessorName", get_processor_name },
+ { NULL }
+ };
+
+ return m;
}
gchar *
hi_more_info(gchar * entry)
{
- gchar *info = (gchar *) g_hash_table_lookup(devices, entry);
+ gchar *info = (gchar *) g_hash_table_lookup(moreinfo, entry);
if (info)
return g_strdup(info);
@@ -115,9 +185,6 @@ void
hi_reload(gint entry)
{
switch (entry) {
- case DEVICES_KERNEL_MODULES:
- scan_modules();
- break;
case DEVICES_BATTERY:
scan_battery();
break;
@@ -130,6 +197,9 @@ hi_reload(gint entry)
case DEVICES_USB:
scan_usb();
break;
+ case DEVICES_SENSORS:
+ read_sensors();
+ break;
case DEVICES_STORAGE:
if (storage_list) {
g_free(storage_list);
@@ -146,27 +216,29 @@ hi_reload(gint entry)
gchar *
hi_info(gint entry)
{
- if (!devices) {
+ if (!moreinfo) {
detect_devices();
}
switch (entry) {
+ case DEVICES_PROCESSORS:
+ return processor_get_info(processors);
+ case DEVICES_MEMORY:
+ return g_strdup("[Memory]\nNot implemented=\n");
case DEVICES_BATTERY:
return g_strdup_printf("%s\n"
"[$ShellParam$]\n"
"ReloadInterval=4000\n", battery_list);
- case DEVICES_KERNEL_MODULES:
- return g_strdup_printf("[Loaded Modules]\n"
- "%s"
- "[$ShellParam$]\n"
- "ViewType=1",
- module_list);
case DEVICES_PCI:
return g_strdup_printf("[PCI Devices]\n"
"%s"
"[$ShellParam$]\n"
"ViewType=1\n",
pci_list);
+ case DEVICES_SENSORS:
+ return g_strdup_printf("[$ShellParam$]\n"
+ "ReloadInterval=5000\n"
+ "%s", sensors);
case DEVICES_PRINTERS:
return g_strdup_printf("%s\n"
"[$ShellParam$]\n"
diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h
index 1f850cc9..eb78d99a 100644
--- a/hardinfo2/hardinfo.h
+++ b/hardinfo2/hardinfo.h
@@ -20,6 +20,7 @@
#define __HARDINFO_H__
#include <gtk/gtk.h>
+#include <shell.h>
typedef struct _ModuleEntry ModuleEntry;
typedef struct _FileTypes FileTypes;
@@ -69,6 +70,7 @@ gchar *file_chooser_build_filename(GtkWidget *chooser, gchar *extension);
gpointer file_types_get_data_by_name(FileTypes *file_types, gchar *name);
/* Misc utility functions */
+void schedule_free(gpointer ptr);
inline gchar *size_human_readable(gfloat size);
void nonblock_sleep(guint msec);
void open_url(gchar *url);
@@ -83,4 +85,8 @@ gboolean ui_init(int *argc, char ***argv);
void parameters_init(int *argc, char ***argv, ProgramParameters *params);
extern ProgramParameters params;
+/* Module stuff */
+void module_register(ShellModule *module);
+gchar *module_call_method(gchar *method);
+
#endif /* __HARDINFO_H__ */
diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h
index f9ac39e5..c1204233 100644
--- a/hardinfo2/shell.h
+++ b/hardinfo2/shell.h
@@ -26,6 +26,7 @@ typedef struct _ShellTree ShellTree;
typedef struct _ShellInfoTree ShellInfoTree;
typedef struct _ShellModule ShellModule;
+typedef struct _ShellModuleMethod ShellModuleMethod;
typedef struct _ShellModuleEntry ShellModuleEntry;
typedef struct _ShellFieldUpdate ShellFieldUpdate;
@@ -111,6 +112,11 @@ struct _ShellModule {
GSList *entries;
};
+struct _ShellModuleMethod {
+ gchar *name;
+ gchar *(*function) (void);
+};
+
struct _ShellModuleEntry {
gchar *name;
GdkPixbuf *icon;
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);
+}