#include "../DBusServer.h"
#include "ActionManager.h"
-static void __triggerActionAppControl(ctx::Json& action);
-static void __triggerActionNotification(ctx::Json& action, std::string pkgId);
-static void __triggerActionDbusCall(ctx::Json& action);
+using namespace ctx;
-void ctx::trigger::action_manager::triggerAction(ctx::Json& action, std::string pkgId)
+static void __triggerActionAppControl(Json& action);
+static void __triggerActionNotification(Json& action, std::string pkgId);
+static void __triggerActionDbusCall(Json& action);
+
+void trigger::action_manager::triggerAction(Json& action, std::string pkgId)
{
- std::string type;
- action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_TYPE, &type);
+ std::list<std::string> types;
+ action.getKeys(&types);
+ IF_FAIL_VOID_TAG(types.size() == 1, _E, "Invalid action");
+
+ std::string& type = *(types.begin());
- if (type.compare(OLD_TRIG_RULE_KEY_ACTION_TYPE_APP_CONTROL) == 0) {
+ if (type.compare(TRIG_RULE_KEY_APP_LAUNCH) == 0) {
__triggerActionAppControl(action);
- } else if (type.compare(OLD_TRIG_RULE_KEY_ACTION_TYPE_NOTIFICATION) == 0) {
+ } else if (type.compare(TRIG_RULE_KEY_NOTIFICATION) == 0) {
__triggerActionNotification(action, pkgId);
- } else if (type.compare(OLD_TRIG_RULE_KEY_ACTION_TYPE_DBUS_CALL) == 0) {
+ } else if (type.compare(TRIG_RULE_KEY_DBUS_CALL) == 0) {
__triggerActionDbusCall(action);
}
}
-void __triggerActionAppControl(ctx::Json& action)
+void __triggerActionAppControl(Json& action)
{
int error;
std::string appctlStr;
- action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_APP_CONTROL, &appctlStr);
+ action.get(TRIG_RULE_KEY_APP_LAUNCH, TRIG_RULE_KEY_APP_LAUNCH_APP_CONTROL, &appctlStr);
char* str = static_cast<char*>(malloc(appctlStr.length()));
if (str == NULL) {
}
}
-void __triggerActionNotification(ctx::Json& action, std::string pkgId)
+void __triggerActionNotification(Json& action, std::string pkgId)
{
int error;
notification_h notification = notification_create(NOTIFICATION_TYPE_NOTI);
std::string title;
- if (action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_NOTI_TITLE, &title)) {
+ if (action.get(TRIG_RULE_KEY_NOTIFICATION, TRIG_RULE_KEY_NOTI_TITLE, &title)) {
error = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_TITLE, title.c_str(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
if (error != NOTIFICATION_ERROR_NONE) {
_E("Set notification title failed(%d)", error);
}
std::string content;
- if (action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_NOTI_CONTENT, &content)) {
+ if (action.get(TRIG_RULE_KEY_NOTIFICATION, TRIG_RULE_KEY_NOTI_CONTENT, &content)) {
error = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
if (error != NOTIFICATION_ERROR_NONE) {
_E("Set notification contents failed(%d)", error);
}
std::string imagePath;
- if (action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_NOTI_ICON_PATH, &imagePath)) {
+ if (action.get(TRIG_RULE_KEY_NOTIFICATION, TRIG_RULE_KEY_NOTI_ICON_PATH, &imagePath)) {
error = notification_set_image(notification, NOTIFICATION_IMAGE_TYPE_ICON, imagePath.c_str());
if (error != NOTIFICATION_ERROR_NONE) {
_E("Set notification icon image failed(%d)", error);
bundle_raw* encoded = NULL;
bundle* appctlBundle = NULL;
app_control_h app = NULL;
- if (action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_APP_CONTROL, &appctlStr)) {
+ if (action.get(TRIG_RULE_KEY_NOTIFICATION, TRIG_RULE_KEY_NOTI_APP_CONTROL, &appctlStr)) {
str = static_cast<char*>(malloc(appctlStr.length()));
if (str == NULL) {
_E("Memory allocation failed");
}
}
-void __triggerActionDbusCall(ctx::Json& action)
+void __triggerActionDbusCall(Json& action)
{
std::string busName, object, iface, method;
GVariant *param = NULL;
- action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_DBUS_NAME, &busName);
+ action.get(TRIG_RULE_KEY_DBUS_CALL, TRIG_RULE_KEY_DBUS_NAME, &busName);
IF_FAIL_VOID_TAG(!busName.empty(), _E, "No target bus name");
- action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_DBUS_OBJECT, &object);
+ action.get(TRIG_RULE_KEY_DBUS_CALL, TRIG_RULE_KEY_DBUS_OBJECT, &object);
IF_FAIL_VOID_TAG(!object.empty(), _E, "No object path");
- action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_DBUS_INTERFACE, &iface);
+ action.get(TRIG_RULE_KEY_DBUS_CALL, TRIG_RULE_KEY_DBUS_INTERFACE, &iface);
IF_FAIL_VOID_TAG(!iface.empty(), _E, "No interface name");
- action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_DBUS_METHOD, &method);
+ action.get(TRIG_RULE_KEY_DBUS_CALL, TRIG_RULE_KEY_DBUS_METHOD, &method);
IF_FAIL_VOID_TAG(!method.empty(), _E, "No method name");
- action.get(NULL, OLD_TRIG_RULE_KEY_ACTION_DBUS_PARAMETER, ¶m);
+ action.get(TRIG_RULE_KEY_DBUS_CALL, TRIG_RULE_KEY_DBUS_PARAMETER, ¶m);
- ctx::DBusServer::call(busName, object, iface, method, param);
+ DBusServer::call(busName, object, iface, method, param);
}
// Event
Json e;
- d.get(NULL, OLD_TRIG_RULE_KEY_EVENT, &e);
+ d.get(NULL, TRIG_RULE_KEY_EVENT, &e);
__event = new(std::nothrow) ContextItem(e);
// Condition
- int cond_num = d.getSize(NULL, OLD_TRIG_RULE_KEY_CONDITION);
- for (int j = 0; j < cond_num; j++) {
+ int condNum = d.getSize(NULL, TRIG_RULE_KEY_CONDITION);
+ for (int j = 0; j < condNum; j++) {
Json c;
- d.getAt(NULL, OLD_TRIG_RULE_KEY_CONDITION, j, &c);
+ d.getAt(NULL, TRIG_RULE_KEY_CONDITION, j, &c);
__condition.push_back(new(std::nothrow) ContextItem(c));
}
+ // Extra
+ Json extra;
+ d.get(NULL, _TRIG_RULE_KEY_EXTRA, &extra);
+ __extra = extra.str();
+
// Action
Json a;
- d.get(NULL, OLD_TRIG_RULE_KEY_ACTION, &a);
+ d.get(NULL, TRIG_RULE_KEY_ACTION, &a);
__action = a.str();
}
#define _CONTEXT_TRIGGER_RULE_H_
#include <string>
+#include <list>
#include <Json.h>
#include "IContextListener.h"
std::string name;
ctx::Json option;
ContextItem(ctx::Json item) {
- std::string n;
- item.get(NULL, OLD_TRIG_RULE_KEY_EVENT_ITEM, &n);
- name = n;
+ std::list<std::string> keyList;
+ item.getKeys(&keyList);
+ name = *keyList.begin();
ctx::Json o;
- if (item.get(NULL, OLD_TRIG_RULE_KEY_EVENT_OPTION, &o))
+ if (item.get(name.c_str(), TRIG_RULE_KEY_OPTION, &o))
option = o.str();
}
};
ctx::Json __statement;
ContextItem* __event;
std::list<ContextItem*> __condition;
+ ctx::Json __extra;
ctx::Json __action;
ctx::Json __result;
{
}
-bool RuleEvaluator::__compareString(std::string op, std::string ruleVar, std::string factVar)
+template <typename T>
+bool RuleEvaluator::__evaluateSingleData(T factVal, Json& comparison, std::string op)
{
- if (op == OPERATOR_EQ) {
- return (ruleVar == factVar);
- } else if (op == OPERATOR_NEQ) {
- return (ruleVar != factVar);
- } else {
- _E("Operator %s not supported", op.c_str());
- return false;
+ T ruleVal;
+ comparison.get(NULL, TRIG_RULE_KEY_VALUE, &ruleVal);
+
+ if (op == TRIG_RULE_OP_EQUAL_TO) {
+ return (ruleVal == factVal);
+ } else if (op == TRIG_RULE_OP_NOT_EQUAL_TO) {
+ return (ruleVal != factVal);
+ } else if (op == TRIG_RULE_OP_GREATER_THAN) {
+ return (ruleVal > factVal);
+ } else if (op == TRIG_RULE_OP_GREATER_THAN_OR_EQUAL_TO) {
+ return (ruleVal >= factVal);
+ } else if (op == TRIG_RULE_OP_LESS_THAN) {
+ return (ruleVal < factVal);
+ } else if (op == TRIG_RULE_OP_LESS_THAN_OR_EQUAL_TO) {
+ return (ruleVal <= factVal);
}
+
+ return false;
}
-bool RuleEvaluator::__compareInt(std::string op, int ruleVar, int factVar)
+template <typename T>
+bool RuleEvaluator::__evaluateDualData(T factVal, Json& comparison, std::string op)
{
- if (op == OPERATOR_EQ) {
- return (ruleVar == factVar);
- } else if (op == OPERATOR_NEQ) {
- return (ruleVar != factVar);
- } else if (op == OPERATOR_LEQ) {
- return (ruleVar <= factVar);
- } else if (op == OPERATOR_GEQ) {
- return (ruleVar >= factVar);
- } else if (op == OPERATOR_LT) {
- return (ruleVar < factVar);
- } else if (op == OPERATOR_GT) {
- return (ruleVar > factVar);
- } else {
- _E("Operator %s not supported", op.c_str());
- return false;
+ T ruleVal1, ruleVal2;
+ comparison.getAt(NULL, TRIG_RULE_KEY_VALUE, 0, &ruleVal1);
+ comparison.getAt(NULL, TRIG_RULE_KEY_VALUE, 1, &ruleVal2);
+
+ if (op == TRIG_RULE_OP_IN) {
+ return (ruleVal1 <= factVal && factVal <= ruleVal2);
+ } else if (op == TRIG_RULE_OP_NOT_IN) {
+ return (factVal < ruleVal1 || ruleVal2 < factVal);
}
+
+ return false;
}
-bool RuleEvaluator::__replaceDataReferences(Json& ruleDataArr, Json eventFactData)
+template <typename T>
+bool RuleEvaluator::__evaluateMultipleData(T factVal, Json& comparison, std::string op)
+{
+ T ruleVal;
+ for (int i = 0; comparison.getAt(NULL, TRIG_RULE_KEY_VALUE, i, &ruleVal); i++) {
+ if (ruleVal == factVal) {
+ if (op == TRIG_RULE_OP_ONE_OF) {
+ return true;
+ } else if (op == TRIG_RULE_OP_NONE_OF) {
+ return false;
+ }
+ }
+ }
+
+ if (op == TRIG_RULE_OP_NONE_OF) {
+ return true;
+ }
+
+ return false;
+}
+
+template <typename T>
+bool RuleEvaluator::__evaluateData(T factVal, Json& comparison)
+{
+ std::string op;
+ comparison.get(NULL, TRIG_RULE_KEY_OPERATOR, &op);
+
+ if (op == TRIG_RULE_OP_EQUAL_TO || op == TRIG_RULE_OP_NOT_EQUAL_TO ||
+ op == TRIG_RULE_OP_GREATER_THAN || op == TRIG_RULE_OP_GREATER_THAN_OR_EQUAL_TO ||
+ op == TRIG_RULE_OP_LESS_THAN || op == TRIG_RULE_OP_LESS_THAN_OR_EQUAL_TO) {
+ return __evaluateSingleData(factVal, comparison, op);
+ } else if (op == TRIG_RULE_OP_IN || op == TRIG_RULE_OP_NOT_IN) {
+ return __evaluateDualData(factVal, comparison, op);
+ } else if (op == TRIG_RULE_OP_ONE_OF || op == TRIG_RULE_OP_NONE_OF) {
+ return __evaluateMultipleData(factVal, comparison, op);
+ }
+
+ return false;
+}
+
+void RuleEvaluator::__replaceSingleDataReferences(Json& eventFactData, Json& ruleComp, std::string& dataKey)
{
- // Replace referencing data to actual value
std::string refVal;
std::string eventRefStr;
int eventRefInt;
- for (int i = 0; i < ruleDataArr.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR); i++) {
- if (!ruleDataArr.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, i, &refVal)) {
- continue;
- }
- if (refVal.substr(0, 1) != TRIG_RULE_REF_KEY_PREFIX) {
- continue;
- }
+ if (!ruleComp.get(dataKey.c_str(), TRIG_RULE_KEY_VALUE, &refVal)) {
+ return;
+ }
- std::string eventKey = refVal.substr(1, refVal.length() - 1);
- if (eventFactData.get(NULL, eventKey.c_str(), &eventRefStr)) {
- ruleDataArr.setAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, i, eventRefStr);
- } else if (eventFactData.get(NULL, eventKey.c_str(), &eventRefInt)) {
- ruleDataArr.setAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, i, eventRefInt);
- } else {
- _W("Option %s not found in event_data", eventKey.c_str());
- }
+ if (refVal.substr(0, 1) != TRIG_RULE_REF_KEY_PREFIX) {
+ return;
}
- return true;
+ std::string eventKey = refVal.substr(1, refVal.length() - 1);
+ if (eventFactData.get(NULL, eventKey.c_str(), &eventRefStr)) {
+ ruleComp.set(dataKey.c_str(), TRIG_RULE_KEY_VALUE, eventRefStr);
+ } else if (eventFactData.get(NULL, eventKey.c_str(), &eventRefInt)) {
+ ruleComp.set(dataKey.c_str(), TRIG_RULE_KEY_VALUE, eventRefInt);
+ } else {
+ _W("Attribute %s not found in event_data", eventKey.c_str());
+ }
}
-bool RuleEvaluator::__replaceOptionReferences(Json& ruleOption, Json eventFactData)
+void RuleEvaluator::__replaceMultipleDataReferences(Json& eventFactData, Json& ruleComp, std::string& dataKey)
{
- // Replace referencing option to actual value
std::string refVal;
std::string eventRefStr;
int eventRefInt;
- std::list<std::string> keyList;
- ruleOption.getKeys(&keyList);
-
- for (std::list<std::string>::iterator it = keyList.begin(); it != keyList.end(); ++it) {
- std::string optionKey = *it;
-
- if (!ruleOption.get(NULL, (*it).c_str(), &refVal)) {
- continue;
- }
- if (!(refVal.substr(0, 1) == TRIG_RULE_REF_KEY_PREFIX)) {
+ for (int i = 0; ruleComp.getAt(dataKey.c_str(), TRIG_RULE_KEY_VALUE, i, &refVal); i++) {
+ if (refVal.substr(0, 1) != TRIG_RULE_REF_KEY_PREFIX) {
continue;
}
std::string eventKey = refVal.substr(1, refVal.length() - 1);
if (eventFactData.get(NULL, eventKey.c_str(), &eventRefStr)) {
- ruleOption.set(NULL, (*it).c_str(), eventRefStr);
+ ruleComp.setAt(dataKey.c_str(), TRIG_RULE_KEY_VALUE, i, eventRefStr);
} else if (eventFactData.get(NULL, eventKey.c_str(), &eventRefInt)) {
- ruleOption.set(NULL, (*it).c_str(), eventRefInt);
+ ruleComp.setAt(dataKey.c_str(), TRIG_RULE_KEY_VALUE, i, eventRefInt);
} else {
- _W("Option %s not found in event_data", eventKey.c_str());
- return false;
+ _W("Attribute %s not found in event_data", eventKey.c_str());
}
}
-
- return true;
}
-bool RuleEvaluator::__replaceEventReferences(Json& rule, Json& fact)
+void RuleEvaluator::__replaceDataReferences(Json eventFactData, Json& ruleComp)
{
- // Replace referencing data/option to actual value
- Json eventFactData;
- if (!fact.get(FACT_KEY_EVENT, FACT_KEY_DATA, &eventFactData)) {
- _E("No event data found, error");
- return false;
- }
+ // Replace referencing data to actual value
+ std::list<std::string> compKeys;
+ ruleComp.getKeys(&compKeys);
- Json ruleCond;
- for (int i = 0; rule.getAt(NULL, OLD_TRIG_RULE_KEY_CONDITION, i, &ruleCond); i++) {
- Json ruleDataArr;
- for (int j = 0; ruleCond.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, j, &ruleDataArr); j++) {
- __replaceDataReferences(ruleDataArr, eventFactData);
- }
+ for (auto it = compKeys.begin(); it != compKeys.end(); ++it) {
+ std::string dataKey = *it;
- Json ruleOption;
- if (ruleCond.get(NULL, OLD_TRIG_RULE_KEY_CONDITION_OPTION, &ruleOption)) {
- __replaceOptionReferences(ruleOption, eventFactData);
- }
- }
-
- return true;
-}
+ std::string op;
+ ruleComp.get(dataKey.c_str(), TRIG_RULE_KEY_OPERATOR, &op);
-bool RuleEvaluator::__evaluateDataString(Json& ruleDataArr, std::string factValStr)
-{
- std::string opVal;
- ruleDataArr.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY_OPERATOR, &opVal);
- bool conjunction = (OLD_TRIG_RULE_KEY_LOGICAL_CONJUNCTION == opVal);
+ std::string val;
+ if (op == TRIG_RULE_OP_EQUAL_TO || op == TRIG_RULE_OP_NOT_EQUAL_TO ||
+ op == TRIG_RULE_OP_GREATER_THAN || op == TRIG_RULE_OP_GREATER_THAN_OR_EQUAL_TO ||
+ op == TRIG_RULE_OP_LESS_THAN || op == TRIG_RULE_OP_LESS_THAN_OR_EQUAL_TO) {
- std::string op;
- for (int i = 0; ruleDataArr.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_OPERATOR_ARR, i, &op); i++) {
- bool result;
- std::string valStr;
- ruleDataArr.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, i, &valStr);
- result = __compareString(op, factValStr, valStr);
-
- if (conjunction && !result) {
- return false;
- } else if (!conjunction && result) {
- return true;
+ __replaceSingleDataReferences(eventFactData, ruleComp, dataKey);
+ } else {
+ __replaceMultipleDataReferences(eventFactData, ruleComp, dataKey);
}
}
- return conjunction;
}
-bool RuleEvaluator::__evaluateDataInt(Json& ruleDataArr, int factValInt)
+bool RuleEvaluator::__evaluateItem(Json& factItem, Json& ruleItem, std::string logicalOp)
{
- std::string opVal;
- ruleDataArr.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY_OPERATOR, &opVal);
- bool conjunction = (OLD_TRIG_RULE_KEY_LOGICAL_CONJUNCTION == opVal);
-
- std::string op;
- for (int i = 0; ruleDataArr.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_OPERATOR_ARR, i, &op); i++) {
- bool result;
- int valInt;
- if (!ruleDataArr.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, i, &valInt)) {
- result = false;
- }
- result = __compareInt(op, factValInt, valInt);
+ std::string name;
+ factItem.get(NULL, FACT_KEY_NAME, &name);
- if (conjunction && !result) {
- return false;
- } else if (!conjunction && result) {
- return true;
- }
- }
- return conjunction;
-}
+ Json comparison;
+ ruleItem.get(name.c_str(), TRIG_RULE_KEY_COMPARISON, &comparison);
-bool RuleEvaluator::__evaluateItem(Json& ruleItem, Json& factItem)
-{
- Json ruleDataArr;
- if (ruleItem.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_ARR) == 0) {
+ std::list<std::string> compKeys;
+ comparison.getKeys(&compKeys);
+ if (compKeys.size() == 0) {
return true;
}
- std::string opKey;
- ruleItem.get(NULL, OLD_TRIG_RULE_KEY_CONDITION_OPERATOR, &opKey);
- bool conjunction = (OLD_TRIG_RULE_KEY_LOGICAL_CONJUNCTION == opKey);
+ bool isConjunction = (TRIG_RULE_LOGICAL_CONJUNCTION == logicalOp);
+
+ for (auto it = compKeys.begin(); it != compKeys.end(); ++it) {
+ std::string dataKey = *it;
+
+ Json comp;
+ comparison.get(NULL, dataKey.c_str(), &comp);
- for (int i = 0; ruleItem.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, &ruleDataArr); i++) {
- std::string dataKey;
- ruleDataArr.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, &dataKey);
std::string factValStr;
int factValInt;
bool result;
if (factItem.get(FACT_KEY_DATA, dataKey.c_str(), &factValStr)) {
- result = __evaluateDataString(ruleDataArr, factValStr);
+ result = __evaluateData(factValStr, comp);
} else if (factItem.get(FACT_KEY_DATA, dataKey.c_str(), &factValInt)) {
- result = __evaluateDataInt(ruleDataArr, factValInt);
+ result = __evaluateData(factValInt, comp);
} else {
_W("Could not get value corresponding to data key %s", dataKey.c_str());
result = false;
}
- if (conjunction && !result) {
+ if (isConjunction && !result) {
return false;
- } else if (!conjunction && result) {
+ } else if (!isConjunction && result) {
return true;
}
}
- return conjunction;
+ return isConjunction;
}
-bool RuleEvaluator::__evaluateRuleEvent(Json& rule, Json& fact)
+bool RuleEvaluator::__evaluateRuleEvent(Json& fact, Json& rule)
{
Json factItem;
Json ruleItem;
fact.get(NULL, FACT_KEY_EVENT, &factItem);
- rule.get(NULL, OLD_TRIG_RULE_KEY_EVENT, &ruleItem);
+ rule.get(NULL, TRIG_RULE_KEY_EVENT, &ruleItem);
+
+ std::string eventOp;
+ rule.get(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_EVENT_LOGICAL_OP, &eventOp);
- return __evaluateItem(ruleItem, factItem);
+ return __evaluateItem(factItem, ruleItem, eventOp);
}
-Json RuleEvaluator::__getConditionFact(Json& ruleCond, Json& fact)
+Json RuleEvaluator::__getConditionFact(Json& fact, Json& ruleCond)
{
- std::string ruleCondName;
- ruleCond.get(NULL, OLD_TRIG_RULE_KEY_CONDITION_ITEM, &ruleCondName);
+ std::list<std::string> condKey;
+ ruleCond.getKeys(&condKey);
+ std::string ruleCondName = *(condKey.begin());
Json factCond;
for (int i = 0; fact.getAt(NULL, FACT_KEY_CONDITION, i, &factCond); i++) {
// Check if fact item option is mathced with condition
Json ruleCondOption;
Json factCondOption;
- ruleCond.get(NULL, OLD_TRIG_RULE_KEY_CONDITION_OPTION, &ruleCondOption);
+ ruleCond.get(ruleCondName.c_str(), TRIG_RULE_KEY_OPTION, &ruleCondOption);
factCond.get(NULL, FACT_KEY_OPTION, &factCondOption);
if (factCondOption == ruleCondOption) {
return factCond;
return EMPTY_JSON_OBJECT;
}
-bool RuleEvaluator::__evaluateRuleCondition(Json& rule, Json& fact)
+bool RuleEvaluator::__evaluateRuleCondition(Json& fact, Json& rule)
{
- Json ruleCond;
- Json factCond;
+ std::string ruleOp;
+ rule.get(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_RULE_LOGICAL_OP, &ruleOp);
+ bool isConjunction = (TRIG_RULE_LOGICAL_CONJUNCTION == ruleOp);
- std::string opCond;
- rule.get(NULL, OLD_TRIG_RULE_KEY_OPERATOR, &opCond);
- bool conjunction = (OLD_TRIG_RULE_KEY_LOGICAL_CONJUNCTION == opCond);
+ Json ruleCond;
+ for (int i = 0; rule.getAt(NULL, TRIG_RULE_KEY_CONDITION, i, &ruleCond); i++) {
+ Json factCond = __getConditionFact(fact, ruleCond);
- for (int i = 0; rule.getAt(NULL, OLD_TRIG_RULE_KEY_CONDITION, i, &ruleCond); i++) {
- factCond = __getConditionFact(ruleCond, fact);
bool result;
if (factCond == EMPTY_JSON_OBJECT) {
result = false;
} else {
- result = __evaluateItem(ruleCond, factCond);
+ std::string condOp;
+ rule.getAt(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_CONDITION_LOGICAL_OP, i, &condOp);
+ result = __evaluateItem(factCond, ruleCond, condOp);
}
- if (conjunction && !result) {
+ if (isConjunction && !result) {
return false;
- } else if (!conjunction && result) {
+ } else if (!isConjunction && result) {
return true;
}
}
- return conjunction;
+ return isConjunction;
+}
+
+bool RuleEvaluator::__replaceOptionReferences(Json eventFactData, Json& ruleOption)
+{
+ // Replace referencing option to actual value
+ std::string refVal;
+ std::string eventRefStr;
+ int eventRefInt;
+
+ std::list<std::string> keyList;
+ ruleOption.getKeys(&keyList);
+
+ for (std::list<std::string>::iterator it = keyList.begin(); it != keyList.end(); ++it) {
+ std::string optionKey = *it;
+
+ if (!ruleOption.get(NULL, optionKey.c_str(), &refVal)) {
+ continue;
+ }
+ if (!(refVal.substr(0, 1) == TRIG_RULE_REF_KEY_PREFIX)) {
+ continue;
+ }
+
+ std::string eventKey = refVal.substr(1, refVal.length() - 1);
+ if (eventFactData.get(NULL, eventKey.c_str(), &eventRefStr)) {
+ ruleOption.set(NULL, optionKey.c_str(), eventRefStr);
+ } else if (eventFactData.get(NULL, eventKey.c_str(), &eventRefInt)) {
+ ruleOption.set(NULL, optionKey.c_str(), eventRefInt);
+ } else {
+ _W("Option %s not found in event_data", eventKey.c_str());
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool RuleEvaluator::__replaceEventReferences(Json& fact, Json& rule)
+{
+ // Replace referencing data/option to actual value
+ Json eventFactData;
+ if (!fact.get(FACT_KEY_EVENT, FACT_KEY_DATA, &eventFactData)) {
+ _E("No event data found, error");
+ return false;
+ }
+
+ Json ruleCond;
+ for (int i = 0; rule.getAt(NULL, TRIG_RULE_KEY_CONDITION, i, &ruleCond); i++) {
+ std::list<std::string> condKey;
+ ruleCond.getKeys(&condKey);
+ std::string ruleCondName = *(condKey.begin());
+
+ Json ruleComp;
+ for (int j = 0; ruleCond.getAt(ruleCondName.c_str(), TRIG_RULE_KEY_COMPARISON, j, &ruleComp); j++) {
+ __replaceDataReferences(eventFactData, ruleComp);
+ }
+
+ Json ruleOption;
+ if (ruleCond.get(ruleCondName.c_str(), TRIG_RULE_KEY_OPTION, &ruleOption)) {
+ __replaceOptionReferences(eventFactData, ruleOption);
+ }
+ }
+
+ return true;
}
bool RuleEvaluator::evaluateRule(Json rule, Json fact)
RuleEvaluator eval;
bool ret;
Json tempJson;
- if (fact.get(NULL, OLD_TRIG_RULE_KEY_CONDITION, &tempJson)) {
+ if (fact.get(NULL, FACT_KEY_CONDITION, &tempJson)) {
Json ruleCopy(rule.str());
- if (!eval.__replaceEventReferences(ruleCopy, fact)) {
+ if (!eval.__replaceEventReferences(fact, ruleCopy)) {
_W("Replace failed");
}
- ret = eval.__evaluateRuleCondition(ruleCopy, fact);
+ ret = eval.__evaluateRuleCondition(fact, ruleCopy);
_D("Checking condition %s", ret ? "true" : "false");
} else {
- ret = eval.__evaluateRuleEvent(rule, fact);
+ ret = eval.__evaluateRuleEvent(fact, rule);
_D("Checking event %s", ret ? "true" : "false");
}
private:
RuleEvaluator();
- bool __evaluateRuleEvent(ctx::Json& rule, ctx::Json& fact);
- bool __evaluateRuleCondition(ctx::Json& rule, ctx::Json& fact);
- bool __evaluateItem(ctx::Json& ruleItem, ctx::Json& factItem);
- bool __evaluateDataString(ctx::Json& ruleDataArr, std::string factValStr);
- bool __evaluateDataInt(ctx::Json& ruleDataArr, int factValInt);
- bool __compareInt(std::string op, int ruleVar, int factVar);
- bool __compareString(std::string op, std::string ruleVar, std::string factVar);
-
- ctx::Json __getConditionFact(ctx::Json& ruleCond, ctx::Json& fact);
-
- bool __replaceEventReferences(ctx::Json& rule, ctx::Json& fact);
- bool __replaceDataReferences(ctx::Json& ruleDataArr, ctx::Json eventFactData);
- bool __replaceOptionReferences(ctx::Json& ruleOption, ctx::Json eventFactData);
+ bool __evaluateRuleEvent(ctx::Json& fact, ctx::Json& rule);
+ bool __evaluateRuleCondition(ctx::Json& fact, ctx::Json& rule);
+ bool __evaluateItem(ctx::Json& factItem, ctx::Json& ruleItem, std::string logicalOp);
+ template <typename T> bool __evaluateData(T factVal, Json& comparison);
+ template <typename T> bool __evaluateSingleData(T factVal, Json& comparison, std::string op);
+ template <typename T> bool __evaluateDualData(T factVal, Json& comparison, std::string op);
+ template <typename T> bool __evaluateMultipleData(T factVal, Json& comparison, std::string op);
+
+ ctx::Json __getConditionFact(ctx::Json& fact, ctx::Json& ruleCond);
+
+ bool __replaceEventReferences(ctx::Json& fact, ctx::Json& rule);
+ void __replaceDataReferences(ctx::Json eventFactData, ctx::Json& ruleComp);
+ void __replaceSingleDataReferences(ctx::Json& eventFactData, ctx::Json& ruleComp, std::string& dataKey);
+ void __replaceMultipleDataReferences(ctx::Json& eventFactData, ctx::Json& ruleComp, std::string& dataKey);
+ bool __replaceOptionReferences(ctx::Json eventFactData, ctx::Json& ruleOption);
public:
static bool evaluateRule(ctx::Json rule, ctx::Json data);
#include "RuleManager.h"
#include "ContextMonitor.h"
#include "Rule.h"
-#include "Timer.h"
#define RULE_TABLE "ContextTriggerRule"
+#define RULE_IDS_JSON "{ \"" TRIG_KEY_ENABLED_IDS "\" : [ ] , \"" TRIG_KEY_DISABLED_IDS "\" : [ ] }";
using namespace ctx;
using namespace ctx::trigger;
return true;
}
-bool RuleManager::__ruleDataArrElemEquals(Json& lElem, Json& rElem)
-{
- std::string lKey, rKey;
- lElem.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, &lKey);
- rElem.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, &rKey);
- if (lKey.compare(rKey))
- return false;
-
- int lValCnt, rValCnt, lValOpCnt, rValOpCnt;
- lValCnt = lElem.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR);
- rValCnt = rElem.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR);
- lValOpCnt = lElem.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_OPERATOR_ARR);
- rValOpCnt = rElem.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_OPERATOR_ARR);
- if (!((lValCnt == rValCnt) && (lValCnt == lValOpCnt) && (lValCnt && rValOpCnt)))
- return false;
-
- if (lValCnt > 1) {
- std::string lOp, rOp;
- lElem.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY_OPERATOR, &lOp);
- rElem.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY_OPERATOR, &rOp);
- if (lOp.compare(rOp))
- return false;
- }
-
- for (int i = 0; i < lValCnt; i++) {
- bool found = false;
- std::string lVal, lValOp;
- lElem.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, i, &lVal);
- lElem.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_OPERATOR_ARR, i, &lValOp);
-
- for (int j = 0; j < lValCnt; j++) {
- std::string rVal, rValOp;
- rElem.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, j, &rVal);
- rElem.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_OPERATOR_ARR, j, &rValOp);
-
- if (!lVal.compare(rVal) && !lValOp.compare(rValOp)) {
- found = true;
- break;
- }
- }
- if (!found)
- return false;
- }
-
- return true;
-}
-
-bool RuleManager::__ruleItemEquals(Json& lItem, Json& rItem)
-{
- // Compare item name
- std::string lItemName, rItemName;
- lItem.get(NULL, OLD_TRIG_RULE_KEY_EVENT_ITEM, &lItemName);
- rItem.get(NULL, OLD_TRIG_RULE_KEY_EVENT_ITEM, &rItemName);
- if (lItemName.compare(rItemName))
- return false;
-
- // Compare option
- Json lOption, rOption;
- lItem.get(NULL, OLD_TRIG_RULE_KEY_EVENT_OPTION, &lOption);
- rItem.get(NULL, OLD_TRIG_RULE_KEY_EVENT_OPTION, &rOption);
- if (lOption != rOption)
- return false;
-
- int lDataArrCnt, rDataArrCnt;
- lDataArrCnt = lItem.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_ARR);
- rDataArrCnt = rItem.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_ARR);
- if (lDataArrCnt != rDataArrCnt)
- return false;
-
- // Compare item operator;
- if (lDataArrCnt > 1) {
- std::string lOp, rOp;
- lItem.get(NULL, OLD_TRIG_RULE_KEY_EVENT_OPERATOR, &lOp);
- rItem.get(NULL, OLD_TRIG_RULE_KEY_EVENT_OPERATOR, &rOp);
- if (lOp.compare(rOp))
- return false;
- }
-
- for (int i = 0; i < lDataArrCnt; i++) {
- bool found = false;
- Json lElem;
- lItem.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, &lElem);
-
- for (int j = 0; j < lDataArrCnt; j++) {
- Json rElem;
- rItem.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, j, &rElem);
-
- if (__ruleDataArrElemEquals(lElem, rElem)) {
- found = true;
- break;
- }
- }
- if (!found)
- return false;
- }
-
- return true;
-}
-
bool RuleManager::__ruleEquals(Json& lRule, Json& rRule)
{
// Compare event
Json lEvent, rEvent;
- lRule.get(NULL, OLD_TRIG_RULE_KEY_EVENT, &lEvent);
- rRule.get(NULL, OLD_TRIG_RULE_KEY_EVENT, &rEvent);
- if (!__ruleItemEquals(lEvent, rEvent))
+ lRule.get(NULL, TRIG_RULE_KEY_EVENT, &lEvent);
+ rRule.get(NULL, TRIG_RULE_KEY_EVENT, &rEvent);
+
+ std::string lEOp, rEOp;
+ lRule.get(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_EVENT_LOGICAL_OP, &lEOp);
+ rRule.get(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_EVENT_LOGICAL_OP, &rEOp);
+
+ if (lEOp != rEOp || lEvent != rEvent)
return false;
// Compare conditions
int lCondCnt, rCondCnt;
- lCondCnt = lRule.getSize(NULL, OLD_TRIG_RULE_KEY_CONDITION);
- rCondCnt = rRule.getSize(NULL, OLD_TRIG_RULE_KEY_CONDITION);
+ lCondCnt = lRule.getSize(NULL, TRIG_RULE_KEY_CONDITION);
+ rCondCnt = rRule.getSize(NULL, TRIG_RULE_KEY_CONDITION);
if (lCondCnt != rCondCnt)
return false;
- if (lCondCnt > 1) {
- std::string lOp, rOp;
- lRule.get(NULL, OLD_TRIG_RULE_KEY_OPERATOR, &lOp);
- rRule.get(NULL, OLD_TRIG_RULE_KEY_OPERATOR, &rOp);
- if (lOp.compare(rOp))
- return false;
- }
+ std::string lOp, rOp;
+ lRule.get(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_RULE_LOGICAL_OP, &lOp);
+ rRule.get(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_RULE_LOGICAL_OP, &rOp);
+ if (lOp != rOp)
+ return false;
for (int i = 0; i < lCondCnt; i++) {
bool found = false;
Json lCond;
- lRule.getAt(NULL, OLD_TRIG_RULE_KEY_CONDITION, i, &lCond);
+ lRule.getAt(NULL, TRIG_RULE_KEY_CONDITION, i, &lCond);
+
+ std::string lCOp;
+ lRule.getAt(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_CONDITION_LOGICAL_OP, i, &lCOp);
for (int j = 0; j < lCondCnt; j++) {
Json rCond;
- rRule.getAt(NULL, OLD_TRIG_RULE_KEY_CONDITION, j, &rCond);
+ rRule.getAt(NULL, TRIG_RULE_KEY_CONDITION, j, &rCond);
- if (__ruleItemEquals(lCond, rCond)) {
+ std::string rCOp;
+ rRule.getAt(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_CONDITION_LOGICAL_OP, j, &rCOp);
+
+ if (lCOp == rCOp && lCond == rCond) {
found = true;
break;
}
// Compare action
Json lAction, rAction;
- lRule.get(NULL, OLD_TRIG_RULE_KEY_ACTION, &lAction);
- rRule.get(NULL, OLD_TRIG_RULE_KEY_ACTION, &rAction);
+ lRule.get(NULL, TRIG_RULE_KEY_ACTION, &lAction);
+ rRule.get(NULL, TRIG_RULE_KEY_ACTION, &rAction);
if (lAction != rAction)
return false;
bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query rowId, details by package id failed");
- Json rDetails;
- rule.get(NULL, OLD_TRIG_RULE_KEY_DETAILS, &rDetails);
std::string rDesc;
- rule.get(NULL, OLD_TRIG_RULE_KEY_DESCRIPTION, &rDesc);
- std::vector<Json>::iterator vecEnd = record.end();
+ rule.get(NULL, TRIG_RULE_KEY_DESCRIPTION, &rDesc);
+ Json rDetails = rule.str();
+ rDetails.remove(NULL, TRIG_RULE_KEY_DESCRIPTION);
+ std::vector<Json>::iterator vecEnd = record.end();
for (std::vector<Json>::iterator vecPos = record.begin(); vecPos != vecEnd; ++vecPos) {
Json elem = *vecPos;
std::string dStr;
int RuleManager::__verifyRule(Json& rule, const char* creator)
{
- Json details;
- rule.get(NULL, OLD_TRIG_RULE_KEY_DETAILS, &details);
-
- std::string eventName;
- rule.get(OLD_TRIG_RULE_KEY_DETAILS "." OLD_TRIG_RULE_KEY_EVENT, OLD_TRIG_RULE_KEY_EVENT_ITEM, &eventName);
-
ContextMonitor* ctxMonitor = ContextMonitor::getInstance();
IF_FAIL_RETURN_TAG(ctxMonitor, ERR_OUT_OF_MEMORY, _E, "Memory allocation failed");
+ // Event
+ Json event;
+ rule.get(NULL, TRIG_RULE_KEY_EVENT, &event);
+
+ std::list<std::string> eventKey;
+ event.getKeys(&eventKey);
+ IF_FAIL_RETURN_TAG(eventKey.size() == 1, ERR_INVALID_PARAMETER, _E, "Invalid event");
+
+ std::string eventName = *eventKey.begin();
IF_FAIL_RETURN_TAG(ctxMonitor->isSupported(eventName), ERR_NOT_SUPPORTED, _I, "Event(%s) is not supported", eventName.c_str());
- if (creator) {
- if (!ctxMonitor->isAllowed(creator, eventName.c_str())) {
- _W("Permission denied for '%s'", eventName.c_str());
- return ERR_PERMISSION_DENIED;
- }
+ if (!ctxMonitor->isAllowed(creator, eventName.c_str())) {
+ _W("Permission denied for '%s'", eventName.c_str());
+ return ERR_PERMISSION_DENIED;
}
- Json it;
- for (int i = 0; rule.getAt(OLD_TRIG_RULE_KEY_DETAILS, OLD_TRIG_RULE_KEY_CONDITION, i, &it); i++) {
- std::string condName;
- it.get(NULL, OLD_TRIG_RULE_KEY_CONDITION_ITEM, &condName);
+ // Conditions
+ Json cond;
+ for (int i = 0; rule.getAt(NULL, TRIG_RULE_KEY_CONDITION, i, &cond); i++) {
+ std::list<std::string> condKey;
+ cond.getKeys(&condKey);
+ IF_FAIL_RETURN_TAG(condKey.size() == 1, ERR_INVALID_PARAMETER, _E, "Invalid condition");
+ std::string condName = *condKey.begin();
IF_FAIL_RETURN_TAG(ctxMonitor->isSupported(condName), ERR_NOT_SUPPORTED, _I, "Condition(%s) is not supported", condName.c_str());
if (!ctxMonitor->isAllowed(creator, condName.c_str())) {
// Insert rule to rule table, get rule id
Json record;
std::string description;
- Json details;
- rule.get(NULL, OLD_TRIG_RULE_KEY_DESCRIPTION, &description);
- rule.get(NULL, OLD_TRIG_RULE_KEY_DETAILS, &details);
+ rule.get(NULL, TRIG_RULE_KEY_DESCRIPTION, &description);
+
+ Json details = rule.str();
+ details.remove(NULL, TRIG_RULE_KEY_DESCRIPTION);
+ record.set(NULL, "details", details.str());
+
record.set(NULL, "creator", creator);
if (pkgId) {
record.set(NULL, "packageId", pkgId);
}
record.set(NULL, "description", description);
- // Handle timer event
- trigger::timer::handleTimerEvent(details);
-
- record.set(NULL, "details", details.str());
ret = __dbManager.insertSync(RULE_TABLE, record, &rid);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Insert rule to db failed");
record[0].get(NULL, "description", &description);
(*requestResult).set(NULL, TRIG_KEY_RULE_ID, ruleId);
- (*requestResult).set(NULL, OLD_TRIG_RULE_KEY_DESCRIPTION, description);
+ (*requestResult).set(NULL, TRIG_RULE_KEY_DESCRIPTION, description);
return ERR_NONE;
}
int RuleManager::getRuleIds(std::string pkgId, Json* requestResult)
{
- (*requestResult) = "{ \"" TRIG_KEY_ENABLED_IDS "\" : [ ] , \"" TRIG_KEY_DISABLED_IDS "\" : [ ] }";
+ (*requestResult) = RULE_IDS_JSON;
std::string q = "SELECT rowId, status FROM ContextTriggerRule WHERE (packageId = '";
q += pkgId;
bool __reenableRule(void);
int __verifyRule(Json& rule, const char* creator);
int64_t __getDuplicatedRuleId(std::string pkgId, Json& rule);
- bool __ruleDataArrElemEquals(Json& lElem, Json& rElem);
- bool __ruleItemEquals(Json& lItem, Json& rItem);
bool __ruleEquals(Json& lRule, Json& rRule);
int __getUninstalledApp(void);
int __clearRuleOfUninstalledPackage(bool isInit = false);
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <context_trigger.h>
-#include <TriggerRuleTypes.h>
-#include <Types.h>
-#include <ProviderTypes.h>
-#include <TimerManager.h>
-#include "Timer.h"
-
-using namespace ctx;
-using namespace ctx::trigger;
-
-static int __arrangeDayOfWeek(Json dayInfo)
-{
- int result = 0;
-
- std::string key_op;
- if (!dayInfo.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY_OPERATOR, &key_op)) {
- result = TimerManager::dowToInt(DOW_EVERYDAY);
- return result;
- }
-
- if (key_op.compare("and") == 0) {
- result = TimerManager::dowToInt(DOW_EVERYDAY);
- }
-
- std::string tmp_d;
- for (int i = 0; dayInfo.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, i, &tmp_d); i++) {
- int dow = TimerManager::dowToInt(tmp_d);
- std::string op;
- dayInfo.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_OPERATOR_ARR, i, &op);
-
- if (op.compare(CONTEXT_TRIGGER_NOT_EQUAL_TO) == 0) {
- dow = TimerManager::dowToInt(DOW_EVERYDAY) & ~dow;
- }
-
- if (key_op.compare("and") == 0) {
- result &= dow;
- } else {
- result |= dow;
- }
- }
- _D("Requested day of week (%#x)", result);
-
- return result;
-}
-
-void timer::handleTimerEvent(Json& rule)
-{
- Json event;
- rule.get(NULL, OLD_TRIG_RULE_KEY_EVENT, &event);
-
- std::string eventName;
- event.get(NULL, OLD_TRIG_RULE_KEY_EVENT_ITEM, &eventName);
- if (eventName.compare(SUBJ_STATE_ALARM) != 0) {
- return;
- }
-
- Json dayInfo;
- Json it;
- int dow;
- for (int i = 0; event.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, &it); i++) {
- std::string key;
- it.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, &key);
-
- if (key.compare(KEY_DAY_OF_WEEK) == 0) {
- dow = __arrangeDayOfWeek(it);
-
- dayInfo.set(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, KEY_DAY_OF_WEEK);
- dayInfo.set(NULL, OLD_TRIG_RULE_KEY_DATA_KEY_OPERATOR, "or");
-
- for (int j = 0; j < DAYS_PER_WEEK; j++) {
- int d = 0x01 << j;
- if (dow & d) {
- std::string day = TimerManager::dowToStr(d);
- dayInfo.append(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, day);
- dayInfo.append(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_OPERATOR_ARR, CONTEXT_TRIGGER_EQUAL_TO);
-
- // Set option
- event.append(OLD_TRIG_RULE_KEY_EVENT_OPTION, KEY_DAY_OF_WEEK, day);
- }
- }
- event.setAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, dayInfo);
- } else if (key.compare(KEY_TIME_OF_DAY) == 0) {
- int time;
- for (int j = 0; it.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR, j, &time); j++) {
- event.append(OLD_TRIG_RULE_KEY_EVENT_OPTION, KEY_TIME_OF_DAY, time);
- }
- }
- }
-
- rule.set(NULL, OLD_TRIG_RULE_KEY_EVENT, event);
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _CONTEXT_TRIGGER_TIMER_H_
-#define _CONTEXT_TRIGGER_TIMER_H_
-
-#include <Json.h>
-
-namespace ctx {
-namespace trigger {
- namespace timer {
-
- void handleTimerEvent(ctx::Json& rule);
-
- } /* namespace timer */
-
-} /* namespace trigger */
-} /* namespace ctx */
-
-#endif /* End of _CONTEXT_TRIGGER_TIMER_H_ */