~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kinfocenter/Modules/base/info_fbsd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * info_fbsd.cpp is part of the KDE program kcminfo.  This displays
 
3
 * various information about the system (hopefully a FreeBSD system)
 
4
 * it's running on.
 
5
 *
 
6
 * All of the devinfo bits were blatantly stolen from the devinfo utility
 
7
 * provided with FreeBSD 5.0 (and later).  No gross hacks were harmed
 
8
 * during the creation of info_fbsd.cpp.  Thanks Mike.
 
9
 */
 
10
 
 
11
/*
 
12
 * all following functions should return true, when the Information
 
13
 * was filled into the QTreeWidget. Returning false indicates that
 
14
 * information was not available.
 
15
 */
 
16
 
 
17
#include "config-infocenter.h" // HAVE_DEVINFO_H
 
18
#include <sys/types.h>
 
19
#include <sys/sysctl.h>
 
20
 
 
21
#ifdef HAVE_DEVINFO_H
 
22
extern "C" {
 
23
#include <devinfo.h>
 
24
}
 
25
#endif
 
26
 
 
27
#include <string.h>
 
28
 
 
29
#include <QMap>
 
30
#include <QFileInfo>
 
31
 
 
32
#include <QTextStream>
 
33
 
 
34
void ProcessChildren(QString name);
 
35
 
 
36
#ifdef HAVE_DEVINFO_H
 
37
extern "C" {
 
38
        int print_irq(struct devinfo_rman *rman, void *arg);
 
39
        int print_dma(struct devinfo_rman *rman, void *arg);
 
40
        int print_ioports(struct devinfo_rman *rman, void *arg);
 
41
        int print_resource(struct devinfo_res *res, void *arg);
 
42
}
 
43
#endif
 
44
 
 
45
bool GetInfo_IRQ(QTreeWidget* tree) {
 
46
#ifdef HAVE_DEVINFO_H
 
47
        /* systat lists the interrupts assigned to devices as well as how many were
 
48
         generated.  Parsing its output however is about as fun as a sandpaper
 
49
         enema.  The best idea would probably be to rip out the guts of systat.
 
50
         Too bad it's not very well commented */
 
51
        /* Oh neat, current now has a neat little utility called devinfo */
 
52
        if (devinfo_init())
 
53
        return false;
 
54
        devinfo_foreach_rman(print_irq, tree);
 
55
        return true;
 
56
#else
 
57
        return false;
 
58
#endif
 
59
}
 
60
 
 
61
bool GetInfo_DMA(QTreeWidget* tree) {
 
62
#ifdef HAVE_DEVINFO_H
 
63
        /* Oh neat, current now has a neat little utility called devinfo */
 
64
        if (devinfo_init())
 
65
        return false;
 
66
        devinfo_foreach_rman(print_dma, tree);
 
67
        return true;
 
68
#else
 
69
        return false;
 
70
#endif
 
71
}
 
72
 
 
73
bool GetInfo_IO_Ports(QTreeWidget* tree) {
 
74
#ifdef HAVE_DEVINFO_H
 
75
        /* Oh neat, current now has a neat little utility called devinfo */
 
76
        if (devinfo_init())
 
77
        return false;
 
78
        devinfo_foreach_rman(print_ioports, tree);
 
79
        return true;
 
80
#else
 
81
        return false;
 
82
#endif
 
83
}
 
84
 
 
85
bool GetInfo_SCSI(QTreeWidget* tree) {
 
86
        FILE *pipe;
 
87
        QTextStream *t;
 
88
        QString s;
 
89
 
 
90
        if (!QFileInfo(QLatin1String("/sbin/camcontrol")).exists()) {
 
91
                s = i18n("SCSI subsystem could not be queried: /sbin/camcontrol could not be found");
 
92
                QStringList list;
 
93
                list << s;
 
94
                new QTreeWidgetItem(tree, list);
 
95
        } else if ((pipe = popen("/sbin/camcontrol devlist 2>&1", "r")) == NULL) {
 
96
                s = i18n("SCSI subsystem could not be queried: /sbin/camcontrol could not be executed");
 
97
                QStringList list;
 
98
                list << s;
 
99
                new QTreeWidgetItem(tree, list);
 
100
        } else {
 
101
 
 
102
                /* This prints out a list of all the scsi devies, perhaps eventually we could
 
103
                 parse it as opposed to schlepping it into a listbox */
 
104
 
 
105
                t = new QTextStream(pipe, QIODevice::ReadOnly);
 
106
 
 
107
                while (true) {
 
108
                        s = t->readLine();
 
109
                        if (s.isEmpty() )
 
110
                                break;
 
111
                        QStringList list;
 
112
                        list << s;
 
113
                        new QTreeWidgetItem(tree, list);
 
114
                }
 
115
 
 
116
                delete t;
 
117
                pclose(pipe);
 
118
        }
 
119
 
 
120
        if (!tree->topLevelItemCount())
 
121
                return false;
 
122
 
 
123
        return true;
 
124
}
 
