[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/plasma/engines/sensors
From:       Michael Olbrich <michael.olbrich () gmx ! net>
Date:       2007-09-01 22:26:33
Message-ID: 1188685593.283873.26832.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 707452 by molbrich:

don't use libsensors


 M  +2 -2      CMakeLists.txt  
 M  +68 -53    sensorsengine.cpp  
 M  +5 -5      sensorsengine.h  


--- trunk/playground/base/plasma/engines/sensors/CMakeLists.txt #707451:707452
@@ -1,11 +1,11 @@
-include_directories(${CMAKE_SOURCE_DIR}/workspace/libs ${SENSORS_INCLUDE_DIR})
+include_directories(${CMAKE_SOURCE_DIR}/workspace/libs)
 
 set(sensors_engine_SRCS
     sensorsengine.cpp
 )
 
 kde4_add_plugin(plasma_engine_sensors ${sensors_engine_SRCS})
-target_link_libraries(plasma_engine_sensors ${KDE4_KDECORE_LIBS} ${PLASMA_LIBS} ${SENSORS_LIBRARIES})
+target_link_libraries(plasma_engine_sensors ${KDE4_KDECORE_LIBS} ${PLASMA_LIBS})
 
 install(TARGETS plasma_engine_sensors DESTINATION ${PLUGIN_INSTALL_DIR})
 install(FILES plasma-engine-sensors.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
--- trunk/playground/base/plasma/engines/sensors/sensorsengine.cpp #707451:707452
@@ -19,6 +19,8 @@
 #include "sensorsengine.h"
 
 #include <QtCore/QTimer>
+#include <QtCore/QDir>
+#include <QtCore/QFile>
 
 #include <KDebug>
 #include <plasma/datacontainer.h>
@@ -27,33 +29,37 @@
     : Plasma::DataEngine(parent)
 {
     Q_UNUSED(args)
-    FILE *f = fopen("/etc/sensors.conf", "r");
-    if (f == 0) {
-        m_state = false;
-        return;
-    }
-    m_state = (sensors_init(f) == 0);
-    fclose(f);
 
-    int nr = 0;
-    const sensors_chip_name *chip;
-    while ((chip = sensors_get_detected_chips(&nr)) != 0) {
-        int nr1 = 0;
-        int nr2 = 0;
-        const sensors_feature_data *feature;
-        while ((feature = sensors_get_all_features(*chip, &nr1, &nr2)) != 0) {
-            QString name = QString(feature->name);
-            name = name.left(name.indexOf('_'));
-            name = QString(chip->busname) + "/" + name;
-            SensorData &data = m_sensors[name];
-            if (data.chip == 0) {
-                data.chip = chip;
+    QDir hwmon("/sys/class/hwmon/");
+    QStringList list = hwmon.entryList(QDir::Dirs|QDir::NoDotAndDotDot);
+    QStringList inputfilter;
+    inputfilter << "*_input";
+    foreach (QString devicename, list) {
+        QDir device(hwmon);
+        if (!device.cd(devicename)) {
+            continue;
+        }
+        if (!device.cd("device")) {
+            continue;
+        }
+        device.setPath(device.canonicalPath());
+        QStringList sensors = device.entryList(inputfilter, QDir::Files);
+        foreach (QString sensor, sensors) {
+            QFile file(device.path() + QDir::separator() + sensor);
+            if (!file.open(QIODevice::ReadOnly)) {
+                continue;
             }
-            if (data.chip == chip) {
-                data.features << feature;
+            QByteArray content = file.readAll();
+            if (content.length() == 0) {
+                continue;
             }
+            file.close();
+            sensor = sensor.left(sensor.indexOf("_input"));
+            SensorData data(device.path(), sensor);
+            m_sensors[device.dirName()+ "/" + sensor] = data;
         }
     }
+
     m_timer = new QTimer(this);
     m_timer->setSingleShot(false);
     connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
@@ -61,44 +67,43 @@
 
 SensorsEngine::~SensorsEngine()
 {
-    sensors_cleanup();
     delete m_timer;
 }
 
 QStringList SensorsEngine::sources() const
 {
-    if (!m_state) {
-        return QStringList();
-    }
     return m_sensors.keys();
 }
 
 bool SensorsEngine::sourceRequested(const QString &name)
 {
-    if (!m_state) {
-            return false;
-    }
     SensorMap::ConstIterator iter = m_sensors.find(name);
     if (iter == m_sensors.end()) {
         return false;
     }
-    const SensorData &data = *iter;
-    QList<const sensors_feature_data*>::ConstIterator it;
-    for (it = data.features.begin(); it != data.features.end(); ++it) {
-        QString n((*it)->name);
-        int i = n.indexOf('_');
-        double value;
-        if (i < 0) { // main feature
-            char *label;
-            if (sensors_get_label(*data.chip, (*it)->number, &label) == 0) {
-                setData(name, I18N_NOOP("label"), QString(label));
-                kDebug() << name << label;
-                free(label);
-            }
+    QDir device((*iter).path);
+    QFileInfo inputInfo(device, (*iter).name + "_input");
+    if (!inputInfo.isReadable()) {
+        return false;
+    }
+    QStringList filter;
+    filter << (*iter).name + "_*";
+    QStringList params = device.entryList(filter, QDir::Files);
+    foreach (QString param, params) {
+        QFile file(device.path() + QDir::separator() + param);
+        if (!file.open(QIODevice::ReadOnly)) {
+            continue;
         }
-        sensors_get_feature(*data.chip, (*it)->number, &value);
-        setData(name, QString("value") + n.mid(i), value);
-        kDebug() << name << QString("value") + n.mid(i) << value;
+        QString content = file.readAll();
+        file.close();
+        param = param.mid((*iter).name.length() + 1);
+        bool ok;
+        int value = content.toInt(&ok);
+        if (ok) {
+            setData(name, param, value);
+        } else {
+            setData(name, param, content);
+        }
     }
     if (!m_timer->isActive()) {
         m_timer->start(1000);
@@ -108,15 +113,25 @@
 
 void SensorsEngine::update(Plasma::DataContainer* source)
 {
-    SensorData &data = m_sensors[source->objectName()];
-    QList<const sensors_feature_data*>::ConstIterator it;
-    for (it = data.features.begin(); it != data.features.end(); ++it) {
-        QString n((*it)->name);
-        int i = n.indexOf('_');
-        double value;
-        sensors_get_feature(*data.chip, (*it)->number, &value);
-        source->setData(QString("value") + n.mid(i), value);
+    SensorData &s = m_sensors[source->objectName()];
+    QFile file(s.path + QDir::separator()
+               + s.name + "_input");
+    if (!file.open(QIODevice::ReadOnly)) {
+        return;
     }
+    QString content = file.readAll();
+    file.close();
+    bool ok;
+    int value = content.toInt(&ok);
+    QVariant data;
+    if (ok) {
+        data = value;
+    } else {
+        data = content;
+    }
+    if (source->data()["input"] != data) {
+          source->setData("input", data);
+    }
 }
 
 void SensorsEngine::timeout()
--- trunk/playground/base/plasma/engines/sensors/sensorsengine.h #707451:707452
@@ -22,8 +22,6 @@
 #include <plasma/dataengine.h>
 #include <QtCore/QMap>
 
-#include <sensors/sensors.h>
-
 class Plasma::DataContainer;
 class QTimer;
 
@@ -46,9 +44,11 @@
 private:
     struct SensorData
     {
-        SensorData() : chip(0) {}
-        const sensors_chip_name *chip;
-        QList<const sensors_feature_data*> features;
+        SensorData() {}
+        SensorData(const QString &p, const QString &n)
+            : path(p), name(n) {}
+        QString path;
+        QString name;
     };
     typedef QMap<QString, SensorData> SensorMap;
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic