dataengine api review: %s/UpdateInterval/PollingInterval/g
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800376
This commit is contained in:
parent
29e32dd145
commit
e850a93871
@ -113,9 +113,9 @@ void DataContainer::checkUsage()
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::connectVisualization(QObject* visualization, uint updateInterval, Plasma::IntervalAlignment alignment)
|
||||
void DataContainer::connectVisualization(QObject* visualization, uint pollingInterval, Plasma::IntervalAlignment alignment)
|
||||
{
|
||||
//kDebug() << "connecting visualization" << visualization << "at interval of" << updateInterval;
|
||||
//kDebug() << "connecting visualization" << visualization << "at interval of" << pollingInterval;
|
||||
QMap<QObject *, SignalRelay *>::iterator objIt = d->relayObjects.find(visualization);
|
||||
bool connected = objIt != d->relayObjects.end();
|
||||
if (connected) {
|
||||
@ -135,7 +135,7 @@ void DataContainer::connectVisualization(QObject* visualization, uint updateInte
|
||||
visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data)));
|
||||
//relay->isUnused();
|
||||
}
|
||||
} else if (updateInterval < 1) {
|
||||
} else if (pollingInterval < 1) {
|
||||
// the visualization was connected already, but not to a relay
|
||||
// and it still doesn't want to connect to a relay, so we have
|
||||
// nothing to do!
|
||||
@ -151,14 +151,14 @@ void DataContainer::connectVisualization(QObject* visualization, uint updateInte
|
||||
}
|
||||
|
||||
|
||||
if (updateInterval < 1) {
|
||||
if (pollingInterval < 1) {
|
||||
// kDebug() << " connecting directly";
|
||||
d->relayObjects[visualization] = 0;
|
||||
connect(this, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)),
|
||||
visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data)));
|
||||
} else {
|
||||
// kDebug() << " connecting to a relay";
|
||||
SignalRelay *relay = d->signalRelay(this, visualization, updateInterval, alignment);
|
||||
SignalRelay *relay = d->signalRelay(this, visualization, pollingInterval, alignment);
|
||||
connect(relay, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)),
|
||||
visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data)));
|
||||
}
|
||||
|
@ -114,9 +114,9 @@ class PLASMA_EXPORT DataContainer : public QObject
|
||||
* for the same visualization without side effects
|
||||
*
|
||||
* @param visualization the object to connect to this DataContainer
|
||||
* @param updateInterval the time in milliseconds between updates
|
||||
* @param pollingInterval the time in milliseconds between updates
|
||||
**/
|
||||
void connectVisualization(QObject* visualization, uint updateInterval, Plasma::IntervalAlignment alignment);
|
||||
void connectVisualization(QObject* visualization, uint pollingInterval, Plasma::IntervalAlignment alignment);
|
||||
|
||||
/**
|
||||
* Disconnects an object from this DataContainer.
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
{}
|
||||
|
||||
SignalRelay* signalRelay(const DataContainer* dc, QObject *visualization,
|
||||
uint updateInterval, Plasma::IntervalAlignment align);
|
||||
uint pollingInterval, Plasma::IntervalAlignment align);
|
||||
|
||||
DataEngine::Data data;
|
||||
QMap<QObject *, SignalRelay *> relayObjects;
|
||||
@ -111,7 +111,7 @@ public:
|
||||
// constant queueing due to more-or-less constant time
|
||||
// async update time? this might make sense for
|
||||
// staggered accesses to the same source by multiple
|
||||
// visualizations causing a minimumUpdateInterval violation.
|
||||
// visualizations causing a minimumPollingInterval violation.
|
||||
// it may not make sense for purely async-and-takes-a-while
|
||||
// type operations (e.g. network fetching).
|
||||
// we need more real world data before making such a change
|
||||
@ -158,15 +158,15 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
SignalRelay* DataContainer::Private::signalRelay(const DataContainer* dc, QObject *visualization, uint updateInterval, Plasma::IntervalAlignment align)
|
||||
SignalRelay* DataContainer::Private::signalRelay(const DataContainer* dc, QObject *visualization, uint pollingInterval, Plasma::IntervalAlignment align)
|
||||
{
|
||||
QMap<uint, SignalRelay *>::const_iterator relayIt = relays.find(updateInterval);
|
||||
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, updateInterval, align);
|
||||
relays[updateInterval] = relay;
|
||||
relay = new SignalRelay(const_cast<DataContainer*>(dc), this, pollingInterval, align);
|
||||
relays[pollingInterval] = relay;
|
||||
} else {
|
||||
relay = relayIt.value();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class DataEngine::Private
|
||||
: engine(e),
|
||||
ref(-1), // first ref
|
||||
updateTimerId(0),
|
||||
minUpdateInterval(-1),
|
||||
minPollingInterval(-1),
|
||||
limit(0),
|
||||
valid(true),
|
||||
script(0),
|
||||
@ -125,20 +125,20 @@ class DataEngine::Private
|
||||
return s;
|
||||
}
|
||||
|
||||
void connectSource(DataContainer* s, QObject* visualization, uint updateInterval,
|
||||
void connectSource(DataContainer* s, QObject* visualization, uint pollingInterval,
|
||||
Plasma::IntervalAlignment align, bool immediateCall = true)
|
||||
{
|
||||
//kDebug() << "connect source called with interval" << updateInterval;
|
||||
if (updateInterval > 0) {
|
||||
//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, minUpdateInterval); // for qMin below
|
||||
updateInterval = qMax(min, updateInterval);
|
||||
uint min = qMax(50, minPollingInterval); // for qMin below
|
||||
pollingInterval = qMax(min, pollingInterval);
|
||||
|
||||
// align on the 50ms
|
||||
updateInterval = updateInterval - (updateInterval % 50);
|
||||
pollingInterval = pollingInterval - (pollingInterval % 50);
|
||||
}
|
||||
|
||||
s->connectVisualization(visualization, updateInterval, align);
|
||||
s->connectVisualization(visualization, pollingInterval, align);
|
||||
|
||||
if (immediateCall) {
|
||||
QMetaObject::invokeMethod(visualization, "dataUpdated",
|
||||
@ -197,7 +197,7 @@ class DataEngine::Private
|
||||
DataEngine* engine;
|
||||
int ref;
|
||||
int updateTimerId;
|
||||
int minUpdateInterval;
|
||||
int minPollingInterval;
|
||||
QTime updateTimestamp;
|
||||
DataEngine::SourceDict sources;
|
||||
QQueue<DataContainer*> sourceQueue;
|
||||
@ -237,7 +237,7 @@ QStringList DataEngine::sources() const
|
||||
}
|
||||
|
||||
void DataEngine::connectSource(const QString& source, QObject* visualization,
|
||||
uint updateInterval, Plasma::IntervalAlignment intervalAlignment) const
|
||||
uint pollingInterval, Plasma::IntervalAlignment intervalAlignment) const
|
||||
{
|
||||
//kDebug() << "connectSource" << source;
|
||||
bool newSource;
|
||||
@ -247,16 +247,16 @@ void DataEngine::connectSource(const QString& source, QObject* visualization,
|
||||
// we suppress the immediate invocation of dataUpdated here if the source was prexisting and they
|
||||
// don't request delayed updates (we want to do an immediate update in that case so they
|
||||
// don't have to wait for the first time out)
|
||||
d->connectSource(s, visualization, updateInterval, intervalAlignment, !newSource || updateInterval > 0);
|
||||
d->connectSource(s, visualization, pollingInterval, intervalAlignment, !newSource || pollingInterval > 0);
|
||||
//kDebug() << " ==> source connected";
|
||||
}
|
||||
}
|
||||
|
||||
void DataEngine::connectAllSources(QObject* visualization, uint updateInterval,
|
||||
void DataEngine::connectAllSources(QObject* visualization, uint pollingInterval,
|
||||
Plasma::IntervalAlignment intervalAlignment) const
|
||||
{
|
||||
foreach (DataContainer* s, d->sources) {
|
||||
d->connectSource(s, visualization, updateInterval, intervalAlignment);
|
||||
d->connectSource(s, visualization, pollingInterval, intervalAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,10 +289,10 @@ DataEngine::Data DataEngine::query(const QString& source) const
|
||||
|
||||
void DataEngine::internalUpdateSource(DataContainer* source)
|
||||
{
|
||||
if (d->minUpdateInterval > 0 &&
|
||||
source->timeSinceLastUpdate() < d->minUpdateInterval) {
|
||||
if (d->minPollingInterval > 0 &&
|
||||
source->timeSinceLastUpdate() < d->minPollingInterval) {
|
||||
// skip updating this source; it's been too soon
|
||||
//kDebug() << "internal update source is delaying" << source->timeSinceLastUpdate() << d->minUpdateInterval;
|
||||
//kDebug() << "internal update source is delaying" << source->timeSinceLastUpdate() << d->minPollingInterval;
|
||||
//but fake an update so that the signalrelay that triggered this gets the data from the
|
||||
//recent update. this way we don't have to worry about queuing - the relay will send a
|
||||
//signal immediately and everyone else is undisturbed.
|
||||
@ -426,17 +426,17 @@ void DataEngine::setSourceLimit(uint limit)
|
||||
}
|
||||
}
|
||||
|
||||
void DataEngine::setMinimumUpdateInterval(int minimumMs)
|
||||
void DataEngine::setMinimumPollingInterval(int minimumMs)
|
||||
{
|
||||
d->minUpdateInterval = minimumMs;
|
||||
d->minPollingInterval = minimumMs;
|
||||
}
|
||||
|
||||
int DataEngine::minimumUpdateInterval() const
|
||||
int DataEngine::minimumPollingInterval() const
|
||||
{
|
||||
return d->minUpdateInterval;
|
||||
return d->minPollingInterval;
|
||||
}
|
||||
|
||||
void DataEngine::setUpdateInterval(uint frequency)
|
||||
void DataEngine::setPollingInterval(uint frequency)
|
||||
{
|
||||
killTimer(d->updateTimerId);
|
||||
d->updateTimerId = 0;
|
||||
@ -451,9 +451,9 @@ NOTE: This is not implemented to prevent having to store the value internally.
|
||||
When there is a good use case for needing access to this value, we can
|
||||
add another member to the Private class and add this method.
|
||||
|
||||
void DataEngine::updateInterval()
|
||||
void DataEngine::pollingInterval()
|
||||
{
|
||||
return d->updateInterval;
|
||||
return d->pollingInterval;
|
||||
}
|
||||
*/
|
||||
|
||||
@ -537,12 +537,12 @@ void DataEngine::timerEvent(QTimerEvent *event)
|
||||
event->accept();
|
||||
|
||||
// if the freq update is less than 0, don't bother
|
||||
if (d->minUpdateInterval < 0) {
|
||||
if (d->minPollingInterval < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// minUpdateInterval
|
||||
if (d->updateTimestamp.elapsed() < d->minUpdateInterval) {
|
||||
// minPollingInterval
|
||||
if (d->updateTimestamp.elapsed() < d->minPollingInterval) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
26
dataengine.h
26
dataengine.h
@ -109,7 +109,7 @@ class PLASMA_EXPORT DataEngine : public QObject
|
||||
*
|
||||
* @param source the name of the data source
|
||||
* @param visualization the object to connect the data source to
|
||||
* @param updateInterval the frequency, in milliseconds, with which to check for updates;
|
||||
* @param pollingInterval the frequency, in milliseconds, with which to check for updates;
|
||||
* a value of 0 (the default) means to update only
|
||||
* when there is new data spontaneously generated
|
||||
* (e.g. by the engine); any other value results in
|
||||
@ -120,7 +120,7 @@ class PLASMA_EXPORT DataEngine : public QObject
|
||||
* @param intervalAlignment the number of ms to align the interval to
|
||||
**/
|
||||
Q_INVOKABLE void connectSource(const QString& source, QObject* visualization,
|
||||
uint updateInterval = 0,
|
||||
uint pollingInterval = 0,
|
||||
Plasma::IntervalAlignment intervalAlignment = NoAlignment) const;
|
||||
|
||||
/**
|
||||
@ -133,14 +133,14 @@ class PLASMA_EXPORT DataEngine : public QObject
|
||||
* one data source to provide sets of related data.
|
||||
*
|
||||
* This method may be called multiple times for the same visualization
|
||||
* without side-effects. This can be useful to change the updateInterval.
|
||||
* without side-effects. This can be useful to change the pollingInterval.
|
||||
*
|
||||
* Note that this method does not automatically connect sources that
|
||||
* may appear later on. Connecting and responding to the sourceAdded sigal
|
||||
* is still required to achieve that.
|
||||
*
|
||||
* @param visualization the object to connect the data source to
|
||||
* @param updateInterval the frequency, in milliseconds, with which to check for updates;
|
||||
* @param pollingInterval the frequency, in milliseconds, with which to check for updates;
|
||||
* a value of 0 (the default) means to update only
|
||||
* when there is new data spontaneously generated
|
||||
* (e.g. by the engine); any other value results in
|
||||
@ -150,7 +150,7 @@ class PLASMA_EXPORT DataEngine : public QObject
|
||||
* If the data has not changed, no update will be sent.
|
||||
* @param intervalAlignment the number of ms to align the interval to
|
||||
**/
|
||||
Q_INVOKABLE void connectAllSources(QObject* visualization, uint updateInterval = 0,
|
||||
Q_INVOKABLE void connectAllSources(QObject* visualization, uint pollingInterval = 0,
|
||||
Plasma::IntervalAlignment intervalAlignment = NoAlignment) const;
|
||||
|
||||
/**
|
||||
@ -253,8 +253,8 @@ class PLASMA_EXPORT DataEngine : public QObject
|
||||
/**
|
||||
* Called by internal updating mechanisms to trigger the engine
|
||||
* to refresh the data contained in a given source. Reimplement this
|
||||
* method when using facilities such as setUpdateInterval.
|
||||
* @see setUpdateInterval
|
||||
* method when using facilities such as setPollingInterval.
|
||||
* @see setPollingInterval
|
||||
*
|
||||
* @param source the name of the source that should be updated
|
||||
* @return true if the data was changed, or false if there was no
|
||||
@ -332,12 +332,12 @@ class PLASMA_EXPORT DataEngine : public QObject
|
||||
* a value of 0 means update immediately on every update request,
|
||||
* a value >0 will result in a minimum time lapse being enforced.
|
||||
**/
|
||||
void setMinimumUpdateInterval(int minimumMs);
|
||||
void setMinimumPollingInterval(int minimumMs);
|
||||
|
||||
/**
|
||||
* @return the minimum time between updates. @see setMinimumupdateInterval
|
||||
* @return the minimum time between updates. @see setMinimumPollingInterval
|
||||
**/
|
||||
int minimumUpdateInterval() const;
|
||||
int minimumPollingInterval() const;
|
||||
|
||||
/**
|
||||
* Sets up an internal update tick for all data sources. On every update,
|
||||
@ -347,15 +347,15 @@ class PLASMA_EXPORT DataEngine : public QObject
|
||||
* @param frequency the time, in milliseconds, between updates. A value of 0
|
||||
* will stop internally triggered updates.
|
||||
**/
|
||||
void setUpdateInterval(uint frequency);
|
||||
void setPollingInterval(uint frequency);
|
||||
|
||||
/**
|
||||
* Returns the current update frequency.
|
||||
* @see setUpdateInterval
|
||||
* @see setPollingInterval
|
||||
NOTE: This is not implemented to prevent having to store the value internally.
|
||||
When there is a good use case for needing access to this value, we can
|
||||
add another member to the Private class and add this method.
|
||||
uint updateInterval();
|
||||
uint pollingInterval();
|
||||
**/
|
||||
|
||||
/**
|
||||
|
@ -99,25 +99,25 @@ void DataEngineScript::setSourceLimit(uint limit)
|
||||
}
|
||||
}
|
||||
|
||||
void DataEngineScript::setMinimumUpdateInterval(int minimumMs)
|
||||
void DataEngineScript::setMinimumPollingInterval(int minimumMs)
|
||||
{
|
||||
if (d->dataEngine) {
|
||||
d->dataEngine->setMinimumUpdateInterval(minimumMs);
|
||||
d->dataEngine->setMinimumPollingInterval(minimumMs);
|
||||
}
|
||||
}
|
||||
|
||||
int DataEngineScript::minimumUpdateInterval() const
|
||||
int DataEngineScript::minimumPollingInterval() const
|
||||
{
|
||||
if (d->dataEngine) {
|
||||
return d->dataEngine->minimumUpdateInterval();
|
||||
return d->dataEngine->minimumPollingInterval();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DataEngineScript::setUpdateInterval(uint frequency)
|
||||
void DataEngineScript::setPollingInterval(uint frequency)
|
||||
{
|
||||
if (d->dataEngine) {
|
||||
d->dataEngine->setUpdateInterval(frequency);
|
||||
d->dataEngine->setPollingInterval(frequency);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,9 +81,9 @@ protected:
|
||||
void clearData(const QString& source);
|
||||
void removeData(const QString& source, const QString& key);
|
||||
void setSourceLimit(uint limit);
|
||||
void setMinimumUpdateInterval(int minimumMs);
|
||||
int minimumUpdateInterval() const;
|
||||
void setUpdateInterval(uint frequency);
|
||||
void setMinimumPollingInterval(int minimumMs);
|
||||
int minimumPollingInterval() const;
|
||||
void setPollingInterval(uint frequency);
|
||||
void clearSources();
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user