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.
28 #include <sys/types.h>
32 #include "alarm-internal.h"
33 #include "alarm-mgr-stub.h"
34 #include "security-server.h"
36 #define ALARM_SERVICE_NAME "appframework.alarm"
37 #define ALARM_OBJECT_PATH "/appframework/alarm"
38 #define ALARM_INTERFACE_NAME "appframework.alarm"
41 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
42 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
44 bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref,
45 int method, alarm_id_t *alarm_id, int *error_code);
46 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
47 alarm_id_t *alarm_id, bundle *b,int *error_code);
48 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
50 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
51 alarm_id_t *alarm_id, int *num_of_ids,
53 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
55 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
56 alarm_info_t *alarm_info, int *error_code);
58 char* __get_cookie(int *error_code)
60 char *e_cookie = NULL;
61 char cookie[256] = {0,};
65 size = security_server_get_cookie_size();
66 retval = security_server_request_cookie(cookie, size);
68 ALARM_MGR_EXCEPTION_PRINT("security_server_request_cookie() is failed. retval = %d", retval);
70 *error_code = ERR_ALARM_SYSTEM_FAIL;
75 e_cookie = g_base64_encode((const guchar *)cookie, size);
76 if (e_cookie == NULL) {
77 ALARM_MGR_EXCEPTION_PRINT("g_base64_encode() is failed.");
79 *error_code = ERR_ALARM_SYSTEM_FAIL;
84 ALARM_MGR_LOG_PRINT("Gets the cookie successfully.");
89 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
90 alarm_id_t *alarm_id, bundle *b,
95 char *e_cookie = NULL;
96 bundle_raw *b_data = NULL;
99 if (bundle_encode(b, &b_data, &datalen))
101 ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n");
103 *error_code = ERR_ALARM_SYSTEM_FAIL;
108 e_cookie = __get_cookie(error_code);
109 if (e_cookie == NULL) {
110 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
114 if (!alarm_manager_call_alarm_create_appsvc_sync((AlarmManager*)context.proxy, context.pid,
115 alarm_info->start.year,
116 alarm_info->start.month,
117 alarm_info->start.day,
118 alarm_info->start.hour,
119 alarm_info->start.min,
120 alarm_info->start.sec,
121 alarm_info->end.year,
122 alarm_info->end.month,
124 alarm_info->mode.u_interval.day_of_week,
125 alarm_info->mode.u_interval.interval,
126 alarm_info->mode.repeat,
127 alarm_info->alarm_type,
128 alarm_info->reserved_info,
129 (char *)b_data, e_cookie,
130 alarm_id, &return_code,
132 /* g_dbus_proxy_call_sync error */
133 /* error_code should be set */
134 ALARM_MGR_EXCEPTION_PRINT(
135 "alarm_manager_call_alarm_create_appsvc_sync()failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
137 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
149 if (return_code != 0) {
151 *error_code = return_code;
160 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
161 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
164 GError *error = NULL;
166 char *e_cookie = NULL;
168 /*TODO: Dbus bus name validation is must & will be added to avoid alarm-server crash*/
169 if (g_quark_to_string(context.quark_app_service_name) == NULL
170 && strlen(dst_service_name) == 4
171 && strncmp(dst_service_name, "null",4) == 0) {
172 ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
174 *error_code = ERR_ALARM_INVALID_PARAM;
179 e_cookie = __get_cookie(error_code);
180 if (e_cookie == NULL) {
181 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
185 if (!alarm_manager_call_alarm_create_sync((AlarmManager*)context.proxy, context.pid,
186 g_quark_to_string(context.quark_app_service_name),
187 g_quark_to_string(context.quark_app_service_name_mod),
188 alarm_info->start.year,
189 alarm_info->start.month,
190 alarm_info->start.day,
191 alarm_info->start.hour,
192 alarm_info->start.min,
193 alarm_info->start.sec,
194 alarm_info->end.year,
195 alarm_info->end.month,
197 alarm_info->mode.u_interval.day_of_week,
198 alarm_info->mode.repeat,
199 alarm_info->alarm_type,
200 alarm_info->reserved_info,
201 dst_service_name, dst_service_name_mod, e_cookie,
202 alarm_id, &return_code,
204 /* g_dbus_proxy_call_sync error error */
205 /* error_code should be set */
206 ALARM_MGR_EXCEPTION_PRINT(
207 "alarm_manager_call_alarm_create_sync()failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
209 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
213 *error_code = ERR_ALARM_SYSTEM_FAIL;
221 if (return_code != 0) {
223 *error_code = return_code;
231 bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref,
232 int method, alarm_id_t *alarm_id, int *error_code)
234 GError *error = NULL;
236 char *e_cookie = NULL;
238 if (g_quark_to_string(context.quark_app_service_name) == NULL) {
239 ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
241 *error_code = ERR_ALARM_INVALID_PARAM;
246 e_cookie = __get_cookie(error_code);
247 if (e_cookie == NULL) {
248 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
252 if (!alarm_manager_call_alarm_create_periodic_sync((AlarmManager*)context.proxy,
253 g_quark_to_string(context.quark_app_service_name),
254 g_quark_to_string(context.quark_app_service_name_mod),
255 interval, is_ref, method, e_cookie, alarm_id, &return_code, NULL, &error)) {
256 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_create_periodic_sync()failed. alarm_id[%d], return_code[%d]",
257 alarm_id, return_code);
259 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
263 *error_code = ERR_ALARM_SYSTEM_FAIL;
271 if (return_code != 0) {
273 *error_code = return_code;
281 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
283 GError *error = NULL;
286 char *e_cookie = NULL;
287 gchar *b_data = NULL;
289 e_cookie = __get_cookie(error_code);
290 if (e_cookie == NULL) {
291 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
295 if (!alarm_manager_call_alarm_get_appsvc_info_sync
296 ((AlarmManager*)context.proxy, context.pid, alarm_id, e_cookie, &b_data, &return_code, NULL, &error)) {
297 /* g_dbus_proxy_call_sync error */
298 /*error_code should be set */
299 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_appsvc_info_sync() failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
301 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
305 *error_code = ERR_ALARM_SYSTEM_FAIL;
317 if (return_code != 0) {
319 *error_code = return_code;
322 b = bundle_decode((bundle_raw *)b_data, strlen(b_data));
335 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code){
337 GError *error = NULL;
339 char *e_cookie = NULL;
341 e_cookie = __get_cookie(error_code);
342 if (e_cookie == NULL) {
343 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
347 if (!alarm_manager_call_alarm_set_rtc_time_sync
348 ((AlarmManager*)context.proxy, context.pid, time->year, time->month, time->day,
349 time->hour, time->min, time->sec, e_cookie, &return_code, NULL, &error)) {
350 /* g_dbus_proxy_call_sync error */
351 /*error_code should be set */
352 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_rtc_time() failed. return_code[%d]", return_code);
354 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
358 *error_code = ERR_ALARM_SYSTEM_FAIL;
367 if (return_code != 0) {
369 *error_code = return_code;
377 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
379 GError *error = NULL;
381 char *e_cookie = NULL;
383 e_cookie = __get_cookie(error_code);
384 if (e_cookie == NULL) {
385 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
389 if (!alarm_manager_call_alarm_delete_sync
390 ((AlarmManager*)context.proxy, context.pid, alarm_id, e_cookie, &return_code, NULL, &error)) {
391 /* g_dbus_proxy_call_sync error */
392 /*error_code should be set */
393 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_sync() failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
395 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
399 *error_code = ERR_ALARM_SYSTEM_FAIL;
408 if (return_code != 0) {
410 *error_code = return_code;
418 bool _send_alarm_delete_all(alarm_context_t context, int *error_code)
420 GError *error = NULL;
422 char *e_cookie = NULL;
424 e_cookie = __get_cookie(error_code);
425 if (e_cookie == NULL) {
426 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
430 if (!alarm_manager_call_alarm_delete_all_sync
431 ((AlarmManager*)context.proxy, context.pid, e_cookie, &return_code, NULL, &error)) {
432 /* g_dbus_proxy_call_sync error */
433 /*error_code should be set */
434 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_all_sync() failed. return_code[%d]", return_code);
436 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
440 *error_code = ERR_ALARM_SYSTEM_FAIL;
449 if (return_code != 0) {
451 *error_code = return_code;
459 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
460 alarm_id_t *alarm_id, int *num_of_ids,
463 GError *error = NULL;
464 GVariant *alarm_array = NULL;
467 if (!alarm_manager_call_alarm_get_list_of_ids_sync((AlarmManager*)context.proxy,
468 context.pid, maxnum_of_ids, &alarm_array,
469 num_of_ids, &return_code, NULL, &error)) {
470 /* g_dbus_proxy_call_sync error */
471 /*error_code should be set */
472 ALARM_MGR_EXCEPTION_PRINT(
473 "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. alarm_id[%d], return_code[%d]", alarm_id, return_code);
475 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
479 *error_code = ERR_ALARM_SYSTEM_FAIL;
485 if (return_code != 0) {
487 *error_code = return_code;
493 GVariantIter *iter = NULL;
495 g_variant_get (alarm_array, "ai", &iter);
496 while (g_variant_iter_loop (iter, "i", &alarm_id[i]))
498 ALARM_MGR_LOG_PRINT("alarm_id (%d)", alarm_id[i]);
501 g_variant_iter_free (iter);
503 g_variant_unref(alarm_array);
509 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
512 GError *error = NULL;
513 gint return_code = 0;
514 char *e_cookie = NULL;
516 e_cookie = __get_cookie(error_code);
517 if (e_cookie == NULL) {
518 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
522 if (!alarm_manager_call_alarm_get_number_of_ids_sync((AlarmManager*)context.proxy, context.pid, e_cookie, num_of_ids, &return_code, NULL, &error)) {
523 /* g_dbus_proxy_call_sync error */
524 /* error_code should be set */
525 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_number_of_ids_sync() failed by dbus. return_code[%d]", return_code);
527 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
531 *error_code = ERR_ALARM_SYSTEM_FAIL;
536 if (return_code != 0) {
538 *error_code = return_code;
546 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
547 alarm_info_t *alarm_info, int *error_code)
549 GError *error = NULL;
551 char *e_cookie = NULL;
553 e_cookie = __get_cookie(error_code);
554 if (e_cookie == NULL) {
555 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
559 if (!alarm_manager_call_alarm_get_info_sync((AlarmManager*)context.proxy,
560 context.pid, alarm_id, e_cookie, &alarm_info->start.year,
561 &alarm_info->start.month, &alarm_info->start.day,
562 &alarm_info->start.hour, &alarm_info->start.min,
563 &alarm_info->start.sec, &alarm_info->end.year,
564 &alarm_info->end.month, &alarm_info->end.day,
565 &alarm_info->mode.u_interval.day_of_week,
566 (gint *)&alarm_info->mode.repeat,
567 &alarm_info->alarm_type, &alarm_info->reserved_info, &return_code, NULL, &error)) {
568 /* g_dbus_proxy_call_sync error */
569 /* error_code should be set */
570 ALARM_MGR_EXCEPTION_PRINT(
571 "alarm_manager_call_alarm_get_info_sync() failed by dbus. alarm_id[%d], return_code[%d]", alarm_id, return_code);
573 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
577 *error_code = ERR_ALARM_SYSTEM_FAIL;
585 if (return_code != 0) {
587 *error_code = return_code;
595 bool _send_alarm_get_next_duetime(alarm_context_t context,
596 alarm_id_t alarm_id, time_t* duetime,
599 GError *error = NULL;
601 char *e_cookie = NULL;
603 e_cookie = __get_cookie(error_code);
604 if (e_cookie == NULL) {
605 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
609 if (!alarm_manager_call_alarm_get_next_duetime_sync((AlarmManager*)context.proxy,
610 context.pid, alarm_id, e_cookie, (gint *)duetime, &return_code, NULL, &error)) {
611 /*g_dbus_proxy_call_sync error */
612 /*error_code should be set */
613 ALARM_MGR_EXCEPTION_PRINT(
614 "alarm_manager_call_alarm_get_next_duetime_sync() failed by dbus. alarm_id[%d], return_code[%d]", alarm_id, return_code);
616 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
620 *error_code = ERR_ALARM_SYSTEM_FAIL;
628 if (return_code != 0) {
630 *error_code = return_code;
638 bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code)
640 GError *error = NULL;
642 char *e_cookie = NULL;
644 e_cookie = __get_cookie(error_code);
645 if (e_cookie == NULL) {
646 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
650 if (!alarm_manager_call_alarm_get_all_info_sync((AlarmManager*)context.proxy, context.pid, e_cookie, db_path, &return_code, NULL, &error)) {
651 /*g_dbus_proxy_call_sync error */
652 /*error_code should be set */
653 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_all_info_sync() failed by dbus. return_code[%d]", return_code);
655 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
659 *error_code = ERR_ALARM_SYSTEM_FAIL;
667 if (return_code != ALARMMGR_RESULT_SUCCESS) {
669 *error_code = return_code;
677 bool _send_alarm_set_time(alarm_context_t context, int new_time, int *error_code)
679 GError *error = NULL;
682 if (!alarm_manager_call_alarm_set_time_sync((AlarmManager*)context.proxy, new_time, &return_code, NULL, &error)) {
683 /*g_dbus_proxy_call_sync error */
684 /*error_code should be set */
685 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_time_sync() failed by dbus. return_code[%d]", return_code);
687 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
691 *error_code = ERR_ALARM_SYSTEM_FAIL;
696 if (return_code != ALARMMGR_RESULT_SUCCESS) {
698 *error_code = return_code;
707 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)
709 GError *error = NULL;
712 if (!alarm_manager_call_alarm_set_time_with_propagation_delay_sync((AlarmManager*)context.proxy, new_sec, new_nsec, req_sec, req_nsec, &return_code, NULL, &error)) {
713 /*g_dbus_proxy_call_sync error */
714 /*error_code should be set */
715 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_time_with_propagation_delay_sync() failed by dbus. return_code[%d]", return_code);
717 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
721 *error_code = ERR_ALARM_SYSTEM_FAIL;
726 if (return_code != ALARMMGR_RESULT_SUCCESS) {
728 *error_code = return_code;
736 bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code)
738 GError *error = NULL;
741 if (!alarm_manager_call_alarm_set_timezone_sync((AlarmManager*)context.proxy, tzpath_str, &return_code, NULL, &error)) {
742 /*g_dbus_proxy_call_sync error */
743 /*error_code should be set */
744 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_timezone_sync() failed by dbus. return_code[%d]", return_code);
746 ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
750 *error_code = ERR_ALARM_SYSTEM_FAIL;
755 if (return_code != ALARMMGR_RESULT_SUCCESS) {
757 *error_code = return_code;