[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/plasma/dataengines/systemmonitor
From: Aaron J. Seigo <aseigo () kde ! org>
Date: 2009-08-03 5:07:22
Message-ID: 1249276042.056808.750.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1006182 by aseigo:
* accept sources before we get our list of sensors
* slightly more efficient grabbing of sensor list (though we can only make adding \
300+ sources so fast)
* be careful with indexes in updateSourceEvent
M +42 -17 systemmonitor.cpp
M +4 -5 systemmonitor.h
--- trunk/KDE/kdebase/workspace/plasma/dataengines/systemmonitor/systemmonitor.cpp \
#1006181:1006182 @@ -51,19 +51,31 @@
QStringList SystemMonitorEngine::sources() const
{
- return m_sensors;
+ return m_sensors;
}
bool SystemMonitorEngine::sourceRequestEvent(const QString &name)
{
- Q_UNUSED(name);
+ if (m_sensors.isEmpty()) {
+ // we don't have our first data yet, so let's trust the requester, at least \
fo rnow + // when we get our list of sensors later, then we'll know for sure \
and remove + // this source if they were wrong
+ setData(name, DataEngine::Data());
+ return true;
+ }
+
return false;
}
bool SystemMonitorEngine::updateSourceEvent(const QString &sensorName)
{
- KSGRD::SensorMgr->sendRequest( "localhost", sensorName, \
(KSGRD::SensorClient*)this, m_sensors.indexOf(sensorName));
- KSGRD::SensorMgr->sendRequest( "localhost", QString("%1?").arg(sensorName), \
(KSGRD::SensorClient*)this, -(m_sensors.indexOf(sensorName)+2)); + const int index \
= m_sensors.indexOf(sensorName); +
+ if (index != -1) {
+ KSGRD::SensorMgr->sendRequest("localhost", sensorName, \
(KSGRD::SensorClient*)this, index); + \
KSGRD::SensorMgr->sendRequest("localhost", QString("%1?").arg(sensorName), \
(KSGRD::SensorClient*)this, -(index + 2)); + }
+
return false;
}
@@ -88,9 +100,9 @@
void SystemMonitorEngine::answerReceived(int id, const QList<QByteArray> &answer)
{
if (id < -1) {
- if (answer.isEmpty() || m_sensors.count() <= (-id - 2)) {
- kDebug() << "sensor info answer was empty, (" << answer.isEmpty() << ") \
or sensors too small ("
- << m_sensors.count() << ") for index" << (-id - 2);
+ if (answer.isEmpty() || m_sensors.count() < (-id - 2)) {
+ kDebug() << "sensor info answer was empty, (" << answer.isEmpty() << ") \
or sensors does not exist to us (" + << (m_sensors.count() < (-id \
- 2)) << ") for index" << (-id - 2); return;
}
@@ -121,23 +133,36 @@
}
if (id == -1) {
- QStringList sensors;
+ QSet<QString> sensors;
+ m_sensors.clear();
+ int count = 0;
foreach (const QByteArray &sens, answer) {
const QStringList newSensorInfo = QString::fromUtf8(sens).split('\t');
+ if (newSensorInfo.count() < 2) {
+ continue;
+ }
+
const QString newSensor = newSensorInfo[0];
- sensors.append(newSensor);
- setData(newSensor, "value", QVariant());
- setData(newSensor, "type", newSensorInfo[1]);
+ sensors.insert(newSensor);
+ m_sensors.append(newSensor);
+ DataEngine::Data d;
+ d.insert("value", QVariant());
+ d.insert("type", newSensorInfo[1]);
+ setData(newSensor, d);
+ KSGRD::SensorMgr->sendRequest( "localhost", \
QString("%1?").arg(newSensor), (KSGRD::SensorClient*)this, -(count + 2)); + \
++count; + }
- KSGRD::SensorMgr->sendRequest( "localhost", \
QString("%1?").arg(newSensor), (KSGRD::SensorClient*)this, \
-(sensors.indexOf(newSensor)+2));
- }
- foreach(const QString& sensor, m_sensors) {
- if (!sensors.contains(sensor)) {
- removeSource(sensor);
+ QHash<QString, Plasma::DataContainer*> sourceDict = containerDict();
+ QHashIterator<QString, Plasma::DataContainer*> it(sourceDict);
+ while (it.hasNext()) {
+ it.next();
+ if (!sensors.contains(it.key())) {
+ removeSource(it.key());
}
}
- m_sensors = sensors;
+
return;
}
--- trunk/KDE/kdebase/workspace/plasma/dataengines/systemmonitor/systemmonitor.h \
#1006181:1006182 @@ -35,19 +35,18 @@
Q_OBJECT
public:
- /** Inherited from Plasma::DataEngine. Returns a list of all the sensors that \
ksysguardd knows about. */ + /** Inherited from Plasma::DataEngine. Returns a \
list of all the sensors that ksysguardd knows about. */ virtual QStringList \
sources() const; SystemMonitorEngine( QObject* parent, const QVariantList& args );
~SystemMonitorEngine();
protected:
bool sourceRequestEvent(const QString &name);
- /** inherited from SensorClient */
+ /** inherited from SensorClient */
virtual void answerReceived( int id, const QList<QByteArray>&answer );
virtual void sensorLost( int );
- virtual bool updateSourceEvent(const QString &sensorName);
+ virtual bool updateSourceEvent(const QString &sensorName);
-
protected slots:
void updateSensors();
void updateMonitorsList();
@@ -55,7 +54,7 @@
private:
QStringList m_sensors;
QTimer* m_timer;
- int m_waitingFor;
+ int m_waitingFor;
};
K_EXPORT_PLASMA_DATAENGINE(systemmonitor, SystemMonitorEngine)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic