diff options
-rw-r--r-- | hardinfo2/arch/linux/common/modules.h | 16 | ||||
-rw-r--r-- | hardinfo2/arch/linux/common/pci.h | 22 | ||||
-rw-r--r-- | hardinfo2/arch/linux/common/resources.h | 44 | ||||
-rw-r--r-- | hardinfo2/computer.c | 17 | ||||
-rw-r--r-- | hardinfo2/devices.c | 16 | ||||
-rw-r--r-- | hardinfo2/hardinfo.h | 1 | ||||
-rw-r--r-- | hardinfo2/shell.h | 2 | ||||
-rw-r--r-- | hardinfo2/util.c | 13 |
8 files changed, 126 insertions, 5 deletions
diff --git a/hardinfo2/arch/linux/common/modules.h b/hardinfo2/arch/linux/common/modules.h index 46f73d2f..32c9c0d6 100644 --- a/hardinfo2/arch/linux/common/modules.h +++ b/hardinfo2/arch/linux/common/modules.h @@ -29,12 +29,18 @@ remove_module_devices(gpointer key, gpointer value, gpointer data) return g_str_has_prefix(key, "MOD"); } +static GHashTable *_module_hash_table = NULL; + static void scan_modules_do(void) { FILE *lsmod; gchar buffer[1024]; + if (!_module_hash_table) { + _module_hash_table = g_hash_table_new(g_str_hash, g_str_equal); + } + if (module_list) { g_free(module_list); } @@ -95,7 +101,15 @@ scan_modules_do(void) if (description && g_str_equal(description, "<none>")) { g_free(description); description = g_strdup(""); - } + + g_hash_table_insert(_module_hash_table, + g_strdup(modname), + g_strdup_printf("Kernel module (%s)", modname)); + } else { + g_hash_table_insert(_module_hash_table, + g_strdup(modname), + g_strdup(description)); + } /* append this module to the list of modules */ module_list = h_strdup_cprintf("$%s$%s=%s\n", diff --git a/hardinfo2/arch/linux/common/pci.h b/hardinfo2/arch/linux/common/pci.h index a89c8841..4ea03356 100644 --- a/hardinfo2/arch/linux/common/pci.h +++ b/hardinfo2/arch/linux/common/pci.h @@ -16,6 +16,18 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +/* + * TODO: This thing must be rewritten. We really should have a struct with all the + * PCI stuff we'll present to the user, and hash them by the PCI ID + * (domain:bus:device.function). + * This way we'll have ways to better organize the output, instead of relying + * on the order the information appears on lspci's output. + * Also, the "Resources" thing might be better implemented (and we won't need + * copies of information scattered everywhere like we do today). + */ + +GHashTable *_pci_devices = NULL; + void __scan_pci(void) { @@ -23,6 +35,10 @@ __scan_pci(void) gchar buffer[256], *buf, *strhash = NULL, *strdevice = NULL; gchar *category = NULL, *name = NULL, *icon; gint n = 0, x = 0; + + if (!_pci_devices) { + _pci_devices = g_hash_table_new(g_str_hash, g_str_equal); + } buf = g_build_filename(g_get_home_dir(), ".hardinfo", "pci.ids", NULL); if (!g_file_test(buf, G_FILE_TEST_EXISTS)) { @@ -169,6 +185,9 @@ __scan_pci(void) else icon = "pci"; name = g_strdup(buf); + g_hash_table_insert(_pci_devices, + g_strdup_printf("0000:%02x:%02x.%x", bus, device, function), + name); strhash = g_strdup_printf("PCI%d", n); strdevice = g_strdup_printf("[Device Information]\n" @@ -187,6 +206,9 @@ __scan_pci(void) url); } + g_hash_table_insert(_pci_devices, + g_strdup_printf("0000:%02x:%02x.%x", bus, device, function), + g_strdup(name)); pci_list = h_strdup_cprintf("$PCI%d$%s=%s\n", pci_list, n, category, name); diff --git a/hardinfo2/arch/linux/common/resources.h b/hardinfo2/arch/linux/common/resources.h index 581d7eba..5e767caa 100644 --- a/hardinfo2/arch/linux/common/resources.h +++ b/hardinfo2/arch/linux/common/resources.h @@ -17,6 +17,41 @@ */ gchar *_resources = NULL; + +#if GLIB_CHECK_VERSION(2,14,0) +static GRegex *_regex_pci = NULL, + *_regex_module = NULL; +static gchar *_resource_obtain_name(gchar *name) +{ + gchar *temp; + + if (!_regex_pci && !_regex_module) { + _regex_pci = g_regex_new("^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\\.[0-9a-fA-F]{1}$", + 0, 0, NULL); + _regex_module = g_regex_new("^[0-9a-zA-Z\\_\\-]+$", 0, 0, NULL); + } + + name = g_strstrip(name); + + if (g_regex_match(_regex_pci, name, 0, NULL)) { + temp = module_call_method_param("devices::getPCIDeviceDescription", name); + return temp ? temp : name; + } + + if (g_regex_match(_regex_module, name, 0, NULL)) { + temp = module_call_method_param("computer::getKernelModuleDescription", name); + return temp ? temp : name; + } + + return name; +} +#else +static gchar *_resource_obtain_name(gchar *name) +{ + return name; +} +#endif + void scan_device_resources(gboolean reload) { SCAN_START(); @@ -32,7 +67,8 @@ void scan_device_resources(gboolean reload) while (fgets(buffer, 256, io)) { gchar **temp = g_strsplit(buffer, ":", 2); - _resources = h_strdup_cprintf("%s=%s\n", _resources, temp[0], temp[1]); + _resources = h_strdup_cprintf("%s=%s\n", _resources, + temp[0], _resource_obtain_name(temp[1])); g_strfreev(temp); } @@ -46,7 +82,8 @@ void scan_device_resources(gboolean reload) while (fgets(buffer, 256, io)) { gchar **temp = g_strsplit(buffer, ":", 2); - _resources = h_strdup_cprintf("%s=%s\n", _resources, temp[0], temp[1]); + _resources = h_strdup_cprintf("%s=%s\n", _resources, + temp[0], _resource_obtain_name(temp[1])); g_strfreev(temp); } @@ -60,7 +97,8 @@ void scan_device_resources(gboolean reload) while (fgets(buffer, 256, io)) { gchar **temp = g_strsplit(buffer, ":", 2); - _resources = h_strdup_cprintf("%s=%s\n", _resources, temp[0], temp[1]); + _resources = h_strdup_cprintf("%s=%s\n", _resources, + temp[0], _resource_obtain_name(temp[1])); g_strfreev(temp); } diff --git a/hardinfo2/computer.c b/hardinfo2/computer.c index 573db3d6..0ae68be3 100644 --- a/hardinfo2/computer.c +++ b/hardinfo2/computer.c @@ -365,10 +365,27 @@ gchar *get_os_kernel(void) return computer->os->kernel; } +gchar *get_kernel_module_description(gchar *module) +{ + gchar *description; + + if (!_module_hash_table) { + scan_modules(FALSE); + } + + description = g_hash_table_lookup(_module_hash_table, module); + if (!description) { + return g_strdup(module); + } + + return g_strdup(description); +} + ShellModuleMethod *hi_exported_methods(void) { static ShellModuleMethod m[] = { {"getOSKernel", get_os_kernel}, + {"getKernelModuleDescription", get_kernel_module_description}, {NULL} }; diff --git a/hardinfo2/devices.c b/hardinfo2/devices.c index df57361d..df7277b1 100644 --- a/hardinfo2/devices.c +++ b/hardinfo2/devices.c @@ -170,6 +170,21 @@ gchar *get_processor_count(void) return g_strdup_printf("%d", g_slist_length(processors)); } +gchar *get_pci_device_description(gchar *pci_id) +{ + gchar *description; + + if (!_pci_devices) { + scan_pci(FALSE); + } + + if ((description = g_hash_table_lookup(_pci_devices, pci_id))) { + return g_strdup(description); + } + + return NULL; +} + ShellModuleMethod *hi_exported_methods(void) { static ShellModuleMethod m[] = { @@ -178,6 +193,7 @@ ShellModuleMethod *hi_exported_methods(void) {"getStorageDevices", get_storage_devices}, {"getPrinters", get_printers}, {"getInputDevices", get_input_devices}, + {"getPCIDeviceDescription", get_pci_device_description}, {NULL} }; diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index 6c617357..43514be2 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -118,6 +118,7 @@ extern ProgramParameters params; /* Module stuff */ gchar *module_call_method(gchar *method); +gchar *module_call_method_param(gchar * method, gchar * parameter); /* Sysfs stuff */ gfloat h_sysfs_read_float(gchar *endpoint, gchar *entry); diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h index 01da254f..f8f3afed 100644 --- a/hardinfo2/shell.h +++ b/hardinfo2/shell.h @@ -124,7 +124,7 @@ struct _ShellModule { struct _ShellModuleMethod { gchar *name; - gchar *(*function) (void); + gpointer function; }; struct _ShellModuleEntry { diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 153b32b8..2cf37291 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -489,6 +489,19 @@ gchar *module_call_method(gchar * method) g_strdup_printf("{Unknown method: \"%s\"}", method); } +gchar *module_call_method_param(gchar * method, gchar * parameter) +{ + gchar *(*function) (gchar *param); + + if (__module_methods == NULL) { + return NULL; + } + + function = g_hash_table_lookup(__module_methods, method); + return function ? g_strdup(function(parameter)) : + g_strdup_printf("{Unknown method: \"%s\"}", method); +} + static ShellModule *module_load(gchar * filename) { ShellModule *module; |