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