summaryrefslogtreecommitdiff
path: root/devices.c
diff options
context:
space:
mode:
authorSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 14:38:41 -0500
committerSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 14:38:41 -0500
commit11b8179a57e675c6672cbe649c655230ae3e9744 (patch)
tree2919c366d51e154e65279156fef5b4f97b8fd2f9 /devices.c
parent720f5023a8f68aaaa54cb6b7bf46efee23b5b4c3 (diff)
Import Upstream version 0.4.2.1
Diffstat (limited to 'devices.c')
-rw-r--r--devices.c436
1 files changed, 326 insertions, 110 deletions
diff --git a/devices.c b/devices.c
index 07946755..76049068 100644
--- a/devices.c
+++ b/devices.c
@@ -1,6 +1,6 @@
/*
* HardInfo - Displays System Information
- * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br>
+ * Copyright (C) 2003-2007 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
@@ -24,170 +24,386 @@
#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"},
- {"PCI Devices", "devices.png"},
- {"USB Devices", "usb.png"},
- {"Printers", "printer.png"},
- {"Input Devices", "keyboard.png"},
- {"Storage", "hdd.png"},
+gchar *callback_processors();
+gchar *callback_memory();
+gchar *callback_battery();
+gchar *callback_pci();
+gchar *callback_sensors();
+gchar *callback_printers();
+gchar *callback_storage();
+gchar *callback_input();
+gchar *callback_usb();
+
+void scan_processors(gboolean reload);
+void scan_memory(gboolean reload);
+void scan_battery(gboolean reload);
+void scan_pci(gboolean reload);
+void scan_sensors(gboolean reload);
+void scan_printers(gboolean reload);
+void scan_storage(gboolean reload);
+void scan_input(gboolean reload);
+void scan_usb(gboolean reload);
+
+static ModuleEntry entries[] = {
+ {"Processor", "processor.png", callback_processors, scan_processors},
+ {"Memory", "memory.png", callback_memory, scan_memory},
+ {"PCI Devices", "devices.png", callback_pci, scan_pci},
+ {"USB Devices", "usb.png", callback_usb, scan_usb},
+ {"Printers", "printer.png", callback_printers, scan_printers,},
+ {"Battery", "battery.png", callback_battery, scan_battery},
+ {"Sensors", "therm.png", callback_sensors, scan_sensors},
+ {"Input Devices", "inputdevices.png", callback_input, scan_input},
+ {"Storage", "hdd.png", callback_storage, scan_storage},
+ { NULL }
};
-static GHashTable *devices = NULL;
-static gchar *module_list = "";
+static GHashTable *moreinfo = NULL;
+static GSList *processors = NULL;
static gchar *printer_list = NULL;
static gchar *pci_list = "";
static gchar *input_list = NULL;
-static gchar *storage_list = "";
+static gchar *storage_list = NULL;
+static gchar *battery_list = NULL;
+static gchar *meminfo = NULL, *lginterval = NULL;
#define WALK_UNTIL(x) while((*buf != '\0') && (*buf != x)) buf++
-#define GET_STR(field_name,ptr) \
- if (strstr(tmp[0], field_name)) { \
- ptr = g_markup_escape_text(g_strstrip(tmp[1]), strlen(tmp[1])); \
- g_strfreev(tmp); \
- continue; \
+#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; \
+ }
+
+#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;
+
+#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>
+#include <arch/this/devmemory.h>
-static void
-detect_devices(void)
+gchar *
+get_processor_name(void)
{
- devices = g_hash_table_new(g_str_hash, g_str_equal);
+ scan_processors(FALSE);
+
+ Processor *p = (Processor *) processors->data;
- shell_status_update("Getting loaded modules information...");
- scan_modules();
+ if (g_slist_length(processors) > 1) {
+ return idle_free(g_strdup_printf("%dx %s",
+ g_slist_length(processors),
+ p->model_name));
+ } else {
+ return p->model_name;
+ }
+}
- shell_status_update("Scanning PCI devices...");
- scan_pci();
+gchar *
+get_storage_devices(void)
+{
+ scan_storage(FALSE);
+
+ return storage_list;
+}
- shell_status_update("Searching for printers...");
- scan_printers();
+gchar *
+get_printers(void)
+{
+ scan_printers(FALSE);
+
+ return printer_list;
+}
- shell_status_update("Scanning input devices...");
- scan_inputdevices();
+gchar *
+get_input_devices(void)
+{
+ scan_input(FALSE);
+
+ return input_list;
+}
- shell_status_update("Scanning USB devices...");
- scan_usb();
+ShellModuleMethod*
+hi_exported_methods(void)
+{
+ static ShellModuleMethod m[] = {
+ { "getProcessorName", get_processor_name },
+ { "getStorageDevices", get_storage_devices },
+ { "getPrinters", get_printers },
+ { "getInputDevices", get_input_devices },
+ { NULL }
+ };
+
+ return m;
+}
- shell_status_update("Scanning IDE devices...");
- scan_ide();
+gchar *
+hi_more_info(gchar * entry)
+{
+ gchar *info = (gchar *) g_hash_table_lookup(moreinfo, entry);
- shell_status_update("Scanning SCSI devices...");
- scan_scsi();
+ if (info)
+ return g_strdup(info);
+
+ return g_strdup("?");
}
gchar *
-hi_more_info(gchar * entry)
+hi_get_field(gchar * field)
{
- gchar *info = (gchar *) g_hash_table_lookup(devices, entry);
+ gchar *info = (gchar *) g_hash_table_lookup(moreinfo, field);
if (info)
return g_strdup(info);
- return g_strdup("[Empty]");
+
+ return g_strdup(field);
}
void
-hi_reload(gint entry)
-{
- switch (entry) {
- case DEVICES_INPUT:
- scan_inputdevices();
- break;
- case DEVICES_PRINTERS:
- scan_printers();
- break;
- case DEVICES_USB:
- scan_usb();
- break;
- case DEVICES_STORAGE:
- if (storage_list) {
- g_free(storage_list);
- g_free(storage_icons);
- storage_list = g_strdup("");
- storage_icons = g_strdup("");
- }
- scan_ide();
- scan_scsi();
- break;
- }
+scan_processors(gboolean reload)
+{
+ SCAN_START();
+ if (!processors)
+ processors = __scan_processors();
+ SCAN_END();
+}
+
+void
+scan_memory(gboolean reload)
+{
+ SCAN_START();
+ __scan_memory();
+ SCAN_END();
+}
+
+void
+scan_battery(gboolean reload)
+{
+ SCAN_START();
+ __scan_battery();
+ SCAN_END();
+}
+
+void
+scan_pci(gboolean reload)
+{
+ SCAN_START();
+ __scan_pci();
+ SCAN_END();
+}
+
+void
+scan_sensors(gboolean reload)
+{
+ SCAN_START();
+ __scan_sensors();
+ SCAN_END();
+}
+
+void
+scan_printers(gboolean reload)
+{
+ SCAN_START();
+ __scan_printers();
+ SCAN_END();
+}
+
+void
+scan_storage(gboolean reload)
+{
+ SCAN_START();
+ g_free(storage_list);
+ storage_list = g_strdup("");
+
+ __scan_ide_devices();
+ __scan_scsi_devices();
+ SCAN_END();
+}
+
+void
+scan_input(gboolean reload)
+{
+ SCAN_START();
+ __scan_input_devices();
+ SCAN_END();
+}
+
+void
+scan_usb(gboolean reload)
+{
+ SCAN_START();
+ __scan_usb();
+ SCAN_END();
}
gchar *
-hi_info(gint entry)
+callback_processors()
{
- if (!devices) {
- detect_devices();
- }
+ return processor_get_info(processors);
+}
- switch (entry) {
- 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_PRINTERS:
- return g_strdup_printf("%s\n"
- "[$ShellParam$]\n"
- "ReloadInterval=5000", printer_list);
- case DEVICES_STORAGE:
- return g_strdup_printf("%s\n"
- "[$ShellParam$]\n"
- "ReloadInterval=5000\n"
- "ViewType=1\n%s", storage_list, storage_icons);
- case DEVICES_INPUT:
- return g_strdup_printf("[Input Devices]\n"
- "%s"
- "[$ShellParam$]\n"
- "ViewType=1\n"
- "ReloadInterval=5000\n%s", input_list, input_icons);
- case DEVICES_USB:
- return g_strdup_printf("%s"
- "[$ShellParam$]\n"
- "ViewType=1\n"
- "ReloadInterval=5000\n",
- usb_list);
- default:
- return g_strdup("[Empty]\nNo info available=");
- }
+gchar *
+callback_memory()
+{
+ return g_strdup_printf("[Memory]\n"
+ "%s\n"
+ "[$ShellParam$]\n"
+ "ViewType=2\n"
+ "LoadGraphSuffix= kB\n"
+ "RescanInterval=2000\n"
+ "%s\n",
+ meminfo,
+ lginterval);
+}
+
+gchar *
+callback_battery()
+{
+ return g_strdup_printf("%s\n"
+ "[$ShellParam$]\n"
+ "ReloadInterval=4000\n", battery_list);
+}
+
+gchar *
+callback_pci()
+{
+ return g_strdup_printf("[PCI Devices]\n"
+ "%s"
+ "[$ShellParam$]\n"
+ "ViewType=1\n",
+ pci_list);
+}
+
+gchar *
+callback_sensors()
+{
+ return g_strdup_printf("[$ShellParam$]\n"
+ "ReloadInterval=5000\n"
+ "%s", sensors);
}
-gint
-hi_n_entries(void)
+gchar *
+callback_printers()
+{
+ return g_strdup_printf("%s\n"
+ "[$ShellParam$]\n"
+ "ReloadInterval=5000", printer_list);
+}
+
+gchar *
+callback_storage()
+{
+ return g_strdup_printf("%s\n"
+ "[$ShellParam$]\n"
+ "ReloadInterval=5000\n"
+ "ViewType=1\n%s", storage_list, storage_icons);
+}
+
+gchar *
+callback_input()
{
- return G_N_ELEMENTS(hi_entries) - 1;
+ return g_strdup_printf("[Input Devices]\n"
+ "%s"
+ "[$ShellParam$]\n"
+ "ViewType=1\n"
+ "ReloadInterval=5000\n%s", input_list, input_icons);
}
-GdkPixbuf *
-hi_icon(gint entry)
+gchar *
+callback_usb()
{
- return icon_cache_get_pixbuf(hi_entries[entry].icon);
+ return g_strdup_printf("%s"
+ "[$ShellParam$]\n"
+ "ViewType=1\n"
+ "ReloadInterval=5000\n",
+ usb_list);
+}
+
+ModuleEntry *
+hi_module_get_entries(void)
+{
+ return entries;
}
gchar *
-hi_name(gint entry)
+hi_module_get_name(void)
{
- return hi_entries[entry].name;
+ return g_strdup("Devices");
}
+
+guchar
+hi_module_get_weight(void)
+{
+ return 160;
+}
+
+void
+hi_module_init(void)
+{
+ moreinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ __init_memory_labels();
+}
+
+ModuleAbout *
+hi_module_get_about(void)
+{
+ static ModuleAbout ma[] = {
+ {
+ .author = "Leandro A. F. Pereira",
+ .description = "Gathers information about hardware devices",
+ .version = VERSION,
+ .license = "GNU GPL version 2"
+ }
+ };
+
+ return ma;
+}
+
+gchar **
+hi_module_get_dependencies(void)
+{
+ static gchar *deps[] = { "computer.so", NULL };
+
+ return deps;
+}
+