try to keep updateSourcEvents to a minimum by only triggering an immediate update from the SignalRelay object if it is not the first visualization connected to the source

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=852899
This commit is contained in:
Aaron J. Seigo 2008-08-26 20:37:53 +00:00
parent df4423255f
commit 3d6b183011
4 changed files with 49 additions and 36 deletions

View File

@ -125,7 +125,11 @@ void DataContainer::connectVisualization(QObject* visualization, uint pollingInt
visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data)));
} else {
//kDebug() << " connecting to a relay";
SignalRelay *relay = d->signalRelay(this, visualization, pollingInterval, alignment);
// we only want to do an imediate update if this is not the first object to connect to us
// if it is the first visualization, then the source will already have been populated
// engine's sourceRequested method
bool immediateUpdate = connected || d->relayObjects.count() > 1;
SignalRelay *relay = d->signalRelay(this, visualization, pollingInterval, alignment, immediateUpdate);
connect(relay, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)),
visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data)));
}

View File

@ -515,7 +515,7 @@ DataContainer* DataEnginePrivate::source(const QString& sourceName, bool createW
s->setObjectName(sourceName);
sources.insert(sourceName, s);
QObject::connect(s, SIGNAL(updateRequested(DataContainer*)),
q, SLOT(internalUpdateSource(DataContainer*)));
q, SLOT(internalUpdateSource(DataContainer*)));
if (limit > 0) {
trimQueue();
@ -524,14 +524,13 @@ DataContainer* DataEnginePrivate::source(const QString& sourceName, bool createW
return s;
}
void DataEnginePrivate::connectSource(DataContainer* s, QObject* visualization,
uint pollingInterval,
Plasma::IntervalAlignment align, bool immediateCall)
void DataEnginePrivate::connectSource(DataContainer* s, QObject* visualization, uint pollingInterval,
Plasma::IntervalAlignment align, bool immediateCall)
{
//kDebug() << "connect source called with interval" << pollingInterval;
if (pollingInterval > 0) {
// never more frequently than allowed, never more than 20 times per second
uint min = qMax(50, minPollingInterval); // for qMin below
uint min = qMax(50, minPollingInterval); // for qMax below
pollingInterval = qMax(min, pollingInterval);
// align on the 50ms
@ -549,8 +548,8 @@ void DataEnginePrivate::connectSource(DataContainer* s, QObject* visualization,
if (immediateCall) {
QMetaObject::invokeMethod(visualization, "dataUpdated",
Q_ARG(QString, s->objectName()),
Q_ARG(Plasma::DataEngine::Data, s->data()));
Q_ARG(QString, s->objectName()),
Q_ARG(Plasma::DataEngine::Data, s->data()));
}
}

View File

@ -23,14 +23,16 @@
namespace Plasma
{
SignalRelay* DataContainerPrivate::signalRelay(const DataContainer* dc, QObject *visualization, uint pollingInterval, Plasma::IntervalAlignment align)
SignalRelay* DataContainerPrivate::signalRelay(const DataContainer* dc, QObject *visualization,
uint pollingInterval, Plasma::IntervalAlignment align,
bool immediateUpdate)
{
QMap<uint, SignalRelay *>::const_iterator relayIt = relays.find(pollingInterval);
SignalRelay *relay = 0;
//FIXME what if we have two applets with the same interval and different alignment?
if (relayIt == relays.end()) {
relay = new SignalRelay(const_cast<DataContainer*>(dc), this, pollingInterval, align);
relay = new SignalRelay(const_cast<DataContainer*>(dc), this, pollingInterval, align, immediateUpdate);
relays[pollingInterval] = relay;
} else {
relay = relayIt.value();
@ -51,6 +53,33 @@ bool DataContainerPrivate::hasUpdates()
return dirty;
}
SignalRelay::SignalRelay(DataContainer* parent, DataContainerPrivate *data, uint ival,
Plasma::IntervalAlignment align, bool immediateUpdate)
: QObject(parent),
dc(parent),
d(data),
m_interval(ival),
m_align(align),
m_resetTimer(true),
m_queued(false)
{
//kDebug() << "signal relay with time of" << m_timerId << "being set up";
m_timerId = startTimer(immediateUpdate ? 0 : m_interval);
if (m_align != Plasma::NoAlignment) {
checkAlignment();
}
}
int SignalRelay::receiverCount() const
{
return receivers(SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)));
}
bool SignalRelay::isUnused()
{
return receivers(SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data))) < 1;
}
void SignalRelay::checkAlignment()
{
int newTime = 0;
@ -115,7 +144,7 @@ void SignalRelay::timerEvent(QTimerEvent *event)
emit dataUpdated(dc->objectName(), d->data);
} else {
// the source wasn't actually updated; so let's put ourselves in the queue
// so we get an dataUpdated() when the data does arrive
// so we get a dataUpdated() call when the data does arrive
//kDebug() << "queued";
m_queued = true;
}

View File

@ -36,7 +36,8 @@ public:
{}
SignalRelay* signalRelay(const DataContainer* dc, QObject *visualization,
uint pollingInterval, Plasma::IntervalAlignment align);
uint pollingInterval, Plasma::IntervalAlignment align,
bool immediateUpdate);
bool hasUpdates();
@ -53,31 +54,11 @@ class SignalRelay : public QObject
Q_OBJECT
public:
SignalRelay(DataContainer* parent, DataContainerPrivate *data, uint ival, Plasma::IntervalAlignment align)
: QObject(parent),
dc(parent),
d(data),
m_interval(ival),
m_align(align),
m_resetTimer(true),
m_queued(false)
{
//kDebug() << "signal relay with time of" << m_timerId << "being set up";
m_timerId = startTimer(0);
if (m_align != Plasma::NoAlignment) {
checkAlignment();
}
}
SignalRelay(DataContainer* parent, DataContainerPrivate *data,
uint ival, Plasma::IntervalAlignment align, bool immediateUpdate);
int receiverCount() const
{
return receivers(SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)));
}
bool isUnused()
{
return receivers(SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data))) < 1;
}
int receiverCount() const;
bool isUnused();
void checkAlignment();
void checkQueueing();