Store the dbus connection while launching the service
[platform/core/context/context-service.git] / src / agent / legacy / 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 CtxJson1;
23
24 namespace trigger {
25
26         class RuleEvaluator {
27         private:
28                 RuleEvaluator();
29
30                 bool __evaluateRuleEvent(ctx::CtxJson1& fact, ctx::CtxJson1& rule);
31                 bool __evaluateRuleCondition(ctx::CtxJson1& fact, ctx::CtxJson1& rule);
32                 bool __evaluateItem(ctx::CtxJson1& factItem, ctx::CtxJson1& ruleItem, std::string logicalOp);
33                 template <typename T> bool __evaluateData(T factVal, CtxJson1& comparison);
34                 template <typename T> bool __evaluateSingleData(T factVal, CtxJson1& comparison, std::string op);
35                 template <typename T> bool __evaluateDualData(T factVal, CtxJson1& comparison, std::string op);
36                 template <typename T> bool __evaluateMultipleData(T factVal, CtxJson1& comparison, std::string op);
37
38                 ctx::CtxJson1 __getConditionFact(ctx::CtxJson1& fact, ctx::CtxJson1& ruleCond);
39
40                 bool __replaceEventReferences(ctx::CtxJson1& fact, ctx::CtxJson1& rule);
41                 void __replaceDataReferences(ctx::CtxJson1 eventFactData, ctx::CtxJson1& ruleComp);
42                 void __replaceSingleDataReferences(ctx::CtxJson1& eventFactData, ctx::CtxJson1& ruleComp, std::string& dataKey);
43                 void __replaceMultipleDataReferences(ctx::CtxJson1& eventFactData, ctx::CtxJson1& ruleComp, std::string& dataKey);
44                 bool __replaceOptionReferences(ctx::CtxJson1 eventFactData, ctx::CtxJson1& ruleOption);
45
46         public:
47                 static bool evaluateRule(ctx::CtxJson1 rule, ctx::CtxJson1 data);
48         };
49
50 }       /* namespace trigger */
51 }       /* namespace ctx */
52
53 #endif  /* End of _CONTEXT_TRIGGER_RULE_EVALUATOR_H_ */