1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/*
* 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 <gtk/gtk.h>
#include <config.h>
#include <string.h>
#include <hardinfo.h>
#include <shell.h>
#include <iconcache.h>
#include <expr.h>
#include <socket.h>
enum {
DEVICES_PROCESSORS,
DEVICES_MEMORY,
DEVICES_PCI,
DEVICES_USB,
DEVICES_PRINTERS,
DEVICES_BATTERY,
DEVICES_SENSORS,
DEVICES_INPUT,
DEVICES_STORAGE,
} Entries;
static ModuleEntry hi_entries[] = {
{"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 *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 *battery_list = NULL;
#define WALK_UNTIL(x) while((*buf != '\0') && (*buf != x)) buf++
#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;
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/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)
{
moreinfo = g_hash_table_new(g_str_hash, g_str_equal);
shell_status_update("Getting processor information...");
if (!processors)
processors = computer_get_processors();
shell_status_update("Scanning PCI devices...");
scan_pci();
shell_status_update("Searching for printers...");
scan_printers();
shell_status_update("Scanning input devices...");
scan_inputdevices();
shell_status_update("Scanning USB devices...");
scan_usb();
shell_status_update("Scanning IDE devices...");
scan_ide();
shell_status_update("Scanning SCSI devices...");
scan_scsi();
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(moreinfo, entry);
if (info)
return g_strdup(info);
return g_strdup("[Empty]");
}
void
hi_reload(gint entry)
{
switch (entry) {
case DEVICES_BATTERY:
scan_battery();
break;
case DEVICES_INPUT:
scan_inputdevices();
break;
case DEVICES_PRINTERS:
scan_printers();
break;
case DEVICES_USB:
scan_usb();
break;
case DEVICES_SENSORS:
read_sensors();
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;
}
}
gchar *
hi_info(gint entry)
{
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_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"
"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=");
}
}
gint
hi_n_entries(void)
{
return G_N_ELEMENTS(hi_entries) - 1;
}
GdkPixbuf *
hi_icon(gint entry)
{
return icon_cache_get_pixbuf(hi_entries[entry].icon);
}
gchar *
hi_name(gint entry)
{
return hi_entries[entry].name;
}
gchar *
hi_module_name(void)
{
return g_strdup("Devices");
}
guchar
hi_module_weight(void)
{
return 160;
}
|