From 10c69359c8f89424ab1320613e6651847fe72a3b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 2 Apr 2016 09:36:48 +0200 Subject: Property filter for resources, and proper modification of resources. We used to remove all non-modified properties. --- common/resourcefacade.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'common') diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 7d42f47..35f7f46 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -39,6 +39,7 @@ KAsync::Job ResourceFacade::create(const Sink::ApplicationDomain::SinkReso const QByteArray providedIdentifier = resource.getProperty("identifier").toByteArray(); // It is currently a requirement that the resource starts with the type const QByteArray identifier = providedIdentifier.isEmpty() ? ResourceConfig::newIdentifier(type) : providedIdentifier; + Trace() << "Creating resource " << type << identifier; ResourceConfig::addResource(identifier, type); auto changedProperties = resource.changedProperties(); changedProperties.removeOne("identifier"); @@ -66,12 +67,11 @@ KAsync::Job ResourceFacade::modify(const Sink::ApplicationDomain::SinkReso changedProperties.removeOne("identifier"); changedProperties.removeOne("type"); if (!changedProperties.isEmpty()) { - // We have some configuration values - QMap configurationValues; + auto config = ResourceConfig::getConfiguration(identifier); for (const auto &property : changedProperties) { - configurationValues.insert(property, resource.getProperty(property)); + config.insert(property, resource.getProperty(property)); } - ResourceConfig::configureResource(identifier, configurationValues); + ResourceConfig::configureResource(identifier, config); } }); } @@ -84,6 +84,7 @@ KAsync::Job ResourceFacade::remove(const Sink::ApplicationDomain::SinkReso Warning() << "We need an \"identifier\" property to identify the resource to configure"; return; } + Trace() << "Removing resource " << identifier; ResourceConfig::removeResource(identifier); // TODO shutdown resource, or use the resource process with a --remove option to cleanup (so we can take advantage of the file locking) QDir dir(Sink::storageLocation()); @@ -93,6 +94,16 @@ KAsync::Job ResourceFacade::remove(const Sink::ApplicationDomain::SinkReso }); } +static bool matchesFilter(const QHash &filter, const QMap &properties) +{ + for (const auto &filterProperty : filter.keys()) { + if (filter.value(filterProperty).toByteArray() != properties.value(filterProperty).toByteArray()) { + return false; + } + } + return true; +} + QPair, typename Sink::ResultEmitter::Ptr> ResourceFacade::load(const Sink::Query &query) { auto resultProvider = new Sink::ResultProvider(); @@ -109,11 +120,13 @@ QPair, typename Sink::ResultEmittersetProperty("type", type); - - const auto configurationValues = ResourceConfig::getConfiguration(res); for (auto it = configurationValues.constBegin(); it != configurationValues.constEnd(); it++) { resource->setProperty(it.key(), it.value()); } -- cgit v1.2.3