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