Remove profile build dependencies
[platform/core/context/context-service.git] / src / trigger / Rule.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_H_
18 #define _CONTEXT_TRIGGER_RULE_H_
19
20 #include <string>
21 #include <list>
22 #include <Json.h>
23 #include "IContextListener.h"
24
25 namespace ctx {
26
27 namespace trigger {
28
29         class RuleManager;
30
31         class Rule : public IContextListener {
32                 private:
33                         struct ContextItem {
34                                 std::string name;
35                                 ctx::Json option;
36                                 ContextItem(ctx::Json item) {
37                                         std::list<std::string> keyList;
38                                         item.getKeys(&keyList);
39                                         name = *keyList.begin();
40
41                                         ctx::Json o;
42                                         if (item.get(name.c_str(), TRIG_RULE_KEY_OPTION, &o))
43                                                 option = o.str();
44                                 }
45                         };
46
47                         ctx::Json __statement;
48                         ContextItem* __event;
49                         std::list<ContextItem*> __condition;
50                         ctx::Json __extra;
51                         ctx::Json __action;
52                         ctx::Json __result;
53
54                         static RuleManager* __ruleMgr;
55
56                         void __clearResult(void);
57                         bool __setConditionOptionBasedOnEvent(ctx::Json& option);
58                         void __onContextDataPrepared(void);
59
60                         static gboolean __handleUninstalledRule(gpointer data);
61
62                 public:
63                         int id;
64                         std::string pkgId;
65
66                         Rule(int i, ctx::Json& d, const char* p, RuleManager* rm);
67                         ~Rule();
68
69                         int start(void);
70                         int stop(void);
71
72                         void onEventReceived(std::string name, ctx::Json option, ctx::Json data);
73                         void onConditionReceived(std::string name, ctx::Json option, ctx::Json data);
74
75         };
76
77 }       /* namespace trigger */
78 }       /* namespace ctx */
79
80 #endif  /* End of _CONTEXT_TRIGGER_RULE_H_ */