Remove ail dependancy
[platform/core/api/notification.git] / src / notification_internal.c
1 /*
2  * Copyright (c) 2000 - 2016 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
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22 #include <libintl.h>
23 #include <dbus/dbus.h>
24 #include <dbus/dbus-glib-lowlevel.h>
25
26 #include <app.h>
27 #include <app_control_internal.h>
28 #include <aul.h>
29 #include <appsvc.h>
30 #include <tizen.h>
31 #include <vconf-keys.h>
32 #include <vconf.h>
33
34 #include <notification.h>
35 #include <notification_list.h>
36 #include <notification_debug.h>
37 #include <notification_private.h>
38 #include <notification_noti.h>
39 #include <notification_ongoing.h>
40 #include <notification_group.h>
41 #include <notification_ipc.h>
42 #include <notification_internal.h>
43
44 typedef struct _notification_cb_list notification_cb_list_s;
45
46 typedef enum __notification_cb_type {
47         NOTIFICATION_CB_NORMAL = 1,
48         NOTIFICATION_CB_DETAILED,
49 } _notification_cb_type_e;
50
51 struct _notification_cb_list {
52         notification_cb_list_s *prev;
53         notification_cb_list_s *next;
54
55         _notification_cb_type_e cb_type;
56         void (*changed_cb) (void *data, notification_type_e type);
57         void (*detailed_changed_cb) (void *data, notification_type_e type, notification_op *op_list, int num_op);
58         void *data;
59 };
60
61 static notification_cb_list_s *g_notification_cb_list = NULL;
62
63 void notification_call_changed_cb(notification_op *op_list, int op_num)
64 {
65         notification_cb_list_s *noti_cb_list = NULL;
66         notification_type_e type = 0;
67
68         if (g_notification_cb_list == NULL)
69                 return;
70
71         noti_cb_list = g_notification_cb_list;
72
73         while (noti_cb_list->prev != NULL)
74                 noti_cb_list = noti_cb_list->prev;
75
76
77         if (op_list == NULL) {
78                 NOTIFICATION_ERR("invalid data");
79                 return ;
80         }
81
82         notification_get_type(op_list->noti, &type);
83
84         while (noti_cb_list != NULL) {
85                 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
86                         noti_cb_list->changed_cb(noti_cb_list->data,
87                                                  type);
88                 }
89                 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
90                         noti_cb_list->detailed_changed_cb(noti_cb_list->data,
91                                                 type, op_list, op_num);
92                 }
93
94                 noti_cb_list = noti_cb_list->next;
95         }
96 }
97
98 EXPORT_API int notification_add_deferred_task(
99                 void (*deferred_task_cb)(void *data), void *user_data)
100 {
101         if (deferred_task_cb == NULL)
102                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
103
104         return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
105 }
106
107 EXPORT_API int notification_del_deferred_task(
108                 void (*deferred_task_cb)(void *data))
109 {
110         if (deferred_task_cb == NULL)
111                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
112
113         return notification_ipc_del_deffered_task(deferred_task_cb);
114 }
115
116 EXPORT_API int notification_resister_changed_cb(void (*changed_cb)
117                                  (void *data, notification_type_e type),
118                                  void *user_data)
119 {
120         notification_cb_list_s *noti_cb_list_new = NULL;
121         notification_cb_list_s *noti_cb_list = NULL;
122
123         if (changed_cb == NULL)
124                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
125
126         noti_cb_list_new =
127             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
128
129         if (noti_cb_list_new == NULL) {
130                 NOTIFICATION_ERR("malloc failed");
131                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
132         }
133
134         noti_cb_list_new->next = NULL;
135         noti_cb_list_new->prev = NULL;
136
137         noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
138         noti_cb_list_new->changed_cb = changed_cb;
139         noti_cb_list_new->detailed_changed_cb = NULL;
140         noti_cb_list_new->data = user_data;
141
142         if (g_notification_cb_list == NULL) {
143                 g_notification_cb_list = noti_cb_list_new;
144         } else {
145                 noti_cb_list = g_notification_cb_list;
146
147                 while (noti_cb_list->next != NULL)
148                         noti_cb_list = noti_cb_list->next;
149
150
151                 noti_cb_list->next = noti_cb_list_new;
152                 noti_cb_list_new->prev = noti_cb_list;
153         }
154
155         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
156                 notification_unresister_changed_cb(changed_cb);
157                 return NOTIFICATION_ERROR_IO_ERROR;
158         }
159
160         return NOTIFICATION_ERROR_NONE;
161 }
162
163 EXPORT_API int notification_unresister_changed_cb(void (*changed_cb)
164                                    (void *data, notification_type_e type))
165 {
166         notification_cb_list_s *noti_cb_list = NULL;
167         notification_cb_list_s *noti_cb_list_prev = NULL;
168         notification_cb_list_s *noti_cb_list_next = NULL;
169
170         noti_cb_list = g_notification_cb_list;
171
172         if (changed_cb == NULL)
173                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
174
175         if (noti_cb_list == NULL)
176                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
177
178         while (noti_cb_list->prev != NULL)
179                 noti_cb_list = noti_cb_list->prev;
180
181
182         do {
183                 if (noti_cb_list->changed_cb == changed_cb) {
184                         noti_cb_list_prev = noti_cb_list->prev;
185                         noti_cb_list_next = noti_cb_list->next;
186
187                         if (noti_cb_list_prev == NULL)
188                                 g_notification_cb_list = noti_cb_list_next;
189                         else
190                                 noti_cb_list_prev->next = noti_cb_list_next;
191
192                         if (noti_cb_list_next == NULL) {
193                                 if (noti_cb_list_prev != NULL)
194                                         noti_cb_list_prev->next = NULL;
195
196                         } else {
197                                 noti_cb_list_next->prev = noti_cb_list_prev;
198                         }
199
200                         free(noti_cb_list);
201
202                         if (g_notification_cb_list == NULL)
203                                 notification_ipc_monitor_fini();
204
205                         return NOTIFICATION_ERROR_NONE;
206                 }
207                 noti_cb_list = noti_cb_list->next;
208         } while (noti_cb_list != NULL);
209
210         return NOTIFICATION_ERROR_INVALID_PARAMETER;
211 }
212
213 EXPORT_API int notification_update_progress(notification_h noti,
214                                                              int priv_id,
215                                                              double progress)
216 {
217         char *caller_pkgname = NULL;
218         int input_priv_id = 0;
219         int ret = 0;
220         double input_progress = 0.0;
221
222         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
223                 if (noti == NULL)
224                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
225                 else
226                         input_priv_id = noti->priv_id;
227
228         } else {
229                 input_priv_id = priv_id;
230         }
231
232         if (noti == NULL)
233                 caller_pkgname = notification_get_pkgname_by_pid();
234         else
235                 caller_pkgname = strdup(noti->caller_pkgname);
236
237         if (progress < 0.0)
238                 input_progress = 0.0;
239         else if (progress > 1.0)
240                 input_progress = 1.0;
241         else
242                 input_progress = progress;
243
244         ret = notification_ongoing_update_progress(caller_pkgname, input_priv_id,
245                                              input_progress);
246
247         if (caller_pkgname)
248                 free(caller_pkgname);
249
250         return ret;
251 }
252
253 EXPORT_API int notification_update_size(notification_h noti,
254                                                          int priv_id,
255                                                          double size)
256 {
257         char *caller_pkgname = NULL;
258         int input_priv_id = 0;
259         int ret = 0;
260         double input_size = 0.0;
261
262         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
263                 if (noti == NULL)
264                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
265                 else
266                         input_priv_id = noti->priv_id;
267         } else {
268                 input_priv_id = priv_id;
269         }
270
271         if (noti == NULL)
272                 caller_pkgname = notification_get_pkgname_by_pid();
273         else
274                 caller_pkgname = strdup(noti->caller_pkgname);
275
276         if (size < 0.0)
277                 input_size = 0.0;
278         else
279                 input_size = size;
280
281         ret = notification_ongoing_update_size(caller_pkgname, input_priv_id,
282                                          input_size);
283
284         if (caller_pkgname)
285                 free(caller_pkgname);
286
287         return ret;
288 }
289
290 EXPORT_API int notification_update_content(notification_h noti,
291                                                          int priv_id,
292                                                          const char *content)
293 {
294         char *caller_pkgname = NULL;
295         int input_priv_id = 0;
296         int ret = 0;
297
298         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
299                 if (noti == NULL)
300                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
301                 else
302                         input_priv_id = noti->priv_id;
303
304         } else {
305                 input_priv_id = priv_id;
306         }
307
308         if (noti == NULL)
309                 caller_pkgname = notification_get_pkgname_by_pid();
310         else
311                 caller_pkgname = strdup(noti->caller_pkgname);
312
313         ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
314                                          content);
315
316         if (caller_pkgname)
317                 free(caller_pkgname);
318
319         return ret;
320 }
321
322 /* notification_set_icon will be removed */
323 EXPORT_API int notification_set_icon(notification_h noti,
324                                                       const char *icon_path)
325 {
326         int ret_err = NOTIFICATION_ERROR_NONE;
327
328         ret_err =
329             notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
330                                    icon_path);
331
332         return ret_err;
333 }
334
335 /* notification_get_icon will be removed */
336 EXPORT_API int notification_get_icon(notification_h noti,
337                                                       char **icon_path)
338 {
339         int ret_err = NOTIFICATION_ERROR_NONE;
340         char *ret_image_path = NULL;
341
342         ret_err =
343             notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
344                                    &ret_image_path);
345
346         if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL)
347                 *icon_path = ret_image_path;
348
349         return ret_err;
350 }
351
352 EXPORT_API int notification_translate_localized_text(notification_h noti)
353 {
354         int noti_err = NOTIFICATION_ERROR_NONE;
355         char *ret_text = NULL;
356         char buf_key[32];
357         char *bundle_val = NULL;
358         char *new_text;
359         bundle *b;
360         notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
361
362         for (; type < NOTIFICATION_TEXT_TYPE_MAX; type++) {
363                 noti_err = notification_get_text(noti, type, &ret_text);
364                 if (noti_err == NOTIFICATION_ERROR_NONE && ret_text) {
365                         b = noti->b_text;
366                         if (b == NULL)
367                                 b = bundle_create();
368
369                         new_text = strdup(ret_text);
370
371                         snprintf(buf_key, sizeof(buf_key), "%d", type);
372                         bundle_get_str(b, buf_key, &bundle_val);
373                         if (bundle_val != NULL)
374                                 bundle_del(b, buf_key);
375
376                         bundle_add_str(b, buf_key, new_text);
377                         free(new_text);
378                         new_text = NULL;
379
380                         noti->num_format_args = 0;
381                         bundle_val = NULL;
382                 }
383         }
384
385         if (noti->b_key) {
386                 bundle_free(noti->b_key);
387                 noti->b_key = NULL;
388         }
389
390         return noti_err;
391 }
392
393 EXPORT_API int notification_set_title(notification_h noti,
394                                                        const char *title,
395                                                        const char *loc_title)
396 {
397         int noti_err = NOTIFICATION_ERROR_NONE;
398
399         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
400                                          title, loc_title,
401                                          NOTIFICATION_VARIABLE_TYPE_NONE);
402
403         return noti_err;
404 }
405
406 EXPORT_API int notification_get_title(notification_h noti,
407                                                        char **title,
408                                                        char **loc_title)
409 {
410         int noti_err = NOTIFICATION_ERROR_NONE;
411         char *ret_text = NULL;
412
413         noti_err =
414             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
415                                   &ret_text);
416
417         if (title != NULL)
418                 *title = ret_text;
419
420         if (loc_title != NULL)
421                 *loc_title = NULL;
422
423         return noti_err;
424 }
425
426 EXPORT_API int notification_set_content(notification_h noti,
427                                                          const char *content,
428                                                          const char *loc_content)
429 {
430         int noti_err = NOTIFICATION_ERROR_NONE;
431
432         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
433                                          content, loc_content,
434                                          NOTIFICATION_VARIABLE_TYPE_NONE);
435
436         return noti_err;
437 }
438
439 EXPORT_API int notification_get_content(notification_h noti,
440                                                          char **content,
441                                                          char **loc_content)
442 {
443         int noti_err = NOTIFICATION_ERROR_NONE;
444         char *ret_text = NULL;
445
446         noti_err =
447             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
448                                   &ret_text);
449
450         if (content != NULL)
451                 *content = ret_text;
452
453         if (loc_content != NULL)
454                 *loc_content = NULL;
455
456         return noti_err;
457
458 #if 0
459         ret =
460             vconf_get_bool
461             (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
462
463         if (ret == -1 || boolval == 0) {
464                 if (content != NULL && noti->default_content != NULL)
465                         *content = noti->default_content;
466
467                 if (loc_content != NULL && noti->loc_default_content != NULL)
468                         *loc_content = noti->loc_default_content;
469         }
470 #endif
471 }
472
473 EXPORT_API int notification_set_application(notification_h noti,
474                                                              const char *pkgname)
475 {
476         if (noti == NULL || pkgname == NULL)
477                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
478
479         if (noti->launch_pkgname)
480                 free(noti->launch_pkgname);
481
482         noti->launch_pkgname = strdup(pkgname);
483
484         return NOTIFICATION_ERROR_NONE;
485 }
486
487 EXPORT_API int notification_get_application(notification_h noti,
488                                                              char **pkgname)
489 {
490         if (noti == NULL || pkgname == NULL)
491                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
492
493         if (noti->launch_pkgname)
494                 *pkgname = noti->launch_pkgname;
495         else
496                 *pkgname = noti->caller_pkgname;
497
498         return NOTIFICATION_ERROR_NONE;
499 }
500
501 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
502                 bundle *group_args)
503 {
504         if (noti == NULL || args == NULL)
505                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
506
507         if (noti->args)
508                 bundle_free(noti->args);
509
510         noti->args = bundle_dup(args);
511
512         if (noti->group_args) {
513                 bundle_free(noti->group_args);
514                 noti->group_args = NULL;
515         }
516
517         if (group_args != NULL)
518                 noti->group_args = bundle_dup(group_args);
519
520         return NOTIFICATION_ERROR_NONE;
521 }
522
523 EXPORT_API int notification_get_args(notification_h noti,
524                                                       bundle **args,
525                                                       bundle **group_args)
526 {
527         if (noti == NULL || args == NULL)
528                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
529
530         if (noti->args)
531                 *args = noti->args;
532         else
533                 *args = NULL;
534
535         if (group_args != NULL && noti->group_args)
536                 *group_args = noti->group_args;
537
538         return NOTIFICATION_ERROR_NONE;
539 }
540
541 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
542                                notification_list_h *list)
543 {
544         notification_list_h get_list = NULL;
545         int ret = 0;
546
547         if (list == NULL)
548                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
549
550         ret = notification_noti_get_grouping_list(type, count, &get_list);
551         if (ret != NOTIFICATION_ERROR_NONE)
552                 return ret;
553
554         *list = get_list;
555
556         return NOTIFICATION_ERROR_NONE;
557 }
558
559 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
560                                                                       notification_type_e type,
561                                                                       int group_id)
562 {
563         int ret = 0;
564         char *caller_pkgname = NULL;
565
566         if (pkgname == NULL)
567                 caller_pkgname = notification_get_pkgname_by_pid();
568         else
569                 caller_pkgname = strdup(pkgname);
570
571         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
572
573         if (caller_pkgname)
574                 free(caller_pkgname);
575
576         return ret;
577 }
578
579 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
580                                                                      notification_type_e type,
581                                                                      int priv_id)
582 {
583         int ret = 0;
584         char *caller_pkgname = NULL;
585
586         if (pkgname == NULL)
587                 caller_pkgname = notification_get_pkgname_by_pid();
588         else
589                 caller_pkgname = strdup(pkgname);
590
591         ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
592
593         if (caller_pkgname)
594                 free(caller_pkgname);
595
596         return ret;
597 }
598
599 EXPORT_API int notification_get_count(notification_type_e type,
600                                                        const char *pkgname,
601                                                        int group_id,
602                                                        int priv_id, int *count)
603 {
604         int ret = 0;
605         char *caller_pkgname = NULL;
606
607         if (count == NULL)
608                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
609
610         if (pkgname == NULL)
611                 caller_pkgname = notification_get_pkgname_by_pid();
612         else
613                 caller_pkgname = strdup(pkgname);
614
615         ret = notification_ipc_request_get_count(
616                         type,
617                         caller_pkgname,
618                         group_id,
619                         priv_id,
620                         count);
621
622         if (caller_pkgname)
623                 free(caller_pkgname);
624
625         return ret;
626 }
627
628 EXPORT_API int notification_clear(notification_type_e type)
629 {
630         int ret = 0;
631
632         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
633                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
634
635         ret = notification_ipc_request_delete_multiple(type, NULL);
636
637         return ret;
638 }
639
640 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
641                                                        void *data)
642 {
643         if (noti_op == NULL || data == NULL)
644                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
645
646         switch (type) {
647         case NOTIFICATION_OP_DATA_TYPE:
648                 *((int *)data) = noti_op->type;
649                 break;
650         case NOTIFICATION_OP_DATA_PRIV_ID:
651                 *((int *)data) = noti_op->priv_id;
652                 break;
653         case NOTIFICATION_OP_DATA_NOTI:
654                 *((notification_h *)data) = noti_op->noti;
655                 break;
656         case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
657                 *((int *)data) = noti_op->extra_info_1;
658                 break;
659         case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
660                 *((int *)data) = noti_op->extra_info_2;
661                 break;
662         default:
663                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
664                 break;
665         }
666
667         return NOTIFICATION_ERROR_NONE;
668 }
669
670 EXPORT_API int notification_set_pkgname(notification_h noti,
671                                                          const char *pkgname)
672 {
673         /* check noti and pkgname are valid data */
674         if (noti == NULL || pkgname == NULL)
675                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
676
677         /* Remove previous caller pkgname */
678         if (noti->caller_pkgname) {
679                 free(noti->caller_pkgname);
680                 noti->caller_pkgname = NULL;
681         }
682
683         noti->caller_pkgname = strdup(pkgname);
684
685         return NOTIFICATION_ERROR_NONE;
686 }
687
688 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
689                                                                 notification_type_e type)
690 {
691         int ret = 0;
692         char *caller_pkgname = NULL;
693
694         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
695                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
696
697         if (pkgname == NULL)
698                 caller_pkgname = notification_get_pkgname_by_pid();
699         else
700                 caller_pkgname = strdup(pkgname);
701
702         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
703
704         if (caller_pkgname)
705                 free(caller_pkgname);
706
707         return ret;
708 }
709
710 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
711                                                                notification_type_e type,
712                                                                int priv_id)
713 {
714         int ret = 0;
715         char *caller_pkgname = NULL;
716
717         if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
718                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
719
720         if (pkgname == NULL)
721                 caller_pkgname = notification_get_pkgname_by_pid();
722         else
723                 caller_pkgname = strdup(pkgname);
724
725         ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
726
727         if (caller_pkgname)
728                 free(caller_pkgname);
729
730         return ret;
731 }
732
733 EXPORT_API int notification_set_execute_option(notification_h noti,
734                                                                 notification_execute_type_e type,
735                                                                 const char *text,
736                                                                 const char *key,
737                                                                 bundle *service_handle)
738 {
739         char buf_key[32] = { 0, };
740         char *ret_val = NULL;
741         bundle *b = NULL;
742
743         if (noti == NULL)
744                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
745
746         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
747             || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
748                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
749
750         /* Create execute option bundle if does not exist */
751         if (noti->b_execute_option == NULL)
752                 noti->b_execute_option = bundle_create();
753
754         b = noti->b_execute_option;
755
756         /* Save text */
757         if (text != NULL) {
758                 /* Make text key */
759                 snprintf(buf_key, sizeof(buf_key), "text%d", type);
760
761                 /* Check text key exist */
762                 bundle_get_str(b, buf_key, &ret_val);
763                 if (ret_val != NULL)
764                         /* Remove previous data */
765                         bundle_del(b, buf_key);
766
767                 /* Add text data */
768                 bundle_add_str(b, buf_key, text);
769         }
770
771         /* Save key */
772         if (key != NULL) {
773                 /* Make key key */
774                 snprintf(buf_key, sizeof(buf_key), "key%d", type);
775
776                 /* Check key key exist */
777                 bundle_get_str(b, buf_key, &ret_val);
778                 if (ret_val != NULL)
779                         /* Remove previous data */
780                         bundle_del(b, buf_key);
781
782                 /* Add text data */
783                 bundle_add_str(b, buf_key, key);
784         }
785
786         switch ((int)type) {
787         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
788                 /* Remove previous data if exist */
789                 if (noti->b_service_responding != NULL) {
790                         bundle_free(noti->b_service_responding);
791                         noti->b_service_responding = NULL;
792                 }
793
794                 /* Save service handle */
795                 if (service_handle != NULL)
796                         noti->b_service_responding = bundle_dup(service_handle);
797
798                 break;
799         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
800                 /* Remove previous data if exist */
801                 if (noti->b_service_single_launch != NULL) {
802                         bundle_free(noti->b_service_single_launch);
803                         noti->b_service_single_launch = NULL;
804                 }
805
806                 /* Save service handle */
807                 if (service_handle != NULL)
808                         noti->b_service_single_launch =
809                                 bundle_dup(service_handle);
810
811                 break;
812         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
813                 /* Remove previous data if exist */
814                 if (noti->b_service_multi_launch != NULL) {
815                         bundle_free(noti->b_service_multi_launch);
816                         noti->b_service_multi_launch = NULL;
817                 }
818
819                 /* Save service handle */
820                 if (service_handle != NULL)
821                         noti->b_service_multi_launch =
822                                 bundle_dup(service_handle);
823
824                 break;
825         }
826
827         return NOTIFICATION_ERROR_NONE;
828 }
829
830 EXPORT_API int notification_get_id(notification_h noti,
831                                                     int *group_id, int *priv_id)
832 {
833         /* check noti is valid data */
834         if (noti == NULL)
835                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
836
837         /* Check group_id is valid data */
838         if (group_id) {
839                 /* Set group id */
840                 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
841                         *group_id = NOTIFICATION_GROUP_ID_NONE;
842                 else
843                         *group_id = noti->group_id;
844         }
845
846         /* Check priv_id is valid data */
847         if (priv_id)
848                 /* Set priv_id */
849                 *priv_id = noti->priv_id;
850
851         return NOTIFICATION_ERROR_NONE;
852 }
853
854 EXPORT_API notification_h notification_load(char *pkgname,
855                                                       int priv_id)
856 {
857         int ret = 0;
858         notification_h noti = NULL;
859
860         noti = (notification_h)calloc(1, sizeof(struct _notification));
861         if (noti == NULL) {
862                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
863                 return NULL;
864         }
865
866         ret = notification_ipc_request_load_noti_by_priv_id(noti, pkgname, priv_id);
867         if (ret != NOTIFICATION_ERROR_NONE) {
868                 notification_free(noti);
869                 return NULL;
870         }
871
872         return noti;
873 }
874
875 EXPORT_API notification_h notification_new(notification_type_e type,
876                                            int group_id, int priv_id)
877 {
878         return notification_create(type);
879 }
880
881 static void _notification_get_text_domain(notification_h noti)
882 {
883 /*
884         if (noti->domain != NULL) {
885
886         }
887
888         if (noti->dir != NULL) {
889
890         }
891 */
892 }
893
894 EXPORT_API int notification_get_execute_option(notification_h noti,
895                                                                 notification_execute_type_e type,
896                                                                 const char **text,
897                                                                 bundle **service_handle)
898 {
899         char buf_key[32] = { 0, };
900         char *ret_val = NULL;
901         char *get_str = NULL;
902         bundle *b = NULL;
903
904         if (noti == NULL)
905                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
906
907         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
908             || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
909                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
910
911
912         switch (type) {
913         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
914                 b = noti->b_service_responding;
915                 break;
916         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
917                 b = noti->b_service_single_launch;
918                 break;
919         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
920                 b = noti->b_service_multi_launch;
921                 break;
922         default:
923                 break;
924         }
925
926         if (b != NULL) {
927         /* Return text */
928                 if (text != NULL) {
929                         /*  Get text domain and dir */
930                         if (noti->domain == NULL || noti->dir == NULL)
931                                 _notification_get_text_domain(noti);
932
933                         /* Make key */
934                         snprintf(buf_key, sizeof(buf_key), "key%d", type);
935
936                         /* Check key key exist */
937                         bundle_get_str(b, buf_key, &ret_val);
938                         if (ret_val != NULL && noti->domain != NULL
939                             && noti->dir != NULL) {
940                                 /* Get application string */
941                                 bindtextdomain(noti->domain, noti->dir);
942
943                                 get_str = dgettext(noti->domain, ret_val);
944
945                                 *text = get_str;
946                         } else if (ret_val != NULL) {
947                                 /* Get system string */
948                                 get_str = dgettext("sys_string", ret_val);
949
950                                 *text = get_str;
951                         } else {
952                                 /* Get basic text */
953                                 snprintf(buf_key, sizeof(buf_key), "text%d",
954                                          type);
955
956                                 bundle_get_str(b, buf_key, &ret_val);
957
958                                 *text = ret_val;
959                         }
960                 }
961         }
962
963         if (service_handle != NULL)
964                 *service_handle = b;
965
966         return NOTIFICATION_ERROR_NONE;
967 }
968
969 EXPORT_API int notification_insert(notification_h noti,
970                                                     int *priv_id)
971 {
972         int ret = 0;
973         int id = 0;
974
975         /* Check noti is vaild data */
976         if (noti == NULL)
977                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
978
979         /* Check noti type is valid type */
980         if (noti->type <= NOTIFICATION_TYPE_NONE
981             || noti->type >= NOTIFICATION_TYPE_MAX)
982                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
983
984         /* Save insert time */
985         noti->insert_time = time(NULL);
986         ret = notification_ipc_request_insert(noti, &id);
987         if (ret != NOTIFICATION_ERROR_NONE)
988                 return ret;
989
990         noti->priv_id = id;
991         NOTIFICATION_DBG("from master:%d", id);
992
993         /* If priv_id is valid data, set priv_id */
994         if (priv_id != NULL)
995                 *priv_id = noti->priv_id;
996
997         return NOTIFICATION_ERROR_NONE;
998 }
999
1000 EXPORT_API int notification_update_async(notification_h noti,
1001                 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1002 {
1003         int ret = 0;
1004
1005         if (noti == NULL)
1006                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1007
1008         /* Update insert time ? */
1009         noti->insert_time = time(NULL);
1010         ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1011
1012         return ret;
1013 }
1014
1015 EXPORT_API int notification_register_detailed_changed_cb(
1016                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1017                 void *user_data)
1018 {
1019         notification_cb_list_s *noti_cb_list_new = NULL;
1020         notification_cb_list_s *noti_cb_list = NULL;
1021
1022         if (detailed_changed_cb == NULL)
1023                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1024
1025         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE)
1026                 return NOTIFICATION_ERROR_IO_ERROR;
1027
1028         noti_cb_list_new =
1029             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
1030
1031         if (noti_cb_list_new == NULL) {
1032                 NOTIFICATION_ERR("malloc failed");
1033                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1034         }
1035
1036         noti_cb_list_new->next = NULL;
1037         noti_cb_list_new->prev = NULL;
1038
1039         noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
1040         noti_cb_list_new->changed_cb = NULL;
1041         noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
1042         noti_cb_list_new->data = user_data;
1043
1044         if (g_notification_cb_list == NULL) {
1045                 g_notification_cb_list = noti_cb_list_new;
1046         } else {
1047                 noti_cb_list = g_notification_cb_list;
1048
1049                 while (noti_cb_list->next != NULL)
1050                         noti_cb_list = noti_cb_list->next;
1051
1052
1053                 noti_cb_list->next = noti_cb_list_new;
1054                 noti_cb_list_new->prev = noti_cb_list;
1055         }
1056         return NOTIFICATION_ERROR_NONE;
1057 }
1058
1059 EXPORT_API int notification_unregister_detailed_changed_cb(
1060                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1061                 void *user_data)
1062 {
1063         notification_cb_list_s *noti_cb_list = NULL;
1064         notification_cb_list_s *noti_cb_list_prev = NULL;
1065         notification_cb_list_s *noti_cb_list_next = NULL;
1066
1067         noti_cb_list = g_notification_cb_list;
1068
1069         if (detailed_changed_cb == NULL)
1070                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1071
1072         if (noti_cb_list == NULL)
1073                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1074
1075
1076         while (noti_cb_list->prev != NULL)
1077                 noti_cb_list = noti_cb_list->prev;
1078
1079
1080         do {
1081                 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
1082                         noti_cb_list_prev = noti_cb_list->prev;
1083                         noti_cb_list_next = noti_cb_list->next;
1084
1085                         if (noti_cb_list_prev == NULL)
1086                                 g_notification_cb_list = noti_cb_list_next;
1087                         else
1088                                 noti_cb_list_prev->next = noti_cb_list_next;
1089
1090                         if (noti_cb_list_next == NULL) {
1091                                 if (noti_cb_list_prev != NULL)
1092                                         noti_cb_list_prev->next = NULL;
1093
1094                         } else {
1095                                 noti_cb_list_next->prev = noti_cb_list_prev;
1096                         }
1097
1098                         free(noti_cb_list);
1099
1100                         if (g_notification_cb_list == NULL)
1101                                 notification_ipc_monitor_fini();
1102
1103                         return NOTIFICATION_ERROR_NONE;
1104                 }
1105                 noti_cb_list = noti_cb_list->next;
1106         } while (noti_cb_list != NULL);
1107
1108         return NOTIFICATION_ERROR_INVALID_PARAMETER;
1109 }
1110
1111 EXPORT_API int notification_is_service_ready(void)
1112 {
1113         return notification_ipc_is_master_ready();
1114 }
1115