4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #ifndef __RULE_MANAGER_H__
21 #define __RULE_MANAGER_H__
23 #include "clips_handler.h"
24 #include "context_monitor.h"
29 class context_trigger;
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);
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);
50 clips_handler clips_h;
51 context_monitor c_monitor;
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);
62 std::map<std::string, int> cond_cnt_map; // <condition instance name, count>
64 }; /* class rule_manager */
68 #endif /* End of __RULE_MANAGER_H__ */