Store the dbus connection while launching the service
[platform/core/context/context-service.git] / src / agent / legacy / trigger / RuleManager.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_MANAGER_H_
18 #define _CONTEXT_TRIGGER_RULE_MANAGER_H_
19
20 #include <set>
21 #include <map>
22 #include <DatabaseManager.h>
23
24 namespace ctx {
25
26         class CtxJson1;
27
28 namespace trigger {
29
30         class Trigger;
31         class Rule;
32
33         class RuleManager {
34                 public:
35                         RuleManager();
36                         ~RuleManager();
37
38                         bool init();
39                         int addRule(std::string creator, const char* pkgId, CtxJson1 rule, CtxJson1* ruleId);
40                         int removeRule(int ruleId);
41                         int enableRule(int ruleId);
42                         int disableRule(int ruleId);
43                         int getRuleById(std::string pkgId, int ruleId, CtxJson1* requestResult);
44                         int getRuleIds(std::string pkgId, CtxJson1* requestResult);
45                         int checkRule(std::string pkgId, int ruleId);
46                         bool isRuleEnabled(int ruleId);
47                         int pauseRuleWithItem(std::string& subject);
48                         int pauseRule(int ruleId);
49                         int resumeRuleWithItem(std::string& subject);
50                         void handleRuleOfUninstalledPackage(std::string pkgId);
51
52                         static bool isUninstalledPackage(std::string pkgId);
53
54                 private:
55                         bool __reenableRule(void);
56                         int __verifyRule(CtxJson1& rule, const char* creator);
57                         int64_t __getDuplicatedRuleId(std::string pkgId, CtxJson1& rule);
58                         bool __ruleEquals(CtxJson1& lRule, CtxJson1& rRule);
59                         int __getUninstalledApp(void);
60                         int __clearRuleOfUninstalledPackage(bool isInit = false);
61                         void __applyTemplates(void);
62
63                         std::set<std::string> __uninstalledPackages;
64                         std::map<int, Rule*> __ruleMap;
65                         DatabaseManager __dbManager;
66    };   /* class RuleManager */
67
68 }       /* namespace trigger */
69 }       /* namespace ctx */
70
71 #endif  /* End of _CONTEXT_TRIGGER_RULE_MANAGER_H_ */