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