Engines
systemmonitor.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "systemmonitor.h"
00020
00021 #include <QTimer>
00022 #include <QProcess>
00023
00024 #include <KLocale>
00025
00026 #include <Plasma/DataContainer>
00027
00028 #include "../../ksysguard/gui/ksgrd/SensorManager.h"
00029
00030 SystemMonitorEngine::SystemMonitorEngine(QObject* parent, const QVariantList& args)
00031 : Plasma::DataEngine(parent)
00032 {
00033 Q_UNUSED(args)
00034
00035 KSGRD::SensorMgr = new KSGRD::SensorManager(this);
00036 KSGRD::SensorMgr->engage( "localhost", "", "ksysguardd" );
00037
00038 m_waitingFor= 0;
00039 KSGRD::SensorMgr->sendRequest( "localhost", "monitors", (KSGRD::SensorClient*)this, -1);
00040 }
00041
00042 SystemMonitorEngine::~SystemMonitorEngine()
00043 {
00044 }
00045
00046 QStringList SystemMonitorEngine::sources() const {
00047 return m_sensors;
00048 }
00049 bool SystemMonitorEngine::sourceRequestEvent(const QString &name)
00050 {
00051 return false;
00052 }
00053 bool SystemMonitorEngine::updateSourceEvent(const QString &sensorName)
00054 {
00055 KSGRD::SensorMgr->sendRequest( "localhost", sensorName, (KSGRD::SensorClient*)this, m_sensors.indexOf(sensorName));
00056 return false;
00057 }
00058
00059 void SystemMonitorEngine::updateSensors()
00060 {
00061 DataEngine::SourceDict sources = containerDict();
00062 DataEngine::SourceDict::iterator it = sources.begin();
00063 if(m_waitingFor != 0)
00064 scheduleSourcesUpdated();
00065 m_waitingFor = 0;
00066 while (it != sources.end()) {
00067 m_waitingFor++;
00068 QString sensorName = it.key();
00069 KSGRD::SensorMgr->sendRequest( "localhost", sensorName, (KSGRD::SensorClient*)this, -1);
00070 ++it;
00071 }
00072 }
00073
00074 void SystemMonitorEngine::answerReceived( int id, const QList<QByteArray>&answer ) {
00075 if(id==-1) {
00076 QStringList sensors;
00077 foreach(const QByteArray &sens, answer) {
00078 QStringList newSensorInfo = QString::fromUtf8(sens).split('\t');
00079 QString newSensor = newSensorInfo[0];
00080 sensors.append(newSensor);
00081 setData(newSensor, "value", QVariant());
00082 }
00083 m_sensors = sensors;
00084 return;
00085 }
00086 m_waitingFor--;
00087 QString reply;
00088 if(!answer.isEmpty())
00089 reply = QString::fromUtf8(answer[0]);
00090
00091 DataEngine::SourceDict sources = containerDict();
00092 DataEngine::SourceDict::const_iterator it = sources.constFind(m_sensors.value(id));
00093 if (it != sources.constEnd()) {
00094 it.value()->setData("value", reply);
00095 }
00096
00097 if(m_waitingFor == 0)
00098 scheduleSourcesUpdated();
00099 }
00100 void SystemMonitorEngine::sensorLost( int ) {
00101 m_waitingFor--;
00102 }
00103 #include "systemmonitor.moc"
00104