tizen 2.4 release
[framework/appfw/alarm-manager.git] / src / alarm-lib-stub.c
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 #include <stdio.h>
26 #include <stdlib.h>
27 #include <errno.h>
28 #include <sys/types.h>
29 #include <string.h>
30 #include <glib.h>
31 #include "alarm.h"
32 #include "alarm-internal.h"
33 #include "alarm-mgr-stub.h"
34 #include "security-server.h"
35
36 #define ALARM_SERVICE_NAME      "appframework.alarm"
37 #define ALARM_OBJECT_PATH       "/appframework/alarm"
38 #define ALARM_INTERFACE_NAME "appframework.alarm"
39
40
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,
43                         int *error_code);
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,
49                         int *error_code);
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,
52                                  int *error_code);
53 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
54                                    int *error_code);
55 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
56                           alarm_info_t *alarm_info, int *error_code);
57
58 char* __get_cookie(int *error_code)
59 {
60         char *e_cookie = NULL;
61         char cookie[256] = {0,};
62         int size = 0;
63         int retval = 0;
64
65         size = security_server_get_cookie_size();
66         retval = security_server_request_cookie(cookie, size);
67         if (retval < 0) {
68                 ALARM_MGR_EXCEPTION_PRINT("security_server_request_cookie() is failed. retval = %d", retval);
69                 if (error_code) {
70                         *error_code = ERR_ALARM_SYSTEM_FAIL;
71                 }
72                 return NULL;
73         }
74
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.");
78                 if (error_code) {
79                         *error_code = ERR_ALARM_SYSTEM_FAIL;
80                 }
81                 return NULL;
82         }
83
84         ALARM_MGR_LOG_PRINT("Gets the cookie successfully.");
85         return e_cookie;
86 }
87
88
89 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
90                         alarm_id_t *alarm_id, bundle *b,
91                         int *error_code)
92 {
93         GError *error = NULL;
94         int return_code = 0;
95         char *e_cookie = NULL;
96         bundle_raw *b_data = NULL;
97         int datalen = 0;
98
99         if (bundle_encode(b, &b_data, &datalen))
100         {
101                 ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n");
102                 if (error_code) {
103                         *error_code = ERR_ALARM_SYSTEM_FAIL;
104                 }
105                 return false;
106         }
107
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);
111                 return false;
112         }
113
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,
123                                                     alarm_info->end.day,
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,
131                                                     NULL, &error)) {
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);
136                 if (error) {
137                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
138                         g_error_free(error);
139                 }
140         }
141
142         g_free(e_cookie);
143
144         if (b_data) {
145                 free(b_data);
146                 b_data = NULL;
147         }
148
149         if (return_code != 0) {
150                 if (error_code) {
151                         *error_code = return_code;
152                 }
153                 return false;
154         }
155
156         return true;
157 }
158
159
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,
162                         int *error_code)
163 {
164         GError *error = NULL;
165         int return_code = 0;
166         char *e_cookie = NULL;
167
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");
173                 if (error_code) {
174                         *error_code = ERR_ALARM_INVALID_PARAM;
175                 }
176                 return false;
177         }
178
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);
182                 return false;
183         }
184
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,
196                                                     alarm_info->end.day,
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,
203                                                     NULL, &error)) {
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);
208                 if (error) {
209                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
210                         g_error_free(error);
211                 }
212                 if (error_code) {
213                         *error_code = ERR_ALARM_SYSTEM_FAIL;
214                 }
215                 g_free(e_cookie);
216                 return false;
217         }
218
219         g_free(e_cookie);
220
221         if (return_code != 0) {
222                 if (error_code) {
223                         *error_code = return_code;
224                 }
225                 return false;
226         }
227
228         return true;
229 }
230
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)
233 {
234         GError *error = NULL;
235         int return_code = 0;
236         char *e_cookie = NULL;
237
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");
240                 if (error_code) {
241                         *error_code = ERR_ALARM_INVALID_PARAM;
242                 }
243                 return false;
244         }
245
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);
249                 return false;
250         }
251
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);
258                 if (error) {
259                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
260                         g_error_free(error);
261                 }
262                 if (error_code) {
263                         *error_code = ERR_ALARM_SYSTEM_FAIL;
264                 }
265                 g_free(e_cookie);
266                 return false;
267         }
268
269         g_free(e_cookie);
270
271         if (return_code != 0) {
272                 if (error_code) {
273                         *error_code = return_code;
274                 }
275                 return false;
276         }
277
278         return true;
279 }
280
281 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
282 {
283         GError *error = NULL;
284         int return_code = 0;
285         bundle *b = NULL;
286         char *e_cookie = NULL;
287         gchar *b_data = NULL;
288
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);
292                 return false;
293         }
294
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);
300                 if (error) {
301                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
302                         g_error_free(error);
303                 }
304                 if (error_code) {
305                         *error_code = ERR_ALARM_SYSTEM_FAIL;
306                 }
307
308                 g_free(e_cookie);
309
310                 if (b_data) {
311                         g_free(b_data);
312                 }
313
314                 return NULL;
315         }
316
317         if (return_code != 0) {
318                 if (error_code) {
319                         *error_code = return_code;
320                 }
321         } else {
322                 b = bundle_decode((bundle_raw *)b_data, strlen(b_data));
323         }
324
325         g_free(e_cookie);
326
327         if (b_data) {
328                 g_free(b_data);
329         }
330
331         return b;
332 }
333
334
335 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code){
336
337         GError *error = NULL;
338         int return_code = 0;
339         char *e_cookie = NULL;
340
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);
344                 return false;
345         }
346
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);
353                 if (error) {
354                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
355                         g_error_free(error);
356                 }
357                 if (error_code) {
358                         *error_code = ERR_ALARM_SYSTEM_FAIL;
359                 }
360
361                 g_free(e_cookie);
362                 return false;
363         }
364
365         g_free(e_cookie);
366
367         if (return_code != 0) {
368                 if (error_code) {
369                         *error_code = return_code;
370                 }
371                 return false;
372         }
373
374         return true;
375 }
376
377 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
378 {
379         GError *error = NULL;
380         int return_code = 0;
381         char *e_cookie = NULL;
382
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);
386                 return false;
387         }
388
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);
394                 if (error) {
395                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
396                         g_error_free(error);
397                 }
398                 if (error_code) {
399                         *error_code = ERR_ALARM_SYSTEM_FAIL;
400                 }
401
402                 g_free(e_cookie);
403                 return false;
404         }
405
406         g_free(e_cookie);
407
408         if (return_code != 0) {
409                 if (error_code) {
410                         *error_code = return_code;
411                 }
412                 return false;
413         }
414
415         return true;
416 }
417
418 bool _send_alarm_delete_all(alarm_context_t context, int *error_code)
419 {
420         GError *error = NULL;
421         int return_code = 0;
422         char *e_cookie = NULL;
423
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);
427                 return false;
428         }
429
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);
435                 if (error) {
436                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
437                         g_error_free(error);
438                 }
439                 if (error_code) {
440                         *error_code = ERR_ALARM_SYSTEM_FAIL;
441                 }
442
443                 g_free(e_cookie);
444                 return false;
445         }
446
447         g_free(e_cookie);
448
449         if (return_code != 0) {
450                 if (error_code) {
451                         *error_code = return_code;
452                 }
453                 return false;
454         }
455
456         return true;
457 }
458
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,
461                                  int *error_code)
462 {
463         GError *error = NULL;
464         GVariant *alarm_array = NULL;
465         int return_code = 0;
466
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);
474                 if (error) {
475                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
476                         g_error_free(error);
477                 }
478                 if (error_code) {
479                         *error_code = ERR_ALARM_SYSTEM_FAIL;
480                 }
481
482                 return false;
483         }
484
485         if (return_code != 0) {
486                 if (error_code) {
487                         *error_code = return_code;
488                 }
489                 return false;
490         }
491         else
492         {
493                 GVariantIter *iter = NULL;
494                 gint i = 0;
495                 g_variant_get (alarm_array, "ai", &iter);
496                 while (g_variant_iter_loop (iter, "i", &alarm_id[i]))
497                 {
498                         ALARM_MGR_LOG_PRINT("alarm_id (%d)", alarm_id[i]);
499                         i++;
500                 }
501                 g_variant_iter_free (iter);
502                 *num_of_ids = i;
503                 g_variant_unref(alarm_array);
504         }
505
506         return true;
507 }
508
509 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
510                                    int *error_code)
511 {
512         GError *error = NULL;
513         gint return_code = 0;
514         char *e_cookie = NULL;
515
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);
519                 return false;
520         }
521
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);
526                 if (error) {
527                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
528                         g_error_free(error);
529                 }
530                 if (error_code) {
531                         *error_code = ERR_ALARM_SYSTEM_FAIL;
532                 }
533                 return false;
534         }
535
536         if (return_code != 0) {
537                 if (error_code) {
538                         *error_code = return_code;
539                 }
540                 return false;
541         }
542
543         return true;
544 }
545
546 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
547                           alarm_info_t *alarm_info, int *error_code)
548 {
549         GError *error = NULL;
550         int return_code = 0;
551         char *e_cookie = NULL;
552
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);
556                 return false;
557         }
558
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);
572                 if (error) {
573                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
574                         g_error_free(error);
575                 }
576                 if (error_code) {
577                         *error_code = ERR_ALARM_SYSTEM_FAIL;
578                 }
579                 g_free(e_cookie);
580                 return false;
581         }
582
583         g_free(e_cookie);
584
585         if (return_code != 0) {
586                 if (error_code) {
587                         *error_code = return_code;
588                 }
589                 return false;
590         }
591
592         return true;
593 }
594
595 bool _send_alarm_get_next_duetime(alarm_context_t context,
596                                  alarm_id_t alarm_id, time_t* duetime,
597                                  int *error_code)
598 {
599         GError *error = NULL;
600         int return_code = 0;
601         char *e_cookie = NULL;
602
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);
606                 return false;
607         }
608
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);
615                 if (error) {
616                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
617                         g_error_free(error);
618                 }
619                 if (error_code) {
620                         *error_code = ERR_ALARM_SYSTEM_FAIL;
621                 }
622                 g_free(e_cookie);
623                 return false;
624         }
625
626         g_free(e_cookie);
627
628         if (return_code != 0) {
629                 if (error_code) {
630                         *error_code = return_code;
631                 }
632                 return false;
633         }
634
635         return true;
636 }
637
638 bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code)
639 {
640         GError *error = NULL;
641         int return_code = 0;
642         char *e_cookie = NULL;
643
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);
647                 return false;
648         }
649
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);
654                 if (error) {
655                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
656                         g_error_free(error);
657                 }
658                 if (error_code) {
659                         *error_code = ERR_ALARM_SYSTEM_FAIL;
660                 }
661                 g_free(e_cookie);
662                 return false;
663         }
664
665         g_free(e_cookie);
666
667         if (return_code != ALARMMGR_RESULT_SUCCESS) {
668                 if (error_code) {
669                         *error_code = return_code;
670                 }
671                 return false;
672         }
673
674         return true;
675 }
676
677 bool _send_alarm_set_time(alarm_context_t context, int new_time, int *error_code)
678 {
679         GError *error = NULL;
680         int return_code = 0;
681
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);
686                 if (error) {
687                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
688                         g_error_free(error);
689                 }
690                 if (error_code) {
691                         *error_code = ERR_ALARM_SYSTEM_FAIL;
692                 }
693                 return false;
694         }
695
696         if (return_code != ALARMMGR_RESULT_SUCCESS) {
697                 if (error_code) {
698                         *error_code = return_code;
699                 }
700                 return false;
701         }
702
703         return true;
704 }
705
706
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)
708 {
709         GError *error = NULL;
710         int return_code = 0;
711
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);
716                 if (error) {
717                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
718                         g_error_free(error);
719                 }
720                 if (error_code) {
721                         *error_code = ERR_ALARM_SYSTEM_FAIL;
722                 }
723                 return false;
724         }
725
726         if (return_code != ALARMMGR_RESULT_SUCCESS) {
727                 if (error_code) {
728                         *error_code = return_code;
729                 }
730                 return false;
731         }
732
733         return true;
734 }
735
736 bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code)
737 {
738         GError *error = NULL;
739         int return_code = 0;
740
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);
745                 if (error) {
746                         ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
747                         g_error_free(error);
748                 }
749                 if (error_code) {
750                         *error_code = ERR_ALARM_SYSTEM_FAIL;
751                 }
752                 return false;
753         }
754
755         if (return_code != ALARMMGR_RESULT_SUCCESS) {
756                 if (error_code) {
757                         *error_code = return_code;
758                 }
759                 return false;
760         }
761
762         return true;
763 }