Migrate from 2.4 code repo
[platform/core/context/context-service.git] / src / context_trigger / timer.h
1 /*
2  * Copyright (c) 2014 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_CONTEXT_TRIGGER_TIMER_H__
18 #define __CONTEXT_CONTEXT_TRIGGER_TIMER_H__
19
20 #include <timer_mgr.h>
21 #include <timer_listener_iface.h>
22 #include <string>
23 #include <map>
24
25 namespace ctx {
26
27         class context_trigger;
28
29         class trigger_timer : public timer_listener_iface {
30         private:
31                 struct ref_count_array_s {
32                         int count[7];   /* reference counts for days of week*/
33                         ref_count_array_s();
34                 };
35
36                 struct timer_state_s {
37                         int timer_id;
38                         int day_of_week; /* day of week, merged into one integer */
39                         timer_state_s() : timer_id(-1), day_of_week(0) {}
40                 };
41
42                 typedef std::map<int, ref_count_array_s> ref_count_map_t;
43                 typedef std::map<int, timer_state_s> timer_state_map_t;
44
45                 ctx::context_trigger *trigger;
46                 std::string zone;
47                 ref_count_map_t ref_count_map;
48                 timer_state_map_t timer_state_map;
49
50                 int merge_day_of_week(int *ref_cnt);
51                 bool reset_timer(int hour);
52                 void on_timer_expired(int hour, int min, int day_of_week);
53
54         protected:
55                 bool on_timer_expired(int timer_id, void *user_data);
56
57         public:
58                 trigger_timer(ctx::context_trigger *tr, std::string z);
59                 ~trigger_timer();
60
61                 bool add(int minute, int day_of_week);
62                 bool remove(int minute, int day_of_week);
63                 void clear();
64                 static int get_day_of_month();
65                 static std::string get_day_of_week();
66                 static int get_minute_of_day();
67                 static int convert_string_to_day_of_week(std::string d);
68                 static std::string convert_day_of_week_to_string(int d);
69                 bool empty();
70         };
71
72 }       /* namespace ctx */
73
74 #endif  /* End of __CONTEXT_CONTEXT_TRIGGER_TIMER_H__ */