2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __CONTEXT_CONTEXT_TRIGGER_TIMER_H__
18 #define __CONTEXT_CONTEXT_TRIGGER_TIMER_H__
20 #include <timer_mgr.h>
21 #include <timer_listener_iface.h>
27 class context_trigger;
29 class trigger_timer : public timer_listener_iface {
31 struct ref_count_array_s {
32 int count[7]; /* reference counts for days of week*/
36 struct timer_state_s {
38 int day_of_week; /* day of week, merged into one integer */
39 timer_state_s() : timer_id(-1), day_of_week(0) {}
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;
45 ctx::context_trigger *trigger;
47 ref_count_map_t ref_count_map;
48 timer_state_map_t timer_state_map;
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);
55 bool on_timer_expired(int timer_id, void *user_data);
58 trigger_timer(ctx::context_trigger *tr, std::string z);
61 bool add(int minute, int day_of_week);
62 bool remove(int minute, int day_of_week);
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);
74 #endif /* End of __CONTEXT_CONTEXT_TRIGGER_TIMER_H__ */