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
|
/*
* sysinfolibsysfs.cpp
*
* This class uses the libsysfs library to collect informations about
* the hardware devices of the client machine.
*
* Created on: Mar 23, 2011
* Author: niklas
*/
#include "sysinfolibsysfs.h"
SysInfoLibsysfs::SysInfoLibsysfs() {
// TODO Auto-generated constructor stub
}
SysInfoLibsysfs::~SysInfoLibsysfs() {
// TODO Auto-generated destructor stub
}
void SysInfoLibsysfs::getInfoAboutNetworkInterface()
{
struct sysfs_class_device *class_device = sysfs_open_class_device("net","eth0");
struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
struct sysfs_device *device = sysfs_get_classdev_device(class_device);
//struct sysfs_driver *driver = sysfs_get_classdev_driver(class_device);
if(device == NULL) {
//qxtLog->debug() << "[libsysfs] device is NULL!";
}
else {
qDebug() << "--- print eth0 device path:";
qDebug() << QString(device->path);
}
sysfs_close_class_device(class_device);
}
void SysInfoLibsysfs::getInfoAboutClassNet()
{
QJson::Serializer serializer;
QVariantList listOfDevices;
struct sysfs_class *sysfsclass = sysfs_open_class("net");
struct dlist *devices = sysfs_get_class_devices(sysfsclass);
struct sysfs_device *dev = NULL;
dlist_for_each_data(devices,dev, struct sysfs_device) {
if(dev == NULL) {
qDebug() << "device is NULL!";
//qxtLog->debug() << "[libsysfs] device is NULL!";
}
else {
qDebug() << "--- print device:";
QVariantMap infos;
infos.insert("name", QString(dev->name));
infos.insert("bus", QString(dev->bus));
infos.insert("bus_id", QString(dev->bus_id));
infos.insert("driver_name", QString(dev->driver_name));
infos.insert("path", QString(dev->path));
infos.insert("subsystem", QString(dev->subsystem));
struct dlist *attrlist = dev->attrlist;
if (attrlist != NULL) {
struct sysfs_attribute *attr = NULL;
QVariantList list;
dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
QVariantMap a;
a.insert("name", QString(attr->name));
a.insert("value", QString(attr->value));
a.insert("len", QString(attr->len));
a.insert("path", QString(attr->path));
a.insert("method", QString(attr->method));
list << a;
}
QByteArray json = serializer.serialize(list);
qDebug() << json;
infos.insert("attrlist", list);
}
listOfDevices << infos;
}
}
sysfs_close_class(sysfsclass);
QByteArray json = serializer.serialize(listOfDevices);
qDebug() << json;
}
|