add_eq/ne API functions return E_INV_RULE if the same values are added 86/142486/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 4 Aug 2017 05:50:04 +0000 (14:50 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 4 Aug 2017 05:56:49 +0000 (14:56 +0900)
Change-Id: Iab9d4a5bd278807e7d85a828260246c25a56b536
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/client/job_scheduler.cpp
src/shared/Attribute.cpp
src/shared/Attribute.h

index 1d4af95290e5a15823310426506f3858f9f5e2bd..a9ddaa30881c1b24b8552534e6510f12be2663ca 100644 (file)
@@ -525,7 +525,8 @@ EXPORT_API int ctx_sched_job_context_attribute_add_eq_int(ctx_sched_job_context_
        IF_FAIL_RETURN(attr, E_PARAM);
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::INTEGER, E_PARAM);
 
-       static_cast<IntegerAttribute*>(attr)->addTarget(value);
+       if (!static_cast<IntegerAttribute*>(attr)->addTarget(value))
+               return E_INV_RULE;
 
        return E_NONE;
 }
@@ -538,7 +539,8 @@ EXPORT_API int ctx_sched_job_context_attribute_add_eq_str(ctx_sched_job_context_
        IF_FAIL_RETURN(attr, E_PARAM);
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::STRING, E_PARAM);
 
-       static_cast<StringAttribute*>(attr)->addTarget(value);
+       if (!static_cast<StringAttribute*>(attr)->addTarget(value))
+               return E_INV_RULE;
 
        return E_NONE;
 }
@@ -551,7 +553,8 @@ EXPORT_API int ctx_sched_job_context_attribute_add_ne_int(ctx_sched_job_context_
        IF_FAIL_RETURN(attr, E_PARAM);
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::INTEGER, E_PARAM);
 
-       static_cast<IntegerAttribute*>(attr)->addNonTarget(value);
+       if (!static_cast<IntegerAttribute*>(attr)->addNonTarget(value))
+               return E_INV_RULE;
 
        return E_NONE;
 }
@@ -564,7 +567,8 @@ EXPORT_API int ctx_sched_job_context_attribute_add_ne_str(ctx_sched_job_context_
        IF_FAIL_RETURN(attr, E_PARAM);
        IF_FAIL_RETURN(attr->getType() == Attribute::Type::STRING, E_PARAM);
 
-       static_cast<StringAttribute*>(attr)->addNonTarget(value);
+       if (!static_cast<StringAttribute*>(attr)->addNonTarget(value))
+               return E_INV_RULE;
 
        return E_NONE;
 }
index 950db58e66945c9d5062a90c8fcff260993d19a7..2cfb7b08ad9534279039f4482593be5875921127 100644 (file)
@@ -114,40 +114,44 @@ const std::set<int>& IntegerAttribute::getTargets()
        return __targets;
 }
 
-IntegerAttribute& IntegerAttribute::setClosedLowerBound(int bound)
+void IntegerAttribute::setClosedLowerBound(int bound)
 {
        __closedLowerBound = std::max(__closedLowerBound, bound);
-       return *this;
 }
 
-IntegerAttribute& IntegerAttribute::setClosedUpperBound(int bound)
+void IntegerAttribute::setClosedUpperBound(int bound)
 {
        __closedUpperBound = std::min(__closedUpperBound, bound);
-       return *this;
 }
 
-IntegerAttribute& IntegerAttribute::setOpenLowerBound(int bound)
+void IntegerAttribute::setOpenLowerBound(int bound)
 {
        __openLowerBound = std::max(__openLowerBound, bound);
-       return *this;
 }
 
-IntegerAttribute& IntegerAttribute::setOpenUpperBound(int bound)
+void IntegerAttribute::setOpenUpperBound(int bound)
 {
        __openUpperBound = std::min(__openUpperBound, bound);
-       return *this;
 }
 
-IntegerAttribute& IntegerAttribute::addTarget(int target)
+bool IntegerAttribute::addTarget(int target)
 {
+       if (__targets.find(target) != __targets.end())
+               return false;
+
        __targets.insert(target);
-       return *this;
+
+       return true;
 }
 
-IntegerAttribute& IntegerAttribute::addNonTarget(int nonTarget)
+bool IntegerAttribute::addNonTarget(int nonTarget)
 {
+       if (__nonTargets.find(nonTarget) != __nonTargets.end())
+               return false;
+
        __nonTargets.insert(nonTarget);
-       return *this;
+
+       return true;
 }
 
 void IntegerAttribute::toJson(Json::Value& jsonNode) const
@@ -218,16 +222,24 @@ Attribute::Type StringAttribute::getType() const
        return Attribute::Type::STRING;
 }
 
-StringAttribute& StringAttribute::addTarget(const std::string& target)
+bool StringAttribute::addTarget(const std::string& target)
 {
+       if (__targets.find(target) != __targets.end())
+               return false;
+
        __targets.insert(target);
-       return *this;
+
+       return true;
 }
 
-StringAttribute& StringAttribute::addNonTarget(const std::string& nonTarget)
+bool StringAttribute::addNonTarget(const std::string& nonTarget)
 {
+       if (__nonTargets.find(nonTarget) != __nonTargets.end())
+               return false;
+
        __nonTargets.insert(nonTarget);
-       return *this;
+
+       return true;
 }
 
 void StringAttribute::toJson(Json::Value& jsonNode) const
index 03406835cad8bcb0453cf0e898e3062aab770507..4f4942ba641c54d2043e29af0f335193d602227c 100644 (file)
@@ -65,12 +65,12 @@ namespace ctx {
 
                const std::set<int>& getTargets();
 
-               IntegerAttribute& setClosedLowerBound(int bound);
-               IntegerAttribute& setClosedUpperBound(int bound);
-               IntegerAttribute& setOpenLowerBound(int bound);
-               IntegerAttribute& setOpenUpperBound(int bound);
-               IntegerAttribute& addTarget(int target);
-               IntegerAttribute& addNonTarget(int nonTarget);
+               void setClosedLowerBound(int bound);
+               void setClosedUpperBound(int bound);
+               void setOpenLowerBound(int bound);
+               void setOpenUpperBound(int bound);
+               bool addTarget(int target);
+               bool addNonTarget(int nonTarget);
 
                void toJson(Json::Value& jsonNode) const;
 
@@ -95,8 +95,8 @@ namespace ctx {
 
                Attribute::Type getType() const;
 
-               StringAttribute& addTarget(const std::string& target);
-               StringAttribute& addNonTarget(const std::string& nonTarget);
+               bool addTarget(const std::string& target);
+               bool addNonTarget(const std::string& nonTarget);
 
                void toJson(Json::Value& jsonNode) const;