Remove duplicated codes
[platform/core/appfw/alarm-manager.git] / lib / alarm-lib-dbus.c
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <sys/types.h>
19 #include <string.h>
20 #include <glib.h>
21 #include <notification.h>
22 #include <notification_ipc.h>
23
24 #include "alarm.h"
25 #include "alarm-internal.h"
26
27 static int __dbus_call_sync(GDBusProxy *proxy, const gchar *method_name,
28                 GVariant *param, GVariant **reply)
29 {
30         int error_code = ALARMMGR_RESULT_SUCCESS;
31         GError *error = NULL;
32
33         *reply = g_dbus_proxy_call_sync(proxy, method_name, param,
34                         G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
35         if (error) {
36                 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
37                         error_code = ERR_ALARM_NO_PERMISSION;
38                 else
39                         error_code = ERR_ALARM_SYSTEM_FAIL;
40
41                 LOGE("%s : g_dbus_proxy_call_sync() failed.\
42                                 error_code[%d]. error->message is %s(%d)",
43                                 method_name, error_code, error->message, error->code);
44
45                 g_error_free(error);
46         }
47
48         return error_code;
49 }
50
51 bool _send_alarm_create_noti(alarm_context_t context, alarm_info_t *alarm_info,
52                 alarm_id_t *alarm_id, notification_h noti, int *error_code)
53 {
54         int return_code = -1;
55         GVariant *noti_gv = NULL;
56         char *noti_data;
57         guchar *data;
58         int datalen = 0;
59         GVariant *param = NULL;
60         GVariant *reply = NULL;
61
62         noti_gv = notification_ipc_make_gvariant_from_noti(noti, true);
63         if (!noti_gv) {
64                 if (error_code)
65                         *error_code = ERR_ALARM_SYSTEM_FAIL;
66                 return false;
67         }
68
69         datalen = g_variant_get_size(noti_gv);
70         if (datalen < 0)
71                 return false;
72
73         data = malloc(datalen);
74         if (!data)
75                 return false;
76
77         g_variant_store(noti_gv, data);
78         noti_data = g_base64_encode((guchar *)data, datalen);
79
80         param = g_variant_new("(iiiiiiiiiixiixs)",
81                         alarm_info->start.year,
82                         alarm_info->start.month,
83                         alarm_info->start.day,
84                         alarm_info->start.hour,
85                         alarm_info->start.min,
86                         alarm_info->start.sec,
87                         alarm_info->end.year,
88                         alarm_info->end.month,
89                         alarm_info->end.day,
90                         alarm_info->mode.u_interval.day_of_week,
91                         (gint64)alarm_info->mode.u_interval.interval,
92                         alarm_info->mode.repeat,
93                         alarm_info->alarm_type,
94                         (gint64)alarm_info->reserved_info,
95                         (char *)noti_data);
96
97         if (noti_data)
98                 free(noti_data);
99         if (data)
100                 free(data);
101         g_variant_unref(noti_gv);
102
103         return_code = __dbus_call_sync(context.proxy, "alarm_create_noti",
104                         param, &reply);
105         if (return_code != ALARMMGR_RESULT_SUCCESS)
106                 return false;
107
108         g_variant_get(reply, "(ii)", alarm_id, &return_code);
109
110         LOGD("alarm_create_noti() success. alarm_id[%d], return_code[%d].",
111                         *alarm_id, return_code);
112
113         if (return_code != 0) {
114                 if (error_code)
115                         *error_code = return_code;
116
117                 g_variant_unref(reply);
118                 return false;
119         }
120
121         g_variant_unref(reply);
122         return true;
123 }
124
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 {
128         int return_code = -1;
129         bundle_raw *b_data = NULL;
130         int datalen = 0;
131         GVariant *param = NULL;
132         GVariant *reply = NULL;
133
134         if (bundle_encode(b, &b_data, &datalen)) {
135                 LOGE("Unable to encode the bundle data\n");
136                 if (error_code)
137                         *error_code = ERR_ALARM_SYSTEM_FAIL;
138                 return false;
139         }
140
141         param = g_variant_new("(iiiiiiiiiixiixs)",
142                         alarm_info->start.year,
143                         alarm_info->start.month,
144                         alarm_info->start.day,
145                         alarm_info->start.hour,
146                         alarm_info->start.min,
147                         alarm_info->start.sec,
148                         alarm_info->end.year,
149                         alarm_info->end.month,
150                         alarm_info->end.day,
151                         alarm_info->mode.u_interval.day_of_week,
152                         (gint64)alarm_info->mode.u_interval.interval,
153                         alarm_info->mode.repeat,
154                         alarm_info->alarm_type,
155                         (gint64)alarm_info->reserved_info,
156                         (char *)b_data);
157
158         if (b_data)
159                 free(b_data);
160
161         return_code = __dbus_call_sync(context.proxy, "alarm_create_appsvc",
162                         param, &reply);
163         if (return_code != ALARMMGR_RESULT_SUCCESS)
164                 return false;
165
166         g_variant_get(reply, "(ii)", alarm_id, &return_code);
167
168         LOGD("alarm_create_appsvc() success. alarm_id[%d], return_code[%d].",
169                         *alarm_id, return_code);
170
171         if (return_code != 0) {
172                 if (error_code)
173                         *error_code = return_code;
174
175                 g_variant_unref(reply);
176                 return false;
177         }
178
179         g_variant_unref(reply);
180         return true;
181 }
182
183 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
184                 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
185                 int *error_code)
186 {
187         int return_code = -1;
188         GVariant *param = NULL;
189         GVariant *reply = NULL;
190
191         /*TODO: Dbus bus name validation is must & will be added to avoid alarm-server crash*/
192         if (context.app_service_name == NULL
193                         && strlen(dst_service_name) == 4
194                         && strncmp(dst_service_name, "null", 4) == 0) {
195                 LOGE("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
196                 if (error_code)
197                         *error_code = ERR_ALARM_INVALID_PARAM;
198                 return false;
199         }
200
201         param = g_variant_new("(ssiiiiiiiiiiiiixss)",
202                         context.app_service_name,
203                         context.app_service_name_mod,
204                         alarm_info->start.year,
205                         alarm_info->start.month,
206                         alarm_info->start.day,
207                         alarm_info->start.hour,
208                         alarm_info->start.min,
209                         alarm_info->start.sec,
210                         alarm_info->msec,
211                         alarm_info->end.year,
212                         alarm_info->end.month,
213                         alarm_info->end.day,
214                         alarm_info->mode.u_interval.day_of_week,
215                         alarm_info->mode.repeat,
216                         alarm_info->alarm_type,
217                         (gint64)alarm_info->reserved_info,
218                         dst_service_name, dst_service_name_mod);
219
220         return_code = __dbus_call_sync(context.proxy, "alarm_create",
221                         param, &reply);
222         if (return_code != ALARMMGR_RESULT_SUCCESS)
223                 return false;
224
225         g_variant_get(reply, "(ii)", alarm_id, &return_code);
226
227         LOGD("alarm_create() dbus sync success. alarm_id[%d], return_code[%d].",
228                         *alarm_id, return_code);
229
230         if (return_code != 0) {
231                 if (error_code)
232                         *error_code = return_code;
233
234                 g_variant_unref(reply);
235                 return false;
236         }
237
238         g_variant_unref(reply);
239         return true;
240 }
241
242 bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref,
243                 int method, alarm_id_t *alarm_id, int *error_code)
244 {
245         int return_code = -1;
246         GVariant *param = NULL;
247         GVariant *reply = NULL;
248
249         if (context.app_service_name == NULL) {
250                 LOGE("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
251                 if (error_code)
252                         *error_code = ERR_ALARM_INVALID_PARAM;
253                 return false;
254         }
255
256         param = g_variant_new("(ssiii)",
257                         context.app_service_name,
258                         context.app_service_name_mod,
259                         interval, is_ref, method);
260
261         return_code = __dbus_call_sync(context.proxy, "alarm_create_periodic",
262                         param, &reply);
263         if (return_code != ALARMMGR_RESULT_SUCCESS)
264                 return false;
265
266         g_variant_get(reply, "(ii)", alarm_id, &return_code);
267
268         LOGD("alarm_create_periodic() dbus sync success. alarm_id[%d], return_code[%d].",
269                         *alarm_id, return_code);
270
271         if (return_code != 0) {
272                 if (error_code)
273                         *error_code = return_code;
274
275                 g_variant_unref(reply);
276                 return false;
277         }
278
279         g_variant_unref(reply);
280         return true;
281 }
282
283 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
284 {
285         int return_code = -1;
286         bundle *b = NULL;
287         gchar *b_data = NULL;
288         GVariant *param = NULL;
289         GVariant *reply = NULL;
290
291         param = g_variant_new("(i)", alarm_id);
292
293         return_code = __dbus_call_sync(context.proxy, "alarm_get_appsvc_info",
294                         param, &reply);
295         if (return_code != ALARMMGR_RESULT_SUCCESS)
296                 return false;
297
298         g_variant_get(reply, "(si)", &b_data, &return_code);
299
300         LOGD("alarm_get_appsvc_info() dbus sync success. return_code[%d].",
301                         return_code);
302
303         if (return_code != 0) {
304                 if (error_code)
305                         *error_code = return_code;
306         } else {
307                 b = bundle_decode((bundle_raw *)b_data, strlen(b_data));
308         }
309
310         if (b_data)
311                 g_free(b_data);
312
313         g_variant_unref(reply);
314         return b;
315 }
316
317 notification_h _send_alarm_get_noti_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
318 {
319         int return_code = -1;
320         int datalen;
321         GVariant *noti_gv = NULL;
322         GVariant *body = NULL;
323         notification_h noti = NULL;
324         gchar *noti_data = NULL;
325         guchar *data;
326         GVariant *param = NULL;
327         GVariant *reply = NULL;
328
329         param = g_variant_new("(i)", alarm_id);
330
331         return_code = __dbus_call_sync(context.proxy, "alarm_get_noti_info",
332                         param, &reply);
333         if (return_code != ALARMMGR_RESULT_SUCCESS)
334                 return false;
335
336         g_variant_get(reply, "(si)", &noti_data, &return_code);
337
338         LOGD("alarm_get_noti_info() dbus sync success. return_code[%d].",
339                         return_code);
340
341         if (return_code != 0) {
342                 if (error_code)
343                         *error_code = return_code;
344         } else {
345                 data = g_base64_decode(noti_data, (gsize *)&datalen);
346
347                 noti_gv = g_variant_new_from_data(G_VARIANT_TYPE("(v)"),
348                                 data, datalen,
349                                 TRUE, NULL, NULL);
350
351                 g_variant_get(noti_gv, "(v)", &body);
352
353                 noti = notification_create(NOTIFICATION_TYPE_NOTI);
354                 notification_ipc_make_noti_from_gvariant(noti, body);
355
356                 g_free(data);
357                 g_variant_unref(noti_gv);
358         }
359
360         if (noti_data)
361                 g_free(noti_data);
362
363         g_variant_unref(reply);
364         return noti;
365 }
366
367 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code)
368 {
369         int return_code = -1;
370         GVariant *param = NULL;
371         GVariant *reply = NULL;
372
373         param = g_variant_new("(iiiiii)", time->year, time->month, time->day,
374                         time->hour, time->min, time->sec);
375
376         return_code = __dbus_call_sync(context.proxy, "alarm_set_rtc_time",
377                         param, &reply);
378         if (return_code != ALARMMGR_RESULT_SUCCESS)
379                 return false;
380
381         g_variant_get(reply, "(i)", &return_code);
382
383         LOGD("alarm_set_rtc_time() dbus sync success. return_code[%d].",
384                         return_code);
385
386         if (return_code != 0) {
387                 if (error_code)
388                         *error_code = return_code;
389
390                 g_variant_unref(reply);
391                 return false;
392         }
393
394         g_variant_unref(reply);
395         return true;
396 }
397
398 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
399 {
400         int return_code = -1;
401         GVariant *param = NULL;
402         GVariant *reply = NULL;
403
404         param = g_variant_new("(i)", alarm_id);
405
406         return_code = __dbus_call_sync(context.proxy, "alarm_delete",
407                         param, &reply);
408         if (return_code != ALARMMGR_RESULT_SUCCESS)
409                 return false;
410
411         g_variant_get(reply, "(i)", &return_code);
412
413         LOGD("alarm_delete() dbus sync success. return_code[%d].",
414                         return_code);
415
416         if (return_code != 0) {
417                 if (error_code)
418                         *error_code = return_code;
419
420                 g_variant_unref(reply);
421                 return false;
422         }
423
424         g_variant_unref(reply);
425         return true;
426 }
427
428 bool _send_alarm_delete_all(alarm_context_t context, int *error_code)
429 {
430         int return_code = -1;
431         GVariant *reply = NULL;
432
433         return_code = __dbus_call_sync(context.proxy, "alarm_delete_all",
434                         NULL, &reply);
435         if (return_code != ALARMMGR_RESULT_SUCCESS)
436                 return false;
437
438         g_variant_get(reply, "(i)", &return_code);
439
440         LOGD("alarm_delete_all() dbus sync success. return_code[%d].",
441                         return_code);
442
443         if (return_code != 0) {
444                 if (error_code)
445                         *error_code = return_code;
446
447                 g_variant_unref(reply);
448                 return false;
449         }
450
451         g_variant_unref(reply);
452         return true;
453 }
454
455 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
456                 GVariantIter **iter, int *num_of_ids,
457                 int *error_code)
458 {
459         int return_code = -1;
460         GVariantIter *iter_temp = NULL;
461         GVariant *arr = NULL;
462         GVariant *param = NULL;
463         GVariant *reply = NULL;
464
465         param = g_variant_new("(i)", maxnum_of_ids);
466
467         return_code = __dbus_call_sync(context.proxy, "alarm_get_list_of_ids",
468                         param, &reply);
469         if (return_code != ALARMMGR_RESULT_SUCCESS)
470                 return false;
471
472         g_variant_get(reply, "(@aiii)", &arr, num_of_ids, &return_code);
473         g_variant_get(arr, "ai", &iter_temp);
474
475         LOGD("alarm_get_list_of_ids() dbus sync success. return_code[%d].",
476                         return_code);
477
478         if (return_code != 0) {
479                 if (error_code)
480                         *error_code = return_code;
481
482                 g_variant_unref(reply);
483                 return false;
484         }
485
486         *iter = iter_temp;
487
488         g_variant_unref(reply);
489
490         return true;
491 }
492
493 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
494                 int *error_code)
495 {
496         int return_code = -1;
497         GVariant *reply = NULL;
498
499         return_code = __dbus_call_sync(context.proxy, "alarm_get_number_of_ids",
500                         NULL, &reply);
501         if (return_code != ALARMMGR_RESULT_SUCCESS)
502                 return false;
503
504         g_variant_get(reply, "(ii)", num_of_ids, &return_code);
505
506         LOGD("alarm_get_number_of_ids() dbus sync success.\
507                         num_of_ids[%d] return_code[%d].",
508                         *num_of_ids, return_code);
509
510         if (return_code != 0) {
511                 if (error_code)
512                         *error_code = return_code;
513
514                 g_variant_unref(reply);
515                 return false;
516         }
517
518         g_variant_unref(reply);
519         return true;
520 }
521
522 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
523                 alarm_info_t *alarm_info, int *error_code)
524 {
525         int return_code = -1;
526         GVariant *param = NULL;
527         GVariant *reply = NULL;
528         gint64 tmp_reserved_info;
529         param = g_variant_new("(i)", alarm_id);
530
531         return_code = __dbus_call_sync(context.proxy, "alarm_get_info",
532                         param, &reply);
533         if (return_code != ALARMMGR_RESULT_SUCCESS)
534                 return false;
535
536         g_variant_get(reply, "(iiiiiiiiiiiixi)",
537                         &alarm_info->start.year,
538                         &alarm_info->start.month,
539                         &alarm_info->start.day,
540                         &alarm_info->start.hour,
541                         &alarm_info->start.min,
542                         &alarm_info->start.sec,
543                         &alarm_info->end.year,
544                         &alarm_info->end.month,
545                         &alarm_info->end.day,
546                         &alarm_info->mode.u_interval.day_of_week,
547                         &alarm_info->mode.repeat,
548                         &alarm_info->alarm_type,
549                         &tmp_reserved_info,
550                         &return_code);
551         alarm_info->reserved_info = (time_t)tmp_reserved_info;
552
553         LOGD("alarm_get_info() dbus sync success. return_code[%d].",
554                         return_code);
555
556         if (return_code != 0) {
557                 if (error_code)
558                         *error_code = return_code;
559
560                 g_variant_unref(reply);
561                 return false;
562         }
563
564         g_variant_unref(reply);
565         return true;
566 }
567
568 bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id,
569                 time_t *duetime, int *error_code)
570 {
571         int return_code = -1;
572         GVariant *param = NULL;
573         GVariant *reply = NULL;
574         gint64 _duetime = 0;
575
576         param = g_variant_new("(i)", alarm_id);
577
578         return_code = __dbus_call_sync(context.proxy, "alarm_get_next_duetime",
579                         param, &reply);
580         if (return_code != ALARMMGR_RESULT_SUCCESS)
581                 return false;
582
583         g_variant_get(reply, "(xi)", &_duetime, &return_code);
584
585         LOGD("alarm_get_next_duetime() dbus sync success. return_code[%d].",
586                         return_code);
587
588         if (return_code != 0) {
589                 if (error_code)
590                         *error_code = return_code;
591
592                 g_variant_unref(reply);
593                 return false;
594         }
595
596         *duetime = (time_t)_duetime;
597         g_variant_unref(reply);
598         return true;
599 }
600
601 bool _send_alarm_get_all_info(alarm_context_t context, char **db_path, int *error_code)
602 {
603         int return_code = -1;
604         GVariant *reply = NULL;
605         char *_db_path = NULL;
606
607         return_code = __dbus_call_sync(context.proxy, "alarm_get_all_info",
608                         NULL, &reply);
609         if (return_code != ALARMMGR_RESULT_SUCCESS)
610                 return false;
611
612         g_variant_get(reply, "(si)", &_db_path, &return_code);
613
614         LOGD("alarm_get_all_info() dbus sync success. db_path[%s] return_code[%d].",
615                         *db_path, return_code);
616
617         if (return_code != ALARMMGR_RESULT_SUCCESS) {
618                 if (error_code)
619                         *error_code = return_code;
620
621                 g_variant_unref(reply);
622                 return false;
623         }
624
625         *db_path = _db_path;
626         g_variant_unref(reply);
627         return true;
628 }
629
630 bool _send_alarm_set_time(alarm_context_t context, time_t new_time, int *error_code)
631 {
632         int return_code = -1;
633         GVariant *param = NULL;
634         GVariant *reply = NULL;
635
636         param = g_variant_new("(x)", (gint64)new_time);
637
638         return_code = __dbus_call_sync(context.proxy, "alarm_set_time",
639                         param, &reply);
640         if (return_code != ALARMMGR_RESULT_SUCCESS)
641                 return false;
642
643         g_variant_get(reply, "(i)", &return_code);
644
645         LOGD("alarm_set_time() dbus sync success. return_code[%d].",
646                         return_code);
647
648         if (return_code != ALARMMGR_RESULT_SUCCESS) {
649                 if (error_code)
650                         *error_code = return_code;
651
652                 g_variant_unref(reply);
653                 return false;
654         }
655
656         g_variant_unref(reply);
657         return true;
658 }
659
660 static void _alarm_set_time_cb(GObject *source_object, GAsyncResult *res,
661                 gpointer user_data)
662 {
663         int return_code = -1;
664         GError *error = NULL;
665         GVariant *reply = NULL;
666         alarm_set_time_data_t *func_data = (alarm_set_time_data_t *)user_data;
667
668         reply = g_dbus_proxy_call_finish(func_data->proxy, res, &error);
669         if (error) {
670                 LOGE("dbus error message: %s", error->message);
671                 g_error_free(error);
672                 return_code = ERR_ALARM_SYSTEM_FAIL;
673         } else {
674                 g_variant_get(reply, "(i)", &return_code);
675                 LOGD("alarm_set_time_async() dbus success. return_code[%d].",
676                                 return_code);
677         }
678
679         if (func_data->callback != NULL)
680                 func_data->callback(return_code, func_data->user_data);
681
682         g_variant_unref(reply);
683         g_free(func_data);
684 }
685
686 bool _send_alarm_set_time_async(alarm_context_t context, time_t new_time, alarm_set_time_cb_t result_cb, void *user_data)
687 {
688         alarm_set_time_data_t *func_data;
689         GVariant *param;
690
691         func_data = g_try_new0(alarm_set_time_data_t, 1);
692
693         if (func_data == NULL)
694                 return false;
695
696         func_data->callback = result_cb;
697         func_data->user_data = user_data;
698         func_data->proxy = context.proxy;
699
700         param = g_variant_new("(x)", (gint64)new_time);
701
702         g_dbus_proxy_call(context.proxy, "alarm_set_time", param,
703                         G_DBUS_CALL_FLAGS_NONE, -1, NULL, _alarm_set_time_cb, func_data);
704
705         return true;
706 }
707
708 bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, struct timespec new_time, struct timespec req_time, int *error_code)
709 {
710         int return_code = -1;
711         GVariant *param = NULL;
712         GVariant *reply = NULL;
713
714         param = g_variant_new("(xxxx)", (gint64)new_time.tv_sec, (gint64)new_time.tv_nsec,
715                                 (gint64)req_time.tv_sec, (gint64)req_time.tv_nsec);
716
717         return_code = __dbus_call_sync(context.proxy, "alarm_set_time_with_propagation_delay",
718                         param, &reply);
719         if (return_code != ALARMMGR_RESULT_SUCCESS)
720                 return false;
721
722         g_variant_get(reply, "(i)", &return_code);
723
724         LOGD("alarm_set_time_with_propagation_delay dbus sync() success.\
725                         return_code[%d]", return_code);
726
727         if (return_code != ALARMMGR_RESULT_SUCCESS) {
728                 if (error_code)
729                         *error_code = return_code;
730
731                 g_variant_unref(reply);
732                 return false;
733         }
734
735         g_variant_unref(reply);
736         return true;
737 }
738
739 static void _alarm_set_time_with_delay_cb(GObject *source_object, GAsyncResult *res,
740                 gpointer user_data)
741 {
742         int return_code = -1;
743         GError *error = NULL;
744         GVariant *reply = NULL;
745         alarm_set_time_data_t *func_data = (alarm_set_time_data_t *)user_data;
746
747         reply = g_dbus_proxy_call_finish(func_data->proxy, res, &error);
748         if (error) {
749                 LOGE("dbus error message: %s", error->message);
750                 g_error_free(error);
751                 return_code = ERR_ALARM_SYSTEM_FAIL;
752         } else {
753                 g_variant_get(reply, "(i)", &return_code);
754
755                 LOGD("alarm_set_time_with_propagation_delay_async() dbus success.\
756                                 return_code[%d].", return_code);
757         }
758
759         if (func_data->callback != NULL)
760                 func_data->callback(return_code, func_data->user_data);
761
762         g_variant_unref(reply);
763         g_free(func_data);
764 }
765
766 bool _send_alarm_set_time_with_propagation_delay_async(alarm_context_t context, struct timespec new_time, struct timespec req_time, alarm_set_time_cb_t result_cb, void *user_data)
767 {
768         alarm_set_time_data_t *func_data;
769         GVariant *param = NULL;
770
771         func_data = g_try_new0(alarm_set_time_data_t, 1);
772
773         if (func_data == NULL)
774                 return false;
775
776         func_data->callback = result_cb;
777         func_data->user_data = user_data;
778         func_data->proxy = context.proxy;
779
780         param = g_variant_new("(xxxx)", (gint64)new_time.tv_sec, (gint64)new_time.tv_nsec,
781                                 (gint64)req_time.tv_sec, (gint64)req_time.tv_nsec);
782
783         g_dbus_proxy_call(context.proxy, "alarm_set_time_with_propagation_delay", param,
784                         G_DBUS_CALL_FLAGS_NONE, -1, NULL, _alarm_set_time_with_delay_cb, func_data);
785
786         return true;
787 }
788
789 bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code)
790 {
791         int return_code = -1;
792         GVariant *param = NULL;
793         GVariant *reply = NULL;
794
795         param = g_variant_new("(s)", tzpath_str);
796
797         return_code = __dbus_call_sync(context.proxy, "alarm_set_timezone",
798                         param, &reply);
799         if (return_code != ALARMMGR_RESULT_SUCCESS)
800                 return false;
801
802         g_variant_get(reply, "(i)", &return_code);
803
804         LOGD("alarm_set_timezone dbus sync() success. tz_path[%s] return_code[%d]",
805                         tzpath_str, return_code);
806
807         if (return_code != ALARMMGR_RESULT_SUCCESS) {
808                 if (error_code)
809                         *error_code = return_code;
810
811                 g_variant_unref(reply);
812                 return false;
813         }
814
815         g_variant_unref(reply);
816         return true;
817 }
818
819 bool _send_alarm_set_global(alarm_context_t context, const alarm_id_t alarm_id, bool global, int *error_code)
820 {
821         int return_code = -1;
822         GVariant *param = NULL;
823         GVariant *reply = NULL;
824
825         param = g_variant_new("(ib)", alarm_id, (gboolean)global);
826
827         return_code = __dbus_call_sync(context.proxy, "alarm_set_global",
828                         param, &reply);
829         if (return_code != ALARMMGR_RESULT_SUCCESS)
830                 return false;
831
832         g_variant_get(reply, "(i)", &return_code);
833
834         LOGD("alarm_set_global dbus sync() success. alarm_id[%d], global[%d]\
835                         return_code[%d]", alarm_id, global, return_code);
836
837         if (return_code != ALARMMGR_RESULT_SUCCESS) {
838                 if (error_code)
839                         *error_code = return_code;
840
841                 g_variant_unref(reply);
842                 return false;
843         }
844
845         g_variant_unref(reply);
846         return true;
847 }
848
849 bool _send_alarm_get_global(alarm_context_t context, const alarm_id_t alarm_id, bool *global, int *error_code)
850 {
851         int return_code = -1;
852         GVariant *param = NULL;
853         GVariant *reply = NULL;
854
855         param = g_variant_new("(i)", alarm_id);
856
857         return_code = __dbus_call_sync(context.proxy, "alarm_get_global",
858                         param, &reply);
859         if (return_code != ALARMMGR_RESULT_SUCCESS)
860                 return false;
861
862         g_variant_get(reply, "(bi)", global, &return_code);
863
864         LOGD("alarm_get_global dbus sync() success. alarm_id[%d], global[%d]\
865                         return_code[%d]", alarm_id, *global, return_code);
866
867         if (return_code != 0) {
868                 if (error_code)
869                         *error_code = return_code;
870
871                 g_variant_unref(reply);
872                 return false;
873         }
874
875         g_variant_unref(reply);
876         return true;
877 }
878
879 bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id,
880                 alarm_info_t *alarm_info, int update_flag, int *error_code)
881 {
882         int return_code = -1;
883         GVariant *param = NULL;
884         GVariant *reply = NULL;
885
886         param = g_variant_new("(iiiiiiiiiixiixi)",
887                         alarm_id,
888                         alarm_info->start.year,
889                         alarm_info->start.month,
890                         alarm_info->start.day,
891                         alarm_info->start.hour,
892                         alarm_info->start.min,
893                         alarm_info->start.sec,
894                         alarm_info->end.year,
895                         alarm_info->end.month,
896                         alarm_info->end.day,
897                         (gint64)alarm_info->mode.u_interval.interval,
898                         alarm_info->mode.repeat,
899                         alarm_info->alarm_type,
900                         (gint64)alarm_info->reserved_info,
901                         update_flag);
902
903         return_code = __dbus_call_sync(context.proxy, "alarm_update",
904                         param, &reply);
905         if (return_code != ALARMMGR_RESULT_SUCCESS)
906                 return false;
907
908         g_variant_get(reply, "(i)", &return_code);
909
910         LOGD("alarm_update dbus sync() success. alarm_id[%d], return_code[%d]",
911                         alarm_id, return_code);
912
913         if (return_code != 0) {
914                 if (error_code)
915                         *error_code = return_code;
916
917                 g_variant_unref(reply);
918                 return false;
919         }
920
921         g_variant_unref(reply);
922         return true;
923 }