#include <string>
#include <vector>
#include <set>
+#include <map>
+#include <algorithm>
+
#include <app_control_internal.h>
#include <aul.h>
#include <pkgmgr-info.h>
int type;
std::string uri;
ctx_sched_job_context_h jobContext;
- std::set<std::string> conjunctionKeys;
- std::set<std::string> disjunctionKeys;
+
+ struct Bound {
+ bool conjunction;
+ int gt;
+ int ge;
+ int lt;
+ int le;
+
+ Bound(bool conj) :
+ conjunction(conj)
+ {
+ if (conj) {
+ gt = INT_MIN;
+ ge = INT_MIN;
+ lt = INT_MAX;
+ le = INT_MAX;
+ } else {
+ gt = INT_MAX;
+ ge = INT_MAX;
+ lt = INT_MIN;
+ le = INT_MIN;
+ }
+ }
+ };
+
+ std::map<std::string, Bound> attributes;
_context_trigger_rule_entry_s(int c, int t, const char* u) :
category(c), type(t), uri(u), jobContext(NULL)
static bool __is_member_key(context_trigger_rule_entry_h entry, const char* key)
{
- if (entry->conjunctionKeys.find(key) != entry->conjunctionKeys.end() ||
- entry->disjunctionKeys.find(key) != entry->disjunctionKeys.end()) {
+ if (entry->attributes.find(key) != entry->attributes.end()) {
_D("'%s' found", key);
return true;
}
IF_FAIL_RETURN_TAG(valid, E_INV_RULE, _E, "Invalid parameter");
IF_FAIL_RETURN(!__is_member_key(entry, key), E_INV_RULE);
- if (logical_type == CONTEXT_TRIGGER_LOGICAL_CONJUNCTION)
- entry->conjunctionKeys.insert(key);
- else
- entry->disjunctionKeys.insert(key);
+ entry->attributes.emplace(key, logical_type == CONTEXT_TRIGGER_LOGICAL_CONJUNCTION);
return E_NONE;
}
if (__getOpType(op) == OpType::NE)
return ctx_sched_job_context_attribute_add_ne_int(entry->jobContext, key, value);
- //TODO: Consider logical disjunction
- if (__getOpType(op) == OpType::GT)
- return ctx_sched_job_context_attribute_set_gt_int(entry->jobContext, key, value);
+ _context_trigger_rule_entry_s::Bound& bound = entry->attributes.find(key)->second;
+
+ if (__getOpType(op) == OpType::GT) {
+ if (bound.conjunction) bound.gt = std::max(bound.gt, value);
+ else bound.gt = std::min(bound.gt, value);
+ return ctx_sched_job_context_attribute_set_gt_int(entry->jobContext, key, bound.gt);
+ }
- if (__getOpType(op) == OpType::GE)
- return ctx_sched_job_context_attribute_set_ge_int(entry->jobContext, key, value);
+ if (__getOpType(op) == OpType::GE) {
+ if (bound.conjunction) bound.ge = std::max(bound.ge, value);
+ else bound.ge = std::min(bound.ge, value);
+ return ctx_sched_job_context_attribute_set_ge_int(entry->jobContext, key, bound.ge);
+ }
- if (__getOpType(op) == OpType::LT)
- return ctx_sched_job_context_attribute_set_lt_int(entry->jobContext, key, value);
+ if (__getOpType(op) == OpType::LT) {
+ if (bound.conjunction) bound.lt = std::min(bound.lt, value);
+ else bound.lt = std::max(bound.lt, value);
+ return ctx_sched_job_context_attribute_set_lt_int(entry->jobContext, key, bound.lt);
+ }
- if (__getOpType(op) == OpType::LE)
- return ctx_sched_job_context_attribute_set_le_int(entry->jobContext, key, value);
+ if (__getOpType(op) == OpType::LE) {
+ if (bound.conjunction) bound.le = std::min(bound.le, value);
+ else bound.le = std::max(bound.le, value);
+ return ctx_sched_job_context_attribute_set_le_int(entry->jobContext, key, bound.le);
+ }
_E("Invalid operator");
return E_INV_RULE;