Store the dbus connection while launching the service
[platform/core/context/context-service.git] / src / agent / legacy / 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 <CtxJson1.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::CtxJson1 option;
36                                 ContextItem(ctx::CtxJson1 item) {
37                                         std::list<std::string> keyList;
38                                         item.getKeys(&keyList);
39                                         name = *keyList.begin();
40
41                                         ctx::CtxJson1 o;
42                                         if (item.get(name.c_str(), TRIG_RULE_KEY_OPTION, &o))
43                                                 option = o.str();
44                                 }
45                         };
46
47                         ctx::CtxJson1 __statement;
48                         ContextItem* __event;
49                         std::list<ContextItem*> __condition;
50                         ctx::CtxJson1 __extra;
51                         ctx::CtxJson1 __action;
52                         ctx::CtxJson1 __result;
53
54                         static RuleManager* __ruleMgr;
55
56                         void __clearResult(void);
57                         bool __setConditionOptionBasedOnEvent(ctx::CtxJson1& 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::CtxJson1& 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::CtxJson1 option, ctx::CtxJson1 data);
73                         void onConditionReceived(std::string name, ctx::CtxJson1 option, ctx::CtxJson1 data);
74
75         };
76
77 }       /* namespace trigger */
78 }       /* namespace ctx */
79
80 #endif  /* End of _CONTEXT_TRIGGER_RULE_H_ */