tizen 2.4 release
[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 #ifndef _ALARM_INTERNAL_H
24 #define _ALARM_INTERNAL_H
25
26 #define MAX_SNOOZE_CNT 5
27 #define REPEAT_MODE_ONCE 0x80
28
29 #define SIG_TIMER 0x32
30 #define ALARM_INFO_MAX 100
31
32 #include "alarm.h"
33 #include <glib.h>
34 #include <dlog.h>
35 #include <bundle.h>
36 #include <appsvc.h>
37 #include <gio/gio.h>
38
39 #include <sqlite3.h>
40
41 #define INIT_ALARM_LIST_SIZE 64
42 #define INIT_SCHEDULED_ALARM_LIST_SIZE 32
43 #define MAX_BUNDLE_NAME_LEN 2048
44 #define MAX_SERVICE_NAME_LEN 256
45 #define MAX_PKG_NAME_LEN MAX_SERVICE_NAME_LEN-8
46 #define MAX_PKG_ID_LEN 256
47 #define MIN_INEXACT_INTERVAL 600
48
49 #define SYSTEM_TIME_CHANGED "setting_time_changed"
50
51 #ifdef LOG_TAG
52 #undef LOG_TAG
53 #endif
54 #define LOG_TAG "ALARM_MANAGER"
55
56 /*Application ID for native application which is not launched by application
57 server.*/
58 #define ALARM_NATIVE_APP_ID 99999
59 /*  Application Instance ID for native application which is not launched by
60 application server.*/
61 #define ALARM_NATIVE_APP_INST_ID 99999
62 /*  Prefix of dbus service name of native application.*/
63 #define ALARM_NATIVE_APP_DBUS_SVC_NAME_PREFIX "NATIVE"
64
65 /* how to send expire event : gproxy or low level dbus
66 * if you want to use gproxy for receiving expire_event, please enable
67 * _EXPIRE_ALARM_INTERFACE_IS_DBUS_GPROXY_ feature
68 * otherwise, lowlevel dbus interface will be used for receiving expire_event.
69 * Now we use low level dbus instead of gproxy
70 */
71 /*#define       _EXPIRE_ALARM_INTERFACE_IS_DBUS_GPROXY_ */
72
73 typedef struct {
74         GDBusConnection *connection;
75         GDBusProxy *proxy;
76         alarm_cb_t alarm_handler;
77         void *user_param;
78         int pid;                /* this specifies pid*/
79         GQuark quark_app_service_name;  /*dbus_service_name is converted
80          to quark value*/
81          GQuark quark_app_service_name_mod;
82 } alarm_context_t;
83
84 typedef union {
85         int day_of_week;                        /**< days of a week */
86         time_t interval;
87 } alarm_interval_u;
88
89 /**
90 * This struct has mode of an alarm
91 */
92 typedef struct {
93         alarm_interval_u u_interval;
94         alarm_repeat_mode_t repeat;     /**< repeat mode */
95 } alarm_mode_t;
96
97 /**
98 *  This enumeration has alarm type
99
100 typedef enum
101 {
102         ALARM_TYPE_DEFAULT = 0x0,
103         ALARM_TYPE_RELATIVE = 0x01,
104         ALARM_TYPE_VOLATILE = 0x02,
105 }alarm_type_t;
106 */
107 #define ALARM_TYPE_RELATIVE             0x80000000      /**< relative  */
108 #define ALARM_TYPE_WITHCB               0x40000000      /**< withcb  */
109 #define ALARM_TYPE_PERIOD               0x10000000      /**< periodic */
110
111 /**
112 * This struct has the information of an alarm
113 */
114
115 typedef struct {
116         alarm_date_t start; /**< start time of the alarm */
117         alarm_date_t end;   /**< end time of the alarm */
118         alarm_mode_t mode;      /**< mode of alarm */
119         int alarm_type;     /**< alarm type*/
120         int reserved_info;
121 } alarm_info_t;
122
123 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm,
124                         alarm_id_t *id, const char *dst_service_name,const char *dst_service_name_mod, int *error_code);
125 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
126                         alarm_id_t *alarm_id, bundle *b,int *error_code);
127 bool _send_alarm_update(alarm_context_t context, int pid, alarm_id_t alarm_id,
128                         alarm_info_t *alarm_info, int *error_code);
129 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
130 bool _send_alarm_delete_all(alarm_context_t context, int *error_code);
131 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
132                         alarm_id_t *alarm_id, int *num_of_ids, int *error_code);
133 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, int *error_code);
134 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, alarm_info_t *alarm_info, int *error_code);
135 bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, time_t* duetime, int *error_code);
136 bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code);
137 bool _send_alarm_reset(alarm_context_t context, int *error_code);
138 bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id, const char *zone);
139 bool _load_alarms_from_registry();
140 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
141 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code);
142 bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, int *error_code);
143 bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code);
144
145 /*  alarm manager*/
146 typedef struct {
147         time_t start;
148         time_t end;
149
150         alarm_id_t alarm_id;
151         int pid;
152         GQuark quark_caller_pkgid;
153         GQuark quark_callee_pkgid;
154         GQuark quark_app_unique_name;   /*the fullpath of application's pid is
155                 converted to quark value.*/
156         GQuark quark_app_service_name;  /*dbus_service_name is converted  to
157                 quark value.app_service_name is a service name  of application
158                 that creates alarm_info.*/
159         GQuark quark_app_service_name_mod;
160         GQuark quark_dst_service_name;  /*dbus_service_name is converted to
161                 quark value.app_service_name is a service name  for
162                 dst_service_name of alarm_create_extend().*/
163         GQuark quark_dst_service_name_mod;
164         time_t due_time;
165
166         GQuark quark_bundle;    /*Bundle Content containing app-svc info*/
167
168         alarm_info_t alarm_info;
169
170         periodic_method_e method;
171         long requested_interval;
172         int is_ref;
173         GQuark zone;
174 } __alarm_info_t;
175
176 typedef struct {
177         char *zone;
178         sqlite3 *alarmmgr_db;
179 } _zone_alarm_db_list_t;
180
181 typedef struct {
182         bool used;
183         __alarm_info_t *__alarm_info;
184 } __alarm_entry_t;
185
186 typedef struct {
187         int timer;
188         time_t c_due_time;
189         GSList *alarms;
190         int gmt_idx;
191         int dst;
192         GDBusConnection *connection;
193 } __alarm_server_context_t;
194
195 typedef struct {
196         bool used;
197         alarm_id_t alarm_id;
198         int pid;
199         __alarm_info_t *__alarm_info;
200 } __scheduled_alarm_t;
201
202 typedef struct {
203         char service_name[MAX_SERVICE_NAME_LEN];
204         alarm_id_t alarm_id;
205 } __expired_alarm_t;
206
207 typedef struct _bg_category_cb_info_t {
208         char *appid;
209         bool has_bg;
210 } bg_category_cb_info_t;
211
212 time_t _alarm_next_duetime(__alarm_info_t *alarm_info);
213 bool _alarm_schedule();
214 bool _clear_scheduled_alarm_list();
215 bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);
216
217 bool _save_alarms(__alarm_info_t *__alarm_info);
218 bool _delete_alarms(alarm_id_t alarm_id, const char *zone);
219 bool _update_alarms(__alarm_info_t *__alarm_info);
220
221 bool _alarm_destory_timer(timer_t timer);
222 bool _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t due_time);
223 bool _alarm_disable_timer(__alarm_server_context_t alarm_context);
224 bool _init_scheduled_alarm_list();
225
226 time_t _get_periodic_alarm_standard_time(void);
227
228 #define ALARM_MGR_LOG_PRINT(FMT, ARG...) LOGD(FMT, ##ARG);
229 #define ALARM_MGR_WARNING_PRINT(FMT, ARG...) LOGW(FMT, ##ARG);
230 #define ALARM_MGR_EXCEPTION_PRINT(FMT, ARG...) LOGE(FMT, ##ARG);
231 #define ALARM_MGR_ASSERT_PRINT(FMT, ARG...) LOGF(FMT, ##ARG);
232
233 #endif /*_ALARM_INTERNAL_H*/