4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
36 #if !GLIB_CHECK_VERSION (2, 31, 0)
37 #include <glib/gmacros.h>
42 #include"alarm-internal.h"
44 #define SIG_TIMER 0x32
46 #define MAX_GCONF_PATH_LEN 256
47 #define MAX_QUERY_LEN 4096
49 extern __alarm_server_context_t alarm_context;
50 extern sqlite3 *alarmmgr_db;
53 extern bool enable_power_on_alarm;
56 bool _save_alarms(__alarm_info_t *__alarm_info);
57 bool _update_alarms(__alarm_info_t *__alarm_info);
58 bool _delete_alarms(alarm_id_t alarm_id);
60 bool _update_power_on(bool on_off);
62 bool _load_alarms_from_registry(void);
64 bool _save_alarms(__alarm_info_t *__alarm_info)
66 char query[MAX_QUERY_LEN] = {0,};
67 char *error_message = NULL;
68 alarm_info_t *alarm_info =
69 (alarm_info_t *) &(__alarm_info->alarm_info);
70 alarm_date_t *start = &alarm_info->start;
71 alarm_mode_t *mode = &alarm_info->mode;
73 snprintf(query, MAX_QUERY_LEN, "insert into alarmmgr( alarm_id, start,\
74 end, pid, app_unique_name, app_service_name, app_service_name_mod, bundle, year,\
75 month, day, hour, min, sec, day_of_week, repeat,\
76 alarm_type, reserved_info, dst_service_name, dst_service_name_mod)\
77 values (%d,%d,%d,%d,'%s','%s','%s','%s',%d,%d,%d,%d,%d,%d,%d,%d,\
79 __alarm_info->alarm_id,
80 (int)__alarm_info->start,
81 (int)__alarm_info->end,
83 (char *)g_quark_to_string(
84 __alarm_info->quark_app_unique_name),
85 (char *)g_quark_to_string(
86 __alarm_info->quark_app_service_name),
87 (char *)g_quark_to_string(
88 __alarm_info->quark_app_service_name_mod),
89 (char *)g_quark_to_string(
90 __alarm_info->quark_bundle),
97 mode->u_interval.day_of_week,
99 alarm_info->alarm_type,
100 alarm_info->reserved_info,
101 (char *)g_quark_to_string(
102 __alarm_info->quark_dst_service_name),
103 (char *)g_quark_to_string(
104 __alarm_info->quark_dst_service_name_mod));
107 sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
108 ALARM_MGR_EXCEPTION_PRINT(
109 "Don't execute query = %s, error message = %s\n", query,
117 bool _update_alarms(__alarm_info_t *__alarm_info)
119 char query[MAX_QUERY_LEN] = {0,};
120 char *error_message = NULL;
121 alarm_info_t *alarm_info =
122 (alarm_info_t *) &(__alarm_info->alarm_info);
123 alarm_date_t *start = &alarm_info->start;
124 alarm_mode_t *mode = &alarm_info->mode;
126 snprintf(query, MAX_QUERY_LEN, "update alarmmgr set start=%d, end=%d,\
127 pid=%d, app_unique_name='%s', app_service_name='%s', app_service_name_mod='%s',\
128 bundle='%s', year=%d, month=%d, day=%d, hour=%d, min=%d, sec=%d,\
129 day_of_week=%d, repeat=%d, alarm_type=%d,\
130 reserved_info=%d, dst_service_name='%s', dst_service_name_mod='%s'\
132 (int)__alarm_info->start,
133 (int)__alarm_info->end,
135 (char *)g_quark_to_string(
136 __alarm_info->quark_app_unique_name),
137 (char *)g_quark_to_string(
138 __alarm_info->quark_app_service_name),
139 (char *)g_quark_to_string(
140 __alarm_info->quark_app_service_name_mod),
141 (char *)g_quark_to_string(
142 __alarm_info->quark_bundle),
149 mode->u_interval.day_of_week,
151 alarm_info->alarm_type,
152 alarm_info->reserved_info,
153 (char *)g_quark_to_string(
154 __alarm_info->quark_dst_service_name),
155 (char *)g_quark_to_string(
156 __alarm_info->quark_dst_service_name_mod),
157 __alarm_info->alarm_id);
160 sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
161 ALARM_MGR_EXCEPTION_PRINT(
162 "Don't execute query = %s, error message = %s\n", query,
171 bool _delete_alarms(alarm_id_t alarm_id)
173 char query[MAX_QUERY_LEN] = {0};
174 char *error_message = NULL;
176 snprintf(query, MAX_QUERY_LEN, "delete from alarmmgr where alarm_id=%d",
180 sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
181 ALARM_MGR_EXCEPTION_PRINT(
182 "Don't execute query = %s, error message = %s\n", query,
192 bool _update_power_on(bool on_off)
194 /* GConfClient* pGCC;
195 char key[MAX_GCONF_PATH_LEN];
196 GError* error = NULL;
199 pGCC = gconf_client_get_default();
203 ALARM_MGR_EXCEPTION_PRINT(" gconf get failed.. \n");
207 sprintf(key,"/Services/AlarmMgr/Auto_poweron");
210 if(!gconf_client_set_bool(pGCC, key, on_off, &error))
212 ALARM_MGR_EXCEPTION_PRINT("set string has failed...\n");
216 gconf_client_suggest_sync(pGCC, NULL);
217 g_object_unref(pGCC);
223 bool _load_alarms_from_registry()
226 char query[MAX_QUERY_LEN] = {0,};
227 sqlite3_stmt *stmt = NULL;
228 const char *tail = NULL;
229 alarm_info_t *alarm_info = NULL;
230 __alarm_info_t *__alarm_info = NULL;
231 alarm_date_t *start = NULL;
232 alarm_mode_t *mode = NULL;
233 char app_unique_name[MAX_SERVICE_NAME_LEN] = {0,};
234 char app_service_name[MAX_SERVICE_NAME_LEN] = {0,};
235 char app_service_name_mod[MAX_SERVICE_NAME_LEN] = {0,};
236 char dst_service_name[MAX_SERVICE_NAME_LEN] = {0,};
237 char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = {0,};
238 char bundle[MAX_BUNDLE_NAME_LEN] = {0,};
241 /*sprintf(path, "/Services/AlarmMgr/Auto_poweron"); */
243 enable_power_on_alarm = 0;
244 /*gconf_client_get_bool(pGCC, path, NULL); */
247 snprintf(query, MAX_QUERY_LEN, "select * from alarmmgr");
250 sqlite3_prepare(alarmmgr_db, query, strlen(query), &stmt, &tail)) {
251 ALARM_MGR_EXCEPTION_PRINT("sqlite3_prepare error\n");
255 for (i = 0; SQLITE_ROW == sqlite3_step(stmt); i++) {
256 __alarm_info = malloc(sizeof(__alarm_info_t));
258 if (G_UNLIKELY(__alarm_info == NULL)){
259 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Malloc failed\n");
262 alarm_info = (alarm_info_t *) &(__alarm_info->alarm_info);
263 start = &alarm_info->start;
264 mode = &alarm_info->mode;
266 memset(app_service_name, 0, MAX_SERVICE_NAME_LEN);
267 memset(app_service_name_mod, 0, MAX_SERVICE_NAME_LEN);
268 memset(dst_service_name, 0, MAX_SERVICE_NAME_LEN);
269 memset(dst_service_name_mod, 0, MAX_SERVICE_NAME_LEN);
271 __alarm_info->alarm_id = sqlite3_column_int(stmt, 0);
272 __alarm_info->start = sqlite3_column_int(stmt, 1);
273 __alarm_info->end = sqlite3_column_int(stmt, 2);
274 __alarm_info->pid = sqlite3_column_int(stmt, 3);
275 strncpy(app_unique_name, (const char *)sqlite3_column_text(stmt, 4),
276 MAX_SERVICE_NAME_LEN - 1);
277 strncpy(app_service_name, (const char *)sqlite3_column_text(stmt, 5),
278 MAX_SERVICE_NAME_LEN - 1);
279 strncpy(app_service_name_mod, (const char *)sqlite3_column_text(stmt, 6),
280 MAX_SERVICE_NAME_LEN - 1);
281 strncpy(bundle, (const char *)sqlite3_column_text(stmt, 7),
282 MAX_BUNDLE_NAME_LEN - 1);
283 start->year = sqlite3_column_int(stmt, 8);
284 start->month = sqlite3_column_int(stmt, 9);
285 start->day = sqlite3_column_int(stmt, 10);
286 start->hour = sqlite3_column_int(stmt, 11);
287 start->min = sqlite3_column_int(stmt, 12);
288 start->sec = sqlite3_column_int(stmt, 13);
289 mode->u_interval.day_of_week = sqlite3_column_int(stmt, 14);
290 mode->repeat = sqlite3_column_int(stmt, 15);
291 alarm_info->alarm_type = sqlite3_column_int(stmt, 16);
292 alarm_info->reserved_info = sqlite3_column_int(stmt, 17);
293 strncpy(dst_service_name, (const char *)sqlite3_column_text(stmt, 18),
294 MAX_SERVICE_NAME_LEN - 1);
295 strncpy(dst_service_name_mod, (const char *)sqlite3_column_text(stmt, 19),
296 MAX_SERVICE_NAME_LEN - 1);
298 __alarm_info->quark_app_unique_name =
299 g_quark_from_string(app_unique_name);
300 __alarm_info->quark_app_service_name =
301 g_quark_from_string(app_service_name);
302 __alarm_info->quark_app_service_name_mod=
303 g_quark_from_string(app_service_name_mod);
304 __alarm_info->quark_dst_service_name =
305 g_quark_from_string(dst_service_name);
306 __alarm_info->quark_dst_service_name_mod=
307 g_quark_from_string(dst_service_name_mod);
308 __alarm_info->quark_bundle = g_quark_from_string(bundle);
310 _alarm_next_duetime(__alarm_info);
311 alarm_context.alarms =
312 g_slist_append(alarm_context.alarms, __alarm_info);
315 if (SQLITE_OK != sqlite3_finalize(stmt)) {
316 ALARM_MGR_EXCEPTION_PRINT("error : sqlite3_finalize\n");