Migrate from 2.4 code repo
[platform/core/context/context-service.git] / src / context_trigger / rule_manager.h
1 /*
2 * context-service
3 *
4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 #ifndef __RULE_MANAGER_H__
21 #define __RULE_MANAGER_H__
22
23 #include "clips_handler.h"
24 #include "context_monitor.h"
25
26 namespace ctx {
27
28         class json;
29         class context_trigger;
30         class fact_reader;
31
32         class rule_manager {
33                 public:
34                         rule_manager();
35                         ~rule_manager();
36                         bool init(ctx::context_trigger* tr, ctx::fact_reader* fr);
37                         int add_rule(std::string creator, ctx::json rule, std::string zone, ctx::json* rule_id);
38                         int remove_rule(int rule_id);
39                         int enable_rule(int rule_id);
40                         int disable_rule(int rule_id);
41                         int get_rule_by_id(std::string creator, int rule_id, ctx::json* request_result);
42                         int get_rule_ids(std::string creator, ctx::json* request_result);
43                         int check_rule(std::string creator, int rule_id);
44                         bool is_rule_enabled(int rule_id);
45
46                         void on_event_received(std::string item, ctx::json option, ctx::json data, std::string zone);
47                         void on_rule_triggered(int rule_id);
48
49                 private:
50                         clips_handler clips_h;
51                         context_monitor c_monitor;
52
53                         bool reenable_rule(void);
54                         int verify_rule(ctx::json& rule, const char* app_id, const char* zone);
55                         int64_t get_duplicated_rule(std::string creator, std::string zone, ctx::json& rule);
56                         bool rule_data_arr_elem_equals(ctx::json& lelem, ctx::json& relem);
57                         bool rule_item_equals(ctx::json& litem, ctx::json& ritem);
58                         bool rule_equals(ctx::json& lrule, ctx::json& rrule);
59                         std::string get_instance_name(std::string name, ctx::json& condition);
60                         void make_condition_option_based_on_event_data(ctx::json& ctemplate, ctx::json& edata, ctx::json* coption);
61
62                         std::map<std::string, int> cond_cnt_map; // <condition instance name, count>
63
64    };   /* class rule_manager */
65
66 }       /* namespace ctx */
67
68 #endif  /* End of __RULE_MANAGER_H__ */