From d3335ce43ba42070fc6b324ce1b3601f49a6e120 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Mon, 11 Jan 2016 18:32:59 +0900 Subject: [PATCH] Added context_fact_types.h Change-Id: Ia0483c06d93d08007d8f02b93202faf298a21b33 Signed-off-by: Somin Kim --- src/context_trigger/context_fact_types.h | 26 ++++++++++++++++++++++++++ src/context_trigger/rule.cpp | 27 +++++++++++---------------- src/context_trigger/rule_evaluator.cpp | 2 ++ 3 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 src/context_trigger/context_fact_types.h diff --git a/src/context_trigger/context_fact_types.h b/src/context_trigger/context_fact_types.h new file mode 100644 index 0000000..7f5ce8a --- /dev/null +++ b/src/context_trigger/context_fact_types.h @@ -0,0 +1,26 @@ +/* + * 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_FACT_TYPES_H__ +#define __CONTEXT_FACT_TYPES_H__ + +#define CONTEXT_FACT_EVENT "EVENT" +#define CONTEXT_FACT_CONDITION "CONDITION" +#define CONTEXT_FACT_NAME "NAME" +#define CONTEXT_FACT_OPTION "OPTION" +#define CONTEXT_FACT_DATA "DATA" + +#endif //__CONTEXT_FACT_TYPES_H__ diff --git a/src/context_trigger/rule.cpp b/src/context_trigger/rule.cpp index 3b6d6ae..803a4fb 100644 --- a/src/context_trigger/rule.cpp +++ b/src/context_trigger/rule.cpp @@ -20,12 +20,7 @@ #include "rule_evaluator.h" #include "context_monitor.h" #include "timer_types.h" - -#define CONTEXT_RULE_EVENT "event" -#define CONTEXT_RULE_CONDITION "condition" -#define CONTEXT_RULE_NAME "name" -#define CONTEXT_RULE_OPTION "option" -#define CONTEXT_RULE_DATA "data" +#include "context_fact_types.h" ctx::trigger_rule::trigger_rule() { @@ -115,9 +110,9 @@ bool ctx::trigger_rule::set_condition_option_based_on_event(ctx::json& option) std::string new_str; int new_val; - if (result.get(CONTEXT_RULE_EVENT "." CONTEXT_RULE_DATA, event_key.c_str(), &new_str)) { + if (result.get(CONTEXT_FACT_EVENT "." CONTEXT_FACT_DATA, event_key.c_str(), &new_str)) { option.set(NULL, opt_key.c_str(), new_str); - } else if (result.get(CONTEXT_RULE_EVENT "." CONTEXT_RULE_DATA, event_key.c_str(), &new_val)) { + } else if (result.get(CONTEXT_FACT_EVENT "." CONTEXT_FACT_DATA, event_key.c_str(), &new_val)) { option.set(NULL, opt_key.c_str(), new_val); } else { _W("Failed to find '%s' in event data", event_key.c_str()); @@ -137,9 +132,9 @@ void ctx::trigger_rule::on_event_received(std::string name, ctx::json option, ct _D("Rule%d received event data", id); // Set event data - result.set(CONTEXT_RULE_EVENT, CONTEXT_RULE_NAME, name); - result.set(CONTEXT_RULE_EVENT, CONTEXT_RULE_OPTION, option); - result.set(CONTEXT_RULE_EVENT, CONTEXT_RULE_DATA, data); + result.set(CONTEXT_FACT_EVENT, CONTEXT_FACT_NAME, name); + result.set(CONTEXT_FACT_EVENT, CONTEXT_FACT_OPTION, option); + result.set(CONTEXT_FACT_EVENT, CONTEXT_FACT_DATA, data); if (condition.size() == 0) { on_context_data_prepared(); @@ -169,12 +164,12 @@ void ctx::trigger_rule::on_condition_received(std::string name, ctx::json option // Set condition data ctx::json item; - item.set(NULL, CONTEXT_RULE_NAME, name); - item.set(NULL, CONTEXT_RULE_OPTION, option); - item.set(NULL, CONTEXT_RULE_DATA, data); - result.array_append(NULL, CONTEXT_RULE_CONDITION, item); + item.set(NULL, CONTEXT_FACT_NAME, name); + item.set(NULL, CONTEXT_FACT_OPTION, option); + item.set(NULL, CONTEXT_FACT_DATA, data); + result.array_append(NULL, CONTEXT_FACT_CONDITION, item); - if (result.array_get_size(NULL, CONTEXT_RULE_CONDITION) == (int) condition.size()) { + if (result.array_get_size(NULL, CONTEXT_FACT_CONDITION) == (int) condition.size()) { on_context_data_prepared(); } } diff --git a/src/context_trigger/rule_evaluator.cpp b/src/context_trigger/rule_evaluator.cpp index 7a9a65f..8071800 100644 --- a/src/context_trigger/rule_evaluator.cpp +++ b/src/context_trigger/rule_evaluator.cpp @@ -15,7 +15,9 @@ */ #include +#include #include "rule_evaluator.h" +#include "context_fact_types.h" bool ctx::rule_evaluator::evaluate_rule(ctx::json& rule, ctx::json& data) { -- 2.7.4