* various FIXME notes in dataengine.cpp; Brian, if you could look through them and ask if you have any questions regarding them

* only check for stored data if the DataContainer is thusly marked; removes a huge bottleneck for non-storage-backed engines; currently this probably breaks storage support (since marking the source as storage related probably happens after it is created and so this doesn't get calle?) but there is a FIXME note there that states what the fix should be
* some code clean ups

CCMAIL:batenkaitos@gmail.com

svn path=/trunk/KDE/kdelibs/; revision=1150416
This commit is contained in:
Aaron J. Seigo 2010-07-15 21:58:58 +00:00
parent 5a75a81f53
commit 451049664e
5 changed files with 49 additions and 35 deletions

View File

@ -34,8 +34,6 @@ DataContainer::DataContainer(QObject *parent)
: QObject(parent),
d(new DataContainerPrivate)
{
d->enableStorage = false;
d->isStored = true;
}
DataContainer::~DataContainer()

View File

@ -201,6 +201,8 @@ void DataEngine::setData(const QString &source, const QString &key, const QVaria
}
if (s->isStorageEnabled()) {
//FIXME: broken. one can't pass in parameters to a slot like this.
// this probably belongs in DataContainer in any case
QTimer::singleShot(180000, this, SLOT(storeSource(objectName())));
}
@ -223,6 +225,8 @@ void DataEngine::setData(const QString &source, const Data &data)
}
if (s->isStorageEnabled()) {
//FIXME: broken. one can't pass in parameters to a slot like this.
// this probably belongs in DataContainer in any case
QTimer::singleShot(180000, this, SLOT(storeSource(objectName())));
}
@ -329,7 +333,7 @@ void DataEngine::removeSource(const QString &source)
}
}
d->storeSource(source);
d->storeSource(s);
s->disconnect(this);
s->deleteLater();
d->sources.erase(it);
@ -763,44 +767,56 @@ void DataEnginePrivate::storeAllSources()
{
//kDebug() << "cache all sources";
foreach (QString sourceName, q->sources()) {
storeSource(sourceName);
DataContainer *s = q->d->source(sourceName, false);
storeSource(s);
}
}
void DataEnginePrivate::storeSource(const QString &sourceName) const
void DataEnginePrivate::storeSource(DataContainer *s) const
{
DataContainer *s = q->d->source(sourceName, false);
if (s) {
if (s->isStorageEnabled() && s->needsToBeStored()) {
s->setNeedsToBeStored(false);
Storage* store = new Storage(q->name(), 0);
KConfigGroup op = store->operationDescription("save");
op.writeEntry("source", sourceName);
DataEngine::Data dataToStore = s->data();
DataEngine::Data::const_iterator it = dataToStore.constBegin();
while (it != dataToStore.constEnd() && dataToStore.constEnd() == s->data().constEnd()) {
QVariant v = it.value();
if ((it.value().type() == QVariant::String) || (it.value().type() == QVariant::Int)) {
op.writeEntry("key", it.key());
op.writeEntry("data", it.value());
} else {
QByteArray b;
QDataStream ds(&b, QIODevice::WriteOnly);
ds << it.value();
op.writeEntry("key", "base64-" + it.key());
op.writeEntry("data", b.toBase64());
}
++it;
ServiceJob* job = store->startOperationCall(op);
job->start();
}
store->deleteLater();
}
return;
if (!s || !s->needsToBeStored()) {
return;
}
// FIXME: this should probably be moved into DataContainer, e.g. DataContainer::store()
s->setNeedsToBeStored(false);
Storage* store = new Storage(q->name(), 0);
KConfigGroup op = store->operationDescription("save");
op.writeEntry("source", s->objectName());
DataEngine::Data dataToStore = s->data();
DataEngine::Data::const_iterator it = dataToStore.constBegin();
//FIXME: this shouldn't be one job per key/value pair, but one job for the entire container
while (it != dataToStore.constEnd() && dataToStore.constEnd() == s->data().constEnd()) {
QVariant v = it.value();
if ((it.value().type() == QVariant::String) || (it.value().type() == QVariant::Int)) {
op.writeEntry("key", it.key());
op.writeEntry("data", it.value());
} else {
QByteArray b;
QDataStream ds(&b, QIODevice::WriteOnly);
ds << it.value();
op.writeEntry("key", "base64-" + it.key());
op.writeEntry("data", b.toBase64());
}
++it;
ServiceJob* job = store->startOperationCall(op);
job->start();
}
//FIXME: this may result in the service being deleted before the jobs ... resulting in the
//jobs potentially being terminated prematurely
store->deleteLater();
}
void DataEnginePrivate::retrieveStoredData(DataContainer *s)
{
if (!s || !s->isStorageEnabled()) {
return;
}
//FIXME: this should probably move into DataContainer, and be triggered in setStorageEnabled
// when it is set to true
Storage* store = new Storage(q->name(), 0);
KConfigGroup ret = store->operationDescription("retrieve");
ret.writeEntry("source", s->objectName());

View File

@ -501,7 +501,7 @@ NoAlignment) const;
Q_PRIVATE_SLOT(d, void internalUpdateSource(DataContainer *source))
Q_PRIVATE_SLOT(d, void sourceDestroyed(QObject *object))
Q_PRIVATE_SLOT(d, void storeAllSources())
Q_PRIVATE_SLOT(d, void storeSource(const QString &sourceName) const)
Q_PRIVATE_SLOT(d, void storeSource(DataContainer *source) const)
DataEnginePrivate *const d;
};

View File

@ -35,7 +35,7 @@ public:
: dirty(false),
cached(false),
enableStorage(false),
isStored(false)
isStored(true)
{}
SignalRelay *signalRelay(const DataContainer *dc, QObject *visualization,

View File

@ -88,7 +88,7 @@ class DataEnginePrivate
* stores the source
* @param sourceName the name of the source to store
*/
void storeSource(const QString &sourceName) const;
void storeSource(DataContainer *source) const;
/**
* stores all sources marked for storage