Remove profile build dependencies
[platform/core/context/context-service.git] / src / trigger / RuleEvaluator.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _CONTEXT_TRIGGER_RULE_EVALUATOR_H_
18 #define _CONTEXT_TRIGGER_RULE_EVALUATOR_H_
19
20 namespace ctx {
21
22         class Json;
23
24 namespace trigger {
25
26         class RuleEvaluator {
27         private:
28                 RuleEvaluator();
29
30                 bool __evaluateRuleEvent(ctx::Json& fact, ctx::Json& rule);
31                 bool __evaluateRuleCondition(ctx::Json& fact, ctx::Json& rule);
32                 bool __evaluateItem(ctx::Json& factItem, ctx::Json& ruleItem, std::string logicalOp);
33                 template <typename T> bool __evaluateData(T factVal, Json& comparison);
34                 template <typename T> bool __evaluateSingleData(T factVal, Json& comparison, std::string op);
35                 template <typename T> bool __evaluateDualData(T factVal, Json& comparison, std::string op);
36                 template <typename T> bool __evaluateMultipleData(T factVal, Json& comparison, std::string op);
37
38                 ctx::Json __getConditionFact(ctx::Json& fact, ctx::Json& ruleCond);
39
40                 bool __replaceEventReferences(ctx::Json& fact, ctx::Json& rule);
41                 void __replaceDataReferences(ctx::Json eventFactData, ctx::Json& ruleComp);
42                 void __replaceSingleDataReferences(ctx::Json& eventFactData, ctx::Json& ruleComp, std::string& dataKey);
43                 void __replaceMultipleDataReferences(ctx::Json& eventFactData, ctx::Json& ruleComp, std::string& dataKey);
44                 bool __replaceOptionReferences(ctx::Json eventFactData, ctx::Json& ruleOption);
45
46         public:
47                 static bool evaluateRule(ctx::Json rule, ctx::Json data);
48         };
49
50 }       /* namespace trigger */
51 }       /* namespace ctx */
52
53 #endif  /* End of _CONTEXT_TRIGGER_RULE_EVALUATOR_H_ */