Added context_fact_types.h 93/56593/1
authorSomin Kim <somin926.kim@samsung.com>
Mon, 11 Jan 2016 09:32:59 +0000 (18:32 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Mon, 11 Jan 2016 09:32:59 +0000 (18:32 +0900)
Change-Id: Ia0483c06d93d08007d8f02b93202faf298a21b33
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
src/context_trigger/context_fact_types.h [new file with mode: 0644]
src/context_trigger/rule.cpp
src/context_trigger/rule_evaluator.cpp

diff --git a/src/context_trigger/context_fact_types.h b/src/context_trigger/context_fact_types.h
new file mode 100644 (file)
index 0000000..7f5ce8a
--- /dev/null
@@ -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__
index 3b6d6ae798599a353687b72b6301eeadd17c9efe..803a4fb25e9f815044b9a4ad153b015c5d694b8c 100644 (file)
 #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();
        }
 }
index 7a9a65f5ecbedeae36895d744bcd213e46b7b6d0..8071800f9a0bdc21cf588e2726642c76e31a25b8 100644 (file)
@@ -15,7 +15,9 @@
  */
 
 #include <json.h>
+#include <context_trigger_types_internal.h>
 #include "rule_evaluator.h"
+#include "context_fact_types.h"
 
 bool ctx::rule_evaluator::evaluate_rule(ctx::json& rule, ctx::json& data)
 {