From ef7c72d2d8ed4b81ac14122d46b942244f4222cb Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Thu, 3 Aug 2017 17:37:58 +0900 Subject: [PATCH] Set the disjunction flag to false, if it has no effect Change-Id: I4594ecb69c620bfa3b45b6e906fdea75dccf38c2 Signed-off-by: Mu-Woong Lee --- src/client/JobManagerProxy.cpp | 18 ++++++++++++++++++ src/shared/JobContext.cpp | 5 +++++ src/shared/JobContext.h | 1 + 3 files changed, 24 insertions(+) diff --git a/src/client/JobManagerProxy.cpp b/src/client/JobManagerProxy.cpp index 88ed6d2..1c19088 100644 --- a/src/client/JobManagerProxy.cpp +++ b/src/client/JobManagerProxy.cpp @@ -37,6 +37,24 @@ int JobManagerProxy::addJob(JobInfo* jobInfo) { IF_FAIL_RETURN(jobInfo, E_PARAM); + // If there is only one requirement, "disjunction == true" is pointless. + if (jobInfo->getRequirements().size() <= 1) + jobInfo->setDisjunction(false); + + // If a requirement has only one attribute, "disjunction == true" is pointless. + for (auto& req : jobInfo->getRequirements()) { + if (req->size() <= 1) + req->setDisjunction(false); + } + + // If a trigger has only one attribute, "disjunction == true" is pointless. + if (jobInfo->getType() == JobInfo::Type::ON_DEMAND) { + for (auto& trg : static_cast(jobInfo)->getTriggers()) { + if (trg->size() <= 1) + trg->setDisjunction(false); + } + } + std::string serialized = jobInfo->serialize(); GVariant* param = g_variant_new("(s)", serialized.c_str()); GVariant* result = NULL; diff --git a/src/shared/JobContext.cpp b/src/shared/JobContext.cpp index 6442b1c..ac135fa 100644 --- a/src/shared/JobContext.cpp +++ b/src/shared/JobContext.cpp @@ -78,6 +78,11 @@ const std::string& JobContext::getUri() const return __uri; } +unsigned int JobContext::size() const +{ + return __attributes.size(); +} + Attribute* JobContext::getAttribute(const std::string& attrName) { for (auto& attr : __attributes) { diff --git a/src/shared/JobContext.h b/src/shared/JobContext.h index 09dfa61..41f99ce 100644 --- a/src/shared/JobContext.h +++ b/src/shared/JobContext.h @@ -41,6 +41,7 @@ namespace ctx { virtual JobContext::Type getType() const = 0; const std::string& getUri() const; + unsigned int size() const; Attribute* getAttribute(const std::string& attrName); bool prepareAttributeInt(const std::string& attrName); -- 2.7.4