125
 
 
126
bool GetInfo_PCI(QTreeWidget* tree) {
 
127
        FILE *pipe;
 
128
        QString s, cmd;
 
129
        QTreeWidgetItem *olditem= NULL;
 
130
 
 
131
        const QStringList headers(i18nc("@title:column Column name for PCI information", "Information"));
 
132
        tree->setHeaderLabels(headers);
 
133
 
 
134
        if (!QFileInfo(QLatin1String("/usr/sbin/pciconf")).exists()) {
 
135
                QStringList list;
 
136
                list << i18n("Could not find any programs with which to query your system's PCI information");
 
137
                new QTreeWidgetItem(tree, list);
 
138
                return true;
 
139
        } else {
 
140
                cmd = "/usr/sbin/pciconf -l -v 2>&1";
 
141
        }
 
142
 
 
143
        // TODO: GetInfo_ReadfromPipe should be improved so that we could pass the program name and its
 
144
        //       arguments to it and remove most of the code below.
 
145
        if ((pipe = popen(cmd.toLatin1(), "r")) == NULL) {
 
146
                QStringList list;
 
147
                list << i18n("PCI subsystem could not be queried: %1 could not be executed", cmd);
 
148
                olditem = new QTreeWidgetItem(olditem, list);
 
149
        } else {
 
150
                /* This prints out a list of all the pci devies, perhaps eventually we could
 
151
                 parse it as opposed to schlepping it into a listbox */
 
152
                QTextStream outputStream(pipe, QIODevice::ReadOnly);
 
153
 
 
154
                while (!outputStream.atEnd()) {
 
155
                        s = outputStream.readLine();
 
156
                        if (s.isEmpty() )
 
157
                                break;
 
158
                        const QStringList list(s);
 
159
                        new QTreeWidgetItem(tree, list);
 
160
                }
 
161
 
 
162
                pclose(pipe);
 
163
        }
 
164
 
 
165
        if (!tree->topLevelItemCount()) {
 
166
                QString str = i18n("The PCI subsystem could not be queried, this may need root privileges.");
 
167
                olditem = new QTreeWidgetItem(tree, olditem);
 
168
                olditem->setText(0, str);
 
169
                return true;
 
170
        }
 
171
 
 
172
        return true;
 
173
}
 
174
 
 
175
bool GetInfo_XServer_and_Video(QTreeWidget* tree) {
 
176
        return GetInfo_XServer_Generic(tree);
 
177
}
 
178
 
 
179
#ifdef HAVE_DEVINFO_H
 
180
 
 
181
int print_irq(struct devinfo_rman *rman, void *arg) {
 
182
        QTreeWidget* tree = (QTreeWidget *)arg;
 
183
        if (strcmp(rman->dm_desc, "Interrupt request lines")==0) {
 
184
 
 
185
                QStringList list;
 
186
                list << rman->dm_desc;
 
187
                new QTreeWidgetItem(tree, list);
 
188
                devinfo_foreach_rman_resource(rman, print_resource, arg);
 
189
        }
 
190
        return 0;
 
191
}
 
192
 
 
193
int print_dma(struct devinfo_rman *rman, void *arg)
 
194
{
 
195
        QTreeWidget* tree = (QTreeWidget *)arg;
 
196
        if (strcmp(rman->dm_desc, "DMA request lines")==0) {
 
197
                QStringList list;
 
198
                list << rman->dm_desc;
 
199
                new QTreeWidgetItem(tree, list);
 
200
                devinfo_foreach_rman_resource(rman, print_resource, arg);
 
201
        }
 
202
        return(0);
 
203
}
 
204
 
 
205
int print_ioports(struct devinfo_rman *rman, void *arg)
 
206
{
 
207
        QTreeWidget* tree = (QTreeWidget*) arg;
 
208
 
 
209
        if (strcmp(rman->dm_desc, "I/O ports")==0) {
 
210
                QStringList list;
 
211
                list << rman->dm_desc;
 
212
                new QTreeWidgetItem(tree, list);
 
213
 
 
214
                devinfo_foreach_rman_resource(rman, print_resource, arg);
 
215
        }
 
216
        else if (strcmp(rman->dm_desc, "I/O memory addresses")==0) {
 
217
                QStringList list;
 
218
                list << rman->dm_desc;
 
219
                new QTreeWidgetItem(tree, list);
 
220
 
 
221
                devinfo_foreach_rman_resource(rman, print_resource, arg);
 
222
        }
 
223
        return 0;
 
224
}
 
225
 
 
226
int print_resource(struct devinfo_res *res, void *arg)
 
227
{
 
228
        struct devinfo_dev *dev;
 
229
        struct devinfo_rman *rman;
 
230
        int hexmode;
 
231
 
 
232
        QTreeWidget* tree = (QTreeWidget*) arg;
 
233
 
 
234
        QString s, tmp;
 
235
 
 
236
        rman = devinfo_handle_to_rman(res->dr_rman);
 
237
        hexmode = (rman->dm_size > 100) || (rman->dm_size == 0);
 
238
        tmp.sprintf(hexmode ? "0x%lx" : "%lu", res->dr_start);
 
239
        s += tmp;
 
240
        if (res->dr_size > 1) {
 
241
                tmp.sprintf(hexmode ? "-0x%lx" : "-%lu",
 
242
                                res->dr_start + res->dr_size - 1);
 
243
                s += tmp;
 
244
        }
 
245
 
 
246
        dev = devinfo_handle_to_device(res->dr_device);
 
247
        if ((dev != NULL) && (dev->dd_name[0] != 0)) {
 
248
                tmp.sprintf(" (%s)", dev->dd_name);
 
249
        } else {
 
250
                tmp.sprintf(" ----");
 
251
        }
 
252
        s += tmp;
 
253
 
 
254
        QStringList list;
 
255
        list << s;
 
256
        new QTreeWidgetItem(tree, list);
 
257
 
 
258
        return 0;
 
259
}
 
260
 
 
261
#endif