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
|
/*
* info_netbsd.cpp is part of the KDE program kcminfo. This displays
* various information about the NetBSD system it's running on.
*
* Originally written by Jaromir Dolecek <dolecek@ics.muni.cz>. CPU info
* code has been imported from implementation of processor.cpp for KDE 1.0
* by David Brownlee <abs@NetBSD.org> as found in NetBSD packages collection.
* Hubert Feyer <hubertf@NetBSD.org> enhanced the sound information printing
* quite a lot, too.
*
* The code is placed into public domain. Do whatever you want with it.
*/
/*
* all following functions should return true, when the Information
* was filled into the Tree Widget. Returning false indicates that
* information was not available.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/mount.h>
#include <stdio.h> /* for NULL */
#include <stdlib.h> /* for malloc(3) */
#include <fstab.h>
#include <QFile>
#include <QStringList>
#include <QTextStream>
#include <QTreeWidgetItemIterator>
#include <QDebug>
#include <kio/global.h> /* for KIO::convertSize() */
typedef struct {
int string;
int name;
const char *title;
} hw_info_mib_list_t;
// this is used to find out which devices are currently
// on system
static bool GetDmesgInfo(QTreeWidget* tree, const char *filter, void func(QTreeWidget* tree, QString s)) {
QFile *dmesg = new QFile("/var/run/dmesg.boot");
bool usepipe = false;
FILE *pipe= NULL;
QTextStream *t;
bool seencpu = false;
QString s;
bool found = false;
if (dmesg->exists() && dmesg->open(QIODevice::ReadOnly)) {
t = new QTextStream(dmesg);
} else {
delete dmesg;
pipe = popen("/sbin/dmesg", "r");
if (!pipe)
return false;
usepipe = true;
t = new QTextStream(pipe, QIODevice::ReadOnly);
}
while (!(s = t->readLine().toLocal8Bit()).isNull()) {
if (!seencpu) {
if (s.contains("cpu"))
seencpu = true;
else
continue;
}
if (s.contains("boot device") || s.contains("WARNING: old BSD partition ID!"))
break;
if (!filter || s.contains(QRegExp(filter))) {
if (func)
func(tree, s);
else {
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
}
found = true;
}
}
delete t;
if (pipe)
pclose(pipe);
else {
dmesg->close();
delete dmesg;
}
return found;
}
void AddIRQLine(QTreeWidget* tree, QString s) {
int irqnum;
QString s2;
char numstr[3];
bool ok;
s2 = s.mid(s.indexOf(QRegExp("[ (]irq "))+5);
irqnum = s2.remove(QRegExp("[^0-9].*")).toInt(&ok);
if (ok)
snprintf(numstr, 3, "%02d", irqnum);
else {
// this should never happen
strcpy(numstr, "??");
}
QStringList list;
list << numstr << s;
new QTreeWidgetItem(tree, list);
}
bool GetInfo_IRQ(QTreeWidget* tree) {
QStringList headers;
headers << i18n("IRQ") << i18n("Device");
tree->setHeaderLabels(headers);
tree->sortItems(0, Qt::AscendingOrder);
tree->setSortingEnabled(false);
(void) GetDmesgInfo(tree, "[ (]irq ", AddIRQLine);
return true;
}
bool GetInfo_DMA(QTreeWidget*) {
return false;
}
bool GetInfo_PCI(QTreeWidget* tree) {
if (!GetDmesgInfo(tree, "at pci", NULL)) {
QStringList list;
list << i18n("No PCI devices found.");
new QTreeWidgetItem(tree, list);
}
return true;
}
bool GetInfo_IO_Ports(QTreeWidget* tree) {
if (!GetDmesgInfo(tree, "port 0x", NULL)) {
QStringList list;
list << i18n("No I/O port devices found.");
new QTreeWidgetItem(tree, list);
}
return true;
}
bool GetInfo_XServer_and_Video(QTreeWidget* tree) {
return GetInfo_XServer_Generic(tree);
}
|