Give detail license information
[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: %d\n", 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_execute_option(notification_h noti,
1416                                                                 notification_execute_type_e type,
1417                                                                 const char *text,
1418                                                                 const char *key,
1419                                                                 bundle *service_handle)
1420 {
1421         char buf_key[32] = { 0, };
1422         const char *ret_val = NULL;
1423         bundle *b = NULL;
1424
1425         if (noti == NULL) {
1426                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1427         }
1428
1429         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1430             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1431                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1432         }
1433
1434         /* Create execute option bundle if does not exist */
1435         if (noti->b_execute_option == NULL) {
1436                 noti->b_execute_option = bundle_create();
1437         }
1438
1439         b = noti->b_execute_option;
1440
1441         /* Save text */
1442         if (text != NULL) {
1443                 /* Make text key */
1444                 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1445
1446                 /* Check text key exist */
1447                 ret_val = bundle_get_val(b, buf_key);
1448                 if (ret_val != NULL) {
1449                         /* Remove previous data */
1450                         bundle_del(b, buf_key);
1451                 }
1452
1453                 /* Add text data */
1454                 bundle_add(b, buf_key, text);
1455         }
1456
1457         /* Save key */
1458         if (key != NULL) {
1459                 /* Make key key */
1460                 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1461
1462                 /* Check key key exist */
1463                 ret_val = bundle_get_val(b, buf_key);
1464                 if (ret_val != NULL) {
1465                         /* Remove previous data */
1466                         bundle_del(b, buf_key);
1467                 }
1468
1469                 /* Add text data */
1470                 bundle_add(b, buf_key, key);
1471         }
1472
1473         switch ((int)type) {
1474                 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1475                         /* Remove previous data if exist */
1476                         if (noti->b_service_responding != NULL) {
1477                                 bundle_free(noti->b_service_responding);
1478                                 noti->b_service_responding = NULL;
1479                         }
1480
1481                         /* Save service handle */
1482                         if (service_handle != NULL) {
1483                                 noti->b_service_responding = bundle_dup(service_handle);
1484                         }
1485                         break;
1486                 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1487                         /* Remove previous data if exist */
1488                         if (noti->b_service_single_launch != NULL) {
1489                                 bundle_free(noti->b_service_single_launch);
1490                                 noti->b_service_single_launch = NULL;
1491                         }
1492
1493                         /* Save service handle */
1494                         if (service_handle != NULL) {
1495                                 noti->b_service_single_launch =
1496                                         bundle_dup(service_handle);
1497                         }
1498                         break;
1499                 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1500                         /* Remove previous data if exist */
1501                         if (noti->b_service_multi_launch != NULL) {
1502                                 bundle_free(noti->b_service_multi_launch);
1503                                 noti->b_service_multi_launch = NULL;
1504                         }
1505
1506                         /* Save service handle */
1507                         if (service_handle != NULL) {
1508                                 noti->b_service_multi_launch =
1509                                         bundle_dup(service_handle);
1510                         }
1511                         break;
1512         }
1513
1514         return NOTIFICATION_ERROR_NONE;
1515 }
1516
1517 EXPORT_API int notification_get_execute_option(notification_h noti,
1518                                                                 notification_execute_type_e type,
1519                                                                 const char **text,
1520                                                                 bundle **service_handle)
1521 {
1522         char buf_key[32] = { 0, };
1523         const char *ret_val = NULL;
1524         char *get_str = NULL;
1525         bundle *b = NULL;
1526
1527         if (noti == NULL) {
1528                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1529         }
1530
1531         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1532             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1533                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1534         }
1535
1536         switch (type) {
1537         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1538                 b = noti->b_service_responding;
1539                 break;
1540         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1541                 b = noti->b_service_single_launch;
1542                 break;
1543         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1544                 b = noti->b_service_multi_launch;
1545         default:
1546                 break;
1547         }
1548
1549         if (b != NULL) {
1550                 // Return text
1551                 if (text != NULL) {
1552                         // Get text domain and dir
1553                         if (noti->domain == NULL || noti->dir == NULL) {
1554                                 _notification_get_text_domain(noti);
1555                         }
1556
1557                         /* Make key */
1558                         snprintf(buf_key, sizeof(buf_key), "key%d", type);
1559
1560                         /* Check key key exist */
1561                         ret_val = bundle_get_val(b, buf_key);
1562                         if (ret_val != NULL && noti->domain != NULL
1563                             && noti->dir != NULL) {
1564                                 /* Get application string */
1565                                 bindtextdomain(noti->domain, noti->dir);
1566
1567                                 get_str = dgettext(noti->domain, ret_val);
1568
1569                                 *text = get_str;
1570                         } else if (ret_val != NULL) {
1571                                 /* Get system string */
1572                                 get_str = dgettext("sys_string", ret_val);
1573
1574                                 *text = get_str;
1575                         } else {
1576                                 /* Get basic text */
1577                                 snprintf(buf_key, sizeof(buf_key), "text%d",
1578                                          type);
1579
1580                                 ret_val = bundle_get_val(b, buf_key);
1581
1582                                 *text = ret_val;
1583                         }
1584                 }
1585         }
1586
1587         if (service_handle != NULL) {
1588                 *service_handle = b;
1589         }
1590
1591         return NOTIFICATION_ERROR_NONE;
1592 }
1593
1594 EXPORT_API int notification_set_property(notification_h noti,
1595                                                           int flags)
1596 {
1597         /* Check noti is valid data */
1598         if (noti == NULL) {
1599                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1600         }
1601
1602         /* Set flags */
1603         noti->flags_for_property = flags;
1604
1605         return NOTIFICATION_ERROR_NONE;
1606 }
1607
1608 EXPORT_API int notification_get_property(notification_h noti,
1609                                                           int *flags)
1610 {
1611         /* Check noti and flags are valid data */
1612         if (noti == NULL || flags == NULL) {
1613                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1614         }
1615
1616         /* Set flags */
1617         *flags = noti->flags_for_property;
1618
1619         return NOTIFICATION_ERROR_NONE;
1620 }
1621
1622 EXPORT_API int notification_set_display_applist(notification_h noti,
1623                                                                  int applist)
1624 {
1625         /* Check noti is valid data */
1626         if (noti == NULL) {
1627                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1628         }
1629
1630         /* Set app list */
1631         noti->display_applist = applist;
1632
1633         return NOTIFICATION_ERROR_NONE;
1634 }
1635
1636 EXPORT_API int notification_get_display_applist(notification_h noti,
1637                                                                  int *applist)
1638 {
1639         /* Check noti and applist are valid data */
1640         if (noti == NULL || applist == NULL) {
1641                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1642         }
1643
1644         /* Set app list */
1645         *applist = noti->display_applist;
1646
1647         return NOTIFICATION_ERROR_NONE;
1648 }
1649
1650 EXPORT_API int notification_set_size(notification_h noti,
1651                                                       double size)
1652 {
1653         /* Check noti is valid data */
1654         if (noti == NULL) {
1655                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1656         }
1657
1658         /* Save progress size */
1659         noti->progress_size = size;
1660
1661         return NOTIFICATION_ERROR_NONE;
1662 }
1663
1664 EXPORT_API int notification_get_size(notification_h noti,
1665                                                       double *size)
1666 {
1667         /* Check noti and size is valid data */
1668         if (noti == NULL || size == NULL) {
1669                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1670         }
1671
1672         /* Set progress size */
1673         *size = noti->progress_size;
1674
1675         return NOTIFICATION_ERROR_NONE;
1676 }
1677
1678 EXPORT_API int notification_set_progress(notification_h noti,
1679                                                           double percentage)
1680 {
1681         /* Check noti is valid data */
1682         if (noti == NULL) {
1683                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1684         }
1685
1686         /* Save progress percentage */
1687         noti->progress_percentage = percentage;
1688
1689         return NOTIFICATION_ERROR_NONE;
1690 }
1691
1692 EXPORT_API int notification_get_progress(notification_h noti,
1693                                                           double *percentage)
1694 {
1695         /* Check noti and percentage are valid data */
1696         if (noti == NULL || percentage == NULL) {
1697                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1698         }
1699
1700         /* Set progress percentage */
1701         *percentage = noti->progress_percentage;
1702
1703         return NOTIFICATION_ERROR_NONE;
1704 }
1705
1706 EXPORT_API int notification_set_pkgname(notification_h noti,
1707                                                          const char *pkgname)
1708 {
1709         /* check noti and pkgname are valid data */
1710         if (noti == NULL || pkgname == NULL) {
1711                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1712         }
1713
1714         /* Remove previous caller pkgname */
1715         if (noti->caller_pkgname) {
1716                 free(noti->caller_pkgname);
1717                 noti->caller_pkgname = NULL;
1718         }
1719
1720         noti->caller_pkgname = strdup(pkgname);
1721
1722         return NOTIFICATION_ERROR_NONE;
1723 }
1724
1725 EXPORT_API int notification_get_pkgname(notification_h noti,
1726                                                          char **pkgname)
1727 {
1728         /* Check noti and pkgname are valid data */
1729         if (noti == NULL || pkgname == NULL) {
1730                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1731         }
1732
1733         /* Get caller pkgname */
1734         if (noti->caller_pkgname) {
1735                 *pkgname = noti->caller_pkgname;
1736         } else {
1737                 *pkgname = NULL;
1738         }
1739
1740         return NOTIFICATION_ERROR_NONE;
1741 }
1742
1743 EXPORT_API int notification_set_layout(notification_h noti,
1744                 notification_ly_type_e layout)
1745 {
1746         /* check noti and pkgname are valid data */
1747         if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1748                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1749         }
1750
1751         noti->layout = layout;
1752
1753         return NOTIFICATION_ERROR_NONE;
1754 }
1755
1756 EXPORT_API int notification_get_layout(notification_h noti,
1757                 notification_ly_type_e *layout)
1758 {
1759         /* Check noti and pkgname are valid data */
1760         if (noti == NULL || layout == NULL) {
1761                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1762         }
1763
1764         *layout = noti->layout;
1765
1766         return NOTIFICATION_ERROR_NONE;
1767 }
1768
1769 EXPORT_API int notification_get_id(notification_h noti,
1770                                                     int *group_id, int *priv_id)
1771 {
1772         /* check noti is valid data */
1773         if (noti == NULL) {
1774                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1775         }
1776
1777         /* Check group_id is valid data */
1778         if (group_id) {
1779                 /* Set group id */
1780                 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1781                         *group_id = NOTIFICATION_GROUP_ID_NONE;
1782                 } else {
1783                         *group_id = noti->group_id;
1784                 }
1785         }
1786
1787         /* Check priv_id is valid data */
1788         if (priv_id) {
1789                 /* Set priv_id */
1790                 *priv_id = noti->priv_id;
1791         }
1792
1793         return NOTIFICATION_ERROR_NONE;
1794 }
1795
1796 EXPORT_API int notification_get_type(notification_h noti,
1797                                                       notification_type_e *type)
1798 {
1799         /* Check noti and type is valid data */
1800         if (noti == NULL || type == NULL) {
1801                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1802         }
1803
1804         /* Set noti type */
1805         *type = noti->type;
1806
1807         return NOTIFICATION_ERROR_NONE;
1808 }
1809
1810 EXPORT_API int notification_post(notification_h noti)
1811 {
1812         int ret = 0;
1813         int id = 0;
1814
1815         /* Check noti is vaild data */
1816         if (noti == NULL) {
1817                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1818         }
1819
1820         /* Check noti type is valid type */
1821         if (noti->type <= NOTIFICATION_TYPE_NONE
1822             || noti->type >= NOTIFICATION_TYPE_MAX) {
1823                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1824         }
1825
1826         /* Save insert time */
1827         noti->insert_time = time(NULL);
1828
1829         ret = notification_ipc_request_insert(noti, &id);
1830         if (ret != NOTIFICATION_ERROR_NONE) {
1831                 return ret;
1832         }
1833         noti->priv_id = id;
1834         NOTIFICATION_DBG("from master:%d", id);
1835
1836         return NOTIFICATION_ERROR_NONE;
1837 }
1838
1839 EXPORT_API int notification_insert(notification_h noti,
1840                                                     int *priv_id)
1841 {
1842         int ret = 0;
1843         int id = 0;
1844
1845         /* Check noti is vaild data */
1846         if (noti == NULL) {
1847                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1848         }
1849
1850         /* Check noti type is valid type */
1851         if (noti->type <= NOTIFICATION_TYPE_NONE
1852             || noti->type >= NOTIFICATION_TYPE_MAX) {
1853                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1854         }
1855
1856         /* Save insert time */
1857         noti->insert_time = time(NULL);
1858         ret = notification_ipc_request_insert(noti, &id);
1859         if (ret != NOTIFICATION_ERROR_NONE) {
1860                 return ret;
1861         }
1862         noti->priv_id = id;
1863         NOTIFICATION_DBG("from master:%d", id);
1864
1865         /* If priv_id is valid data, set priv_id */
1866         if (priv_id != NULL) {
1867                 *priv_id = noti->priv_id;
1868         }
1869
1870         return NOTIFICATION_ERROR_NONE;
1871 }
1872
1873 EXPORT_API int notification_update(notification_h noti)
1874 {
1875         int ret = 0;
1876
1877         /* Check noti is valid data */
1878         if (noti != NULL) {
1879                 /* Update insert time ? */
1880                 noti->insert_time = time(NULL);
1881                 ret = notification_ipc_request_update(noti);
1882         } else {
1883                 notification_ipc_request_refresh();
1884                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1885         }
1886         return ret;
1887 }
1888
1889 EXPORT_API int notification_update_async(notification_h noti,
1890                 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1891 {
1892         int ret = 0;
1893
1894         if (noti == NULL) {
1895                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1896         }
1897
1898         /* Update insert time ? */
1899         noti->insert_time = time(NULL);
1900         ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1901
1902         return ret;
1903 }
1904
1905 EXPORT_API int notifiation_clear(notification_type_e type)
1906 {
1907         int ret = 0;
1908
1909         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1910                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1911         }
1912
1913         ret = notification_ipc_request_delete_multiple(type, NULL);
1914
1915         return ret;
1916 }
1917
1918 EXPORT_API int notification_clear(notification_type_e type)
1919 {
1920         int ret = 0;
1921
1922         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1923                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1924         }
1925
1926         ret = notification_ipc_request_delete_multiple(type, NULL);
1927
1928         return ret;
1929 }
1930
1931 EXPORT_API int notification_delete_all(notification_type_e type)
1932 {
1933         int ret = 0;
1934         char *caller_pkgname = NULL;
1935
1936         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1937                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1938         }
1939
1940         caller_pkgname = _notification_get_pkgname_by_pid();
1941
1942         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1943
1944         if (caller_pkgname) {
1945                 free(caller_pkgname);
1946         }
1947
1948         return ret;
1949 }
1950
1951 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
1952                                                                 notification_type_e type)
1953 {
1954         int ret = 0;
1955         char *caller_pkgname = NULL;
1956
1957         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1958                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1959         }
1960
1961         if (pkgname == NULL) {
1962                 caller_pkgname = _notification_get_pkgname_by_pid();
1963         } else {
1964                 caller_pkgname = strdup(pkgname);
1965         }
1966
1967         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1968
1969         if (caller_pkgname) {
1970                 free(caller_pkgname);
1971         }
1972
1973         return ret;
1974 }
1975
1976 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
1977                                                                notification_type_e type,
1978                                                                int priv_id)
1979 {
1980         int ret = 0;
1981         char *caller_pkgname = NULL;
1982
1983         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1984                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1985         }
1986
1987         if (pkgname == NULL) {
1988                 caller_pkgname = _notification_get_pkgname_by_pid();
1989         } else {
1990                 caller_pkgname = strdup(pkgname);
1991         }
1992
1993         ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
1994
1995         if (caller_pkgname) {
1996                 free(caller_pkgname);
1997         }
1998
1999         return ret;
2000 }
2001
2002 EXPORT_API int notification_delete(notification_h noti)
2003 {
2004         int ret = 0;
2005
2006         if (noti == NULL) {
2007                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2008         }
2009
2010         ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
2011
2012         return ret;
2013 }
2014
2015 EXPORT_API int notification_update_progress(notification_h noti,
2016                                                              int priv_id,
2017                                                              double progress)
2018 {
2019         char *caller_pkgname = NULL;
2020         int input_priv_id = 0;
2021         int ret = 0;
2022         double input_progress = 0.0;
2023
2024         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2025                 if (noti == NULL) {
2026                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2027                 } else {
2028                         input_priv_id = noti->priv_id;
2029                 }
2030         } else {
2031                 input_priv_id = priv_id;
2032         }
2033
2034         if (noti == NULL) {
2035                 caller_pkgname = _notification_get_pkgname_by_pid();
2036         } else {
2037                 caller_pkgname = strdup(noti->caller_pkgname);
2038         }
2039
2040         if (progress < 0.0) {
2041                 input_progress = 0.0;
2042         } else if (progress > 1.0) {
2043                 input_progress = 1.0;
2044         } else {
2045                 input_progress = progress;
2046         }
2047
2048         ret = notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2049                                              input_progress);
2050
2051         if (caller_pkgname) {
2052                 free(caller_pkgname);
2053         }
2054
2055         return ret;
2056 }
2057
2058 EXPORT_API int notification_update_size(notification_h noti,
2059                                                          int priv_id,
2060                                                          double size)
2061 {
2062         char *caller_pkgname = NULL;
2063         int input_priv_id = 0;
2064         int ret = 0;
2065         double input_size = 0.0;
2066
2067         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2068                 if (noti == NULL) {
2069                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2070                 } else {
2071                         input_priv_id = noti->priv_id;
2072                 }
2073         } else {
2074                 input_priv_id = priv_id;
2075         }
2076
2077         if (noti == NULL) {
2078                 caller_pkgname = _notification_get_pkgname_by_pid();
2079         } else {
2080                 caller_pkgname = strdup(noti->caller_pkgname);
2081         }
2082
2083         if (size < 0.0) {
2084                 input_size = 0.0;
2085         } else {
2086                 input_size = size;
2087         }
2088
2089         ret = notification_ongoing_update_size(caller_pkgname, input_priv_id,
2090                                          input_size);
2091
2092         if (caller_pkgname) {
2093                 free(caller_pkgname);
2094         }
2095
2096         return ret;
2097 }
2098
2099 EXPORT_API int notification_update_content(notification_h noti,
2100                                                          int priv_id,
2101                                                          const char *content)
2102 {
2103         char *caller_pkgname = NULL;
2104         int input_priv_id = 0;
2105         int ret = 0;
2106
2107         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2108                 if (noti == NULL) {
2109                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2110                 } else {
2111                         input_priv_id = noti->priv_id;
2112                 }
2113         } else {
2114                 input_priv_id = priv_id;
2115         }
2116
2117         if (noti == NULL) {
2118                 caller_pkgname = _notification_get_pkgname_by_pid();
2119         } else {
2120                 caller_pkgname = strdup(noti->caller_pkgname);
2121         }
2122
2123         ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
2124                                          content);
2125
2126         if (caller_pkgname) {
2127                 free(caller_pkgname);
2128         }
2129
2130         return ret;
2131 }
2132
2133 static notification_h _notification_create(notification_type_e type)
2134 {
2135         notification_h noti = NULL;
2136
2137         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2138                 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2139                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
2140                 return NULL;
2141         }
2142
2143         noti = (notification_h) calloc(1, sizeof(struct _notification));
2144         if (noti == NULL) {
2145                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2146                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
2147                 return NULL;
2148         }
2149
2150         noti->type = type;
2151
2152         if (type == NOTIFICATION_TYPE_NOTI)
2153                 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2154         else if (type == NOTIFICATION_TYPE_ONGOING)
2155                 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
2156
2157         noti->caller_pkgname = _notification_get_pkgname_by_pid();
2158         noti->group_id = NOTIFICATION_GROUP_ID_NONE;
2159         noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
2160         noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2161         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2162         noti->led_operation = NOTIFICATION_LED_OP_OFF;
2163         noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2164         /*!
2165          * \NOTE
2166          * Other fields are already initialized with ZERO.
2167          */
2168         set_last_result(NOTIFICATION_ERROR_NONE);
2169         return noti;
2170 }
2171
2172 EXPORT_API notification_h notification_new(notification_type_e type,
2173                                            int group_id, int priv_id)
2174 {
2175         return _notification_create(type);
2176 }
2177
2178 EXPORT_API notification_h notification_create(notification_type_e type)
2179 {
2180         return _notification_create(type);
2181 }
2182
2183 EXPORT_API notification_h notification_load(char *pkgname,
2184                                                       int priv_id)
2185 {
2186         int ret = 0;
2187         notification_h noti = NULL;
2188
2189         noti = (notification_h) calloc(1, sizeof(struct _notification));
2190         if (noti == NULL) {
2191                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2192                 return NULL;
2193         }
2194
2195         ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id);
2196         if (ret != NOTIFICATION_ERROR_NONE) {
2197                 notification_free(noti);
2198                 return NULL;
2199         }
2200
2201         return noti;
2202 }
2203
2204 EXPORT_API notification_h  notification_load_by_tag(const char *tag)
2205 {
2206         int ret = 0;
2207         notification_h noti = NULL;
2208         char *caller_pkgname = NULL;
2209
2210         if (tag == NULL) {
2211                 NOTIFICATION_ERR("Invalid parameter");
2212                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
2213                 return NULL;
2214         }
2215
2216         caller_pkgname = _notification_get_pkgname_by_pid();
2217         if (!caller_pkgname) {
2218                 NOTIFICATION_ERR("Failed to get a package name");
2219                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
2220
2221                 return NULL;
2222         }
2223
2224         noti = (notification_h) calloc(1, sizeof(struct _notification));
2225         if (noti == NULL) {
2226                 NOTIFICATION_ERR("Failed to alloc a new notification");
2227                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
2228                 free(caller_pkgname);
2229
2230                 return NULL;
2231         }
2232
2233         ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, tag);
2234
2235         free(caller_pkgname);
2236
2237         set_last_result(ret);
2238
2239         if (ret != NOTIFICATION_ERROR_NONE) {
2240                 notification_free(noti);
2241                 return NULL;
2242         }
2243
2244         return noti;
2245 }
2246
2247 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
2248 {
2249         notification_h new_noti = NULL;
2250
2251         if (noti == NULL || clone == NULL) {
2252                 NOTIFICATION_ERR("INVALID PARAMETER.");
2253                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2254         }
2255
2256         new_noti = (notification_h) calloc(1, sizeof(struct _notification));
2257         if (new_noti == NULL) {
2258                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2259                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
2260         }
2261
2262         new_noti->type = noti->type;
2263         new_noti->layout = noti->layout;
2264
2265         new_noti->group_id = noti->group_id;
2266         new_noti->internal_group_id = noti->internal_group_id;
2267         new_noti->priv_id = noti->priv_id;
2268
2269         if(noti->caller_pkgname != NULL) {
2270                 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2271         } else {
2272                 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2273         }
2274         if(noti->launch_pkgname != NULL) {
2275                 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2276         } else {
2277                 new_noti->launch_pkgname = NULL;
2278         }
2279
2280         if(noti->args != NULL) {
2281                 new_noti->args = bundle_dup(noti->args);
2282         } else {
2283                 new_noti->args = NULL;
2284         }
2285         if(noti->group_args != NULL) {
2286                 new_noti->group_args = bundle_dup(noti->group_args);
2287         } else {
2288                 new_noti->group_args = NULL;
2289         }
2290
2291         if(noti->b_execute_option != NULL) {
2292                 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2293         } else {
2294                 new_noti->b_execute_option = NULL;
2295         }
2296         if(noti->b_service_responding != NULL) {
2297                 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2298         } else {
2299                 new_noti->b_service_responding = NULL;
2300         }
2301         if(noti->b_service_single_launch != NULL) {
2302                 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2303         } else {
2304                 new_noti->b_service_single_launch = NULL;
2305         }
2306         if(noti->b_service_multi_launch != NULL) {
2307                 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2308         } else {
2309                 new_noti->b_service_multi_launch = NULL;
2310         }
2311
2312         new_noti->sound_type = noti->sound_type;
2313         if(noti->sound_path != NULL) {
2314                 new_noti->sound_path = strdup(noti->sound_path);
2315         } else {
2316                 new_noti->sound_path = NULL;
2317         }
2318         new_noti->vibration_type = noti->vibration_type;
2319         if(noti->vibration_path != NULL) {
2320                 new_noti->vibration_path = strdup(noti->vibration_path);
2321         } else {
2322                 new_noti->vibration_path = NULL;
2323         }
2324         new_noti->led_operation = noti->led_operation;
2325         new_noti->led_argb = noti->led_argb;
2326         new_noti->led_on_ms = noti->led_on_ms;
2327         new_noti->led_off_ms = noti->led_off_ms;
2328
2329         if(noti->domain != NULL) {
2330                 new_noti->domain = strdup(noti->domain);
2331         } else {
2332                 new_noti->domain = NULL;
2333         }
2334         if(noti->dir != NULL) {
2335                 new_noti->dir = strdup(noti->dir);
2336         } else {
2337                 new_noti->dir = NULL;
2338         }
2339
2340         if(noti->b_text != NULL) {
2341                 new_noti->b_text = bundle_dup(noti->b_text);
2342         } else {
2343                 new_noti->b_text = NULL;
2344         }
2345         if(noti->b_key != NULL) {
2346                 new_noti->b_key = bundle_dup(noti->b_key);
2347         } else {
2348                 new_noti->b_key = NULL;
2349         }
2350         if(noti->b_format_args != NULL) {
2351                 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2352         } else {
2353                 new_noti->b_format_args = NULL;
2354         }
2355         new_noti->num_format_args = noti->num_format_args;
2356
2357         if(noti->b_image_path != NULL) {
2358                 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2359         } else {
2360                 new_noti->b_image_path = NULL;
2361         }
2362
2363         new_noti->time = noti->time;
2364         new_noti->insert_time = noti->insert_time;
2365
2366         new_noti->flags_for_property = noti->flags_for_property;
2367         new_noti->display_applist = noti->display_applist;
2368
2369         new_noti->progress_size = noti->progress_size;
2370         new_noti->progress_percentage = noti->progress_percentage;
2371
2372         new_noti->app_icon_path = NULL;
2373         new_noti->app_name = NULL;
2374         new_noti->temp_title = NULL;
2375         new_noti->temp_content = NULL;
2376
2377         *clone = new_noti;
2378
2379         return NOTIFICATION_ERROR_NONE;
2380 }
2381
2382
2383 EXPORT_API int notification_free(notification_h noti)
2384 {
2385         if (noti == NULL) {
2386                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2387         }
2388
2389         if (noti->caller_pkgname) {
2390                 free(noti->caller_pkgname);
2391         }
2392         if (noti->launch_pkgname) {
2393                 free(noti->launch_pkgname);
2394         }
2395         if (noti->args) {
2396                 bundle_free(noti->args);
2397         }
2398         if (noti->group_args) {
2399                 bundle_free(noti->group_args);
2400         }
2401
2402         if (noti->b_execute_option) {
2403                 bundle_free(noti->b_execute_option);
2404         }
2405         if (noti->b_service_responding) {
2406                 bundle_free(noti->b_service_responding);
2407         }
2408         if (noti->b_service_single_launch) {
2409                 bundle_free(noti->b_service_single_launch);
2410         }
2411         if (noti->b_service_multi_launch) {
2412                 bundle_free(noti->b_service_multi_launch);
2413         }
2414
2415         if (noti->sound_path) {
2416                 free(noti->sound_path);
2417         }
2418         if (noti->vibration_path) {
2419                 free(noti->vibration_path);
2420         }
2421
2422         if (noti->domain) {
2423                 free(noti->domain);
2424         }
2425         if (noti->dir) {
2426                 free(noti->dir);
2427         }
2428
2429         if (noti->b_text) {
2430                 bundle_free(noti->b_text);
2431         }
2432         if (noti->b_key) {
2433                 bundle_free(noti->b_key);
2434         }
2435         if (noti->b_format_args) {
2436                 bundle_free(noti->b_format_args);
2437         }
2438
2439         if (noti->b_image_path) {
2440                 bundle_free(noti->b_image_path);
2441         }
2442
2443         if (noti->app_icon_path) {
2444                 free(noti->app_icon_path);
2445         }
2446         if (noti->app_name) {
2447                 free(noti->app_name);
2448         }
2449         if (noti->temp_title) {
2450                 free(noti->temp_title);
2451         }
2452         if (noti->temp_content) {
2453                 free(noti->temp_content);
2454         }
2455
2456         if (noti->tag) {
2457                 free(noti->tag);
2458         }
2459
2460         free(noti);
2461
2462         return NOTIFICATION_ERROR_NONE;
2463 }
2464
2465 EXPORT_API int
2466 notification_resister_changed_cb(void (*changed_cb)
2467                                  (void *data, notification_type_e type),
2468                                  void *user_data)
2469 {
2470         notification_cb_list_s *noti_cb_list_new = NULL;
2471         notification_cb_list_s *noti_cb_list = NULL;
2472
2473         if (changed_cb == NULL) {
2474                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2475         }
2476         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2477                 return NOTIFICATION_ERROR_IO_ERROR;
2478         }
2479
2480         noti_cb_list_new =
2481             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2482
2483         noti_cb_list_new->next = NULL;
2484         noti_cb_list_new->prev = NULL;
2485
2486         noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
2487         noti_cb_list_new->changed_cb = changed_cb;
2488         noti_cb_list_new->detailed_changed_cb = NULL;
2489         noti_cb_list_new->data = user_data;
2490
2491         if (g_notification_cb_list == NULL) {
2492                 g_notification_cb_list = noti_cb_list_new;
2493         } else {
2494                 noti_cb_list = g_notification_cb_list;
2495
2496                 while (noti_cb_list->next != NULL) {
2497                         noti_cb_list = noti_cb_list->next;
2498                 }
2499
2500                 noti_cb_list->next = noti_cb_list_new;
2501                 noti_cb_list_new->prev = noti_cb_list;
2502         }
2503         return NOTIFICATION_ERROR_NONE;
2504 }
2505
2506 EXPORT_API int
2507 notification_unresister_changed_cb(void (*changed_cb)
2508                                    (void *data, notification_type_e type))
2509 {
2510         notification_cb_list_s *noti_cb_list = NULL;
2511         notification_cb_list_s *noti_cb_list_prev = NULL;
2512         notification_cb_list_s *noti_cb_list_next = NULL;
2513
2514         noti_cb_list = g_notification_cb_list;
2515
2516         if (changed_cb == NULL) {
2517                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2518         }
2519         if (noti_cb_list == NULL) {
2520                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2521         }
2522
2523         while (noti_cb_list->prev != NULL) {
2524                 noti_cb_list = noti_cb_list->prev;
2525         }
2526
2527         do {
2528                 if (noti_cb_list->changed_cb == changed_cb) {
2529                         noti_cb_list_prev = noti_cb_list->prev;
2530                         noti_cb_list_next = noti_cb_list->next;
2531
2532                         if (noti_cb_list_prev == NULL) {
2533                                 g_notification_cb_list = noti_cb_list_next;
2534                         } else {
2535                                 noti_cb_list_prev->next = noti_cb_list_next;
2536                         }
2537
2538                         if (noti_cb_list_next == NULL) {
2539                                 if (noti_cb_list_prev != NULL) {
2540                                         noti_cb_list_prev->next = NULL;
2541                                 }
2542                         } else {
2543                                 noti_cb_list_next->prev = noti_cb_list_prev;
2544                         }
2545
2546                         free(noti_cb_list);
2547
2548                         if (g_notification_cb_list == NULL)
2549                                 notification_ipc_monitor_fini();
2550
2551                         return NOTIFICATION_ERROR_NONE;
2552                 }
2553                 noti_cb_list = noti_cb_list->next;
2554         } while (noti_cb_list != NULL);
2555
2556         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2557 }
2558
2559 EXPORT_API int
2560 notification_register_detailed_changed_cb(
2561                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2562                 void *user_data)
2563 {
2564         notification_cb_list_s *noti_cb_list_new = NULL;
2565         notification_cb_list_s *noti_cb_list = NULL;
2566
2567         if (detailed_changed_cb == NULL) {
2568                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2569         }
2570         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2571                 return NOTIFICATION_ERROR_IO_ERROR;
2572         }
2573
2574         noti_cb_list_new =
2575             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2576
2577         noti_cb_list_new->next = NULL;
2578         noti_cb_list_new->prev = NULL;
2579
2580         noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
2581         noti_cb_list_new->changed_cb = NULL;
2582         noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
2583         noti_cb_list_new->data = user_data;
2584
2585         if (g_notification_cb_list == NULL) {
2586                 g_notification_cb_list = noti_cb_list_new;
2587         } else {
2588                 noti_cb_list = g_notification_cb_list;
2589
2590                 while (noti_cb_list->next != NULL) {
2591                         noti_cb_list = noti_cb_list->next;
2592                 }
2593
2594                 noti_cb_list->next = noti_cb_list_new;
2595                 noti_cb_list_new->prev = noti_cb_list;
2596         }
2597         return NOTIFICATION_ERROR_NONE;
2598 }
2599
2600 EXPORT_API int
2601 notification_unregister_detailed_changed_cb(
2602                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2603                 void *user_data)
2604 {
2605         notification_cb_list_s *noti_cb_list = NULL;
2606         notification_cb_list_s *noti_cb_list_prev = NULL;
2607         notification_cb_list_s *noti_cb_list_next = NULL;
2608
2609         noti_cb_list = g_notification_cb_list;
2610
2611         if (detailed_changed_cb == NULL) {
2612                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2613         }
2614         if (noti_cb_list == NULL) {
2615                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2616         }
2617
2618         while (noti_cb_list->prev != NULL) {
2619                 noti_cb_list = noti_cb_list->prev;
2620         }
2621
2622         do {
2623                 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
2624                         noti_cb_list_prev = noti_cb_list->prev;
2625                         noti_cb_list_next = noti_cb_list->next;
2626
2627                         if (noti_cb_list_prev == NULL) {
2628                                 g_notification_cb_list = noti_cb_list_next;
2629                         } else {
2630                                 noti_cb_list_prev->next = noti_cb_list_next;
2631                         }
2632
2633                         if (noti_cb_list_next == NULL) {
2634                                 if (noti_cb_list_prev != NULL) {
2635                                         noti_cb_list_prev->next = NULL;
2636                                 }
2637                         } else {
2638                                 noti_cb_list_next->prev = noti_cb_list_prev;
2639                         }
2640
2641                         free(noti_cb_list);
2642
2643                         if (g_notification_cb_list == NULL)
2644                                 notification_ipc_monitor_fini();
2645
2646                         return NOTIFICATION_ERROR_NONE;
2647                 }
2648                 noti_cb_list = noti_cb_list->next;
2649         } while (noti_cb_list != NULL);
2650
2651         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2652 }
2653
2654 EXPORT_API int notification_get_count(notification_type_e type,
2655                                                        const char *pkgname,
2656                                                        int group_id,
2657                                                        int priv_id, int *count)
2658 {
2659         int ret = 0;
2660         int noti_count = 0;
2661
2662         if (count == NULL) {
2663                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2664         }
2665
2666         ret =
2667             notification_noti_get_count(type, pkgname, group_id, priv_id,
2668                                         &noti_count);
2669         if (ret != NOTIFICATION_ERROR_NONE) {
2670                 return ret;
2671         }
2672
2673         *count = noti_count;
2674
2675         return NOTIFICATION_ERROR_NONE;
2676 }
2677
2678 EXPORT_API int notification_get_list(notification_type_e type,
2679                                                       int count,
2680                                                       notification_list_h *list)
2681 {
2682         notification_list_h get_list = NULL;
2683         int ret = 0;
2684
2685         if (list == NULL) {
2686                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2687         }
2688
2689         ret = notification_noti_get_grouping_list(type, count, &get_list);
2690         if (ret != NOTIFICATION_ERROR_NONE) {
2691                 return ret;
2692         }
2693
2694         *list = get_list;
2695
2696         return NOTIFICATION_ERROR_NONE;
2697 }
2698
2699 EXPORT_API int
2700 notification_get_grouping_list(notification_type_e type, int count,
2701                                notification_list_h * list)
2702 {
2703         notification_list_h get_list = NULL;
2704         int ret = 0;
2705
2706         if (list == NULL) {
2707                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2708         }
2709
2710         ret = notification_noti_get_grouping_list(type, count, &get_list);
2711         if (ret != NOTIFICATION_ERROR_NONE) {
2712                 return ret;
2713         }
2714
2715         *list = get_list;
2716
2717         return NOTIFICATION_ERROR_NONE;
2718 }
2719
2720 EXPORT_API int notification_get_detail_list(const char *pkgname,
2721                                                              int group_id,
2722                                                              int priv_id,
2723                                                              int count,
2724                                                              notification_list_h *list)
2725 {
2726         notification_list_h get_list = NULL;
2727         int ret = 0;
2728
2729         if (list == NULL) {
2730                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2731         }
2732
2733         ret =
2734             notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2735                                               &get_list);
2736         if (ret != NOTIFICATION_ERROR_NONE) {
2737                 return ret;
2738         }
2739
2740         *list = get_list;
2741
2742         return NOTIFICATION_ERROR_NONE;
2743 }
2744
2745 EXPORT_API int notification_free_list(notification_list_h list)
2746 {
2747         notification_list_h cur_list = NULL;
2748         notification_h noti = NULL;
2749
2750         if (list == NULL) {
2751                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2752         }
2753
2754         cur_list = notification_list_get_head(list);
2755
2756         while (cur_list != NULL) {
2757                 noti = notification_list_get_data(cur_list);
2758                 cur_list = notification_list_remove(cur_list, noti);
2759
2760                 notification_free(noti);
2761         }
2762
2763         return NOTIFICATION_ERROR_NONE;
2764 }
2765
2766 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
2767                                                        void *data)
2768 {
2769         if (noti_op == NULL || data == NULL) {
2770                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2771         }
2772
2773         switch (type) {
2774                 case NOTIFICATION_OP_DATA_TYPE:
2775                         *((int*)data) = noti_op->type;
2776                         break;
2777                 case NOTIFICATION_OP_DATA_PRIV_ID:
2778                         *((int*)data) = noti_op->priv_id;
2779                         break;
2780                 case NOTIFICATION_OP_DATA_NOTI:
2781                         *((notification_h *)data) = noti_op->noti;
2782                         break;
2783                 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
2784                         *((int*)data) = noti_op->extra_info_1;
2785                         break;
2786                 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
2787                         *((int*)data) = noti_op->extra_info_2;
2788                         break;
2789                 default:
2790                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2791                         break;
2792         }
2793
2794         return NOTIFICATION_ERROR_NONE;
2795 }
2796
2797 void notification_call_changed_cb(notification_op *op_list, int op_num)
2798 {
2799         notification_cb_list_s *noti_cb_list = NULL;
2800         notification_type_e type = 0;
2801
2802         if (g_notification_cb_list == NULL) {
2803                 return;
2804         }
2805         noti_cb_list = g_notification_cb_list;
2806
2807         while (noti_cb_list->prev != NULL) {
2808                 noti_cb_list = noti_cb_list->prev;
2809         }
2810
2811         if (op_list == NULL) {
2812                 NOTIFICATION_ERR("invalid data");
2813                 return ;
2814         }
2815
2816         notification_get_type(op_list->noti, &type);
2817
2818         while (noti_cb_list != NULL) {
2819                 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
2820                         noti_cb_list->changed_cb(noti_cb_list->data,
2821                                                  type);
2822                 }
2823                 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
2824                         noti_cb_list->detailed_changed_cb(noti_cb_list->data,
2825                                                 type, op_list, op_num);
2826                 }
2827
2828                 noti_cb_list = noti_cb_list->next;
2829         }
2830 }
2831
2832 EXPORT_API int notification_is_service_ready(void)
2833 {
2834         return notification_ipc_is_master_ready();
2835 }
2836
2837 EXPORT_API int
2838 notification_add_deferred_task(
2839                 void (*deferred_task_cb)(void *data), void *user_data)
2840 {
2841         if (deferred_task_cb == NULL) {
2842                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2843         }
2844
2845         return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
2846 }
2847
2848 EXPORT_API int
2849 notification_del_deferred_task(
2850                 void (*deferred_task_cb)(void *data))
2851 {
2852         if (deferred_task_cb == NULL) {
2853                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2854         }
2855
2856         return notification_ipc_del_deffered_task(deferred_task_cb);
2857 }
2858
2859 /* notification_set_icon will be removed */
2860 EXPORT_API int notification_set_icon(notification_h noti,
2861                                                       const char *icon_path)
2862 {
2863         int ret_err = NOTIFICATION_ERROR_NONE;
2864
2865         ret_err =
2866             notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2867                                    icon_path);
2868
2869         return ret_err;
2870 }
2871
2872 /* notification_get_icon will be removed */
2873 EXPORT_API int notification_get_icon(notification_h noti,
2874                                                       char **icon_path)
2875 {
2876         int ret_err = NOTIFICATION_ERROR_NONE;
2877         char *ret_image_path = NULL;
2878
2879         ret_err =
2880             notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2881                                    &ret_image_path);
2882
2883         if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
2884                 *icon_path = ret_image_path;
2885
2886                 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
2887         }
2888
2889         return ret_err;
2890 }
2891
2892 EXPORT_API int notification_set_title(notification_h noti,
2893                                                        const char *title,
2894                                                        const char *loc_title)
2895 {
2896         int noti_err = NOTIFICATION_ERROR_NONE;
2897
2898         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2899                                          title, loc_title,
2900                                          NOTIFICATION_VARIABLE_TYPE_NONE);
2901
2902         return noti_err;
2903 }
2904
2905 EXPORT_API int notification_get_title(notification_h noti,
2906                                                        char **title,
2907                                                        char **loc_title)
2908 {
2909         int noti_err = NOTIFICATION_ERROR_NONE;
2910         char *ret_text = NULL;
2911
2912         noti_err =
2913             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2914                                   &ret_text);
2915
2916         if (title != NULL) {
2917                 *title = ret_text;
2918         }
2919
2920         if (loc_title != NULL) {
2921                 *loc_title = NULL;
2922         }
2923
2924         return noti_err;
2925 }
2926
2927 EXPORT_API int notification_set_content(notification_h noti,
2928                                                          const char *content,
2929                                                          const char *loc_content)
2930 {
2931         int noti_err = NOTIFICATION_ERROR_NONE;
2932
2933         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2934                                          content, loc_content,
2935                                          NOTIFICATION_VARIABLE_TYPE_NONE);
2936
2937         return noti_err;
2938 }
2939
2940 EXPORT_API int notification_get_content(notification_h noti,
2941                                                          char **content,
2942                                                          char **loc_content)
2943 {
2944         int noti_err = NOTIFICATION_ERROR_NONE;
2945         char *ret_text = NULL;
2946
2947         noti_err =
2948             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2949                                   &ret_text);
2950
2951         if (content != NULL) {
2952                 *content = ret_text;
2953         }
2954
2955         if (loc_content != NULL) {
2956                 *loc_content = NULL;
2957         }
2958
2959         return noti_err;
2960
2961 #if 0
2962         ret =
2963             vconf_get_bool
2964             (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
2965
2966         if (ret == -1 || boolval == 0) {
2967                 if (content != NULL && noti->default_content != NULL) {
2968                         *content = noti->default_content;
2969                 }
2970
2971                 if (loc_content != NULL && noti->loc_default_content != NULL) {
2972                         *loc_content = noti->loc_default_content;
2973                 }
2974         }
2975 #endif
2976 }
2977
2978 EXPORT_API int notification_set_args(notification_h noti,
2979                                                       bundle * args,
2980                                                       bundle * group_args)
2981 {
2982         if (noti == NULL || args == NULL) {
2983                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2984         }
2985
2986         if (noti->args) {
2987                 bundle_free(noti->args);
2988         }
2989
2990         noti->args = bundle_dup(args);
2991
2992         if (noti->group_args) {
2993                 bundle_free(noti->group_args);
2994                 noti->group_args = NULL;
2995         }
2996
2997         if (group_args != NULL) {
2998                 noti->group_args = bundle_dup(group_args);
2999         }
3000
3001         return NOTIFICATION_ERROR_NONE;
3002 }
3003
3004 EXPORT_API int notification_get_args(notification_h noti,
3005                                                       bundle ** args,
3006                                                       bundle ** group_args)
3007 {
3008         if (noti == NULL || args == NULL) {
3009                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3010         }
3011
3012         if (noti->args) {
3013                 *args = noti->args;
3014         } else {
3015                 *args = NULL;
3016         }
3017
3018         if (group_args != NULL && noti->group_args) {
3019                 *group_args = noti->group_args;
3020         }
3021
3022         return NOTIFICATION_ERROR_NONE;
3023 }
3024
3025 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
3026                                                                       notification_type_e type,
3027                                                                       int group_id)
3028 {
3029         int ret = 0;
3030         char *caller_pkgname = NULL;
3031
3032         if (pkgname == NULL) {
3033                 caller_pkgname = _notification_get_pkgname_by_pid();
3034         } else {
3035                 caller_pkgname = strdup(pkgname);
3036         }
3037
3038         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
3039         if (ret != NOTIFICATION_ERROR_NONE) {
3040                 if (caller_pkgname) {
3041                         free(caller_pkgname);
3042                 }
3043                 return ret;
3044         }
3045
3046         if (caller_pkgname) {
3047                 free(caller_pkgname);
3048         }
3049         return NOTIFICATION_ERROR_NONE;
3050 }
3051
3052 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
3053                                                                      notification_type_e type,
3054                                                                      int priv_id)
3055 {
3056         int ret = 0;
3057         char *caller_pkgname = NULL;
3058
3059         if (pkgname == NULL) {
3060                 caller_pkgname = _notification_get_pkgname_by_pid();
3061         } else {
3062                 caller_pkgname = strdup(pkgname);
3063         }
3064
3065         ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
3066         if (ret != NOTIFICATION_ERROR_NONE) {
3067                 if (caller_pkgname) {
3068                         free(caller_pkgname);
3069                 }
3070                 return ret;
3071         }
3072
3073         if (caller_pkgname) {
3074                 free(caller_pkgname);
3075         }
3076         return NOTIFICATION_ERROR_NONE;
3077 }
3078
3079 EXPORT_API int  notification_set_tag(notification_h noti, const char *tag)
3080 {
3081         /* Check noti is valid data */
3082         if (noti == NULL) {
3083                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3084         }
3085
3086         if (tag != NULL) {
3087                 /* save input TAG */
3088                 if (noti->tag != NULL) {
3089                         free(noti->tag);
3090                 }
3091                 noti->tag = strdup(tag);
3092         }
3093
3094         return NOTIFICATION_ERROR_NONE;
3095
3096 }
3097
3098 EXPORT_API int  notification_get_tag(notification_h noti, const char **tag)
3099 {
3100         /* Check noti is valid data */
3101         if (noti == NULL) {
3102                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3103         }
3104
3105         /* Set sound type */
3106         *tag = noti->tag;
3107         return NOTIFICATION_ERROR_NONE;
3108 }
3109
3110 EXPORT_API int notification_register_toast_message(void (*posted_toast_cb) (void *data))
3111 {
3112         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
3113                 return NOTIFICATION_ERROR_IO_ERROR;
3114         }
3115
3116         posted_toast_message_cb = posted_toast_cb;
3117
3118         return NOTIFICATION_ERROR_NONE;
3119 }
3120
3121 void notification_call_posted_toast_cb(const char *message)
3122 {
3123         if (posted_toast_message_cb != NULL) {
3124                 posted_toast_message_cb(message);
3125         }
3126 }