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