Merge branch 'tizen_2.4' of ssh://spin:29418/apps/home/notification into tizen
[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 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         notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
550         //int display_option_flag = 0;
551
552         char *temp_str = NULL;
553         char *translated_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                                         num_args++;
712                                 }
713                         }
714
715                         /* Check variable IN pos */
716                         for (temp_str = (char *)get_str; *temp_str != '\0';
717                              temp_str++) {
718                                 if (*temp_str != '%') {
719                                         strncat(result_str, temp_str, 1);
720                                 } else {
721                                         if (*(temp_str + 1) == '%') {
722                                                 strncat(result_str, temp_str,
723                                                         1);
724                                         } else if (*(temp_str + 1) == 'd') {
725                                                 /* Get var Type */
726                                                 ret_variable_int = 0;
727
728                                                 snprintf(buf_key,
729                                                          sizeof(buf_key),
730                                                          "%dtype%d", check_type,
731                                                          num_args);
732                                                 ret_val =
733                                                     bundle_get_val(b, buf_key);
734                                                 ret_var_type = atoi(ret_val);
735                                                 if (ret_var_type ==
736                                                     NOTIFICATION_VARIABLE_TYPE_COUNT)
737                                                 {
738                                                         /* Get notification count */
739                                                         notification_noti_get_count
740                                                             (noti->type,
741                                                              noti->caller_pkgname,
742                                                              noti->group_id,
743                                                              noti->priv_id,
744                                                              &ret_variable_int);
745                                                 } else {
746                                                         /* Get var Value */
747                                                         snprintf(buf_key,
748                                                                  sizeof
749                                                                  (buf_key),
750                                                                  "%dvalue%d",
751                                                                  check_type,
752                                                                  num_args);
753                                                         ret_val =
754                                                             bundle_get_val(b,
755                                                                            buf_key);
756                                                         ret_variable_int =
757                                                             atoi(ret_val);
758                                                 }
759
760                                                 snprintf(buf_str,
761                                                          sizeof(buf_str), "%d",
762                                                          ret_variable_int);
763
764                                                 int src_len = strlen(result_str);
765                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
766
767                                                 strncat(result_str, buf_str,
768                                                                 max_len);
769
770                                                 temp_str++;
771
772                                                 num_args++;
773                                         } else if (*(temp_str + 1) == 's') {
774                                                 /* Get var Value */
775                                                 snprintf(buf_key,
776                                                          sizeof(buf_key),
777                                                          "%dvalue%d",
778                                                          check_type, num_args);
779                                                 ret_val =
780                                                     bundle_get_val(b, buf_key);
781
782                                                 if (ret_val != NULL && noti->domain != NULL     && noti->dir != NULL) {
783                                                         /* Get application string */
784                                                         bindtextdomain(noti->domain, noti->dir);
785                                                         translated_str = dgettext(noti->domain, ret_val);
786                                                         NOTIFICATION_INFO("translated_str[%s]", translated_str);
787                                                 } else if (ret_val != NULL) {
788                                                         /* Get system string */
789                                                         translated_str = dgettext("sys_string", ret_val);
790                                                         NOTIFICATION_INFO("translated_str[%s]", translated_str);
791                                                 } else {
792                                                         translated_str = NULL;
793                                                 }
794
795                                                 strncpy(buf_str, translated_str, sizeof(buf_str));
796
797                                                 int src_len = strlen(result_str);
798                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
799
800                                                 strncat(result_str, buf_str,
801                                                                 max_len);
802
803                                                 temp_str++;
804
805                                                 num_args++;
806                                         } else if (*(temp_str + 1) == 'f') {
807                                                 /* Get var Value */
808                                                 snprintf(buf_key,
809                                                          sizeof(buf_key),
810                                                          "%dvalue%d",
811                                                          check_type, num_args);
812                                                 ret_val =
813                                                     bundle_get_val(b, buf_key);
814                                                 ret_variable_double =
815                                                     atof(ret_val);
816
817                                                 snprintf(buf_str,
818                                                          sizeof(buf_str),
819                                                          "%.2f",
820                                                          ret_variable_double);
821
822                                                 int src_len = strlen(result_str);
823                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
824
825                                                 strncat(result_str, buf_str,
826                                                                 max_len);
827
828                                                 temp_str++;
829
830                                                 num_args++;
831                                         } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
832                                                 if (*(temp_str + 3) == 'd') {
833                                                         /* Get var Type */
834                                                         ret_variable_int = 0;
835
836                                                         snprintf(buf_key,
837                                                                  sizeof(buf_key),
838                                                                  "%dtype%d", check_type,
839                                                                  num_args + *(temp_str + 1) - 49);
840                                                         ret_val =
841                                                             bundle_get_val(b, buf_key);
842                                                         ret_var_type = atoi(ret_val);
843                                                         if (ret_var_type ==
844                                                             NOTIFICATION_VARIABLE_TYPE_COUNT)
845                                                         {
846                                                                 /* Get notification count */
847                                                                 notification_noti_get_count
848                                                                     (noti->type,
849                                                                      noti->caller_pkgname,
850                                                                      noti->group_id,
851                                                                      noti->priv_id,
852                                                                      &ret_variable_int);
853                                                         } else {
854                                                                 /* Get var Value */
855                                                                 snprintf(buf_key,
856                                                                          sizeof
857                                                                          (buf_key),
858                                                                          "%dvalue%d",
859                                                                          check_type,
860                                                                          num_args + *(temp_str + 1) - 49);
861                                                                 ret_val =
862                                                                     bundle_get_val(b,
863                                                                                    buf_key);
864                                                                 ret_variable_int =
865                                                                     atoi(ret_val);
866                                                         }
867
868                                                         snprintf(buf_str,
869                                                                  sizeof(buf_str), "%d",
870                                                                  ret_variable_int);
871
872                                                         int src_len = strlen(result_str);
873                                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
874
875                                                         strncat(result_str, buf_str,
876                                                                         max_len);
877
878                                                         temp_str += 3;
879                                                 } else if (*(temp_str + 3) == 's') {
880                                                         /* Get var Value */
881                                                         snprintf(buf_key,
882                                                                  sizeof(buf_key),
883                                                                  "%dvalue%d",
884                                                                  check_type, num_args + *(temp_str + 1) - 49);
885                                                         ret_val =
886                                                             bundle_get_val(b, buf_key);
887
888                                                         snprintf(buf_str,
889                                                                  sizeof(buf_str), "%s",
890                                                                  ret_val);
891
892                                                         int src_len = strlen(result_str);
893                                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
894
895                                                         strncat(result_str, buf_str,
896                                                                         max_len);
897
898                                                         temp_str += 3;
899                                                 } else if (*(temp_str + 3) == 'f') {
900                                                         /* Get var Value */
901                                                         snprintf(buf_key,
902                                                                  sizeof(buf_key),
903                                                                  "%dvalue%d",
904                                                                  check_type, num_args + *(temp_str + 1) - 49);
905                                                         ret_val =
906                                                             bundle_get_val(b, buf_key);
907                                                         ret_variable_double =
908                                                             atof(ret_val);
909
910                                                         snprintf(buf_str,
911                                                                  sizeof(buf_str),
912                                                                  "%.2f",
913                                                                  ret_variable_double);
914
915                                                         int src_len = strlen(result_str);
916                                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
917
918                                                         strncat(result_str, buf_str,
919                                                                         max_len);
920
921                                                         temp_str += 3;
922                                                 }
923                                         }
924                                 }
925
926                         }
927
928                         /* Check last variable is count, LEFT pos */
929                         if (num_args < noti->num_format_args) {
930                                 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
931                                          check_type, num_args);
932                                 ret_val = bundle_get_val(b, buf_key);
933                                 ret_var_type = atoi(ret_val);
934                                 if (ret_var_type ==
935                                     NOTIFICATION_VARIABLE_TYPE_COUNT) {
936                                         /* Get var Value */
937                                         snprintf(buf_key, sizeof(buf_key),
938                                                  "%dvalue%d", check_type,
939                                                  num_args);
940                                         ret_val = bundle_get_val(b, buf_key);
941                                         ret_variable_int = atoi(ret_val);
942
943                                         if (ret_variable_int ==
944                                             NOTIFICATION_COUNT_POS_RIGHT) {
945                                                 notification_noti_get_count
946                                                     (noti->type,
947                                                      noti->caller_pkgname,
948                                                      noti->group_id,
949                                                      noti->priv_id,
950                                                      &ret_variable_int);
951                                                 snprintf(buf_str,
952                                                          sizeof(buf_str), " %d",
953                                                          ret_variable_int);
954
955                                                 int src_len = strlen(result_str);
956                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
957
958                                                 strncat(result_str, buf_str,
959                                                                 max_len);
960
961                                                 num_args++;
962                                         }
963
964                                 }
965                         }
966
967                         switch (check_type) {
968                         case NOTIFICATION_TEXT_TYPE_TITLE:
969                         case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
970                                 if (noti->temp_title != NULL)
971                                         free(noti->temp_title);
972
973                                 noti->temp_title = strdup(result_str);
974
975                                 *text = noti->temp_title;
976                                 break;
977                         case NOTIFICATION_TEXT_TYPE_CONTENT:
978                         case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
979                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
980                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
981                                 if (noti->temp_content !=
982                                     NULL)
983                                         free(noti->temp_content);
984
985                                 noti->temp_content = strdup(result_str);
986
987                                 *text = noti->temp_content;
988                                 break;
989                         default:
990                                 break;
991                         }
992
993                 }
994
995         } else {
996                 *text = NULL;
997         }
998
999         NOTIFICATION_INFO("text[%s]", *text);
1000
1001         return NOTIFICATION_ERROR_NONE;
1002 }
1003
1004 EXPORT_API int notification_set_text_domain(notification_h noti,
1005                                                              const char *domain,
1006                                                              const char *dir)
1007 {
1008         /* check noti and domain is valid data */
1009         if (noti == NULL || domain == NULL || dir == NULL) {
1010                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1011         }
1012
1013         /* Check domain */
1014         if (noti->domain) {
1015                 /* Remove previous domain */
1016                 free(noti->domain);
1017         }
1018         /* Copy domain */
1019         noti->domain = strdup(domain);
1020
1021         /* Check locale dir */
1022         if (noti->dir) {
1023                 /* Remove previous locale dir */
1024                 free(noti->dir);
1025         }
1026         /* Copy locale dir */
1027         noti->dir = strdup(dir);
1028
1029         return NOTIFICATION_ERROR_NONE;
1030 }
1031
1032 EXPORT_API int notification_get_text_domain(notification_h noti,
1033                                                              char **domain,
1034                                                              char **dir)
1035 {
1036         /* Check noti is valid data */
1037         if (noti == NULL) {
1038                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1039         }
1040
1041         /* Get domain */
1042         if (domain != NULL && noti->domain != NULL) {
1043                 *domain = noti->domain;
1044         }
1045
1046         /* Get locale dir */
1047         if (dir != NULL && noti->dir != NULL) {
1048                 *dir = noti->dir;
1049         }
1050
1051         return NOTIFICATION_ERROR_NONE;
1052 }
1053
1054 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
1055                                                                 time_t time)
1056 {
1057         int ret = NOTIFICATION_ERROR_NONE;
1058         char buf[256] = { 0, };
1059         char buf_tag[512] = { 0, };
1060
1061         if (noti == NULL) {
1062                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1063         }
1064         if (time <= 0) {
1065                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1066         }
1067         if (type <= NOTIFICATION_TEXT_TYPE_NONE
1068             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1069                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1070         }
1071
1072
1073         snprintf(buf, sizeof(buf), "%lu", time);
1074         ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
1075
1076         if (ret != NOTIFICATION_ERROR_NONE) {
1077                 return ret;
1078         }
1079
1080         return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1081 }
1082
1083 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
1084                                                                 time_t *time)
1085 {
1086         int ret = NOTIFICATION_ERROR_NONE;
1087
1088         if (noti == NULL) {
1089                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1090         }
1091         if (time == NULL) {
1092                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1093         }
1094         if (type <= NOTIFICATION_TEXT_TYPE_NONE
1095             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1096                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1097         }
1098
1099         char *ret_text = NULL;
1100         ret = notification_get_text(noti, type, &ret_text);
1101
1102         if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
1103                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1104         }
1105
1106         if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
1107                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1108         }
1109
1110         char *tag_value = NULL;
1111         tag_value = notification_noti_strip_tag(ret_text);
1112         if (tag_value == NULL) {
1113                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1114         }
1115
1116         *time = atol(tag_value);
1117         free(tag_value);
1118
1119         return NOTIFICATION_ERROR_NONE;
1120 }
1121
1122 EXPORT_API int notification_set_sound(notification_h noti,
1123                                                        notification_sound_type_e type,
1124                                                        const char *path)
1125 {
1126         /* Check noti is valid data */
1127         if (noti == NULL) {
1128                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1129         }
1130
1131         /* Check type is valid */
1132         if (type < NOTIFICATION_SOUND_TYPE_NONE
1133             || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1134                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1135         }
1136
1137         /* Save sound type */
1138         noti->sound_type = type;
1139
1140         /* Save sound path if user data type */
1141         if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1142                 if (noti->sound_path != NULL) {
1143                         free(noti->sound_path);
1144                 }
1145
1146                 noti->sound_path = strdup(path);
1147         } else {
1148                 if (noti->sound_path != NULL) {
1149                         free(noti->sound_path);
1150                         noti->sound_path = NULL;
1151                 }
1152                 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1153                         noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1154                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
1155                 }
1156         }
1157
1158         return NOTIFICATION_ERROR_NONE;
1159 }
1160
1161 EXPORT_API int notification_get_sound(notification_h noti,
1162                                                        notification_sound_type_e *type,
1163                                                        const char **path)
1164 {
1165         /* check noti and type is valid data */
1166         if (noti == NULL || type == NULL) {
1167                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1168         }
1169
1170         /* Set sound type */
1171         *type = noti->sound_type;
1172
1173         /* Set sound path if user data type */
1174         if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1175             && path != NULL) {
1176                 *path = noti->sound_path;
1177         }
1178
1179         return NOTIFICATION_ERROR_NONE;
1180 }
1181
1182 EXPORT_API int notification_set_vibration(notification_h noti,
1183                                                            notification_vibration_type_e type,
1184                                                            const char *path)
1185 {
1186         /* Check noti is valid data */
1187         if (noti == NULL) {
1188                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1189         }
1190
1191         /* Check type is valid */
1192         if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1193             || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1194                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1195         }
1196
1197         /* Save vibration type */
1198         noti->vibration_type = type;
1199
1200         /* Save sound path if user data type */
1201         if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1202                 if (noti->vibration_path != NULL) {
1203                         free(noti->vibration_path);
1204                 }
1205
1206                 noti->vibration_path = strdup(path);
1207         } else {
1208                 if (noti->vibration_path != NULL) {
1209                         free(noti->vibration_path);
1210                         noti->vibration_path = NULL;
1211                 }
1212                 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1213                         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1214                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
1215                 }
1216         }
1217
1218         return NOTIFICATION_ERROR_NONE;
1219
1220 }
1221
1222 EXPORT_API int notification_get_vibration(notification_h noti,
1223                                                            notification_vibration_type_e *type,
1224                                                            const char **path)
1225 {
1226         /* check noti and type is valid data */
1227         if (noti == NULL || type == NULL) {
1228                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1229         }
1230
1231         /* Set vibration type */
1232         *type = noti->vibration_type;
1233
1234         /* Set sound path if user data type */
1235         if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1236             && path != NULL) {
1237                 *path = noti->vibration_path;
1238         }
1239
1240         return NOTIFICATION_ERROR_NONE;
1241 }
1242
1243 EXPORT_API int notification_set_led(notification_h noti,
1244                                                            notification_led_op_e operation,
1245                                                            int led_argb)
1246 {
1247         /* Check noti is valid data */
1248         if (noti == NULL) {
1249                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1250         }
1251
1252         /* Check operation is valid */
1253         if (operation < NOTIFICATION_LED_OP_OFF
1254             || operation >= NOTIFICATION_LED_OP_MAX) {
1255                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1256         }
1257
1258         /* Save led operation */
1259         noti->led_operation = operation;
1260
1261         /* Save led argb if operation is turning on LED with custom color */
1262         if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1263                 noti->led_argb = led_argb;
1264         }
1265
1266         return NOTIFICATION_ERROR_NONE;
1267 }
1268
1269 EXPORT_API int notification_get_led(notification_h noti,
1270                                                            notification_led_op_e *operation,
1271                                                            int *led_argb)
1272 {
1273         /* check noti and operation is valid data */
1274         if (noti == NULL || operation == NULL) {
1275                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1276         }
1277
1278         /* Set led operation */
1279         *operation = noti->led_operation;
1280
1281         /* Save led argb if operation is turning on LED with custom color */
1282         if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1283             && led_argb != NULL) {
1284                 *led_argb = noti->led_argb;
1285         }
1286
1287         return NOTIFICATION_ERROR_NONE;
1288 }
1289
1290 EXPORT_API int notification_set_led_time_period(notification_h noti,
1291                                                                         int on_ms, int off_ms)
1292 {
1293         /* Check noti is valid data */
1294         if (noti == NULL || on_ms < 0 || off_ms < 0) {
1295                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1296         }
1297
1298         /* Save led operation */
1299         noti->led_on_ms = on_ms;
1300         noti->led_off_ms = off_ms;
1301
1302         return NOTIFICATION_ERROR_NONE;
1303 }
1304
1305 EXPORT_API int notification_get_led_time_period(notification_h noti,
1306                                                                         int *on_ms, int *off_ms)
1307 {
1308         /* check noti and operation is valid data */
1309         if (noti == NULL) {
1310                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1311         }
1312
1313         if (on_ms)
1314                 *(on_ms) = noti->led_on_ms;
1315         if (off_ms)
1316                 *(off_ms) = noti->led_off_ms;
1317
1318         return NOTIFICATION_ERROR_NONE;
1319 }
1320
1321 EXPORT_API int notification_set_application(notification_h noti,
1322                                                              const char *pkgname)
1323 {
1324         if (noti == NULL || pkgname == NULL) {
1325                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1326         }
1327
1328         if (noti->launch_pkgname) {
1329                 free(noti->launch_pkgname);
1330         }
1331
1332         noti->launch_pkgname = strdup(pkgname);
1333
1334         return NOTIFICATION_ERROR_NONE;
1335 }
1336
1337 EXPORT_API int notification_get_application(notification_h noti,
1338                                                              char **pkgname)
1339 {
1340         if (noti == NULL || pkgname == NULL) {
1341                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1342         }
1343
1344         if (noti->launch_pkgname) {
1345                 *pkgname = noti->launch_pkgname;
1346         } else {
1347                 *pkgname = noti->caller_pkgname;
1348         }
1349
1350         return NOTIFICATION_ERROR_NONE;
1351 }
1352
1353 EXPORT_API int notification_set_launch_option(notification_h noti,
1354                                                                 notification_launch_option_type type, void *option)
1355 {
1356         int ret = 0;
1357         bundle *b = NULL;
1358         app_control_h app_control = option;
1359
1360         if (noti == NULL) {
1361                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1362         }
1363         if (app_control == NULL) {
1364                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1365         }
1366         if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1367                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1368         }
1369
1370         if ((ret = app_control_export_as_bundle(app_control, &b)) == APP_CONTROL_ERROR_NONE) {
1371                 return notification_set_execute_option(noti,
1372                                 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1373                                 NULL, NULL,
1374                                 b);
1375         } else {
1376                 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1377                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1378         }
1379 }
1380
1381 EXPORT_API int notification_get_launch_option(notification_h noti,
1382                                                                 notification_launch_option_type type, void *option)
1383 {
1384         int ret = 0;
1385         bundle *b = NULL;
1386         app_control_h *app_control = (app_control_h *)option;
1387         app_control_h app_control_new = NULL;
1388
1389         if (noti == NULL) {
1390                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1391         }
1392         if (app_control == NULL) {
1393                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1394         }
1395         if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1396                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1397         }
1398
1399         ret = notification_get_execute_option(noti,
1400                                 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1401                                 NULL,
1402                                 &b);
1403         if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1404                 ret = app_control_create(&app_control_new);
1405                 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1406                         ret = app_control_import_from_bundle(app_control_new, b);
1407                         if (ret == APP_CONTROL_ERROR_NONE) {
1408                                 *app_control = app_control_new;
1409                         } else {
1410                                 app_control_destroy(app_control_new);
1411                                 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1412                                 return NOTIFICATION_ERROR_IO_ERROR;
1413                         }
1414                 } else {
1415                         NOTIFICATION_ERR("Failed to create app control:%d", ret);
1416                         return NOTIFICATION_ERROR_IO_ERROR;
1417                 }
1418         } else {
1419                 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1420                 return ret;
1421         }
1422
1423         return NOTIFICATION_ERROR_NONE;
1424 }
1425
1426 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1427 {
1428         int err = NOTIFICATION_ERROR_NONE;
1429         bundle *app_control_bundle = NULL;
1430
1431         if (noti == NULL) {
1432                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1433                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1434                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1435         }
1436
1437         if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1438                 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1439                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1440                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1441                 goto out;
1442         }
1443
1444         if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1445                 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1446                 goto out;
1447         }
1448
1449         if (noti->b_event_handler[event_type] != NULL) {
1450                 bundle_free(noti->b_event_handler[event_type]);
1451         }
1452
1453         noti->b_event_handler[event_type] = app_control_bundle;
1454
1455 out:
1456         return err;
1457 }
1458
1459 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1460 {
1461         int err = NOTIFICATION_ERROR_NONE;
1462         bundle *b = NULL;
1463         app_control_h app_control_new = NULL;
1464
1465         if (noti == NULL) {
1466                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1467                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1468                 goto out;
1469         }
1470         if (event_handler == NULL) {
1471                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1472                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1473                 goto out;
1474         }
1475         if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1476                 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1477                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1478                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1479                 goto out;
1480         }
1481
1482         b = noti->b_event_handler[event_type];
1483
1484         if (b == NULL) {
1485                 NOTIFICATION_DBG("No event handler\n");
1486                 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1487                 goto out;
1488         }
1489
1490         err = app_control_create(&app_control_new);
1491         if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1492                 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1493                 err = NOTIFICATION_ERROR_IO_ERROR;
1494                 goto out;
1495         }
1496
1497         err = app_control_import_from_bundle(app_control_new, b);
1498         if (err == APP_CONTROL_ERROR_NONE) {
1499                 *event_handler = app_control_new;
1500         }
1501         else {
1502                 app_control_destroy(app_control_new);
1503                 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1504                 err = NOTIFICATION_ERROR_IO_ERROR;
1505                 goto out;
1506         }
1507
1508 out:
1509         if (event_handler)
1510                 *event_handler = app_control_new;
1511
1512         return err;
1513 }
1514
1515 EXPORT_API int notification_set_execute_option(notification_h noti,
1516                                                                 notification_execute_type_e type,
1517                                                                 const char *text,
1518                                                                 const char *key,
1519                                                                 bundle *service_handle)
1520 {
1521         char buf_key[32] = { 0, };
1522         const char *ret_val = NULL;
1523         bundle *b = NULL;
1524
1525         if (noti == NULL) {
1526                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1527         }
1528
1529         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1530             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1531                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1532         }
1533
1534         /* Create execute option bundle if does not exist */
1535         if (noti->b_execute_option == NULL) {
1536                 noti->b_execute_option = bundle_create();
1537         }
1538
1539         b = noti->b_execute_option;
1540
1541         /* Save text */
1542         if (text != NULL) {
1543                 /* Make text key */
1544                 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1545
1546                 /* Check text key exist */
1547                 ret_val = bundle_get_val(b, buf_key);
1548                 if (ret_val != NULL) {
1549                         /* Remove previous data */
1550                         bundle_del(b, buf_key);
1551                 }
1552
1553                 /* Add text data */
1554                 bundle_add(b, buf_key, text);
1555         }
1556
1557         /* Save key */
1558         if (key != NULL) {
1559                 /* Make key key */
1560                 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1561
1562                 /* Check key key exist */
1563                 ret_val = bundle_get_val(b, buf_key);
1564                 if (ret_val != NULL) {
1565                         /* Remove previous data */
1566                         bundle_del(b, buf_key);
1567                 }
1568
1569                 /* Add text data */
1570                 bundle_add(b, buf_key, key);
1571         }
1572
1573         switch ((int)type) {
1574                 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1575                         /* Remove previous data if exist */
1576                         if (noti->b_service_responding != NULL) {
1577                                 bundle_free(noti->b_service_responding);
1578                                 noti->b_service_responding = NULL;
1579                         }
1580
1581                         /* Save service handle */
1582                         if (service_handle != NULL) {
1583                                 noti->b_service_responding = bundle_dup(service_handle);
1584                         }
1585                         break;
1586                 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1587                         /* Remove previous data if exist */
1588                         if (noti->b_service_single_launch != NULL) {
1589                                 bundle_free(noti->b_service_single_launch);
1590                                 noti->b_service_single_launch = NULL;
1591                         }
1592
1593                         /* Save service handle */
1594                         if (service_handle != NULL) {
1595                                 noti->b_service_single_launch =
1596                                         bundle_dup(service_handle);
1597                         }
1598                         break;
1599                 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1600                         /* Remove previous data if exist */
1601                         if (noti->b_service_multi_launch != NULL) {
1602                                 bundle_free(noti->b_service_multi_launch);
1603                                 noti->b_service_multi_launch = NULL;
1604                         }
1605
1606                         /* Save service handle */
1607                         if (service_handle != NULL) {
1608                                 noti->b_service_multi_launch =
1609                                         bundle_dup(service_handle);
1610                         }
1611                         break;
1612         }
1613
1614         return NOTIFICATION_ERROR_NONE;
1615 }
1616
1617 EXPORT_API int notification_get_execute_option(notification_h noti,
1618                                                                 notification_execute_type_e type,
1619                                                                 const char **text,
1620                                                                 bundle **service_handle)
1621 {
1622         char buf_key[32] = { 0, };
1623         const char *ret_val = NULL;
1624         char *get_str = NULL;
1625         bundle *b = NULL;
1626
1627         if (noti == NULL) {
1628                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1629         }
1630
1631         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1632             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1633                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1634         }
1635
1636         switch (type) {
1637         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1638                 b = noti->b_service_responding;
1639                 break;
1640         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1641                 b = noti->b_service_single_launch;
1642                 break;
1643         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1644                 b = noti->b_service_multi_launch;
1645         default:
1646                 break;
1647         }
1648
1649         if (b != NULL) {
1650                 // Return text
1651                 if (text != NULL) {
1652                         // Get text domain and dir
1653                         if (noti->domain == NULL || noti->dir == NULL) {
1654                                 _notification_get_text_domain(noti);
1655                         }
1656
1657                         /* Make key */
1658                         snprintf(buf_key, sizeof(buf_key), "key%d", type);
1659
1660                         /* Check key key exist */
1661                         ret_val = bundle_get_val(b, buf_key);
1662                         if (ret_val != NULL && noti->domain != NULL
1663                             && noti->dir != NULL) {
1664                                 /* Get application string */
1665                                 bindtextdomain(noti->domain, noti->dir);
1666
1667                                 get_str = dgettext(noti->domain, ret_val);
1668
1669                                 *text = get_str;
1670                         } else if (ret_val != NULL) {
1671                                 /* Get system string */
1672                                 get_str = dgettext("sys_string", ret_val);
1673
1674                                 *text = get_str;
1675                         } else {
1676                                 /* Get basic text */
1677                                 snprintf(buf_key, sizeof(buf_key), "text%d",
1678                                          type);
1679
1680                                 ret_val = bundle_get_val(b, buf_key);
1681
1682                                 *text = ret_val;
1683                         }
1684                 }
1685         }
1686
1687         if (service_handle != NULL) {
1688                 *service_handle = b;
1689         }
1690
1691         return NOTIFICATION_ERROR_NONE;
1692 }
1693
1694 EXPORT_API int notification_set_property(notification_h noti,
1695                                                           int flags)
1696 {
1697         /* Check noti is valid data */
1698         if (noti == NULL) {
1699                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1700         }
1701
1702         /* Set flags */
1703         noti->flags_for_property = flags;
1704
1705         return NOTIFICATION_ERROR_NONE;
1706 }
1707
1708 EXPORT_API int notification_get_property(notification_h noti,
1709                                                           int *flags)
1710 {
1711         /* Check noti and flags are valid data */
1712         if (noti == NULL || flags == NULL) {
1713                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1714         }
1715
1716         /* Set flags */
1717         *flags = noti->flags_for_property;
1718
1719         return NOTIFICATION_ERROR_NONE;
1720 }
1721
1722 EXPORT_API int notification_set_display_applist(notification_h noti,
1723                                                                  int applist)
1724 {
1725         /* Check noti is valid data */
1726         if (noti == NULL) {
1727                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1728         }
1729
1730         /* Set app list */
1731         noti->display_applist = applist;
1732
1733         return NOTIFICATION_ERROR_NONE;
1734 }
1735
1736 EXPORT_API int notification_get_display_applist(notification_h noti,
1737                                                                  int *applist)
1738 {
1739         /* Check noti and applist are valid data */
1740         if (noti == NULL || applist == NULL) {
1741                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1742         }
1743
1744         /* Set app list */
1745         *applist = noti->display_applist;
1746
1747         return NOTIFICATION_ERROR_NONE;
1748 }
1749
1750 EXPORT_API int notification_set_size(notification_h noti,
1751                                                       double size)
1752 {
1753         /* Check noti is valid data */
1754         if (noti == NULL) {
1755                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1756         }
1757
1758         /* Save progress size */
1759         noti->progress_size = size;
1760
1761         return NOTIFICATION_ERROR_NONE;
1762 }
1763
1764 EXPORT_API int notification_get_size(notification_h noti,
1765                                                       double *size)
1766 {
1767         /* Check noti and size is valid data */
1768         if (noti == NULL || size == NULL) {
1769                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1770         }
1771
1772         /* Set progress size */
1773         *size = noti->progress_size;
1774
1775         return NOTIFICATION_ERROR_NONE;
1776 }
1777
1778 EXPORT_API int notification_set_progress(notification_h noti,
1779                                                           double percentage)
1780 {
1781         /* Check noti is valid data */
1782         if (noti == NULL) {
1783                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1784         }
1785
1786         /* Save progress percentage */
1787         noti->progress_percentage = percentage;
1788
1789         return NOTIFICATION_ERROR_NONE;
1790 }
1791
1792 EXPORT_API int notification_get_progress(notification_h noti,
1793                                                           double *percentage)
1794 {
1795         /* Check noti and percentage are valid data */
1796         if (noti == NULL || percentage == NULL) {
1797                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1798         }
1799
1800         /* Set progress percentage */
1801         *percentage = noti->progress_percentage;
1802
1803         return NOTIFICATION_ERROR_NONE;
1804 }
1805
1806 EXPORT_API int notification_set_pkgname(notification_h noti,
1807                                                          const char *pkgname)
1808 {
1809         /* check noti and pkgname are valid data */
1810         if (noti == NULL || pkgname == NULL) {
1811                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1812         }
1813
1814         /* Remove previous caller pkgname */
1815         if (noti->caller_pkgname) {
1816                 free(noti->caller_pkgname);
1817                 noti->caller_pkgname = NULL;
1818         }
1819
1820         noti->caller_pkgname = strdup(pkgname);
1821
1822         return NOTIFICATION_ERROR_NONE;
1823 }
1824
1825 EXPORT_API int notification_get_pkgname(notification_h noti,
1826                                                          char **pkgname)
1827 {
1828         /* Check noti and pkgname are valid data */
1829         if (noti == NULL || pkgname == NULL) {
1830                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1831         }
1832
1833         /* Get caller pkgname */
1834         if (noti->caller_pkgname) {
1835                 *pkgname = noti->caller_pkgname;
1836         } else {
1837                 *pkgname = NULL;
1838         }
1839
1840         return NOTIFICATION_ERROR_NONE;
1841 }
1842
1843 EXPORT_API int notification_set_layout(notification_h noti,
1844                 notification_ly_type_e layout)
1845 {
1846         /* check noti and pkgname are valid data */
1847         if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1848                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1849         }
1850
1851         noti->layout = layout;
1852
1853         return NOTIFICATION_ERROR_NONE;
1854 }
1855
1856 EXPORT_API int notification_get_layout(notification_h noti,
1857                 notification_ly_type_e *layout)
1858 {
1859         /* Check noti and pkgname are valid data */
1860         if (noti == NULL || layout == NULL) {
1861                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1862         }
1863
1864         *layout = noti->layout;
1865
1866         return NOTIFICATION_ERROR_NONE;
1867 }
1868
1869 EXPORT_API int notification_get_id(notification_h noti,
1870                                                     int *group_id, int *priv_id)
1871 {
1872         /* check noti is valid data */
1873         if (noti == NULL) {
1874                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1875         }
1876
1877         /* Check group_id is valid data */
1878         if (group_id) {
1879                 /* Set group id */
1880                 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1881                         *group_id = NOTIFICATION_GROUP_ID_NONE;
1882                 } else {
1883                         *group_id = noti->group_id;
1884                 }
1885         }
1886
1887         /* Check priv_id is valid data */
1888         if (priv_id) {
1889                 /* Set priv_id */
1890                 *priv_id = noti->priv_id;
1891         }
1892
1893         return NOTIFICATION_ERROR_NONE;
1894 }
1895
1896 EXPORT_API int notification_get_type(notification_h noti,
1897                                                       notification_type_e *type)
1898 {
1899         /* Check noti and type is valid data */
1900         if (noti == NULL || type == NULL) {
1901                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1902         }
1903
1904         /* Set noti type */
1905         *type = noti->type;
1906
1907         return NOTIFICATION_ERROR_NONE;
1908 }
1909
1910 EXPORT_API int notification_post(notification_h noti)
1911 {
1912         int ret = 0;
1913         int id = 0;
1914
1915         /* Check noti is vaild data */
1916         if (noti == NULL) {
1917                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1918         }
1919
1920         /* Check noti type is valid type */
1921         if (noti->type <= NOTIFICATION_TYPE_NONE
1922             || noti->type >= NOTIFICATION_TYPE_MAX) {
1923                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1924         }
1925
1926         /* Save insert time */
1927         noti->insert_time = time(NULL);
1928
1929         ret = notification_ipc_request_insert(noti, &id);
1930         if (ret != NOTIFICATION_ERROR_NONE) {
1931                 return ret;
1932         }
1933         noti->priv_id = id;
1934         NOTIFICATION_DBG("from master:%d", id);
1935
1936         return NOTIFICATION_ERROR_NONE;
1937 }
1938
1939 EXPORT_API int notification_insert(notification_h noti,
1940                                                     int *priv_id)
1941 {
1942         int ret = 0;
1943         int id = 0;
1944
1945         /* Check noti is vaild data */
1946         if (noti == NULL) {
1947                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1948         }
1949
1950         /* Check noti type is valid type */
1951         if (noti->type <= NOTIFICATION_TYPE_NONE
1952             || noti->type >= NOTIFICATION_TYPE_MAX) {
1953                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1954         }
1955
1956         /* Save insert time */
1957         noti->insert_time = time(NULL);
1958         ret = notification_ipc_request_insert(noti, &id);
1959         if (ret != NOTIFICATION_ERROR_NONE) {
1960                 return ret;
1961         }
1962         noti->priv_id = id;
1963         NOTIFICATION_DBG("from master:%d", id);
1964
1965         /* If priv_id is valid data, set priv_id */
1966         if (priv_id != NULL) {
1967                 *priv_id = noti->priv_id;
1968         }
1969
1970         return NOTIFICATION_ERROR_NONE;
1971 }
1972
1973 EXPORT_API int notification_update(notification_h noti)
1974 {
1975         int ret = 0;
1976
1977         /* Check noti is valid data */
1978         if (noti != NULL) {
1979                 /* Update insert time ? */
1980                 noti->insert_time = time(NULL);
1981                 ret = notification_ipc_request_update(noti);
1982         } else {
1983                 notification_ipc_request_refresh();
1984                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1985         }
1986         return ret;
1987 }
1988
1989 EXPORT_API int notification_update_async(notification_h noti,
1990                 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1991 {
1992         int ret = 0;
1993
1994         if (noti == NULL) {
1995                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1996         }
1997
1998         /* Update insert time ? */
1999         noti->insert_time = time(NULL);
2000         ret = notification_ipc_request_update_async(noti, result_cb, user_data);
2001
2002         return ret;
2003 }
2004
2005 EXPORT_API int notifiation_clear(notification_type_e type)
2006 {
2007         int ret = 0;
2008
2009         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2010                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2011         }
2012
2013         ret = notification_ipc_request_delete_multiple(type, NULL);
2014
2015         return ret;
2016 }
2017
2018 EXPORT_API int notification_clear(notification_type_e type)
2019 {
2020         int ret = 0;
2021
2022         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2023                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2024         }
2025
2026         ret = notification_ipc_request_delete_multiple(type, NULL);
2027
2028         return ret;
2029 }
2030
2031 EXPORT_API int notification_delete_all(notification_type_e type)
2032 {
2033         int ret = 0;
2034         char *caller_pkgname = NULL;
2035
2036         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2037                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2038         }
2039
2040         caller_pkgname = notification_get_pkgname_by_pid();
2041
2042         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
2043
2044         if (caller_pkgname) {
2045                 free(caller_pkgname);
2046         }
2047
2048         return ret;
2049 }
2050
2051 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
2052                                                                 notification_type_e type)
2053 {
2054         int ret = 0;
2055         char *caller_pkgname = NULL;
2056
2057         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2058                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2059         }
2060
2061         if (pkgname == NULL) {
2062                 caller_pkgname = notification_get_pkgname_by_pid();
2063         } else {
2064                 caller_pkgname = strdup(pkgname);
2065         }
2066
2067         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
2068
2069         if (caller_pkgname) {
2070                 free(caller_pkgname);
2071         }
2072
2073         return ret;
2074 }
2075
2076 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
2077                                                                notification_type_e type,
2078                                                                int priv_id)
2079 {
2080         int ret = 0;
2081         char *caller_pkgname = NULL;
2082
2083         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2084                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2085         }
2086
2087         if (pkgname == NULL) {
2088                 caller_pkgname = notification_get_pkgname_by_pid();
2089         } else {
2090                 caller_pkgname = strdup(pkgname);
2091         }
2092
2093         ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
2094
2095         if (caller_pkgname) {
2096                 free(caller_pkgname);
2097         }
2098
2099         return ret;
2100 }
2101
2102 EXPORT_API int notification_delete(notification_h noti)
2103 {
2104         int ret = 0;
2105
2106         if (noti == NULL) {
2107                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2108         }
2109
2110         ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
2111
2112         return ret;
2113 }
2114
2115 EXPORT_API int notification_update_progress(notification_h noti,
2116                                                              int priv_id,
2117                                                              double progress)
2118 {
2119         char *caller_pkgname = NULL;
2120         int input_priv_id = 0;
2121         int ret = 0;
2122         double input_progress = 0.0;
2123
2124         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2125                 if (noti == NULL) {
2126                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2127                 } else {
2128                         input_priv_id = noti->priv_id;
2129                 }
2130         } else {
2131                 input_priv_id = priv_id;
2132         }
2133
2134         if (noti == NULL) {
2135                 caller_pkgname = notification_get_pkgname_by_pid();
2136         } else {
2137                 caller_pkgname = strdup(noti->caller_pkgname);
2138         }
2139
2140         if (progress < 0.0) {
2141                 input_progress = 0.0;
2142         } else if (progress > 1.0) {
2143                 input_progress = 1.0;
2144         } else {
2145                 input_progress = progress;
2146         }
2147
2148         ret = notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2149                                              input_progress);
2150
2151         if (caller_pkgname) {
2152                 free(caller_pkgname);
2153         }
2154
2155         return ret;
2156 }
2157
2158 EXPORT_API int notification_update_size(notification_h noti,
2159                                                          int priv_id,
2160                                                          double size)
2161 {
2162         char *caller_pkgname = NULL;
2163         int input_priv_id = 0;
2164         int ret = 0;
2165         double input_size = 0.0;
2166
2167         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2168                 if (noti == NULL) {
2169                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2170                 } else {
2171                         input_priv_id = noti->priv_id;
2172                 }
2173         } else {
2174                 input_priv_id = priv_id;
2175         }
2176
2177         if (noti == NULL) {
2178                 caller_pkgname = notification_get_pkgname_by_pid();
2179         } else {
2180                 caller_pkgname = strdup(noti->caller_pkgname);
2181         }
2182
2183         if (size < 0.0) {
2184                 input_size = 0.0;
2185         } else {
2186                 input_size = size;
2187         }
2188
2189         ret = notification_ongoing_update_size(caller_pkgname, input_priv_id,
2190                                          input_size);
2191
2192         if (caller_pkgname) {
2193                 free(caller_pkgname);
2194         }
2195
2196         return ret;
2197 }
2198
2199 EXPORT_API int notification_update_content(notification_h noti,
2200                                                          int priv_id,
2201                                                          const char *content)
2202 {
2203         char *caller_pkgname = NULL;
2204         int input_priv_id = 0;
2205         int ret = 0;
2206
2207         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2208                 if (noti == NULL) {
2209                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2210                 } else {
2211                         input_priv_id = noti->priv_id;
2212                 }
2213         } else {
2214                 input_priv_id = priv_id;
2215         }
2216
2217         if (noti == NULL) {
2218                 caller_pkgname = notification_get_pkgname_by_pid();
2219         } else {
2220                 caller_pkgname = strdup(noti->caller_pkgname);
2221         }
2222
2223         ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
2224                                          content);
2225
2226         if (caller_pkgname) {
2227                 free(caller_pkgname);
2228         }
2229
2230         return ret;
2231 }
2232
2233 static notification_h _notification_create(notification_type_e type)
2234 {
2235         notification_h noti = NULL;
2236
2237         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2238                 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2239                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
2240                 return NULL;
2241         }
2242
2243         noti = (notification_h) calloc(1, sizeof(struct _notification));
2244         if (noti == NULL) {
2245                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2246                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
2247                 return NULL;
2248         }
2249
2250         noti->type = type;
2251
2252         if (type == NOTIFICATION_TYPE_NOTI)
2253                 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2254         else if (type == NOTIFICATION_TYPE_ONGOING)
2255                 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
2256
2257         noti->caller_pkgname = notification_get_pkgname_by_pid();
2258         noti->group_id = NOTIFICATION_GROUP_ID_NONE;
2259         noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
2260         noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2261         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2262         noti->led_operation = NOTIFICATION_LED_OP_OFF;
2263         noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
2264         /*!
2265          * \NOTE
2266          * Other fields are already initialized with ZERO.
2267          */
2268         set_last_result(NOTIFICATION_ERROR_NONE);
2269         return noti;
2270 }
2271
2272 EXPORT_API notification_h notification_new(notification_type_e type,
2273                                            int group_id, int priv_id)
2274 {
2275         return _notification_create(type);
2276 }
2277
2278 EXPORT_API notification_h notification_create(notification_type_e type)
2279 {
2280         return _notification_create(type);
2281 }
2282
2283 EXPORT_API notification_h notification_load(char *pkgname,
2284                                                       int priv_id)
2285 {
2286         int ret = 0;
2287         notification_h noti = NULL;
2288
2289         noti = (notification_h) calloc(1, sizeof(struct _notification));
2290         if (noti == NULL) {
2291                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2292                 return NULL;
2293         }
2294
2295         ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id);
2296         if (ret != NOTIFICATION_ERROR_NONE) {
2297                 notification_free(noti);
2298                 return NULL;
2299         }
2300
2301         return noti;
2302 }
2303
2304 EXPORT_API notification_h  notification_load_by_tag(const char *tag)
2305 {
2306         int ret = 0;
2307         notification_h noti = NULL;
2308         char *caller_pkgname = NULL;
2309
2310         if (tag == NULL) {
2311                 NOTIFICATION_ERR("Invalid parameter");
2312                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
2313                 return NULL;
2314         }
2315
2316         caller_pkgname = notification_get_pkgname_by_pid();
2317         if (!caller_pkgname) {
2318                 NOTIFICATION_ERR("Failed to get a package name");
2319                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
2320
2321                 return NULL;
2322         }
2323
2324         noti = (notification_h) calloc(1, sizeof(struct _notification));
2325         if (noti == NULL) {
2326                 NOTIFICATION_ERR("Failed to alloc a new notification");
2327                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
2328                 free(caller_pkgname);
2329
2330                 return NULL;
2331         }
2332
2333         ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, tag);
2334
2335         free(caller_pkgname);
2336
2337         set_last_result(ret);
2338
2339         if (ret != NOTIFICATION_ERROR_NONE) {
2340                 notification_free(noti);
2341                 return NULL;
2342         }
2343
2344         return noti;
2345 }
2346
2347 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
2348 {
2349         int i = 0;
2350         notification_h new_noti = NULL;
2351
2352         if (noti == NULL || clone == NULL) {
2353                 NOTIFICATION_ERR("INVALID PARAMETER.");
2354                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2355         }
2356
2357         new_noti = (notification_h) calloc(1, sizeof(struct _notification));
2358         if (new_noti == NULL) {
2359                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2360                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
2361         }
2362
2363         new_noti->type = noti->type;
2364         new_noti->layout = noti->layout;
2365
2366         new_noti->group_id = noti->group_id;
2367         new_noti->internal_group_id = noti->internal_group_id;
2368         new_noti->priv_id = noti->priv_id;
2369
2370         if(noti->caller_pkgname != NULL) {
2371                 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2372         } else {
2373                 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
2374         }
2375         if(noti->launch_pkgname != NULL) {
2376                 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2377         } else {
2378                 new_noti->launch_pkgname = NULL;
2379         }
2380
2381         if(noti->args != NULL) {
2382                 new_noti->args = bundle_dup(noti->args);
2383         } else {
2384                 new_noti->args = NULL;
2385         }
2386         if(noti->group_args != NULL) {
2387                 new_noti->group_args = bundle_dup(noti->group_args);
2388         } else {
2389                 new_noti->group_args = NULL;
2390         }
2391
2392         if(noti->b_execute_option != NULL) {
2393                 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2394         } else {
2395                 new_noti->b_execute_option = NULL;
2396         }
2397         if(noti->b_service_responding != NULL) {
2398                 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2399         } else {
2400                 new_noti->b_service_responding = NULL;
2401         }
2402         if(noti->b_service_single_launch != NULL) {
2403                 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2404         } else {
2405                 new_noti->b_service_single_launch = NULL;
2406         }
2407         if(noti->b_service_multi_launch != NULL) {
2408                 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2409         } else {
2410                 new_noti->b_service_multi_launch = NULL;
2411         }
2412
2413         for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
2414                 if(noti->b_event_handler[i] != NULL) {
2415                         new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
2416                 } else {
2417                         new_noti->b_event_handler[i] = NULL;
2418                 }
2419         }
2420
2421         new_noti->sound_type = noti->sound_type;
2422         if(noti->sound_path != NULL) {
2423                 new_noti->sound_path = strdup(noti->sound_path);
2424         } else {
2425                 new_noti->sound_path = NULL;
2426         }
2427         new_noti->vibration_type = noti->vibration_type;
2428         if(noti->vibration_path != NULL) {
2429                 new_noti->vibration_path = strdup(noti->vibration_path);
2430         } else {
2431                 new_noti->vibration_path = NULL;
2432         }
2433         new_noti->led_operation = noti->led_operation;
2434         new_noti->led_argb = noti->led_argb;
2435         new_noti->led_on_ms = noti->led_on_ms;
2436         new_noti->led_off_ms = noti->led_off_ms;
2437
2438         if(noti->domain != NULL) {
2439                 new_noti->domain = strdup(noti->domain);
2440         } else {
2441                 new_noti->domain = NULL;
2442         }
2443         if(noti->dir != NULL) {
2444                 new_noti->dir = strdup(noti->dir);
2445         } else {
2446                 new_noti->dir = NULL;
2447         }
2448
2449         if(noti->b_text != NULL) {
2450                 new_noti->b_text = bundle_dup(noti->b_text);
2451         } else {
2452                 new_noti->b_text = NULL;
2453         }
2454         if(noti->b_key != NULL) {
2455                 new_noti->b_key = bundle_dup(noti->b_key);
2456         } else {
2457                 new_noti->b_key = NULL;
2458         }
2459         if(noti->b_format_args != NULL) {
2460                 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2461         } else {
2462                 new_noti->b_format_args = NULL;
2463         }
2464         new_noti->num_format_args = noti->num_format_args;
2465
2466         if(noti->b_image_path != NULL) {
2467                 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2468         } else {
2469                 new_noti->b_image_path = NULL;
2470         }
2471
2472         new_noti->time = noti->time;
2473         new_noti->insert_time = noti->insert_time;
2474
2475         new_noti->flags_for_property = noti->flags_for_property;
2476         new_noti->display_applist = noti->display_applist;
2477
2478         new_noti->progress_size = noti->progress_size;
2479         new_noti->progress_percentage = noti->progress_percentage;
2480
2481         new_noti->app_icon_path = NULL;
2482         new_noti->app_name = NULL;
2483         new_noti->temp_title = NULL;
2484         new_noti->temp_content = NULL;
2485
2486         *clone = new_noti;
2487
2488         return NOTIFICATION_ERROR_NONE;
2489 }
2490
2491
2492 EXPORT_API int notification_free(notification_h noti)
2493 {
2494         int i = 0;
2495         if (noti == NULL) {
2496                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2497         }
2498
2499         if (noti->caller_pkgname) {
2500                 free(noti->caller_pkgname);
2501         }
2502         if (noti->launch_pkgname) {
2503                 free(noti->launch_pkgname);
2504         }
2505         if (noti->args) {
2506                 bundle_free(noti->args);
2507         }
2508         if (noti->group_args) {
2509                 bundle_free(noti->group_args);
2510         }
2511
2512         if (noti->b_execute_option) {
2513                 bundle_free(noti->b_execute_option);
2514         }
2515         if (noti->b_service_responding) {
2516                 bundle_free(noti->b_service_responding);
2517         }
2518         if (noti->b_service_single_launch) {
2519                 bundle_free(noti->b_service_single_launch);
2520         }
2521         if (noti->b_service_multi_launch) {
2522                 bundle_free(noti->b_service_multi_launch);
2523         }
2524
2525         for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
2526                 if(noti->b_event_handler[i] != NULL) {
2527                         bundle_free(noti->b_event_handler[i]);
2528                 }
2529         }
2530
2531         if (noti->sound_path) {
2532                 free(noti->sound_path);
2533         }
2534         if (noti->vibration_path) {
2535                 free(noti->vibration_path);
2536         }
2537
2538         if (noti->domain) {
2539                 free(noti->domain);
2540         }
2541         if (noti->dir) {
2542                 free(noti->dir);
2543         }
2544
2545         if (noti->b_text) {
2546                 bundle_free(noti->b_text);
2547         }
2548         if (noti->b_key) {
2549                 bundle_free(noti->b_key);
2550         }
2551         if (noti->b_format_args) {
2552                 bundle_free(noti->b_format_args);
2553         }
2554
2555         if (noti->b_image_path) {
2556                 bundle_free(noti->b_image_path);
2557         }
2558
2559         if (noti->app_icon_path) {
2560                 free(noti->app_icon_path);
2561         }
2562         if (noti->app_name) {
2563                 free(noti->app_name);
2564         }
2565         if (noti->temp_title) {
2566                 free(noti->temp_title);
2567         }
2568         if (noti->temp_content) {
2569                 free(noti->temp_content);
2570         }
2571
2572         if (noti->tag) {
2573                 free(noti->tag);
2574         }
2575
2576         free(noti);
2577
2578         return NOTIFICATION_ERROR_NONE;
2579 }
2580
2581 EXPORT_API int
2582 notification_resister_changed_cb(void (*changed_cb)
2583                                  (void *data, notification_type_e type),
2584                                  void *user_data)
2585 {
2586         notification_cb_list_s *noti_cb_list_new = NULL;
2587         notification_cb_list_s *noti_cb_list = NULL;
2588
2589         if (changed_cb == NULL) {
2590                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2591         }
2592         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2593                 return NOTIFICATION_ERROR_IO_ERROR;
2594         }
2595
2596         noti_cb_list_new =
2597             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2598
2599         if (noti_cb_list_new == NULL) {
2600                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
2601         }
2602
2603         noti_cb_list_new->next = NULL;
2604         noti_cb_list_new->prev = NULL;
2605
2606         noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
2607         noti_cb_list_new->changed_cb = changed_cb;
2608         noti_cb_list_new->detailed_changed_cb = NULL;
2609         noti_cb_list_new->data = user_data;
2610
2611         if (g_notification_cb_list == NULL) {
2612                 g_notification_cb_list = noti_cb_list_new;
2613         } else {
2614                 noti_cb_list = g_notification_cb_list;
2615
2616                 while (noti_cb_list->next != NULL) {
2617                         noti_cb_list = noti_cb_list->next;
2618                 }
2619
2620                 noti_cb_list->next = noti_cb_list_new;
2621                 noti_cb_list_new->prev = noti_cb_list;
2622         }
2623         return NOTIFICATION_ERROR_NONE;
2624 }
2625
2626 EXPORT_API int
2627 notification_unresister_changed_cb(void (*changed_cb)
2628                                    (void *data, notification_type_e type))
2629 {
2630         notification_cb_list_s *noti_cb_list = NULL;
2631         notification_cb_list_s *noti_cb_list_prev = NULL;
2632         notification_cb_list_s *noti_cb_list_next = NULL;
2633
2634         noti_cb_list = g_notification_cb_list;
2635
2636         if (changed_cb == NULL) {
2637                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2638         }
2639         if (noti_cb_list == NULL) {
2640                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2641         }
2642
2643         while (noti_cb_list->prev != NULL) {
2644                 noti_cb_list = noti_cb_list->prev;
2645         }
2646
2647         do {
2648                 if (noti_cb_list->changed_cb == changed_cb) {
2649                         noti_cb_list_prev = noti_cb_list->prev;
2650                         noti_cb_list_next = noti_cb_list->next;
2651
2652                         if (noti_cb_list_prev == NULL) {
2653                                 g_notification_cb_list = noti_cb_list_next;
2654                         } else {
2655                                 noti_cb_list_prev->next = noti_cb_list_next;
2656                         }
2657
2658                         if (noti_cb_list_next == NULL) {
2659                                 if (noti_cb_list_prev != NULL) {
2660                                         noti_cb_list_prev->next = NULL;
2661                                 }
2662                         } else {
2663                                 noti_cb_list_next->prev = noti_cb_list_prev;
2664                         }
2665
2666                         free(noti_cb_list);
2667
2668                         if (g_notification_cb_list == NULL)
2669                                 notification_ipc_monitor_fini();
2670
2671                         return NOTIFICATION_ERROR_NONE;
2672                 }
2673                 noti_cb_list = noti_cb_list->next;
2674         } while (noti_cb_list != NULL);
2675
2676         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2677 }
2678
2679 EXPORT_API int
2680 notification_register_detailed_changed_cb(
2681                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2682                 void *user_data)
2683 {
2684         notification_cb_list_s *noti_cb_list_new = NULL;
2685         notification_cb_list_s *noti_cb_list = NULL;
2686
2687         if (detailed_changed_cb == NULL) {
2688                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2689         }
2690         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2691                 return NOTIFICATION_ERROR_IO_ERROR;
2692         }
2693
2694         noti_cb_list_new =
2695             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2696
2697         if (noti_cb_list_new == NULL) {
2698                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
2699         }
2700
2701         noti_cb_list_new->next = NULL;
2702         noti_cb_list_new->prev = NULL;
2703
2704         noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
2705         noti_cb_list_new->changed_cb = NULL;
2706         noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
2707         noti_cb_list_new->data = user_data;
2708
2709         if (g_notification_cb_list == NULL) {
2710                 g_notification_cb_list = noti_cb_list_new;
2711         } else {
2712                 noti_cb_list = g_notification_cb_list;
2713
2714                 while (noti_cb_list->next != NULL) {
2715                         noti_cb_list = noti_cb_list->next;
2716                 }
2717
2718                 noti_cb_list->next = noti_cb_list_new;
2719                 noti_cb_list_new->prev = noti_cb_list;
2720         }
2721         return NOTIFICATION_ERROR_NONE;
2722 }
2723
2724 EXPORT_API int
2725 notification_unregister_detailed_changed_cb(
2726                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2727                 void *user_data)
2728 {
2729         notification_cb_list_s *noti_cb_list = NULL;
2730         notification_cb_list_s *noti_cb_list_prev = NULL;
2731         notification_cb_list_s *noti_cb_list_next = NULL;
2732
2733         noti_cb_list = g_notification_cb_list;
2734
2735         if (detailed_changed_cb == NULL) {
2736                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2737         }
2738         if (noti_cb_list == NULL) {
2739                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2740         }
2741
2742         while (noti_cb_list->prev != NULL) {
2743                 noti_cb_list = noti_cb_list->prev;
2744         }
2745
2746         do {
2747                 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
2748                         noti_cb_list_prev = noti_cb_list->prev;
2749                         noti_cb_list_next = noti_cb_list->next;
2750
2751                         if (noti_cb_list_prev == NULL) {
2752                                 g_notification_cb_list = noti_cb_list_next;
2753                         } else {
2754                                 noti_cb_list_prev->next = noti_cb_list_next;
2755                         }
2756
2757                         if (noti_cb_list_next == NULL) {
2758                                 if (noti_cb_list_prev != NULL) {
2759                                         noti_cb_list_prev->next = NULL;
2760                                 }
2761                         } else {
2762                                 noti_cb_list_next->prev = noti_cb_list_prev;
2763                         }
2764
2765                         free(noti_cb_list);
2766
2767                         if (g_notification_cb_list == NULL)
2768                                 notification_ipc_monitor_fini();
2769
2770                         return NOTIFICATION_ERROR_NONE;
2771                 }
2772                 noti_cb_list = noti_cb_list->next;
2773         } while (noti_cb_list != NULL);
2774
2775         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2776 }
2777
2778 EXPORT_API int notification_get_count(notification_type_e type,
2779                                                        const char *pkgname,
2780                                                        int group_id,
2781                                                        int priv_id, int *count)
2782 {
2783         int ret = 0;
2784         int noti_count = 0;
2785
2786         if (count == NULL) {
2787                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2788         }
2789
2790         ret =
2791             notification_noti_get_count(type, pkgname, group_id, priv_id,
2792                                         &noti_count);
2793         if (ret != NOTIFICATION_ERROR_NONE) {
2794                 return ret;
2795         }
2796
2797         *count = noti_count;
2798
2799         return NOTIFICATION_ERROR_NONE;
2800 }
2801
2802 EXPORT_API int notification_get_list(notification_type_e type,
2803                                                       int count,
2804                                                       notification_list_h *list)
2805 {
2806         notification_list_h get_list = NULL;
2807         int ret = 0;
2808
2809         if (list == NULL) {
2810                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2811         }
2812
2813         ret = notification_noti_get_grouping_list(type, count, &get_list);
2814         if (ret != NOTIFICATION_ERROR_NONE) {
2815                 return ret;
2816         }
2817
2818         *list = get_list;
2819
2820         return NOTIFICATION_ERROR_NONE;
2821 }
2822
2823 EXPORT_API int
2824 notification_get_grouping_list(notification_type_e type, int count,
2825                                notification_list_h * list)
2826 {
2827         notification_list_h get_list = NULL;
2828         int ret = 0;
2829
2830         if (list == NULL) {
2831                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2832         }
2833
2834         ret = notification_noti_get_grouping_list(type, count, &get_list);
2835         if (ret != NOTIFICATION_ERROR_NONE) {
2836                 return ret;
2837         }
2838
2839         *list = get_list;
2840
2841         return NOTIFICATION_ERROR_NONE;
2842 }
2843
2844 EXPORT_API int notification_get_detail_list(const char *pkgname,
2845                                                              int group_id,
2846                                                              int priv_id,
2847                                                              int count,
2848                                                              notification_list_h *list)
2849 {
2850         notification_list_h get_list = NULL;
2851         int ret = 0;
2852
2853         if (list == NULL) {
2854                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2855         }
2856
2857         ret =
2858             notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2859                                               &get_list);
2860         if (ret != NOTIFICATION_ERROR_NONE) {
2861                 return ret;
2862         }
2863
2864         *list = get_list;
2865
2866         return NOTIFICATION_ERROR_NONE;
2867 }
2868
2869 EXPORT_API int notification_free_list(notification_list_h list)
2870 {
2871         notification_list_h cur_list = NULL;
2872         notification_h noti = NULL;
2873
2874         if (list == NULL) {
2875                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2876         }
2877
2878         cur_list = notification_list_get_head(list);
2879
2880         while (cur_list != NULL) {
2881                 noti = notification_list_get_data(cur_list);
2882                 cur_list = notification_list_remove(cur_list, noti);
2883
2884                 notification_free(noti);
2885         }
2886
2887         return NOTIFICATION_ERROR_NONE;
2888 }
2889
2890 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
2891                                                        void *data)
2892 {
2893         if (noti_op == NULL || data == NULL) {
2894                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2895         }
2896
2897         switch (type) {
2898                 case NOTIFICATION_OP_DATA_TYPE:
2899                         *((int*)data) = noti_op->type;
2900                         break;
2901                 case NOTIFICATION_OP_DATA_PRIV_ID:
2902                         *((int*)data) = noti_op->priv_id;
2903                         break;
2904                 case NOTIFICATION_OP_DATA_NOTI:
2905                         *((notification_h *)data) = noti_op->noti;
2906                         break;
2907                 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
2908                         *((int*)data) = noti_op->extra_info_1;
2909                         break;
2910                 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
2911                         *((int*)data) = noti_op->extra_info_2;
2912                         break;
2913                 default:
2914                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
2915                         break;
2916         }
2917
2918         return NOTIFICATION_ERROR_NONE;
2919 }
2920
2921 void notification_call_changed_cb(notification_op *op_list, int op_num)
2922 {
2923         notification_cb_list_s *noti_cb_list = NULL;
2924         notification_type_e type = 0;
2925
2926         if (g_notification_cb_list == NULL) {
2927                 return;
2928         }
2929         noti_cb_list = g_notification_cb_list;
2930
2931         while (noti_cb_list->prev != NULL) {
2932                 noti_cb_list = noti_cb_list->prev;
2933         }
2934
2935         if (op_list == NULL) {
2936                 NOTIFICATION_ERR("invalid data");
2937                 return ;
2938         }
2939
2940         notification_get_type(op_list->noti, &type);
2941
2942         while (noti_cb_list != NULL) {
2943                 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
2944                         noti_cb_list->changed_cb(noti_cb_list->data,
2945                                                  type);
2946                 }
2947                 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
2948                         noti_cb_list->detailed_changed_cb(noti_cb_list->data,
2949                                                 type, op_list, op_num);
2950                 }
2951
2952                 noti_cb_list = noti_cb_list->next;
2953         }
2954 }
2955
2956 EXPORT_API int notification_is_service_ready(void)
2957 {
2958         return notification_ipc_is_master_ready();
2959 }
2960
2961 EXPORT_API int
2962 notification_add_deferred_task(
2963                 void (*deferred_task_cb)(void *data), void *user_data)
2964 {
2965         if (deferred_task_cb == NULL) {
2966                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2967         }
2968
2969         return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
2970 }
2971
2972 EXPORT_API int
2973 notification_del_deferred_task(
2974                 void (*deferred_task_cb)(void *data))
2975 {
2976         if (deferred_task_cb == NULL) {
2977                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2978         }
2979
2980         return notification_ipc_del_deffered_task(deferred_task_cb);
2981 }
2982
2983 /* notification_set_icon will be removed */
2984 EXPORT_API int notification_set_icon(notification_h noti,
2985                                                       const char *icon_path)
2986 {
2987         int ret_err = NOTIFICATION_ERROR_NONE;
2988
2989         ret_err =
2990             notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2991                                    icon_path);
2992
2993         return ret_err;
2994 }
2995
2996 /* notification_get_icon will be removed */
2997 EXPORT_API int notification_get_icon(notification_h noti,
2998                                                       char **icon_path)
2999 {
3000         int ret_err = NOTIFICATION_ERROR_NONE;
3001         char *ret_image_path = NULL;
3002
3003         ret_err =
3004             notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
3005                                    &ret_image_path);
3006
3007         if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
3008                 *icon_path = ret_image_path;
3009
3010                 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
3011         }
3012
3013         return ret_err;
3014 }
3015
3016 EXPORT_API int notification_set_title(notification_h noti,
3017                                                        const char *title,
3018                                                        const char *loc_title)
3019 {
3020         int noti_err = NOTIFICATION_ERROR_NONE;
3021
3022         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
3023                                          title, loc_title,
3024                                          NOTIFICATION_VARIABLE_TYPE_NONE);
3025
3026         return noti_err;
3027 }
3028
3029 EXPORT_API int notification_get_title(notification_h noti,
3030                                                        char **title,
3031                                                        char **loc_title)
3032 {
3033         int noti_err = NOTIFICATION_ERROR_NONE;
3034         char *ret_text = NULL;
3035
3036         noti_err =
3037             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
3038                                   &ret_text);
3039
3040         if (title != NULL) {
3041                 *title = ret_text;
3042         }
3043
3044         if (loc_title != NULL) {
3045                 *loc_title = NULL;
3046         }
3047
3048         return noti_err;
3049 }
3050
3051 EXPORT_API int notification_set_content(notification_h noti,
3052                                                          const char *content,
3053                                                          const char *loc_content)
3054 {
3055         int noti_err = NOTIFICATION_ERROR_NONE;
3056
3057         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
3058                                          content, loc_content,
3059                                          NOTIFICATION_VARIABLE_TYPE_NONE);
3060
3061         return noti_err;
3062 }
3063
3064 EXPORT_API int notification_get_content(notification_h noti,
3065                                                          char **content,
3066                                                          char **loc_content)
3067 {
3068         int noti_err = NOTIFICATION_ERROR_NONE;
3069         char *ret_text = NULL;
3070
3071         noti_err =
3072             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
3073                                   &ret_text);
3074
3075         if (content != NULL) {
3076                 *content = ret_text;
3077         }
3078
3079         if (loc_content != NULL) {
3080                 *loc_content = NULL;
3081         }
3082
3083         return noti_err;
3084
3085 #if 0
3086         ret =
3087             vconf_get_bool
3088             (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
3089
3090         if (ret == -1 || boolval == 0) {
3091                 if (content != NULL && noti->default_content != NULL) {
3092                         *content = noti->default_content;
3093                 }
3094
3095                 if (loc_content != NULL && noti->loc_default_content != NULL) {
3096                         *loc_content = noti->loc_default_content;
3097                 }
3098         }
3099 #endif
3100 }
3101
3102 EXPORT_API int notification_set_args(notification_h noti,
3103                                                       bundle * args,
3104                                                       bundle * group_args)
3105 {
3106         if (noti == NULL || args == NULL) {
3107                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3108         }
3109
3110         if (noti->args) {
3111                 bundle_free(noti->args);
3112         }
3113
3114         noti->args = bundle_dup(args);
3115
3116         if (noti->group_args) {
3117                 bundle_free(noti->group_args);
3118                 noti->group_args = NULL;
3119         }
3120
3121         if (group_args != NULL) {
3122                 noti->group_args = bundle_dup(group_args);
3123         }
3124
3125         return NOTIFICATION_ERROR_NONE;
3126 }
3127
3128 EXPORT_API int notification_get_args(notification_h noti,
3129                                                       bundle ** args,
3130                                                       bundle ** group_args)
3131 {
3132         if (noti == NULL || args == NULL) {
3133                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3134         }
3135
3136         if (noti->args) {
3137                 *args = noti->args;
3138         } else {
3139                 *args = NULL;
3140         }
3141
3142         if (group_args != NULL && noti->group_args) {
3143                 *group_args = noti->group_args;
3144         }
3145
3146         return NOTIFICATION_ERROR_NONE;
3147 }
3148
3149 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
3150                                                                       notification_type_e type,
3151                                                                       int group_id)
3152 {
3153         int ret = 0;
3154         char *caller_pkgname = NULL;
3155
3156         if (pkgname == NULL) {
3157                 caller_pkgname = notification_get_pkgname_by_pid();
3158         } else {
3159                 caller_pkgname = strdup(pkgname);
3160         }
3161
3162         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
3163         if (ret != NOTIFICATION_ERROR_NONE) {
3164                 if (caller_pkgname) {
3165                         free(caller_pkgname);
3166                 }
3167                 return ret;
3168         }
3169
3170         if (caller_pkgname) {
3171                 free(caller_pkgname);
3172         }
3173         return NOTIFICATION_ERROR_NONE;
3174 }
3175
3176 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
3177                                                                      notification_type_e type,
3178                                                                      int priv_id)
3179 {
3180         int ret = 0;
3181         char *caller_pkgname = NULL;
3182
3183         if (pkgname == NULL) {
3184                 caller_pkgname = notification_get_pkgname_by_pid();
3185         } else {
3186                 caller_pkgname = strdup(pkgname);
3187         }
3188
3189         ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
3190         if (ret != NOTIFICATION_ERROR_NONE) {
3191                 if (caller_pkgname) {
3192                         free(caller_pkgname);
3193                 }
3194                 return ret;
3195         }
3196
3197         if (caller_pkgname) {
3198                 free(caller_pkgname);
3199         }
3200         return NOTIFICATION_ERROR_NONE;
3201 }
3202
3203 EXPORT_API int  notification_set_tag(notification_h noti, const char *tag)
3204 {
3205         /* Check noti is valid data */
3206         if (noti == NULL) {
3207                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3208         }
3209
3210         if (tag != NULL) {
3211                 /* save input TAG */
3212                 if (noti->tag != NULL) {
3213                         free(noti->tag);
3214                 }
3215                 noti->tag = strdup(tag);
3216         }
3217
3218         return NOTIFICATION_ERROR_NONE;
3219
3220 }
3221
3222 EXPORT_API int  notification_get_tag(notification_h noti, const char **tag)
3223 {
3224         /* Check noti is valid data */
3225         if (noti == NULL) {
3226                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3227         }
3228
3229         /* Set sound type */
3230         *tag = noti->tag;
3231         return NOTIFICATION_ERROR_NONE;
3232 }
3233
3234 EXPORT_API int notification_register_toast_message(void (*posted_toast_cb) (void *data))
3235 {
3236         if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
3237                 return NOTIFICATION_ERROR_IO_ERROR;
3238         }
3239
3240         posted_toast_message_cb = posted_toast_cb;
3241
3242         return NOTIFICATION_ERROR_NONE;
3243 }
3244
3245 void notification_call_posted_toast_cb(const char *message)
3246 {
3247         if (posted_toast_message_cb != NULL) {
3248                 posted_toast_message_cb((void*)message);
3249         }
3250 }
3251
3252 EXPORT_API int notification_set_permission(notification_h handle, notification_permission_type_e permission_type, const char *app_id)
3253 {
3254         return NOTIFICATION_ERROR_INVALID_OPERATION;
3255 }
3256
3257 EXPORT_API int notification_get_permission(notification_h handle, notification_permission_type_e *permission_type, const char **app_id)
3258 {
3259         return NOTIFICATION_ERROR_INVALID_OPERATION;
3260 }
3261
3262 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
3263 {
3264         if (noti == NULL)
3265                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3266
3267         return NOTIFICATION_ERROR_NONE;
3268 }
3269
3270 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
3271 {
3272         if (noti == NULL)
3273                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
3274
3275         return NOTIFICATION_ERROR_NONE;
3276 }