a3121914ef7a26957ba52f5433342f9a6a3cc782
[framework/appfw/alarm-manager.git] / include / alarm-internal.h
1 /*
2  *  alarm-manager
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
7  * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23
24
25
26 #ifndef _ALARM_INTERNAL_H
27 #define _ALARM_INTERNAL_H
28
29 #define MAX_SNOOZE_CNT 5
30 #define REPEAT_MODE_ONCE 0x80
31
32 #define SIG_TIMER 0x32
33 #define ALARM_INFO_MAX 100
34
35 #include "alarm.h"
36 #include <dbus/dbus-glib.h>
37 #include <glib.h>
38 #include <dlog.h>
39 #include <bundle.h>
40 #include <appsvc.h>
41
42 #define __APP_SYNC
43
44 #define INIT_ALARM_LIST_SIZE 64
45 #define INIT_SCHEDULED_ALARM_LIST_SIZE 32
46 #define MAX_BUNDLE_NAME_LEN 2048
47 #define MAX_SERVICE_NAME_LEN 256
48 #define MAX_PKG_NAME_LEN MAX_SERVICE_NAME_LEN-8
49
50 #define SYSTEM_TIME_CHANGED "setting_time_changed"
51
52 #ifdef LOG_TAG
53 #undef LOG_TAG
54 #endif
55 #define LOG_TAG "ALARM_MANAGER"
56
57 /*Application ID for native application which is not launched by application
58 server.*/
59 #define ALARM_NATIVE_APP_ID 99999
60 /*  Application Instance ID for native application which is not launched by
61 application server.*/
62 #define ALARM_NATIVE_APP_INST_ID 99999
63 /*  Prefix of dbus service name of native application.*/
64 #define ALARM_NATIVE_APP_DBUS_SVC_NAME_PREFIX "NATIVE"
65
66 /* how to send expire event : gproxy or low level dbus
67 * if you want to use gproxy for receiving expire_event, please enable
68 * _EXPIRE_ALARM_INTERFACE_IS_DBUS_GPROXY_ feature
69 * otherwise, lowlevel dbus interface will be used for receiving expire_event.
70 * Now we use low level dbus instead of gproxy
71 */
72 /*#define       _EXPIRE_ALARM_INTERFACE_IS_DBUS_GPROXY_ */
73
74 typedef struct {
75         DBusGConnection *bus;
76         DBusGProxy *proxy;
77         alarm_cb_t alarm_handler;
78         void *user_param;
79         int pid;                /* this specifies pid*/
80         GQuark quark_app_service_name;  /*dbus_service_name is converted
81          to quark value*/
82          GQuark quark_app_service_name_mod;
83 } alarm_context_t;
84
85 typedef union {
86         int day_of_week;                        /**< days of a week */
87         time_t interval;
88 } alarm_interval_u;
89
90 /**
91 * This struct has mode of an alarm
92 */
93 typedef struct {
94         alarm_interval_u u_interval;
95         alarm_repeat_mode_t repeat;     /**< repeat mode */
96 } alarm_mode_t;
97
98 /**
99 *  This enumeration has alarm type
100
101 typedef enum
102 {
103         ALARM_TYPE_DEFAULT = 0x0,
104         ALARM_TYPE_RELATIVE = 0x01,
105         ALARM_TYPE_VOLATILE = 0x02,
106 }alarm_type_t;
107 */
108 #define ALARM_TYPE_RELATIVE             0x80000000      /**< relative  */
109 #define ALARM_TYPE_WITHCB               0x40000000      /**< withcb  */
110
111
112 /**
113 * This struct has the information of an alarm
114 */
115
116 typedef struct {
117         alarm_date_t start; /**< start time of the alarm */
118         alarm_date_t end;   /**< end time of the alarm */
119         alarm_mode_t mode;      /**< mode of alarm */
120         int alarm_type;     /**< alarm type*/
121         int reserved_info;
122 } alarm_info_t;
123
124 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm,
125                          alarm_id_t *id, const char *dst_service_name,const char *dst_service_name_mod,
126                          int *error_code);
127 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
128                         alarm_id_t *alarm_id, bundle *b,int *error_code);
129 bool _send_alarm_update(alarm_context_t context, int pid, alarm_id_t alarm_id,
130                          alarm_info_t *alarm_info, int *error_code);
131 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
132                          int *error_code);
133 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
134                                   alarm_id_t *alarm_id, int *num_of_ids,
135                                   int *error_code);
136 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
137                                     int *error_code);
138 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
139                            alarm_info_t *alarm_info, int *error_code);
140 bool _send_alarm_reset(alarm_context_t context, int *error_code);
141
142 bool _send_alarm_power_on(alarm_context_t context, bool on_off,
143                            int *error_code);
144 bool _send_alarm_check_next_duetime(alarm_context_t context, int *error_code);
145 bool _send_alarm_power_off(alarm_context_t context, int *error_code);
146 bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id);
147 bool _load_alarms_from_registry();
148 bool _alarm_find_mintime_power_on(time_t *min_time);
149 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
150 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code);
151
152 /*  alarm manager*/
153 typedef struct {
154         time_t start;
155         time_t end;
156
157         int alarm_id;
158         int pid;
159         GQuark quark_app_unique_name;   /*the fullpath of application's pid is
160                 converted to quark value.*/
161         GQuark quark_app_service_name;  /*dbus_service_name is converted  to
162                 quark value.app_service_name is a service name  of application
163                 that creates alarm_info.*/
164         GQuark quark_app_service_name_mod;
165         GQuark quark_dst_service_name;  /*dbus_service_name is converted to
166                 quark value.app_service_name is a service name  for
167                 dst_service_name of alarm_create_extend().*/
168         GQuark quark_dst_service_name_mod;
169         time_t due_time;
170
171         GQuark quark_bundle;    /*Bundle Content containing app-svc info*/
172
173         alarm_info_t alarm_info;
174
175 } __alarm_info_t;
176
177 typedef struct {
178         bool used;
179         __alarm_info_t *__alarm_info;
180 } __alarm_entry_t;
181
182 typedef struct {
183         timer_t timer;
184         time_t c_due_time;
185         GSList *alarms;
186         int gmt_idx;
187         int dst;
188         DBusGConnection *bus;
189 } __alarm_server_context_t;
190
191 typedef struct {
192         bool used;
193         alarm_id_t alarm_id;
194         int pid;
195         __alarm_info_t *__alarm_info;
196 } __scheduled_alarm_t;
197
198 typedef struct {
199         char service_name[MAX_SERVICE_NAME_LEN];
200         alarm_id_t alarm_id;
201 } __expired_alarm_t;
202
203 time_t _alarm_next_duetime(__alarm_info_t *alarm_info);
204 bool _alarm_schedule();
205 bool _clear_scheduled_alarm_list();
206 bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);
207
208 bool _save_alarms(__alarm_info_t *__alarm_info);
209 bool _delete_alarms(alarm_id_t alarm_id);
210 bool _update_alarms(__alarm_info_t *__alarm_info);
211
212 timer_t _alarm_create_timer();
213 bool _alarm_destory_timer(timer_t timer);
214 bool _alarm_set_timer(__alarm_server_context_t *alarm_context, timer_t timer,
215                        time_t due_time, alarm_id_t id);
216 bool _alarm_disable_timer(__alarm_server_context_t alarm_context);
217 bool _init_scheduled_alarm_list();
218
219 int _set_rtc_time(time_t _time);
220 int _set_sys_time(time_t _time);
221 int _set_time(time_t _time);
222
223
224 #ifdef _DEBUG_MODE_
225 #define ALARM_MGR_LOG_PRINT(FMT, ARG...)  do { printf("%5d", getpid()); printf
226         ("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)
227 #define ALARM_MGR_EXCEPTION_PRINT(FMT, ARG...)  do { printf("%5d", getpid());
228         printf("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)
229 #define ALARM_MGR_ASSERT_PRINT(FMT, ARG...) do { printf("%5d", getpid()); printf
230         ("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)
231 #else
232 #define ALARM_MGR_LOG_PRINT(FMT, ARG...) LOGD(FMT, ##ARG);
233 #define ALARM_MGR_EXCEPTION_PRINT(FMT, ARG...) LOGW(FMT, ##ARG);
234 #define ALARM_MGR_ASSERT_PRINT(FMT, ARG...) LOGE(FMT, ##ARG);
235 #endif
236
237 /* int alarmmgr_check_next_duetime();*/
238
239 #ifdef __APP_SYNC
240 bool _sync_scheduler_app_sync_on();
241 void _sync_scheduler_init();
242 void _sync_scheduler_repeating_alarms(__alarm_info_t *alarm_info);
243 void _sync_scheduler_remove_repeating_alarm(alarm_id_t alarm_id);
244 #endif //__APP_SYNC
245
246
247 #endif /*_ALARM_INTERNAL_H*/