tizen 2.4 release
[framework/context/context-service.git] / src / context_trigger / context_monitor.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_MONITOR_H__
18 #define __CONTEXT_MONITOR_H__
19
20 #include <map>
21 #include "timer.h"
22
23 namespace ctx {
24
25         class json;
26         class fact_reader;
27         class context_fact;
28
29         class context_monitor {
30         public:
31                 context_monitor();
32                 ~context_monitor();
33                 bool init(ctx::fact_reader* fr, ctx::context_trigger* tr);
34
35                 int subscribe(int rule_id, std::string subject, ctx::json event);
36                 int unsubscribe(int rule_id, std::string subject, ctx::json option);
37                 int read(std::string subject, json option, ctx::json* result);
38                 bool is_supported(std::string subject);
39                 bool is_allowed(const char *client, const char *subject);
40
41         private:
42                 int subscribe_timer(ctx::json option);
43                 int unsubscribe_timer(ctx::json option);
44                 int read_day_of_month(ctx::json* result);
45                 int read_day_of_week(ctx::json* result);
46                 int read_time(ctx::json* result);
47                 std::map<int, int> request_map; // <rule_id, fact_read_req_id>
48                 std::map<int, int> read_req_cnt_map;    // <fact_read_req_id, count>
49                 ctx::context_trigger* trigger;
50                 ctx::trigger_timer* timer;
51
52         };      /* class context_monitor */
53
54 }       /* namespace ctx */
55
56 #endif  /* End of __CONTEXT_MONITOR_H__ */