New API set for 'heads-up notification'
[platform/core/api/notification.git] / src / notification.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 static void (*posted_toast_message_cb) (void *data);
70
71 #define NOTI_TEXT_RESULT_LEN 2048
72 #define NOTI_PKGNAME_LEN        512
73
74 static char *_notification_get_pkgname_by_pid(void)
75 {
76         char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
77         int pid = 0, ret = AUL_R_OK;
78         int fd;
79         char  *dup_pkgname;
80
81         pid = getpid();
82
83         ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
84         if (ret != AUL_R_OK) {
85                 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
86
87                 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
88
89                 fd = open(buf, O_RDONLY);
90                 if (fd < 0) {
91                         return NULL;
92                 }
93
94                 ret = read(fd, pkgname, sizeof(pkgname) - 1);
95                 close(fd);
96
97                 if (ret <= 0) {
98                         return NULL;
99                 }
100
101                 pkgname[ret] = '\0';
102                 /*!
103                  * \NOTE
104                  * "ret" is not able to be larger than "sizeof(pkgname) - 1",
105                  * if the system is not going wrong.
106                  */
107         } else {
108                 if (strlen(pkgname) <= 0) {
109                         return NULL;
110                 }
111         }
112
113         dup_pkgname = strdup(pkgname);
114         if (!dup_pkgname)
115                 NOTIFICATION_ERR("Heap: %s\n", strerror(errno));
116
117         return dup_pkgname;
118 }
119
120 static void _notification_get_text_domain(notification_h noti)
121 {
122         if (noti->domain != NULL) {
123
124         }
125
126         if (noti->dir != NULL) {
127
128         }
129 }
130
131 EXPORT_API int notification_set_image(notification_h noti,
132                                                        notification_image_type_e type,
133                                                        const char *image_path)
134 {
135         bundle *b = NULL;
136         char buf_key[32] = { 0, };
137         const char *ret_val = NULL;
138
139         /* Check noti and image_path are valid data */
140         if (noti == NULL || image_path == NULL) {
141                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
142         }
143
144         /* Check image type is valid type */
145         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
146             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
147                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
148         }
149
150         /* Check image path bundle is exist */
151         if (noti->b_image_path) {
152                 /* If image path bundle is exist, store local bundle value */
153                 b = noti->b_image_path;
154
155                 /* Set image type to key as char string type */
156                 snprintf(buf_key, sizeof(buf_key), "%d", type);
157
158                 /* Get value using key */
159                 ret_val = bundle_get_val(b, buf_key);
160                 if (ret_val != NULL) {
161                         /* If key is exist, remove this value to store new image path */
162                         bundle_del(b, buf_key);
163                 }
164
165                 /* Add new image path with type key */
166                 bundle_add(b, buf_key, image_path);
167         } else {
168                 /* If image path bundle is not exist, create new one */
169                 b = bundle_create();
170
171                 /* Set image type to key as char string type */
172                 snprintf(buf_key, sizeof(buf_key), "%d", type);
173
174                 /* Add new image path with type key */
175                 bundle_add(b, buf_key, image_path);
176
177                 /* Save to image path bundle */
178                 noti->b_image_path = b;
179         }
180
181         return NOTIFICATION_ERROR_NONE;
182 }
183
184 EXPORT_API int notification_get_image(notification_h noti,
185                                                        notification_image_type_e type,
186                                                        char **image_path)
187 {
188         bundle *b = NULL;
189         char buf_key[32] = { 0, };
190         const char *ret_val = NULL;
191
192         /* Check noti and image_path is valid data */
193         if (noti == NULL || image_path == NULL) {
194                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
195         }
196
197         /* Check image type is valid data */
198         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
199             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
200                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
201         }
202
203         /* Check image path bundle exist */
204         if (noti->b_image_path) {
205                 /* If image path bundle exist, store local bundle data */
206                 b = noti->b_image_path;
207
208                 /* Set image type to key as char string type */
209                 snprintf(buf_key, sizeof(buf_key), "%d", type);
210
211                 /* Get value of key */
212                 ret_val = bundle_get_val(b, buf_key);
213
214                 *image_path = (char *)ret_val;
215         } else {
216                 /* If image path bundle does not exist, image path is NULL */
217                 *image_path = NULL;
218         }
219
220         /* If image path is NULL and type is ICON, icon path set from AIL */
221         /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
222         if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
223                 /* Check App icon path is already set */
224                 if (noti->app_icon_path != NULL) {
225                         /* image path will be app icon path */
226                         *image_path = noti->app_icon_path;
227                 } else {
228                         *image_path = NULL;
229                 }
230         }
231
232         return NOTIFICATION_ERROR_NONE;
233 }
234
235 EXPORT_API int notification_set_time(notification_h noti,
236                                                       time_t input_time)
237 {
238         /* Check noti is valid data */
239         if (noti == NULL) {
240                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
241         }
242
243         if (input_time == 0) {
244                 /* If input time is 0, set current time */
245                 noti->time = time(NULL);
246         } else {
247                 /* save input time */
248                 noti->time = input_time;
249         }
250
251         return NOTIFICATION_ERROR_NONE;
252 }
253
254 EXPORT_API int notification_get_time(notification_h noti,
255                                                       time_t * ret_time)
256 {
257         /* Check noti and time is valid data */
258         if (noti == NULL || ret_time == NULL) {
259                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
260         }
261
262         /* Set time infomation */
263         *ret_time = noti->time;
264
265         return NOTIFICATION_ERROR_NONE;
266 }
267
268 EXPORT_API int notification_get_insert_time(notification_h noti,
269                                                              time_t * ret_time)
270 {
271         /* Check noti and ret_time is valid data */
272         if (noti == NULL || ret_time == NULL) {
273                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
274         }
275
276         /* Set insert time information */
277         *ret_time = noti->insert_time;
278
279         return NOTIFICATION_ERROR_NONE;
280 }
281
282 EXPORT_API int notification_set_text(notification_h noti,
283                                                       notification_text_type_e type,
284                                                       const char *text,
285                                                       const char *key,
286                                                       int args_type, ...)
287 {
288         bundle *b = NULL;
289         char buf_key[32] = { 0, };
290         char buf_val[1024] = { 0, };
291         const char *ret_val = NULL;
292         va_list var_args;
293         notification_variable_type_e var_type;
294         int num_args = 0;
295         int noti_err = NOTIFICATION_ERROR_NONE;
296         int var_value_int = 0;
297         double var_value_double = 0.0;
298         char *var_value_string = NULL;
299         notification_count_pos_type_e var_value_count =
300             NOTIFICATION_COUNT_POS_NONE;
301
302         /* Check noti is valid data */
303         if (noti == NULL) {
304                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
305         }
306
307         /* Check text type is valid type */
308         if (type <= NOTIFICATION_TEXT_TYPE_NONE
309             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
310                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
311         }
312
313         /* Check text bundle exist */
314         if (text != NULL) {
315                 if (noti->b_text != NULL) {
316                         /* If text bundle exist, store local bundle data */
317                         b = noti->b_text;
318
319                         /* Make type to key as char string */
320                         snprintf(buf_key, sizeof(buf_key), "%d", type);
321
322                         /* Get value using type key */
323                         ret_val = bundle_get_val(b, buf_key);
324                         if (ret_val != NULL) {
325                                 /* If value exist, remove this to add new value */
326                                 bundle_del(b, buf_key);
327                         }
328
329                         snprintf(buf_val, sizeof(buf_val), "%s", text);
330
331                         /* Add new text value */
332                         bundle_add(b, buf_key, buf_val);
333                 } else {
334                         /* If text bundle does not exist, create new one */
335                         b = bundle_create();
336
337                         /* Make type to key as char string */
338                         snprintf(buf_key, sizeof(buf_key), "%d", type);
339
340                         snprintf(buf_val, sizeof(buf_val), "%s", text);
341
342                         /* Add new text value */
343                         bundle_add(b, buf_key, buf_val);
344
345                         /* Save text bundle */
346                         noti->b_text = b;
347                 }
348         } else {
349                 /* Reset if text is NULL */
350                 if (noti->b_text != NULL) {
351                         /* If text bundle exist, store local bundle data */
352                         b = noti->b_text;
353
354                         /* Make type to key as char string */
355                         snprintf(buf_key, sizeof(buf_key), "%d", type);
356
357                         /* Get value using type key */
358                         ret_val = bundle_get_val(b, buf_key);
359                         if (ret_val != NULL) {
360                                 /* If value exist, remove this */
361                                 bundle_del(b, buf_key);
362                         }
363                 }
364         }
365
366         /* Save key if key is valid data */
367         if (key != NULL) {
368                 /* Check key bundle exist */
369                 if (noti->b_key != NULL) {
370                         /* If key bundle exist,  store local bundle data */
371                         b = noti->b_key;
372
373                         /* Make type to key as char string */
374                         snprintf(buf_key, sizeof(buf_key), "%d", type);
375
376                         /* Get value using type key */
377                         ret_val = bundle_get_val(b, buf_key);
378                         if (ret_val != NULL) {
379                                 /* If value exist, remove this to add new value */
380                                 bundle_del(b, buf_key);
381                         }
382
383                         snprintf(buf_val, sizeof(buf_val), "%s", key);
384
385                         /* Add new key value */
386                         bundle_add(b, buf_key, buf_val);
387                 } else {
388                         /* If key bundle does not exist, create new one */
389                         b = bundle_create();
390
391                         /* Make type to key as char string */
392                         snprintf(buf_key, sizeof(buf_key), "%d", type);
393
394                         snprintf(buf_val, sizeof(buf_val), "%s", key);
395
396                         /* Add new key value */
397                         bundle_add(b, buf_key, buf_val);
398
399                         /* Save key bundle */
400                         noti->b_key = b;
401                 }
402         } else {
403                 /* Reset if key is NULL */
404                 if (noti->b_key != NULL) {
405                         /* If key bundle exist,  store local bundle data */
406                         b = noti->b_key;
407
408                         /* Make type to key as char string */
409                         snprintf(buf_key, sizeof(buf_key), "%d", type);
410
411                         /* Get value using type key */
412                         ret_val = bundle_get_val(b, buf_key);
413                         if (ret_val != NULL) {
414                                 /* If value exist, remove this */
415                                 bundle_del(b, buf_key);
416                         }
417                 }
418         }
419
420         if (noti->b_format_args != NULL) {
421                 b = noti->b_format_args;
422         } else {
423                 b = bundle_create();
424         }
425
426         va_start(var_args, args_type);
427
428         var_type = args_type;
429         num_args = 0;
430
431         while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
432                 /* Type */
433                 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
434                 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
435
436                 ret_val = bundle_get_val(b, buf_key);
437                 if (ret_val != NULL) {
438                         bundle_del(b, buf_key);
439                 }
440
441                 bundle_add(b, buf_key, buf_val);
442
443                 switch (var_type) {
444                 case NOTIFICATION_VARIABLE_TYPE_INT:
445                         var_value_int = va_arg(var_args, int);
446
447                         /* Value */
448                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
449                                  num_args);
450                         snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
451
452                         ret_val = bundle_get_val(b, buf_key);
453                         if (ret_val != NULL) {
454                                 bundle_del(b, buf_key);
455                         }
456
457                         bundle_add(b, buf_key, buf_val);
458                         break;
459                 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
460                         var_value_double = va_arg(var_args, double);
461
462                         /* Value */
463                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
464                                  num_args);
465                         snprintf(buf_val, sizeof(buf_val), "%.2f",
466                                  var_value_double);
467
468                         ret_val = bundle_get_val(b, buf_key);
469                         if (ret_val != NULL) {
470                                 bundle_del(b, buf_key);
471                         }
472
473                         bundle_add(b, buf_key, buf_val);
474                         break;
475                 case NOTIFICATION_VARIABLE_TYPE_STRING:
476                         var_value_string = va_arg(var_args, char *);
477
478                         /* Value */
479                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
480                                  num_args);
481                         snprintf(buf_val, sizeof(buf_val), "%s",
482                                  var_value_string);
483
484                         ret_val = bundle_get_val(b, buf_key);
485                         if (ret_val != NULL) {
486                                 bundle_del(b, buf_key);
487                         }
488
489                         bundle_add(b, buf_key, buf_val);
490                         break;
491                 case NOTIFICATION_VARIABLE_TYPE_COUNT:
492                         var_value_count =
493                             va_arg(var_args, notification_count_pos_type_e);
494
495                         /* Value */
496                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
497                                  num_args);
498                         snprintf(buf_val, sizeof(buf_val), "%d",
499                                  var_value_count);
500
501                         ret_val = bundle_get_val(b, buf_key);
502                         if (ret_val != NULL) {
503                                 bundle_del(b, buf_key);
504                         }
505
506                         bundle_add(b, buf_key, buf_val);
507                         break;
508                 default:
509                         NOTIFICATION_ERR("Error. invalid variable type. : %d",
510                                          var_type);
511                         noti_err = NOTIFICATION_ERROR_INVALID_PARAMETER;
512                         break;
513                 }
514
515                 num_args++;
516                 var_type = va_arg(var_args, notification_variable_type_e);
517         }
518         va_end(var_args);
519
520         if (noti_err == NOTIFICATION_ERROR_NONE) {
521                 noti->num_format_args = num_args;
522         } else {
523                 noti->num_format_args = 0;
524         }
525
526         snprintf(buf_key, sizeof(buf_key), "num%d", type);
527         snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
528
529         ret_val = bundle_get_val(b, buf_key);
530         if (ret_val != NULL) {
531                 bundle_del(b, buf_key);
532         }
533
534         bundle_add(b, buf_key, buf_val);
535
536         noti->b_format_args = b;
537
538         return noti_err;
539 }
540
541 EXPORT_API int notification_get_text(notification_h noti,
542                                                       notification_text_type_e type,
543                                                       char **text)
544 {
545         bundle *b = NULL;
546         char buf_key[32] = { 0, };
547         const char *ret_val = NULL;
548         const char *get_str = NULL;
549         const char *get_check_type_str = NULL;
550         notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
551         //int display_option_flag = 0;
552
553         char *temp_str = NULL;
554         char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
555         char buf_str[1024] = { 0, };
556         int num_args = 0;
557         notification_variable_type_e ret_var_type = 0;
558         int ret_variable_int = 0;
559         double ret_variable_double = 0.0;
560
561         /* Check noti is valid data */
562         if (noti == NULL || text == NULL) {
563                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
564         }
565
566         /* Check text type is valid type */
567         if (type <= NOTIFICATION_TEXT_TYPE_NONE
568             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
569                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
570         }
571
572         /* Check key */
573         if (noti->b_key != NULL) {
574                 b = noti->b_key;
575
576                 /* Get text domain and dir */
577                 //_notification_get_text_domain(noti);
578
579                 snprintf(buf_key, sizeof(buf_key), "%d", type);
580
581                 ret_val = bundle_get_val(b, buf_key);
582                 if (ret_val != NULL && noti->domain != NULL
583                     && noti->dir != NULL) {
584                         /* Get application string */
585                         bindtextdomain(noti->domain, noti->dir);
586
587                         get_str = dgettext(noti->domain, ret_val);
588                 } else if (ret_val != NULL) {
589                         /* Get system string */
590                         get_str = dgettext("sys_string", ret_val);
591                 } else {
592                         get_str = NULL;
593                 }
594         }
595
596         if (get_str == NULL && noti->b_text != NULL) {
597                 b = noti->b_text;
598                 /* Get basic text */
599                 snprintf(buf_key, sizeof(buf_key), "%d", type);
600
601                 get_str = bundle_get_val(b, buf_key);
602         }
603
604         check_type = type;
605
606         /* Set display option is off type when option is off, type is noti */
607         /*if (get_str != NULL && display_option_flag == 1
608             && noti->type == NOTIFICATION_TYPE_NOTI) {
609                 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
610                     || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
611                         // Set check_type to option content string 
612                         if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
613                                 check_type =
614                                     NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
615                         } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
616                                 check_type =
617                                     NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
618                         }
619
620                         // Check key 
621                         if (noti->b_key != NULL) {
622                                 b = noti->b_key;
623
624                                 // Get text domain and dir 
625                                 _notification_get_text_domain(noti);
626
627                                 snprintf(buf_key, sizeof(buf_key), "%d",
628                                          check_type);
629
630                                 ret_val = bundle_get_val(b, buf_key);
631                                 if (ret_val != NULL && noti->domain != NULL
632                                     && noti->dir != NULL) {
633                                         // Get application string 
634                                         bindtextdomain(noti->domain, noti->dir);
635
636                                         get_check_type_str =
637                                             dgettext(noti->domain, ret_val);
638                                 } else if (ret_val != NULL) {
639                                         // Get system string 
640                                         get_check_type_str =
641                                             dgettext("sys_string", ret_val);
642                                 } else {
643                                         get_check_type_str = NULL;
644                                 }
645                         }
646
647                         if (get_check_type_str == NULL && noti->b_text != NULL) {
648                                 b = noti->b_text;
649                                 // Get basic text 
650                                 snprintf(buf_key, sizeof(buf_key), "%d",
651                                          check_type);
652
653                                 get_check_type_str = bundle_get_val(b, buf_key);
654                         }
655                 }
656
657                 if (get_check_type_str != NULL) {
658                         // Replace option off type string 
659                         get_str = get_check_type_str;
660                 } else {
661                         // Set default string 
662                         get_str =
663                             dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
664                 }
665         }*/
666
667         if (get_str != NULL) {
668                 /* Get number format args */
669                 b = noti->b_format_args;
670                 noti->num_format_args = 0;
671
672                 if (b != NULL) {
673                         snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
674                         ret_val = bundle_get_val(b, buf_key);
675                         if (ret_val != NULL) {
676                                 noti->num_format_args = atoi(ret_val);
677                         }
678                 }
679
680                 if (noti->num_format_args == 0) {
681                         *text = (char *)get_str;
682                 } else {
683                         /* Check first variable is count, LEFT pos */
684                         snprintf(buf_key, sizeof(buf_key), "%dtype%d",
685                                  check_type, num_args);
686                         ret_val = bundle_get_val(b, buf_key);
687                         ret_var_type = atoi(ret_val);
688
689                         if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
690                                 /* Get var Value */
691                                 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
692                                          check_type, num_args);
693                                 ret_val = bundle_get_val(b, buf_key);
694                                 ret_variable_int = atoi(ret_val);
695
696                                 if (ret_variable_int ==
697                                     NOTIFICATION_COUNT_POS_LEFT) {
698                                         notification_noti_get_count(noti->type,
699                                                                     noti->caller_pkgname,
700                                                                     noti->group_id,
701                                                                     noti->priv_id,
702                                                                     &ret_variable_int);
703                                         snprintf(buf_str, sizeof(buf_str),
704                                                  "%d ", ret_variable_int);
705
706                                         int src_len = strlen(result_str);
707                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
708
709                                         strncat(result_str, buf_str,
710                                                         max_len);
711
712                                         num_args++;
713                                 }
714
715                         }
716
717                         /* Check variable IN pos */
718                         for (temp_str = (char *)get_str; *temp_str != '\0';
719                              temp_str++) {
720                                 if (*temp_str != '%') {
721                                         strncat(result_str, temp_str, 1);
722                                 } else {
723                                         if (*(temp_str + 1) == '%') {
724                                                 strncat(result_str, temp_str,
725                                                         1);
726                                         } else if (*(temp_str + 1) == 'd') {
727                                                 /* Get var Type */
728                                                 ret_variable_int = 0;
729
730                                                 snprintf(buf_key,
731                                                          sizeof(buf_key),
732                                                          "%dtype%d", check_type,
733                                                          num_args);
734                                                 ret_val =
735                                                     bundle_get_val(b, buf_key);
736                                                 ret_var_type = atoi(ret_val);
737                                                 if (ret_var_type ==
738                                                     NOTIFICATION_VARIABLE_TYPE_COUNT)
739                                                 {
740                                                         /* Get notification count */
741                                                         notification_noti_get_count
742                                                             (noti->type,
743                                                              noti->caller_pkgname,
744                                                              noti->group_id,
745                                                              noti->priv_id,
746                                                              &ret_variable_int);
747                                                 } else {
748                                                         /* Get var Value */
749                                                         snprintf(buf_key,
750                                                                  sizeof
751                                                                  (buf_key),
752                                                                  "%dvalue%d",
753                                                                  check_type,
754                                                                  num_args);
755                                                         ret_val =
756                                                             bundle_get_val(b,
757                                                                            buf_key);
758                                                         ret_variable_int =
759                                                             atoi(ret_val);
760                                                 }
761
762                                                 snprintf(buf_str,
763                                                          sizeof(buf_str), "%d",
764                                                          ret_variable_int);
765
766                                                 int src_len = strlen(result_str);
767                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
768
769                                                 strncat(result_str, buf_str,
770                                                                 max_len);
771
772                                                 temp_str++;
773
774                                                 num_args++;
775                                         } else if (*(temp_str + 1) == 's') {
776                                                 /* Get var Value */
777                                                 snprintf(buf_key,
778                                                          sizeof(buf_key),
779                                                          "%dvalue%d",
780                                                          check_type, num_args);
781                                                 ret_val =
782                                                     bundle_get_val(b, buf_key);
783
784                                                 snprintf(buf_str,
785                                                          sizeof(buf_str), "%s",
786                                                          ret_val);
787
788                                                 int src_len = strlen(result_str);
789                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
790
791                                                 strncat(result_str, buf_str,
792                                                                 max_len);
793
794                                                 temp_str++;
795
796                                                 num_args++;
797                                         } else if (*(temp_str + 1) == 'f') {
798                                                 /* Get var Value */
799                                                 snprintf(buf_key,
800                                                          sizeof(buf_key),
801                                                          "%dvalue%d",
802                                                          check_type, num_args);
803                                                 ret_val =
804                                                     bundle_get_val(b, buf_key);
805                                                 ret_variable_double =
806                                                     atof(ret_val);
807
808                                                 snprintf(buf_str,
809                                                          sizeof(buf_str),
810                                                          "%.2f",
811                                                          ret_variable_double);
812
813                                                 int src_len = strlen(result_str);
814                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
815
816                                                 strncat(result_str, buf_str,
817                                                                 max_len);
818
819                                                 temp_str++;
820
821                                                 num_args++;
822                                         } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
823                                                 if (*(temp_str + 3) == 'd') {
824                                                         /* Get var Type */
825                                                         ret_variable_int = 0;
826
827                                                         snprintf(buf_key,
828                                                                  sizeof(buf_key),
829                                                                  "%dtype%d", check_type,
830                                                                  num_args + *(temp_str + 1) - 49);
831                                                         ret_val =
832                                                             bundle_get_val(b, buf_key);
833                                                         ret_var_type = atoi(ret_val);
834                                                         if (ret_var_type ==
835                                                             NOTIFICATION_VARIABLE_TYPE_COUNT)
836                                                         {
837                                                                 /* Get notification count */
838                                                                 notification_noti_get_count
839                                                                     (noti->type,
840                                                                      noti->caller_pkgname,
841                                                                      noti->group_id,
842                                                                      noti->priv_id,
843                                                                      &ret_variable_int);
844                                                         } else {
845                                                                 /* Get var Value */
846                                                                 snprintf(buf_key,
847                                                                          sizeof
848                                                                          (buf_key),
849                                                                          "%dvalue%d",
850                                                                          check_type,
851                                                                          num_args + *(temp_str + 1) - 49);
852                                                                 ret_val =
853                                                                     bundle_get_val(b,
854                                                                                    buf_key);
855                                                                 ret_variable_int =
856                                                                     atoi(ret_val);
857                                                         }
858
859                                                         snprintf(buf_str,
860                                                                  sizeof(buf_str), "%d",
861                                                                  ret_variable_int);
862
863                                                         int src_len = strlen(result_str);
864                                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
865
866                                                         strncat(result_str, buf_str,
867                                                                         max_len);
868
869                                                         temp_str += 3;
870                                                 } else if (*(temp_str + 3) == 's') {
871                                                         /* Get var Value */
872                                                         snprintf(buf_key,
873                                                                  sizeof(buf_key),
874                                                                  "%dvalue%d",
875                                                                  check_type, num_args + *(temp_str + 1) - 49);
876                                                         ret_val =
877                                                             bundle_get_val(b, buf_key);
878
879                                                         snprintf(buf_str,
880                                                                  sizeof(buf_str), "%s",
881                                                                  ret_val);
882
883                                                         int src_len = strlen(result_str);
884                                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
885
886                                                         strncat(result_str, buf_str,
887                                                                         max_len);
888
889                                                         temp_str += 3;
890                                                 } else if (*(temp_str + 3) == 'f') {
891                                                         /* Get var Value */
892                                                         snprintf(buf_key,
893                                                                  sizeof(buf_key),
894                                                                  "%dvalue%d",
895                                                                  check_type, num_args + *(temp_str + 1) - 49);
896                                                         ret_val =
897                                                             bundle_get_val(b, buf_key);
898                                                         ret_variable_double =
899                                                             atof(ret_val);
900
901                                                         snprintf(buf_str,
902                                                                  sizeof(buf_str),
903                                                                  "%.2f",
904                                                                  ret_variable_double);
905
906                                                         int src_len = strlen(result_str);
907                                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
908
909                                                         strncat(result_str, buf_str,
910                                                                         max_len);
911
912                                                         temp_str += 3;
913                                                 }
914                                         }
915                                 }
916
917                         }
918
919                         /* Check last variable is count, LEFT pos */
920                         if (num_args < noti->num_format_args) {
921                                 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
922                                          check_type, num_args);
923                                 ret_val = bundle_get_val(b, buf_key);
924                                 ret_var_type = atoi(ret_val);
925                                 if (ret_var_type ==
926                                     NOTIFICATION_VARIABLE_TYPE_COUNT) {
927                                         /* Get var Value */
928                                         snprintf(buf_key, sizeof(buf_key),
929                                                  "%dvalue%d", check_type,
930                                                  num_args);
931                                         ret_val = bundle_get_val(b, buf_key);
932                                         ret_variable_int = atoi(ret_val);
933
934                                         if (ret_variable_int ==
935                                             NOTIFICATION_COUNT_POS_RIGHT) {
936                                                 notification_noti_get_count
937                                                     (noti->type,
938                                                      noti->caller_pkgname,
939                                                      noti->group_id,
940                                                      noti->priv_id,
941                                                      &ret_variable_int);
942                                                 snprintf(buf_str,
943                                                          sizeof(buf_str), " %d",
944                                                          ret_variable_int);
945
946                                                 int src_len = strlen(result_str);
947                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
948
949                                                 strncat(result_str, buf_str,
950                                                                 max_len);
951
952                                                 num_args++;
953                                         }
954
955                                 }
956                         }
957
958                         switch (check_type) {
959                         case NOTIFICATION_TEXT_TYPE_TITLE:
960                         case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
961                                 if (noti->temp_title != NULL)
962                                         free(noti->temp_title);
963
964                                 noti->temp_title = strdup(result_str);
965
966                                 *text = noti->temp_title;
967                                 break;
968                         case NOTIFICATION_TEXT_TYPE_CONTENT:
969                         case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
970                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
971                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
972                                 if (noti->temp_content !=
973                                     NULL)
974                                         free(noti->temp_content);
975
976                                 noti->temp_content = strdup(result_str);
977
978                                 *text = noti->temp_content;
979                                 break;
980                         default:
981                                 break;
982                         }
983
984                 }
985
986         } else {
987                 *text = NULL;
988         }
989
990         return NOTIFICATION_ERROR_NONE;
991 }
992
993 EXPORT_API int notification_set_text_domain(notification_h noti,
994                                                              const char *domain,
995                                                              const char *dir)
996 {
997         /* check noti and domain is valid data */
998         if (noti == NULL || domain == NULL || dir == NULL) {
999                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1000         }
1001
1002         /* Check domain */
1003         if (noti->domain) {
1004                 /* Remove previous domain */
1005                 free(noti->domain);
1006         }
1007         /* Copy domain */
1008         noti->domain = strdup(domain);
1009
1010         /* Check locale dir */
1011         if (noti->dir) {
1012                 /* Remove previous locale dir */
1013                 free(noti->dir);
1014         }
1015         /* Copy locale dir */
1016         noti->dir = strdup(dir);
1017
1018         return NOTIFICATION_ERROR_NONE;
1019 }
1020
1021 EXPORT_API int notification_get_text_domain(notification_h noti,
1022                                                              char **domain,
1023                                                              char **dir)
1024 {
1025         /* Check noti is valid data */
1026         if (noti == NULL) {
1027                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1028         }
1029
1030         /* Get domain */
1031         if (domain != NULL && noti->domain != NULL) {
1032                 *domain = noti->domain;
1033         }
1034
1035         /* Get locale dir */
1036         if (dir != NULL && noti->dir != NULL) {
1037                 *dir = noti->dir;
1038         }
1039
1040         return NOTIFICATION_ERROR_NONE;
1041 }
1042
1043 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
1044                                                                 time_t time)
1045 {
1046         int ret = NOTIFICATION_ERROR_NONE;
1047         char buf[256] = { 0, };
1048         char buf_tag[512] = { 0, };
1049
1050         if (noti == NULL) {
1051                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1052         }
1053         if (time <= 0) {
1054                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1055         }
1056         if (type <= NOTIFICATION_TEXT_TYPE_NONE
1057             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1058                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1059         }
1060
1061
1062         snprintf(buf, sizeof(buf), "%lu", time);
1063         ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
1064
1065         if (ret != NOTIFICATION_ERROR_NONE) {
1066                 return ret;
1067         }
1068
1069         return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1070 }
1071
1072 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
1073                                                                 time_t *time)
1074 {
1075         int ret = NOTIFICATION_ERROR_NONE;
1076
1077         if (noti == NULL) {
1078                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1079         }
1080         if (time == NULL) {
1081                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1082         }
1083         if (type <= NOTIFICATION_TEXT_TYPE_NONE
1084             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1085                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1086         }
1087
1088         char *ret_text = NULL;
1089         ret = notification_get_text(noti, type, &ret_text);
1090
1091         if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
1092                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1093         }
1094
1095         if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
1096                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1097         }
1098
1099         char *tag_value = NULL;
1100         tag_value = notification_noti_strip_tag(ret_text);
1101         if (tag_value == NULL) {
1102                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1103         }
1104
1105         *time = atol(tag_value);
1106         free(tag_value);
1107
1108         return NOTIFICATION_ERROR_NONE;
1109 }
1110
1111 EXPORT_API int notification_set_sound(notification_h noti,
1112                                                        notification_sound_type_e type,
1113                                                        const char *path)
1114 {
1115         /* Check noti is valid data */
1116         if (noti == NULL) {
1117                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1118         }
1119
1120         /* Check type is valid */
1121         if (type < NOTIFICATION_SOUND_TYPE_NONE
1122             || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1123                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1124         }
1125
1126         /* Save sound type */
1127         noti->sound_type = type;
1128
1129         /* Save sound path if user data type */
1130         if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1131                 if (noti->sound_path != NULL) {
1132                         free(noti->sound_path);
1133                 }
1134
1135                 noti->sound_path = strdup(path);
1136         } else {
1137                 if (noti->sound_path != NULL) {
1138                         free(noti->sound_path);
1139                         noti->sound_path = NULL;
1140                 }
1141                 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1142                         noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1143                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
1144                 }
1145         }
1146
1147         return NOTIFICATION_ERROR_NONE;
1148 }
1149
1150 EXPORT_API int notification_get_sound(notification_h noti,
1151                                                        notification_sound_type_e *type,
1152                                                        const char **path)
1153 {
1154         /* check noti and type is valid data */
1155         if (noti == NULL || type == NULL) {
1156                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1157         }
1158
1159         /* Set sound type */
1160         *type = noti->sound_type;
1161
1162         /* Set sound path if user data type */
1163         if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1164             && path != NULL) {
1165                 *path = noti->sound_path;
1166         }
1167
1168         return NOTIFICATION_ERROR_NONE;
1169 }
1170
1171 EXPORT_API int notification_set_vibration(notification_h noti,
1172                                                            notification_vibration_type_e type,
1173                                                            const char *path)
1174 {
1175         /* Check noti is valid data */
1176         if (noti == NULL) {
1177                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1178         }
1179
1180         /* Check type is valid */
1181         if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1182             || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1183                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1184         }
1185
1186         /* Save vibration type */
1187         noti->vibration_type = type;
1188
1189         /* Save sound path if user data type */
1190         if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1191                 if (noti->vibration_path != NULL) {
1192                         free(noti->vibration_path);
1193                 }
1194
1195                 noti->vibration_path = strdup(path);
1196         } else {
1197                 if (noti->vibration_path != NULL) {
1198                         free(noti->vibration_path);
1199                         noti->vibration_path = NULL;
1200                 }
1201                 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1202                         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1203                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
1204                 }
1205         }
1206
1207         return NOTIFICATION_ERROR_NONE;
1208
1209 }
1210
1211 EXPORT_API int notification_get_vibration(notification_h noti,
1212                                                            notification_vibration_type_e *type,
1213                                                            const char **path)
1214 {
1215         /* check noti and type is valid data */
1216         if (noti == NULL || type == NULL) {
1217                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1218         }
1219
1220         /* Set vibration type */
1221         *type = noti->vibration_type;
1222
1223         /* Set sound path if user data type */
1224         if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1225             && path != NULL) {
1226                 *path = noti->vibration_path;
1227         }
1228
1229         return NOTIFICATION_ERROR_NONE;
1230 }
1231
1232 EXPORT_API int notification_set_led(notification_h noti,
1233                                                            notification_led_op_e operation,
1234                                                            int led_argb)
1235 {
1236         /* Check noti is valid data */
1237         if (noti == NULL) {
1238                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1239         }
1240
1241         /* Check operation is valid */
1242         if (operation < NOTIFICATION_LED_OP_OFF
1243             || operation >= NOTIFICATION_LED_OP_MAX) {
1244                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1245         }
1246
1247         /* Save led operation */
1248         noti->led_operation = operation;
1249
1250         /* Save led argb if operation is turning on LED with custom color */
1251         if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1252                 noti->led_argb = led_argb;
1253         }
1254
1255         return NOTIFICATION_ERROR_NONE;
1256 }
1257
1258 EXPORT_API int notification_get_led(notification_h noti,
1259                                                            notification_led_op_e *operation,
1260                                                            int *led_argb)
1261 {
1262         /* check noti and operation is valid data */
1263         if (noti == NULL || operation == NULL) {
1264                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1265         }
1266
1267         /* Set led operation */
1268         *operation = noti->led_operation;
1269
1270         /* Save led argb if operation is turning on LED with custom color */
1271         if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1272             && led_argb != NULL) {
1273                 *led_argb = noti->led_argb;
1274         }
1275
1276         return NOTIFICATION_ERROR_NONE;
1277 }
1278
1279 EXPORT_API int notification_set_led_time_period(notification_h noti,
1280                                                                         int on_ms, int off_ms)
1281 {
1282         /* Check noti is valid data */
1283         if (noti == NULL || on_ms < 0 || off_ms < 0) {
1284                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1285         }
1286
1287         /* Save led operation */
1288         noti->led_on_ms = on_ms;
1289         noti->led_off_ms = off_ms;
1290
1291         return NOTIFICATION_ERROR_NONE;
1292 }
1293
1294 EXPORT_API int notification_get_led_time_period(notification_h noti,
1295                                                                         int *on_ms, int *off_ms)
1296 {
1297         /* check noti and operation is valid data */
1298         if (noti == NULL) {
1299                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1300         }
1301
1302         if (on_ms)
1303                 *(on_ms) = noti->led_on_ms;
1304         if (off_ms)
1305                 *(off_ms) = noti->led_off_ms;
1306
1307         return NOTIFICATION_ERROR_NONE;
1308 }
1309
1310 EXPORT_API int notification_set_application(notification_h noti,
1311                                                              const char *pkgname)
1312 {
1313         if (noti == NULL || pkgname == NULL) {
1314                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1315         }
1316
1317         if (noti->launch_pkgname) {
1318                 free(noti->launch_pkgname);
1319         }
1320
1321         noti->launch_pkgname = strdup(pkgname);
1322
1323         return NOTIFICATION_ERROR_NONE;
1324 }
1325
1326 EXPORT_API int notification_get_application(notification_h noti,
1327                                                              char **pkgname)
1328 {
1329         if (noti == NULL || pkgname == NULL) {
1330                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1331         }
1332
1333         if (noti->launch_pkgname) {
1334                 *pkgname = noti->launch_pkgname;
1335         } else {
1336                 *pkgname = noti->caller_pkgname;
1337         }
1338
1339         return NOTIFICATION_ERROR_NONE;
1340 }
1341
1342 EXPORT_API int notification_set_launch_option(notification_h noti,
1343                                                                 notification_launch_option_type type, void *option)
1344 {
1345         int ret = 0;
1346         bundle *b = NULL;
1347         app_control_h app_control = option;
1348
1349         if (noti == NULL) {
1350                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1351         }
1352         if (app_control == NULL) {
1353                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1354         }
1355         if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1356                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1357         }
1358
1359         if ((ret = app_control_to_bundle(app_control, &b)) == APP_CONTROL_ERROR_NONE) {
1360                 return notification_set_execute_option(noti,
1361                                 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1362                                 NULL, NULL,
1363                                 b);
1364         } else {
1365                 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1366                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1367         }
1368 }
1369
1370 EXPORT_API int notification_get_launch_option(notification_h noti,
1371                                                                 notification_launch_option_type type, void *option)
1372 {
1373         int ret = 0;
1374         bundle *b = NULL;
1375         app_control_h *app_control = (app_control_h *)option;
1376         app_control_h app_control_new = NULL;
1377
1378         if (noti == NULL) {
1379                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1380         }
1381         if (app_control == NULL) {
1382                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1383         }
1384         if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1385                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1386         }
1387
1388         ret = notification_get_execute_option(noti,
1389                                 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1390                                 NULL,
1391                                 &b);
1392         if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1393                 ret = app_control_create(&app_control_new);
1394                 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1395                         ret = app_control_import_from_bundle(app_control_new, b);
1396                         if (ret == APP_CONTROL_ERROR_NONE) {
1397                                 *app_control = app_control_new;
1398                         } else {
1399                                 app_control_destroy(app_control_new);
1400                                 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1401                                 return NOTIFICATION_ERROR_IO_ERROR;
1402                         }
1403                 } else {
1404                         NOTIFICATION_ERR("Failed to create app control:%d", ret);
1405                         return NOTIFICATION_ERROR_IO_ERROR;
1406                 }
1407         } else {
1408                 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1409                 return ret;
1410         }
1411
1412         return NOTIFICATION_ERROR_NONE;
1413 }
1414
1415 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1416 {
1417         return NOTIFICATION_ERROR_NOT_SUPPORTED;
1418 }
1419
1420 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1421 {
1422         return NOTIFICATION_ERROR_NOT_SUPPORTED;
1423 }
1424
1425 EXPORT_API int notification_set_execute_option(notification_h noti,
1426                                                                 notification_execute_type_e type,
1427                                                                 const char *text,
1428                                                                 const char *key,
1429                                                                 bundle *service_handle)
1430 {
1431         char buf_key[32] = { 0, };
1432         const char *ret_val = NULL;
1433         bundle *b = NULL;
1434
1435         if (noti == NULL) {
1436                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1437         }
1438
1439         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1440             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1441                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1442         }
1443
1444         /* Create execute option bundle if does not exist */
1445         if (noti->b_execute_option == NULL) {
1446                 noti->b_execute_option = bundle_create();
1447         }
1448
1449         b = noti->b_execute_option;
1450
1451         /* Save text */
1452         if (text != NULL) {
1453                 /* Make text key */
1454                 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1455
1456                 /* Check text key exist */
1457                 ret_val = bundle_get_val(b, buf_key);
1458                 if (ret_val != NULL) {
1459                         /* Remove previous data */
1460                         bundle_del(b, buf_key);
1461                 }
1462
1463                 /* Add text data */
1464                 bundle_add(b, buf_key, text);
1465         }
1466
1467         /* Save key */
1468         if (key != NULL) {
1469                 /* Make key key */
1470                 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1471
1472                 /* Check key key exist */
1473                 ret_val = bundle_get_val(b, buf_key);
1474                 if (ret_val != NULL) {
1475                         /* Remove previous data */
1476                         bundle_del(b, buf_key);
1477                 }
1478
1479                 /* Add text data */
1480                 bundle_add(b, buf_key, key);
1481         }
1482
1483         switch ((int)type) {
1484                 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1485                         /* Remove previous data if exist */
1486                         if (noti->b_service_responding != NULL) {
1487                                 bundle_free(noti->b_service_responding);
1488                                 noti->b_service_responding = NULL;
1489                         }
1490
1491                         /* Save service handle */
1492                         if (service_handle != NULL) {
1493                                 noti->b_service_responding = bundle_dup(service_handle);
1494                         }
1495                         break;
1496                 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1497                         /* Remove previous data if exist */
1498                         if (noti->b_service_single_launch != NULL) {
1499                                 bundle_free(noti->b_service_single_launch);
1500                                 noti->b_service_single_launch = NULL;
1501                         }
1502
1503                         /* Save service handle */
1504                         if (service_handle != NULL) {
1505                                 noti->b_service_single_launch =
1506                                         bundle_dup(service_handle);
1507                         }
1508                         break;
1509                 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1510                         /* Remove previous data if exist */
1511                         if (noti->b_service_multi_launch != NULL) {
1512                                 bundle_free(noti->b_service_multi_launch);
1513                                 noti->b_service_multi_launch = NULL;
1514                         }
1515
1516                         /* Save service handle */
1517                         if (service_handle != NULL) {
1518                                 noti->b_service_multi_launch =
1519                                         bundle_dup(service_handle);
1520                         }
1521                         break;
1522         }
1523
1524         return NOTIFICATION_ERROR_NONE;
1525 }
1526
1527 EXPORT_API int notification_get_execute_option(notification_h noti,
1528                                                                 notification_execute_type_e type,
1529                                                                 const char **text,
1530                                                                 bundle **service_handle)
1531 {
1532         char buf_key[32] = { 0, };
1533         const char *ret_val = NULL;
1534         char *get_str = NULL;
1535         bundle *b = NULL;
1536
1537         if (noti == NULL) {
1538                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1539         }
1540
1541         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1542             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1543                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1544         }
1545
1546         switch (type) {
1547         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1548                 b = noti->b_service_responding;
1549                 break;
1550         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1551                 b = noti->b_service_single_launch;
1552                 break;
1553         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1554                 b = noti->b_service_multi_launch;
1555         default:
1556                 break;
1557         }
1558
1559         if (b != NULL) {
1560                 // Return text
1561                 if (text != NULL) {
1562                         // Get text domain and dir
1563                         if (noti->domain == NULL || noti->dir == NULL) {
1564                                 _notification_get_text_domain(noti);
1565                         }
1566
1567                         /* Make key */
1568                         snprintf(buf_key, sizeof(buf_key), "key%d", type);
1569
1570                         /* Check key key exist */
1571                         ret_val = bundle_get_val(b, buf_key);
1572                         if (ret_val != NULL && noti->domain != NULL
1573                             && noti->dir != NULL) {
1574                                 /* Get application string */
1575                                 bindtextdomain(noti->domain, noti->dir);
1576
1577                                 get_str = dgettext(noti->domain, ret_val);
1578
1579                                 *text = get_str;
1580                         } else if (ret_val != NULL) {
1581                                 /* Get system string */
1582                                 get_str = dgettext("sys_string", ret_val);
1583
1584                                 *text = get_str;
1585                         } else {
1586                                 /* Get basic text */
1587                                 snprintf(buf_key, sizeof(buf_key), "text%d",
1588                                          type);
1589
1590                                 ret_val = bundle_get_val(b, buf_key);
1591
1592                                 *text = ret_val;
1593                         }
1594                 }
1595         }
1596
1597         if (service_handle != NULL) {
1598                 *service_handle = b;
1599         }
1600
1601         return NOTIFICATION_ERROR_NONE;
1602 }
1603
1604 EXPORT_API int notification_set_property(notification_h noti,
1605                                                           int flags)
1606 {
1607         /* Check noti is valid data */
1608         if (noti == NULL) {
1609                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1610         }
1611
1612         /* Set flags */
1613         noti->flags_for_property = flags;
1614
1615         return NOTIFICATION_ERROR_NONE;
1616 }
1617
1618 EXPORT_API int notification_get_property(notification_h noti,
1619                                                           int *flags)
1620 {
1621         /* Check noti and flags are valid data */
1622         if (noti == NULL || flags == NULL) {
1623                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1624         }
1625
1626         /* Set flags */
1627         *flags = noti->flags_for_property;
1628
1629         return NOTIFICATION_ERROR_NONE;
1630 }
1631
1632 EXPORT_API int notification_set_display_applist(notification_h noti,
1633                                                                  int applist)
1634 {
1635         /* Check noti is valid data */
1636         if (noti == NULL) {
1637                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1638         }
1639
1640         /* Set app list */
1641         noti->display_applist = applist;
1642
1643         return NOTIFICATION_ERROR_NONE;
1644 }
1645
1646 EXPORT_API int notification_get_display_applist(notification_h noti,
1647                                                                  int *applist)
1648 {
1649         /* Check noti and applist are valid data */
1650         if (noti == NULL || applist == NULL) {
1651                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1652         }
1653
1654         /* Set app list */
1655         *applist = noti->display_applist;
1656
1657         return NOTIFICATION_ERROR_NONE;
1658 }
1659
1660 EXPORT_API int notification_set_size(notification_h noti,
1661                                                       double size)
1662 {
1663         /* Check noti is valid data */
1664         if (noti == NULL) {
1665                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1666         }
1667
1668         /* Save progress size */
1669         noti->progress_size = size;
1670
1671         return NOTIFICATION_ERROR_NONE;
1672 }
1673
1674 EXPORT_API int notification_get_size(notification_h noti,
1675                                                       double *size)
1676 {
1677         /* Check noti and size is valid data */
1678         if (noti == NULL || size == NULL) {
1679                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1680         }
1681
1682         /* Set progress size */
1683         *size = noti->progress_size;
1684
1685         return NOTIFICATION_ERROR_NONE;
1686 }
1687
1688 EXPORT_API int notification_set_progress(notification_h noti,
1689                                                           double percentage)
1690 {
1691         /* Check noti is valid data */
1692         if (noti == NULL) {
1693                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1694         }
1695
1696         /* Save progress percentage */
1697         noti->progress_percentage = percentage;
1698
1699         return NOTIFICATION_ERROR_NONE;
1700 }
1701
1702 EXPORT_API int notification_get_progress(notification_h noti,
1703                                                           double *percentage)
1704 {
1705         /* Check noti and percentage are valid data */
1706         if (noti == NULL || percentage == NULL) {
1707                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1708         }
1709
1710         /* Set progress percentage */
1711         *percentage = noti->progress_percentage;
1712
1713         return NOTIFICATION_ERROR_NONE;
1714 }
1715
1716 EXPORT_API int notification_set_pkgname(notification_h noti,
1717                                                          const char *pkgname)
1718 {
1719         /* check noti and pkgname are valid data */
1720         if (noti == NULL || pkgname == NULL) {
1721                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1722         }
1723
1724         /* Remove previous caller pkgname */
1725         if (noti->caller_pkgname) {
1726                 free(noti->caller_pkgname);
1727                 noti->caller_pkgname = NULL;
1728         }
1729
1730         noti->caller_pkgname = strdup(pkgname);
1731
1732         return NOTIFICATION_ERROR_NONE;
1733 }
1734
1735 EXPORT_API int notification_get_pkgname(notification_h noti,
1736                                                          char **pkgname)
1737 {
1738         /* Check noti and pkgname are valid data */
1739         if (noti == NULL || pkgname == NULL) {
1740                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1741         }
1742
1743         /* Get caller pkgname */
1744         if (noti->caller_pkgname) {
1745                 *pkgname = noti->caller_pkgname;
1746         } else {
1747                 *pkgname = NULL;
1748         }
1749
1750         return NOTIFICATION_ERROR_NONE;
1751 }
1752
1753 EXPORT_API int notification_set_layout(notification_h noti,
1754                 notification_ly_type_e layout)
1755 {
1756         /* check noti and pkgname are valid data */
1757         if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1758                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1759         }
1760
1761         noti->layout = layout;
1762
1763         return NOTIFICATION_ERROR_NONE;
1764 }
1765
1766 EXPORT_API int notification_get_layout(notification_h noti,
1767                 notification_ly_type_e *layout)
1768 {
1769         /* Check noti and pkgname are valid data */
1770         if (noti == NULL || layout == NULL) {
1771                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1772         }
1773
1774         *layout = noti->layout;
1775
1776         return NOTIFICATION_ERROR_NONE;
1777 }
1778
1779 EXPORT_API int notification_get_id(notification_h noti,
1780                                                     int *group_id, int *priv_id)
1781 {
1782         /* check noti is valid data */
1783         if (noti == NULL) {
1784                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1785         }
1786
1787         /* Check group_id is valid data */
1788         if (group_id) {
1789                 /* Set group id */
1790                 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1791                         *group_id = NOTIFICATION_GROUP_ID_NONE;
1792                 } else {
1793                         *group_id = noti->group_id;
1794                 }
1795         }
1796
1797         /* Check priv_id is valid data */
1798         if (priv_id) {
1799                 /* Set priv_id */
1800                 *priv_id = noti->priv_id;
1801         }
1802
1803         return NOTIFICATION_ERROR_NONE;
1804 }
1805
1806 EXPORT_API int notification_get_type(notification_h noti,
1807                                                       notification_type_e *type)
1808 {
1809         /* Check noti and type is valid data */
1810         if (noti == NULL || type == NULL) {
1811                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1812         }
1813
1814         /* Set noti type */
1815         *type = noti->type;
1816
1817         return NOTIFICATION_ERROR_NONE;
1818 }
1819
1820 EXPORT_API int notification_post(notification_h noti)
1821 {
1822         int ret = 0;
1823         int id = 0;
1824
1825         /* Check noti is vaild data */
1826         if (noti == NULL) {
1827                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1828         }
1829
1830         /* Check noti type is valid type */
1831         if (noti->type <= NOTIFICATION_TYPE_NONE
1832             || noti->type >= NOTIFICATION_TYPE_MAX) {
1833                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1834         }
1835
1836         /* Save insert time */
1837         noti->insert_time = time(NULL);
1838
1839         ret = notification_ipc_request_insert(noti, &id);
1840         if (ret != NOTIFICATION_ERROR_NONE) {
1841                 return ret;
1842         }
1843         noti->priv_id = id;
1844         NOTIFICATION_DBG("from master:%d", id);
1845
1846         return NOTIFICATION_ERROR_NONE;
1847 }
1848
1849 EXPORT_API int notification_insert(notification_h noti,
1850                                                     int *priv_id)
1851 {
1852         int ret = 0;
1853         int id = 0;
1854
1855         /* Check noti is vaild data */
1856         if (noti == NULL) {
1857                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1858         }
1859
1860         /* Check noti type is valid type */
1861         if (noti->type <= NOTIFICATION_TYPE_NONE
1862             || noti->type >= NOTIFICATION_TYPE_MAX) {
1863                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1864         }
1865
1866         /* Save insert time */
1867         noti->insert_time = time(NULL);
1868         ret = notification_ipc_request_insert(noti, &id);
1869         if (ret != NOTIFICATION_ERROR_NONE) {
1870                 return ret;
1871         }
1872         noti->priv_id = id;
1873         NOTIFICATION_DBG("from master:%d", id);
1874
1875         /* If priv_id is valid data, set priv_id */
1876         if (priv_id != NULL) {
1877                 *priv_id = noti->priv_id;
1878         }
1879
1880         return NOTIFICATION_ERROR_NONE;
1881 }
1882
1883 EXPORT_API int notification_update(notification_h noti)
1884 {
1885         int ret = 0;
1886
1887         /* Check noti is valid data */
1888         if (noti != NULL) {
1889                 /* Update insert time ? */
1890                 noti->insert_time = time(NULL);
1891                 ret = notification_ipc_request_update(noti);
1892         } else {
1893                 notification_ipc_request_refresh();
1894                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1895         }
1896         return ret;
1897 }
1898
1899 EXPORT_API int notification_update_async(notification_h noti,
1900                 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1901 {
1902         int ret = 0;
1903
1904         if (noti == NULL) {
1905                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1906         }
1907
1908         /* Update insert time ? */
1909         noti->insert_time = time(NULL);
1910         ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1911
1912         return ret;
1913 }
1914
1915 EXPORT_API int notifiation_clear(notification_type_e type)
1916 {
1917         int ret = 0;
1918
1919         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1920                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1921         }
1922
1923         ret = notification_ipc_request_delete_multiple(type, NULL);
1924
1925         return ret;
1926 }
1927
1928 EXPORT_API int notification_clear(notification_type_e type)
1929 {
1930         int ret = 0;
1931
1932         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1933                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1934         }
1935
1936         ret = notification_ipc_request_delete_multiple(type, NULL);
1937
1938         return ret;
1939 }
1940
1941 EXPORT_API int notification_delete_all(notification_type_e type)
1942 {
1943         int ret = 0;
1944         char *caller_pkgname = NULL;
1945
1946         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1947                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1948         }
1949
1950         caller_pkgname = _notification_get_pkgname_by_pid();
1951
1952         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1953
1954         if (caller_pkgname) {
1955                 free(caller_pkgname);
1956         }
1957
1958         return ret;
1959 }
1960
1961 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
1962                                                                 notification_type_e type)
1963 {
1964         int ret = 0;
1965         char *caller_pkgname = NULL;
1966
1967         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1968                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1969         }
1970
1971         if (pkgname == NULL) {
1972                 caller_pkgname = _notification_get_pkgname_by_pid();
1973         } else {
1974                 caller_pkgname = strdup(pkgname);
1975         }
1976
1977         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1978
1979         if (caller_pkgname) {
1980                 free(caller_pkgname);
1981         }
1982
1983         return ret;
1984 }
1985
1986 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
1987                                                                notification_type_e type,
1988                                                                int priv_id)
1989 {
1990         int ret = 0;
1991         char *caller_pkgname = NULL;
1992
1993         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1994                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1995         }
1996
1997         if (pkgname == NULL) {
1998                 caller_pkgname = _notification_get_pkgname_by_pid();
1999         } else {
2000                 caller_pkgname = strdup(pkgname);
2001         }
2002
2003         ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
2004
2005         if (caller_pkgname) {
2006                 free(caller_pkgname);
2007         }
2008
2009         return ret;
2010 }
2011
2012 EXPORT_API int notification_delete(notification_h noti)
2013 {
2014         int ret = 0;
2015
2016         if (noti == NULL) {
2017                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2018         }
2019
2020         ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
2021
2022         return ret;
2023 }
2024
2025 EXPORT_API int notification_update_progress(notification_h noti,
2026                                                              int priv_id,
2027                                                              double progress)
2028 {
2029         char *caller_pkgname = NULL;
2030         int input_priv_id = 0;
2031         int ret = 0;
2032         double input_progress = 0.0;
2033
2034         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2035                 if (noti == NULL) {
2036                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2037                 } else {
2038                         input_priv_id = noti->priv_id;
2039                 }
2040         } else {
2041                 input_priv_id = priv_id;
2042         }
2043
2044         if (noti == NULL) {
2045                 caller_pkgname = _notification_get_pkgname_by_pid();
2046         } else {
2047                 caller_pkgname = strdup(noti->caller_pkgname);
2048         }
2049
2050         if (progress < 0.0) {
2051                 input_progress = 0.0;
2052         } else if (progress > 1.0) {
2053                 input_progress = 1.0;
2054         } else {
2055                 input_progress = progress;
2056         }
2057
2058         ret = notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2059                                              input_progress);
2060
2061         if (caller_pkgname) {
2062                 free(caller_pkgname);
2063         }
2064
2065         return ret;
2066 }
2067
2068 EXPORT_API int notification_update_size(notification_h noti,
2069                                                          int priv_id,
2070                                                          double size)
2071 {
2072         char *caller_pkgname = NULL;
2073         int input_priv_id = 0;
2074         int ret = 0;
2075         double input_size = 0.0;
2076
2077         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2078                 if (noti == NULL) {
2079                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2080                 } else {
2081                         input_priv_id = noti->priv_id;
2082                 }
2083         } else {
2084                 input_priv_id = priv_id;
2085         }
2086
2087         if (noti == NULL) {
2088                 caller_pkgname = _notification_get_pkgname_by_pid();
2089         } else {
2090                 caller_pkgname = strdup(noti->caller_pkgname);
2091         }
2092
2093         if (size < 0.0) {
2094                 input_size = 0.0;
2095         } else {
2096                 input_size = size;
2097         }
2098
2099         ret = notification_ongoing_update_size(caller_pkgname, input_priv_id,
2100                                          input_size);
2101
2102         if (caller_pkgname) {
2103                 free(caller_pkgname);
2104         }
2105
2106         return ret;
2107 }
2108
2109 EXPORT_API int notification_update_content(notification_h noti,
2110                                                          int priv_id,
2111                                                          const char *content)
2112 {
2113         char *caller_pkgname = NULL;
2114         int input_priv_id = 0;
2115         int ret = 0;
2116
2117         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2118                 if (noti == NULL) {
2119                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2120                 } else {
2121                         input_priv_id = noti->priv_id;
2122                 }
2123         } else {
2124                 input_priv_id = priv_id;
2125         }
2126
2127         if (noti == NULL) {
2128                 caller_pkgname = _notification_get_pkgname_by_pid();
2129         } else {
2130                 caller_pkgname = strdup(noti->caller_pkgname);
2131         }
2132
2133         ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
2134                                          content);
2135
2136         if (caller_pkgname) {
2137                 free(caller_pkgname);
2138         }
2139
2140         return ret;
2141 }
2142
2143 static notification_h _notification_create(notification_type_e type)
2144 {
2145         notification_h noti = NULL;
2146
2147         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2148                 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2149                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
2150                 return NULL;
2151         }
2152
2153         noti = (notification_h) calloc(1, sizeof(struct _notification));
2154         if (noti == NULL) {
2155                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2156                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
2157                 return NULL;
2158         }
2159
2160         noti->type = type;
2161
2162         if (type == NOTIFICATION_TYPE_NOTI)
2163                 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2164         else if (type == NOTIFICATION_TYPE_ONGOING)
2165                 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
2166
2167         noti->caller_pkgname = _notification_get_pkgname_by_pid();
2168         noti->group_id = NOTIFICATION_GROUP_ID_NONE;
2169         noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
2170         noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2171         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2172         noti->led_operation = NOTIFICATION_LED_OP_OFF;
2173         noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2174         /*!
2175          * \NOTE
2176          * Other fields are already initialized with ZERO.
2177          */
2178         set_last_result(NOTIFICATION_ERROR_NONE);
2179         return noti;
2180 }
2181
2182 EXPORT_API notification_h notification_new(notification_type_e type,
2183                                            int group_id, int priv_id)
2184 {
2185         return _notification_create(type);
2186 }
2187
2188 EXPORT_API notification_h notification_create(notification_type_e type)
2189 {
2190         return _notification_create(type);
2191 }
2192
2193 EXPORT_API notification_h notification_load(char *pkgname,
2194                                                       int priv_id)
2195 {
2196         int ret = 0;
2197         notification_h noti = NULL;
2198
2199         noti = (notification_h) calloc(1, sizeof(struct _notification));
2200         if (noti == NULL) {
2201                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2202                 return NULL;
2203         }
2204
2205         ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id);
2206         if (ret != NOTIFICATION_ERROR_NONE) {
2207                 notification_free(noti);
2208                 return NULL;
2209         }
2210
2211         return noti;
2212 }
2213
2214 EXPORT_API notification_h  notification_load_by_tag(const char *tag)
2215 {
2216         int ret = 0;
2217         notification_h noti = NULL;
2218         char *caller_pkgname = NULL;
2219
2220         if (tag == NULL) {
2221                 NOTIFICATION_ERR("Invalid parameter");
2222                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
2223                 return NULL;
2224         }
2225
2226         caller_pkgname = _notification_get_pkgname_by_pid();
2227         if (!caller_pkgname) {
2228                 NOTIFICATION_ERR("Failed to get a package name");
2229                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
2230
2231                 return NULL;
2232         }
2233
2234         noti = (notification_h) calloc(1, sizeof(struct _notification));
2235         if (noti == NULL) {
2236                 NOTIFICATION_ERR("Failed to alloc a new notification");
2237                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
2238                 free(caller_pkgname);
2239
2240                 return NULL;
2241         }
2242
2243         ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, tag);
2244
2245         free(caller_pkgname);
2246
2247         set_last_result(ret);
2248
2249         if (ret != NOTIFICATION_ERROR_NONE) {
2250                 notification_free(noti);
2251                 return NULL;
2252         }
2253
2254         return noti;
2255 }
2256
2257 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
2258 {
2259         notification_h new_noti = NULL;
2260
2261         if (noti == NULL || clone == NULL) {
2262                 NOTIFICATION_ERR("INVALID PARAMETER.");
2263                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2264         }
2265
2266         new_noti = (notification_h) calloc(1, sizeof(struct _notification));
2267         if (new_noti == NULL) {
2268                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2269                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
2270         }
2271
2272         new_noti->type = noti->type;
2273         new_noti->layout = noti->layout;
2274
2275         new_noti->group_id = noti->group_id;
2276         new_noti->internal_group_id = noti->internal_group_id;
2277         new_noti->priv_id = noti->priv_id;
2278
2279         if(noti->caller_pkgname != NULL) {
2280                 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2281         } else {
2282                 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2283         }
2284         if(noti->launch_pkgname != NULL) {
2285                 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2286         } else {
2287                 new_noti->launch_pkgname = NULL;
2288         }
2289
2290         if(noti->args != NULL) {
2291                 new_noti->args = bundle_dup(noti->args);
2292         } else {
2293                 new_noti->args = NULL;
2294         }
2295         if(noti->group_args != NULL) {
2296                 new_noti->group_args = bundle_dup(noti->group_args);
2297         } else {
2298                 new_noti->group_args = NULL;
2299         }
2300
2301         if(noti->b_execute_option != NULL) {
2302                 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2303         } else {
2304                 new_noti->b_execute_option = NULL;
2305         }
2306         if(noti->b_service_responding != NULL) {
2307                 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2308         } else {
2309                 new_noti->b_service_responding = NULL;
2310         }
2311         if(noti->b_service_single_launch != NULL) {
2312                 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2313         } else {
2314                 new_noti->b_service_single_launch = NULL;
2315         }
2316         if(noti->b_service_multi_launch != NULL) {
2317                 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2318         } else {
2319                 new_noti->b_service_multi_launch = NULL;
2320         }
2321
2322         new_noti->sound_type = noti->sound_type;
2323         if(noti->sound_path != NULL) {
2324                 new_noti->sound_path = strdup(noti->sound_path);
2325         } else {
2326                 new_noti->sound_path = NULL;
2327         }
2328         new_noti->vibration_type = noti->vibration_type;
2329         if(noti->vibration_path != NULL) {
2330                 new_noti->vibration_path = strdup(noti->vibration_path);
2331         } else {
2332                 new_noti->vibration_path = NULL;
2333         }
2334         new_noti->led_operation = noti->led_operation;
2335         new_noti->led_argb = noti->led_argb;
2336         new_noti->led_on_ms = noti->led_on_ms;
2337         new_noti->led_off_ms = noti->led_off_ms;
2338
2339         if(noti->domain != NULL) {
2340                 new_noti->domain = strdup(noti->domain);
2341         } else {
2342                 new_noti->domain = NULL;
2343         }
2344         if(noti->dir != NULL) {
2345                 new_noti->dir = strdup(noti->dir);
2346         } else {
2347                 new_noti->dir = NULL;
2348         }
2349
2350         if(noti->b_text != NULL) {
2351                 new_noti->b_text = bundle_dup(noti->b_text);
2352         } else {
2353                 new_noti->b_text = NULL;
2354         }
2355         if(noti->b_key != NULL) {
2356                 new_noti->b_key = bundle_dup(noti->b_key);
2357         } else {
2358                 new_noti->b_key = NULL;
2359         }
2360         if(noti->b_format_args != NULL) {
2361                 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2362         } else {
2363                 new_noti->b_format_args = NULL;
2364         }
2365         new_noti->num_format_args = noti->num_format_args;
2366
2367         if(noti->b_image_path != NULL) {
2368                 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2369         } else {
2370                 new_noti->b_image_path = NULL;
2371         }
2372
2373         new_noti->time = noti->time;
2374         new_noti->insert_time = noti->insert_time;
2375
2376         new_noti->flags_for_property = noti->flags_for_property;
2377         new_noti->display_applist = noti->display_applist;
2378
2379         new_noti->progress_size = noti->progress_size;
2380         new_noti->progress_percentage = noti->progress_percentage;
2381
2382         new_noti->app_icon_path = NULL;
2383         new_noti->app_name = NULL;
2384         new_noti->temp_title = NULL;
2385         new_noti->temp_content = NULL;
2386
2387         *clone = new_noti;
2388
2389         return NOTIFICATION_ERROR_NONE;
2390 }
2391
2392
2393 EXPORT_API int notification_free(notification_h noti)
2394 {
2395         if (noti == NULL) {
2396                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2397         }
2398
2399         if (noti->caller_pkgname) {
2400                 free(noti->caller_pkgname);
2401         }
2402         if (noti->launch_pkgname) {
2403                 free(noti->launch_pkgname);
2404         }
2405         if (noti->args) {
2406                 bundle_free(noti->args);
2407         }
2408         if (noti->group_args) {
2409                 bundle_free(noti->group_args);
2410         }
2411
2412         if (noti->b_execute_option) {
2413                 bundle_free(noti->b_execute_option);
2414         }
2415         if (noti->b_service_responding) {
2416                 bundle_free(noti->b_service_responding);
2417         }
2418         if (noti->b_service_single_launch) {
2419                 bundle_free(noti->b_service_single_launch);
2420         }
2421         if (noti->b_service_multi_launch) {
2422                 bundle_free(noti->b_service_multi_launch);
2423         }
2424
2425         if (noti->sound_path) {
2426                 free(noti->sound_path);
2427         }
2428         if (noti->vibration_path) {
2429                 free(noti->vibration_path);
2430         }
2431
2432         if (noti->domain) {
2433                 free(noti->domain);
2434         }
2435         if (noti->dir) {
2436                 free(noti->dir);
2437         }
2438
2439         if (noti->b_text) {
2440                 bundle_free(noti->b_text);
2441         }
2442         if (noti->b_key) {
2443                 bundle_free(noti->b_key);
2444         }
2445         if (noti->b_format_args) {
2446                 bundle_free(noti->b_format_args);
2447         }
2448
2449         if (noti->b_image_path) {
2450                 bundle_free(noti->b_image_path);
2451         }
2452
2453         if (noti->app_icon_path) {
2454                 free(noti->app_icon_path);
2455         }
2456         if (noti->app_name) {
2457                 free(noti->app_name);
2458         }
2459         if (noti->temp_title) {
2460                 free(noti->temp_title);
2461         }
2462         if (noti->temp_content) {
2463                 free(noti->temp_content);
2464         }
2465
2466         if (noti->tag) {
2467                 free(noti->tag);
2468         }
2469
2470         free(noti);
2471
2472         return NOTIFICATION_ERROR_NONE;
2473 }
2474
2475 EXPORT_API int
2476 notification_resister_changed_cb(void (*changed_cb)
2477                                  (void *data, notification_type_e type),
2478                                  void *user_data)
2479 {
2480         notification_cb_list_s *noti_cb_list_new = NULL;
2481         notification_cb_list_s *noti_cb_list = NULL;
2482
2483         if (changed_cb == NULL) {
2484                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2485         }
2486         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2487                 return NOTIFICATION_ERROR_IO_ERROR;
2488         }
2489
2490         noti_cb_list_new =
2491             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2492
2493         noti_cb_list_new->next = NULL;
2494         noti_cb_list_new->prev = NULL;
2495
2496         noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
2497         noti_cb_list_new->changed_cb = changed_cb;
2498         noti_cb_list_new->detailed_changed_cb = NULL;
2499         noti_cb_list_new->data = user_data;
2500
2501         if (g_notification_cb_list == NULL) {
2502                 g_notification_cb_list = noti_cb_list_new;
2503         } else {
2504                 noti_cb_list = g_notification_cb_list;
2505
2506                 while (noti_cb_list->next != NULL) {
2507                         noti_cb_list = noti_cb_list->next;
2508                 }
2509
2510                 noti_cb_list->next = noti_cb_list_new;
2511                 noti_cb_list_new->prev = noti_cb_list;
2512         }
2513         return NOTIFICATION_ERROR_NONE;
2514 }
2515
2516 EXPORT_API int
2517 notification_unresister_changed_cb(void (*changed_cb)
2518                                    (void *data, notification_type_e type))
2519 {
2520         notification_cb_list_s *noti_cb_list = NULL;
2521         notification_cb_list_s *noti_cb_list_prev = NULL;
2522         notification_cb_list_s *noti_cb_list_next = NULL;
2523
2524         noti_cb_list = g_notification_cb_list;
2525
2526         if (changed_cb == NULL) {
2527                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2528         }
2529         if (noti_cb_list == NULL) {
2530                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2531         }
2532
2533         while (noti_cb_list->prev != NULL) {
2534                 noti_cb_list = noti_cb_list->prev;
2535         }
2536
2537         do {
2538                 if (noti_cb_list->changed_cb == changed_cb) {
2539                         noti_cb_list_prev = noti_cb_list->prev;
2540                         noti_cb_list_next = noti_cb_list->next;
2541
2542                         if (noti_cb_list_prev == NULL) {
2543                                 g_notification_cb_list = noti_cb_list_next;
2544                         } else {
2545                                 noti_cb_list_prev->next = noti_cb_list_next;
2546                         }
2547
2548                         if (noti_cb_list_next == NULL) {
2549                                 if (noti_cb_list_prev != NULL) {
2550                                         noti_cb_list_prev->next = NULL;
2551                                 }
2552                         } else {
2553                                 noti_cb_list_next->prev = noti_cb_list_prev;
2554                         }
2555
2556                         free(noti_cb_list);
2557
2558                         if (g_notification_cb_list == NULL)
2559                                 notification_ipc_monitor_fini();
2560
2561                         return NOTIFICATION_ERROR_NONE;
2562                 }
2563                 noti_cb_list = noti_cb_list->next;
2564         } while (noti_cb_list != NULL);
2565
2566         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2567 }
2568
2569 EXPORT_API int
2570 notification_register_detailed_changed_cb(
2571                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2572                 void *user_data)
2573 {
2574         notification_cb_list_s *noti_cb_list_new = NULL;
2575         notification_cb_list_s *noti_cb_list = NULL;
2576
2577         if (detailed_changed_cb == NULL) {
2578                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2579         }
2580         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2581                 return NOTIFICATION_ERROR_IO_ERROR;
2582         }
2583
2584         noti_cb_list_new =
2585             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2586
2587         noti_cb_list_new->next = NULL;
2588         noti_cb_list_new->prev = NULL;
2589
2590         noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
2591         noti_cb_list_new->changed_cb = NULL;
2592         noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
2593         noti_cb_list_new->data = user_data;
2594
2595         if (g_notification_cb_list == NULL) {
2596                 g_notification_cb_list = noti_cb_list_new;
2597         } else {
2598                 noti_cb_list = g_notification_cb_list;
2599
2600                 while (noti_cb_list->next != NULL) {
2601                         noti_cb_list = noti_cb_list->next;
2602                 }
2603
2604                 noti_cb_list->next = noti_cb_list_new;
2605                 noti_cb_list_new->prev = noti_cb_list;
2606         }
2607         return NOTIFICATION_ERROR_NONE;
2608 }
2609
2610 EXPORT_API int
2611 notification_unregister_detailed_changed_cb(
2612                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2613                 void *user_data)
2614 {
2615         notification_cb_list_s *noti_cb_list = NULL;
2616         notification_cb_list_s *noti_cb_list_prev = NULL;
2617         notification_cb_list_s *noti_cb_list_next = NULL;
2618
2619         noti_cb_list = g_notification_cb_list;
2620
2621         if (detailed_changed_cb == NULL) {
2622                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2623         }
2624         if (noti_cb_list == NULL) {
2625                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2626         }
2627
2628         while (noti_cb_list->prev != NULL) {
2629                 noti_cb_list = noti_cb_list->prev;
2630         }
2631
2632         do {
2633                 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
2634                         noti_cb_list_prev = noti_cb_list->prev;
2635                         noti_cb_list_next = noti_cb_list->next;
2636
2637                         if (noti_cb_list_prev == NULL) {
2638                                 g_notification_cb_list = noti_cb_list_next;
2639                         } else {
2640                                 noti_cb_list_prev->next = noti_cb_list_next;
2641                         }
2642
2643                         if (noti_cb_list_next == NULL) {
2644                                 if (noti_cb_list_prev != NULL) {
2645                                         noti_cb_list_prev->next = NULL;
2646                                 }
2647                         } else {
2648                                 noti_cb_list_next->prev = noti_cb_list_prev;
2649                         }
2650
2651                         free(noti_cb_list);
2652
2653                         if (g_notification_cb_list == NULL)
2654                                 notification_ipc_monitor_fini();
2655
2656                         return NOTIFICATION_ERROR_NONE;
2657                 }
2658                 noti_cb_list = noti_cb_list->next;
2659         } while (noti_cb_list != NULL);
2660
2661         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2662 }
2663
2664 EXPORT_API int notification_get_count(notification_type_e type,
2665                                                        const char *pkgname,
2666                                                        int group_id,
2667                                                        int priv_id, int *count)
2668 {
2669         int ret = 0;
2670         int noti_count = 0;
2671
2672         if (count == NULL) {
2673                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2674         }
2675
2676         ret =
2677             notification_noti_get_count(type, pkgname, group_id, priv_id,
2678                                         &noti_count);
2679         if (ret != NOTIFICATION_ERROR_NONE) {
2680                 return ret;
2681         }
2682
2683         *count = noti_count;
2684
2685         return NOTIFICATION_ERROR_NONE;
2686 }
2687
2688 EXPORT_API int notification_get_list(notification_type_e type,
2689                                                       int count,
2690                                                       notification_list_h *list)
2691 {
2692         notification_list_h get_list = NULL;
2693         int ret = 0;
2694
2695         if (list == NULL) {
2696                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2697         }
2698
2699         ret = notification_noti_get_grouping_list(type, count, &get_list);
2700         if (ret != NOTIFICATION_ERROR_NONE) {
2701                 return ret;
2702         }
2703
2704         *list = get_list;
2705
2706         return NOTIFICATION_ERROR_NONE;
2707 }
2708
2709 EXPORT_API int
2710 notification_get_grouping_list(notification_type_e type, int count,
2711                                notification_list_h * list)
2712 {
2713         notification_list_h get_list = NULL;
2714         int ret = 0;
2715
2716         if (list == NULL) {
2717                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2718         }
2719
2720         ret = notification_noti_get_grouping_list(type, count, &get_list);
2721         if (ret != NOTIFICATION_ERROR_NONE) {
2722                 return ret;
2723         }
2724
2725         *list = get_list;
2726
2727         return NOTIFICATION_ERROR_NONE;
2728 }
2729
2730 EXPORT_API int notification_get_detail_list(const char *pkgname,
2731                                                              int group_id,
2732                                                              int priv_id,
2733                                                              int count,
2734                                                              notification_list_h *list)
2735 {
2736         notification_list_h get_list = NULL;
2737         int ret = 0;
2738
2739         if (list == NULL) {
2740                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2741         }
2742
2743         ret =
2744             notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2745                                               &get_list);
2746         if (ret != NOTIFICATION_ERROR_NONE) {
2747                 return ret;
2748         }
2749
2750         *list = get_list;
2751
2752         return NOTIFICATION_ERROR_NONE;
2753 }
2754
2755 EXPORT_API int notification_free_list(notification_list_h list)
2756 {
2757         notification_list_h cur_list = NULL;
2758         notification_h noti = NULL;
2759
2760         if (list == NULL) {
2761                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2762         }
2763
2764         cur_list = notification_list_get_head(list);
2765
2766         while (cur_list != NULL) {
2767                 noti = notification_list_get_data(cur_list);
2768                 cur_list = notification_list_remove(cur_list, noti);
2769
2770                 notification_free(noti);
2771         }
2772
2773         return NOTIFICATION_ERROR_NONE;
2774 }
2775
2776 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
2777                                                        void *data)
2778 {
2779         if (noti_op == NULL || data == NULL) {
2780                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2781         }
2782
2783         switch (type) {
2784                 case NOTIFICATION_OP_DATA_TYPE:
2785                         *((int*)data) = noti_op->type;
2786                         break;
2787                 case NOTIFICATION_OP_DATA_PRIV_ID:
2788                         *((int*)data) = noti_op->priv_id;
2789                         break;
2790                 case NOTIFICATION_OP_DATA_NOTI:
2791                         *((notification_h *)data) = noti_op->noti;
2792                         break;
2793                 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
2794                         *((int*)data) = noti_op->extra_info_1;
2795                         break;
2796                 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
2797                         *((int*)data) = noti_op->extra_info_2;
2798                         break;
2799                 default:
2800                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2801                         break;
2802         }
2803
2804         return NOTIFICATION_ERROR_NONE;
2805 }
2806
2807 void notification_call_changed_cb(notification_op *op_list, int op_num)
2808 {
2809         notification_cb_list_s *noti_cb_list = NULL;
2810         notification_type_e type = 0;
2811
2812         if (g_notification_cb_list == NULL) {
2813                 return;
2814         }
2815         noti_cb_list = g_notification_cb_list;
2816
2817         while (noti_cb_list->prev != NULL) {
2818                 noti_cb_list = noti_cb_list->prev;
2819         }
2820
2821         if (op_list == NULL) {
2822                 NOTIFICATION_ERR("invalid data");
2823                 return ;
2824         }
2825
2826         notification_get_type(op_list->noti, &type);
2827
2828         while (noti_cb_list != NULL) {
2829                 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
2830                         noti_cb_list->changed_cb(noti_cb_list->data,
2831                                                  type);
2832                 }
2833                 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
2834                         noti_cb_list->detailed_changed_cb(noti_cb_list->data,
2835                                                 type, op_list, op_num);
2836                 }
2837
2838                 noti_cb_list = noti_cb_list->next;
2839         }
2840 }
2841
2842 EXPORT_API int notification_is_service_ready(void)
2843 {
2844         return notification_ipc_is_master_ready();
2845 }
2846
2847 EXPORT_API int
2848 notification_add_deferred_task(
2849                 void (*deferred_task_cb)(void *data), void *user_data)
2850 {
2851         if (deferred_task_cb == NULL) {
2852                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2853         }
2854
2855         return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
2856 }
2857
2858 EXPORT_API int
2859 notification_del_deferred_task(
2860                 void (*deferred_task_cb)(void *data))
2861 {
2862         if (deferred_task_cb == NULL) {
2863                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2864         }
2865
2866         return notification_ipc_del_deffered_task(deferred_task_cb);
2867 }
2868
2869 /* notification_set_icon will be removed */
2870 EXPORT_API int notification_set_icon(notification_h noti,
2871                                                       const char *icon_path)
2872 {
2873         int ret_err = NOTIFICATION_ERROR_NONE;
2874
2875         ret_err =
2876             notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2877                                    icon_path);
2878
2879         return ret_err;
2880 }
2881
2882 /* notification_get_icon will be removed */
2883 EXPORT_API int notification_get_icon(notification_h noti,
2884                                                       char **icon_path)
2885 {
2886         int ret_err = NOTIFICATION_ERROR_NONE;
2887         char *ret_image_path = NULL;
2888
2889         ret_err =
2890             notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2891                                    &ret_image_path);
2892
2893         if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
2894                 *icon_path = ret_image_path;
2895
2896                 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
2897         }
2898
2899         return ret_err;
2900 }
2901
2902 EXPORT_API int notification_set_title(notification_h noti,
2903                                                        const char *title,
2904                                                        const char *loc_title)
2905 {
2906         int noti_err = NOTIFICATION_ERROR_NONE;
2907
2908         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2909                                          title, loc_title,
2910                                          NOTIFICATION_VARIABLE_TYPE_NONE);
2911
2912         return noti_err;
2913 }
2914
2915 EXPORT_API int notification_get_title(notification_h noti,
2916                                                        char **title,
2917                                                        char **loc_title)
2918 {
2919         int noti_err = NOTIFICATION_ERROR_NONE;
2920         char *ret_text = NULL;
2921
2922         noti_err =
2923             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2924                                   &ret_text);
2925
2926         if (title != NULL) {
2927                 *title = ret_text;
2928         }
2929
2930         if (loc_title != NULL) {
2931                 *loc_title = NULL;
2932         }
2933
2934         return noti_err;
2935 }
2936
2937 EXPORT_API int notification_set_content(notification_h noti,
2938                                                          const char *content,
2939                                                          const char *loc_content)
2940 {
2941         int noti_err = NOTIFICATION_ERROR_NONE;
2942
2943         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2944                                          content, loc_content,
2945                                          NOTIFICATION_VARIABLE_TYPE_NONE);
2946
2947         return noti_err;
2948 }
2949
2950 EXPORT_API int notification_get_content(notification_h noti,
2951                                                          char **content,
2952                                                          char **loc_content)
2953 {
2954         int noti_err = NOTIFICATION_ERROR_NONE;
2955         char *ret_text = NULL;
2956
2957         noti_err =
2958             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2959                                   &ret_text);
2960
2961         if (content != NULL) {
2962                 *content = ret_text;
2963         }
2964
2965         if (loc_content != NULL) {
2966                 *loc_content = NULL;
2967         }
2968
2969         return noti_err;
2970
2971 #if 0
2972         ret =
2973             vconf_get_bool
2974             (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
2975
2976         if (ret == -1 || boolval == 0) {
2977                 if (content != NULL && noti->default_content != NULL) {
2978                         *content = noti->default_content;
2979                 }
2980
2981                 if (loc_content != NULL && noti->loc_default_content != NULL) {
2982                         *loc_content = noti->loc_default_content;
2983                 }
2984         }
2985 #endif
2986 }
2987
2988 EXPORT_API int notification_set_args(notification_h noti,
2989                                                       bundle * args,
2990                                                       bundle * group_args)
2991 {
2992         if (noti == NULL || args == NULL) {
2993                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2994         }
2995
2996         if (noti->args) {
2997                 bundle_free(noti->args);
2998         }
2999
3000         noti->args = bundle_dup(args);
3001
3002         if (noti->group_args) {
3003                 bundle_free(noti->group_args);
3004                 noti->group_args = NULL;
3005         }
3006
3007         if (group_args != NULL) {
3008                 noti->group_args = bundle_dup(group_args);
3009         }
3010
3011         return NOTIFICATION_ERROR_NONE;
3012 }
3013
3014 EXPORT_API int notification_get_args(notification_h noti,
3015                                                       bundle ** args,
3016                                                       bundle ** group_args)
3017 {
3018         if (noti == NULL || args == NULL) {
3019                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3020         }
3021
3022         if (noti->args) {
3023                 *args = noti->args;
3024         } else {
3025                 *args = NULL;
3026         }
3027
3028         if (group_args != NULL && noti->group_args) {
3029                 *group_args = noti->group_args;
3030         }
3031
3032         return NOTIFICATION_ERROR_NONE;
3033 }
3034
3035 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
3036                                                                       notification_type_e type,
3037                                                                       int group_id)
3038 {
3039         int ret = 0;
3040         char *caller_pkgname = NULL;
3041
3042         if (pkgname == NULL) {
3043                 caller_pkgname = _notification_get_pkgname_by_pid();
3044         } else {
3045                 caller_pkgname = strdup(pkgname);
3046         }
3047
3048         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
3049         if (ret != NOTIFICATION_ERROR_NONE) {
3050                 if (caller_pkgname) {
3051                         free(caller_pkgname);
3052                 }
3053                 return ret;
3054         }
3055
3056         if (caller_pkgname) {
3057                 free(caller_pkgname);
3058         }
3059         return NOTIFICATION_ERROR_NONE;
3060 }
3061
3062 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
3063                                                                      notification_type_e type,
3064                                                                      int priv_id)
3065 {
3066         int ret = 0;
3067         char *caller_pkgname = NULL;
3068
3069         if (pkgname == NULL) {
3070                 caller_pkgname = _notification_get_pkgname_by_pid();
3071         } else {
3072                 caller_pkgname = strdup(pkgname);
3073         }
3074
3075         ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
3076         if (ret != NOTIFICATION_ERROR_NONE) {
3077                 if (caller_pkgname) {
3078                         free(caller_pkgname);
3079                 }
3080                 return ret;
3081         }
3082
3083         if (caller_pkgname) {
3084                 free(caller_pkgname);
3085         }
3086         return NOTIFICATION_ERROR_NONE;
3087 }
3088
3089 EXPORT_API int  notification_set_tag(notification_h noti, const char *tag)
3090 {
3091         /* Check noti is valid data */
3092         if (noti == NULL) {
3093                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3094         }
3095
3096         if (tag != NULL) {
3097                 /* save input TAG */
3098                 if (noti->tag != NULL) {
3099                         free(noti->tag);
3100                 }
3101                 noti->tag = strdup(tag);
3102         }
3103
3104         return NOTIFICATION_ERROR_NONE;
3105
3106 }
3107
3108 EXPORT_API int  notification_get_tag(notification_h noti, const char **tag)
3109 {
3110         /* Check noti is valid data */
3111         if (noti == NULL) {
3112                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3113         }
3114
3115         /* Set sound type */
3116         *tag = noti->tag;
3117         return NOTIFICATION_ERROR_NONE;
3118 }
3119
3120 EXPORT_API int notification_register_toast_message(void (*posted_toast_cb) (void *data))
3121 {
3122         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
3123                 return NOTIFICATION_ERROR_IO_ERROR;
3124         }
3125
3126         posted_toast_message_cb = posted_toast_cb;
3127
3128         return NOTIFICATION_ERROR_NONE;
3129 }
3130
3131 void notification_call_posted_toast_cb(const char *message)
3132 {
3133         if (posted_toast_message_cb != NULL) {
3134                 posted_toast_message_cb(message);
3135         }
3136 }