4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
28 #include <dbus/dbus.h>
29 #include <dbus/dbus-glib-lowlevel.h>
34 #include <vconf-keys.h>
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>
46 typedef struct _notification_cb_list notification_cb_list_s;
48 typedef enum __notification_cb_type {
49 NOTIFICATION_CB_NORMAL = 1,
50 NOTIFICATION_CB_DETAILED,
51 } _notification_cb_type_e;
53 struct _notification_cb_list {
54 notification_cb_list_s *prev;
55 notification_cb_list_s *next;
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);
63 static notification_cb_list_s *g_notification_cb_list = NULL;
65 #define NOTI_TEXT_RESULT_LEN 2048
66 #define NOTI_PKGNAME_LEN 512
68 static char *_notification_get_pkgname_by_pid(void)
70 char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
71 int pid = 0, ret = AUL_R_OK;
77 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
78 if (ret != AUL_R_OK) {
79 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
81 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
83 fd = open(buf, O_RDONLY);
88 ret = read(fd, pkgname, sizeof(pkgname) - 1);
98 * "ret" is not able to be larger than "sizeof(pkgname) - 1",
99 * if the system is not going wrong.
102 if (strlen(pkgname) <= 0) {
107 dup_pkgname = strdup(pkgname);
109 NOTIFICATION_ERR("Heap: %s\n", strerror(errno));
114 static void _notification_get_text_domain(notification_h noti)
116 if (noti->domain != NULL) {
120 if (noti->dir != NULL) {
125 /* notification_set_icon will be removed */
126 EXPORT_API notification_error_e notification_set_icon(notification_h noti,
127 const char *icon_path)
129 int ret_err = NOTIFICATION_ERROR_NONE;
132 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
138 /* notification_get_icon will be removed */
139 EXPORT_API notification_error_e notification_get_icon(notification_h noti,
142 int ret_err = NOTIFICATION_ERROR_NONE;
143 char *ret_image_path = NULL;
146 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
149 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
150 *icon_path = ret_image_path;
152 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
158 EXPORT_API notification_error_e notification_set_image(notification_h noti,
159 notification_image_type_e type,
160 const char *image_path)
163 char buf_key[32] = { 0, };
164 const char *ret_val = NULL;
166 /* Check noti and image_path are valid data */
167 if (noti == NULL || image_path == NULL) {
168 return NOTIFICATION_ERROR_INVALID_DATA;
171 /* Check image type is valid type */
172 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
173 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
174 return NOTIFICATION_ERROR_INVALID_DATA;
177 /* Check image path bundle is exist */
178 if (noti->b_image_path) {
179 /* If image path bundle is exist, store local bundle value */
180 b = noti->b_image_path;
182 /* Set image type to key as char string type */
183 snprintf(buf_key, sizeof(buf_key), "%d", type);
185 /* Get value using key */
186 ret_val = bundle_get_val(b, buf_key);
187 if (ret_val != NULL) {
188 /* If key is exist, remove this value to store new image path */
189 bundle_del(b, buf_key);
192 /* Add new image path with type key */
193 bundle_add(b, buf_key, image_path);
195 /* If image path bundle is not exist, create new one */
198 /* Set image type to key as char string type */
199 snprintf(buf_key, sizeof(buf_key), "%d", type);
201 /* Add new image path with type key */
202 bundle_add(b, buf_key, image_path);
204 /* Save to image path bundle */
205 noti->b_image_path = b;
208 return NOTIFICATION_ERROR_NONE;
211 EXPORT_API notification_error_e notification_get_image(notification_h noti,
212 notification_image_type_e type,
216 char buf_key[32] = { 0, };
217 const char *ret_val = NULL;
219 /* Check noti and image_path is valid data */
220 if (noti == NULL || image_path == NULL) {
221 return NOTIFICATION_ERROR_INVALID_DATA;
224 /* Check image type is valid data */
225 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
226 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
227 return NOTIFICATION_ERROR_INVALID_DATA;
230 /* Check image path bundle exist */
231 if (noti->b_image_path) {
232 /* If image path bundle exist, store local bundle data */
233 b = noti->b_image_path;
235 /* Set image type to key as char string type */
236 snprintf(buf_key, sizeof(buf_key), "%d", type);
238 /* Get value of key */
239 ret_val = bundle_get_val(b, buf_key);
241 *image_path = (char *)ret_val;
243 /* If image path bundle does not exist, image path is NULL */
247 /* If image path is NULL and type is ICON, icon path set from AIL */
248 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
249 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
250 /* Check App icon path is already set */
251 if (noti->app_icon_path != NULL) {
252 /* image path will be app icon path */
253 *image_path = noti->app_icon_path;
259 return NOTIFICATION_ERROR_NONE;
262 EXPORT_API notification_error_e notification_set_time(notification_h noti,
265 /* Check noti is valid data */
267 return NOTIFICATION_ERROR_INVALID_DATA;
270 if (input_time == 0) {
271 /* If input time is 0, set current time */
272 noti->time = time(NULL);
274 /* save input time */
275 noti->time = input_time;
278 return NOTIFICATION_ERROR_NONE;
281 EXPORT_API notification_error_e notification_get_time(notification_h noti,
284 /* Check noti and time is valid data */
285 if (noti == NULL || ret_time == NULL) {
286 return NOTIFICATION_ERROR_INVALID_DATA;
289 /* Set time infomation */
290 *ret_time = noti->time;
292 return NOTIFICATION_ERROR_NONE;
295 EXPORT_API notification_error_e notification_get_insert_time(notification_h noti,
298 /* Check noti and ret_time is valid data */
299 if (noti == NULL || ret_time == NULL) {
300 return NOTIFICATION_ERROR_INVALID_DATA;
303 /* Set insert time information */
304 *ret_time = noti->insert_time;
306 return NOTIFICATION_ERROR_NONE;
309 EXPORT_API notification_error_e notification_set_title(notification_h noti,
311 const char *loc_title)
313 int noti_err = NOTIFICATION_ERROR_NONE;
315 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
317 NOTIFICATION_VARIABLE_TYPE_NONE);
322 EXPORT_API notification_error_e notification_get_title(notification_h noti,
326 int noti_err = NOTIFICATION_ERROR_NONE;
327 char *ret_text = NULL;
330 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
337 if (loc_title != NULL) {
344 EXPORT_API notification_error_e notification_set_content(notification_h noti,
346 const char *loc_content)
348 int noti_err = NOTIFICATION_ERROR_NONE;
350 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
351 content, loc_content,
352 NOTIFICATION_VARIABLE_TYPE_NONE);
357 EXPORT_API notification_error_e notification_get_content(notification_h noti,
361 int noti_err = NOTIFICATION_ERROR_NONE;
362 char *ret_text = NULL;
365 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
368 if (content != NULL) {
372 if (loc_content != NULL) {
381 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
383 if (ret == -1 || boolval == 0) {
384 if (content != NULL && noti->default_content != NULL) {
385 *content = noti->default_content;
388 if (loc_content != NULL && noti->loc_default_content != NULL) {
389 *loc_content = noti->loc_default_content;
395 EXPORT_API notification_error_e notification_set_text(notification_h noti,
396 notification_text_type_e type,
402 char buf_key[32] = { 0, };
403 char buf_val[1024] = { 0, };
404 const char *ret_val = NULL;
406 notification_variable_type_e var_type;
408 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
409 int var_value_int = 0;
410 double var_value_double = 0.0;
411 char *var_value_string = NULL;
412 notification_count_pos_type_e var_value_count =
413 NOTIFICATION_COUNT_POS_NONE;
415 /* Check noti is valid data */
417 return NOTIFICATION_ERROR_INVALID_DATA;
420 /* Check text type is valid type */
421 if (type <= NOTIFICATION_TEXT_TYPE_NONE
422 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
423 return NOTIFICATION_ERROR_INVALID_DATA;
426 /* Check text bundle exist */
428 if (noti->b_text != NULL) {
429 /* If text bundle exist, store local bundle data */
432 /* Make type to key as char string */
433 snprintf(buf_key, sizeof(buf_key), "%d", type);
435 /* Get value using type key */
436 ret_val = bundle_get_val(b, buf_key);
437 if (ret_val != NULL) {
438 /* If value exist, remove this to add new value */
439 bundle_del(b, buf_key);
442 snprintf(buf_val, sizeof(buf_val), "%s", text);
444 /* Add new text value */
445 bundle_add(b, buf_key, buf_val);
447 /* If text bundle does not exist, create new one */
450 /* Make type to key as char string */
451 snprintf(buf_key, sizeof(buf_key), "%d", type);
453 snprintf(buf_val, sizeof(buf_val), "%s", text);
455 /* Add new text value */
456 bundle_add(b, buf_key, buf_val);
458 /* Save text bundle */
462 /* Reset if text is NULL */
463 if (noti->b_text != NULL) {
464 /* If text bundle exist, store local bundle data */
467 /* Make type to key as char string */
468 snprintf(buf_key, sizeof(buf_key), "%d", type);
470 /* Get value using type key */
471 ret_val = bundle_get_val(b, buf_key);
472 if (ret_val != NULL) {
473 /* If value exist, remove this */
474 bundle_del(b, buf_key);
479 /* Save key if key is valid data */
481 /* Check key bundle exist */
482 if (noti->b_key != NULL) {
483 /* If key bundle exist, store local bundle data */
486 /* Make type to key as char string */
487 snprintf(buf_key, sizeof(buf_key), "%d", type);
489 /* Get value using type key */
490 ret_val = bundle_get_val(b, buf_key);
491 if (ret_val != NULL) {
492 /* If value exist, remove this to add new value */
493 bundle_del(b, buf_key);
496 snprintf(buf_val, sizeof(buf_val), "%s", key);
498 /* Add new key value */
499 bundle_add(b, buf_key, buf_val);
501 /* If key bundle does not exist, create new one */
504 /* Make type to key as char string */
505 snprintf(buf_key, sizeof(buf_key), "%d", type);
507 snprintf(buf_val, sizeof(buf_val), "%s", key);
509 /* Add new key value */
510 bundle_add(b, buf_key, buf_val);
512 /* Save key bundle */
516 /* Reset if key is NULL */
517 if (noti->b_key != NULL) {
518 /* If key bundle exist, store local bundle data */
521 /* Make type to key as char string */
522 snprintf(buf_key, sizeof(buf_key), "%d", type);
524 /* Get value using type key */
525 ret_val = bundle_get_val(b, buf_key);
526 if (ret_val != NULL) {
527 /* If value exist, remove this */
528 bundle_del(b, buf_key);
533 if (noti->b_format_args != NULL) {
534 b = noti->b_format_args;
539 va_start(var_args, args_type);
541 var_type = args_type;
544 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
546 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
547 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
549 ret_val = bundle_get_val(b, buf_key);
550 if (ret_val != NULL) {
551 bundle_del(b, buf_key);
554 bundle_add(b, buf_key, buf_val);
557 case NOTIFICATION_VARIABLE_TYPE_INT:
558 var_value_int = va_arg(var_args, int);
561 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
563 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
565 ret_val = bundle_get_val(b, buf_key);
566 if (ret_val != NULL) {
567 bundle_del(b, buf_key);
570 bundle_add(b, buf_key, buf_val);
572 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
573 var_value_double = va_arg(var_args, double);
576 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
578 snprintf(buf_val, sizeof(buf_val), "%.2f",
581 ret_val = bundle_get_val(b, buf_key);
582 if (ret_val != NULL) {
583 bundle_del(b, buf_key);
586 bundle_add(b, buf_key, buf_val);
588 case NOTIFICATION_VARIABLE_TYPE_STRING:
589 var_value_string = va_arg(var_args, char *);
592 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
594 snprintf(buf_val, sizeof(buf_val), "%s",
597 ret_val = bundle_get_val(b, buf_key);
598 if (ret_val != NULL) {
599 bundle_del(b, buf_key);
602 bundle_add(b, buf_key, buf_val);
604 case NOTIFICATION_VARIABLE_TYPE_COUNT:
606 va_arg(var_args, notification_count_pos_type_e);
609 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
611 snprintf(buf_val, sizeof(buf_val), "%d",
614 ret_val = bundle_get_val(b, buf_key);
615 if (ret_val != NULL) {
616 bundle_del(b, buf_key);
619 bundle_add(b, buf_key, buf_val);
622 NOTIFICATION_ERR("Error. invalid variable type. : %d",
624 noti_err = NOTIFICATION_ERROR_INVALID_DATA;
629 var_type = va_arg(var_args, notification_variable_type_e);
633 if (noti_err == NOTIFICATION_ERROR_NONE) {
634 noti->num_format_args = num_args;
636 noti->num_format_args = 0;
639 snprintf(buf_key, sizeof(buf_key), "num%d", type);
640 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
642 ret_val = bundle_get_val(b, buf_key);
643 if (ret_val != NULL) {
644 bundle_del(b, buf_key);
647 bundle_add(b, buf_key, buf_val);
649 noti->b_format_args = b;
654 EXPORT_API notification_error_e notification_get_text(notification_h noti,
655 notification_text_type_e type,
659 char buf_key[32] = { 0, };
660 const char *ret_val = NULL;
661 const char *get_str = NULL;
662 const char *get_check_type_str = NULL;
663 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
664 int display_option_flag = 0;
666 char *temp_str = NULL;
667 char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
668 char buf_str[1024] = { 0, };
670 notification_variable_type_e ret_var_type = 0;
671 int ret_variable_int = 0;
672 double ret_variable_double = 0.0;
674 /* Check noti is valid data */
675 if (noti == NULL || text == NULL) {
676 return NOTIFICATION_ERROR_INVALID_DATA;
679 /* Check text type is valid type */
680 if (type <= NOTIFICATION_TEXT_TYPE_NONE
681 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
682 return NOTIFICATION_ERROR_INVALID_DATA;
686 if (noti->b_key != NULL) {
689 /* Get text domain and dir */
690 _notification_get_text_domain(noti);
692 snprintf(buf_key, sizeof(buf_key), "%d", type);
694 ret_val = bundle_get_val(b, buf_key);
695 if (ret_val != NULL && noti->domain != NULL
696 && noti->dir != NULL) {
697 /* Get application string */
698 bindtextdomain(noti->domain, noti->dir);
700 get_str = dgettext(noti->domain, ret_val);
701 } else if (ret_val != NULL) {
702 /* Get system string */
703 get_str = dgettext("sys_string", ret_val);
709 if (get_str == NULL && noti->b_text != NULL) {
712 snprintf(buf_key, sizeof(buf_key), "%d", type);
714 get_str = bundle_get_val(b, buf_key);
719 /* Set display option is off type when option is off, type is noti */
720 if (get_str != NULL && display_option_flag == 1
721 && noti->type == NOTIFICATION_TYPE_NOTI) {
722 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
723 || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
724 /* Set check_type to option content string */
725 if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
727 NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
728 } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
730 NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
734 if (noti->b_key != NULL) {
737 /* Get text domain and dir */
738 _notification_get_text_domain(noti);
740 snprintf(buf_key, sizeof(buf_key), "%d",
743 ret_val = bundle_get_val(b, buf_key);
744 if (ret_val != NULL && noti->domain != NULL
745 && noti->dir != NULL) {
746 /* Get application string */
747 bindtextdomain(noti->domain, noti->dir);
750 dgettext(noti->domain, ret_val);
751 } else if (ret_val != NULL) {
752 /* Get system string */
754 dgettext("sys_string", ret_val);
756 get_check_type_str = NULL;
760 if (get_check_type_str == NULL && noti->b_text != NULL) {
763 snprintf(buf_key, sizeof(buf_key), "%d",
766 get_check_type_str = bundle_get_val(b, buf_key);
770 if (get_check_type_str != NULL) {
771 /* Replace option off type string */
772 get_str = get_check_type_str;
774 /* Set default string */
776 dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
780 if (get_str != NULL) {
781 /* Get number format args */
782 b = noti->b_format_args;
783 noti->num_format_args = 0;
786 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
787 ret_val = bundle_get_val(b, buf_key);
788 if (ret_val != NULL) {
789 noti->num_format_args = atoi(ret_val);
793 if (noti->num_format_args == 0) {
794 *text = (char *)get_str;
796 /* Check first variable is count, LEFT pos */
797 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
798 check_type, num_args);
799 ret_val = bundle_get_val(b, buf_key);
800 ret_var_type = atoi(ret_val);
802 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
804 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
805 check_type, num_args);
806 ret_val = bundle_get_val(b, buf_key);
807 ret_variable_int = atoi(ret_val);
809 if (ret_variable_int ==
810 NOTIFICATION_COUNT_POS_LEFT) {
811 notification_noti_get_count(noti->type,
812 noti->caller_pkgname,
816 snprintf(buf_str, sizeof(buf_str),
817 "%d ", ret_variable_int);
819 int src_len = strlen(result_str);
820 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
822 strncat(result_str, buf_str,
830 /* Check variable IN pos */
831 for (temp_str = (char *)get_str; *temp_str != '\0';
833 if (*temp_str != '%') {
834 strncat(result_str, temp_str, 1);
836 if (*(temp_str + 1) == '%') {
837 strncat(result_str, temp_str,
839 } else if (*(temp_str + 1) == 'd') {
841 ret_variable_int = 0;
845 "%dtype%d", check_type,
848 bundle_get_val(b, buf_key);
849 ret_var_type = atoi(ret_val);
851 NOTIFICATION_VARIABLE_TYPE_COUNT)
853 /* Get notification count */
854 notification_noti_get_count
856 noti->caller_pkgname,
876 sizeof(buf_str), "%d",
879 int src_len = strlen(result_str);
880 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
882 strncat(result_str, buf_str,
888 } else if (*(temp_str + 1) == 's') {
893 check_type, num_args);
895 bundle_get_val(b, buf_key);
898 sizeof(buf_str), "%s",
901 int src_len = strlen(result_str);
902 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
904 strncat(result_str, buf_str,
910 } else if (*(temp_str + 1) == 'f') {
915 check_type, num_args);
917 bundle_get_val(b, buf_key);
918 ret_variable_double =
924 ret_variable_double);
926 int src_len = strlen(result_str);
927 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
929 strncat(result_str, buf_str,
940 /* Check last variable is count, LEFT pos */
941 if (num_args < noti->num_format_args) {
942 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
943 check_type, num_args);
944 ret_val = bundle_get_val(b, buf_key);
945 ret_var_type = atoi(ret_val);
947 NOTIFICATION_VARIABLE_TYPE_COUNT) {
949 snprintf(buf_key, sizeof(buf_key),
950 "%dvalue%d", check_type,
952 ret_val = bundle_get_val(b, buf_key);
953 ret_variable_int = atoi(ret_val);
955 if (ret_variable_int ==
956 NOTIFICATION_COUNT_POS_RIGHT) {
957 notification_noti_get_count
959 noti->caller_pkgname,
964 sizeof(buf_str), " %d",
967 int src_len = strlen(result_str);
968 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
970 strncat(result_str, buf_str,
979 switch (check_type) {
980 case NOTIFICATION_TEXT_TYPE_TITLE:
981 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
982 if (noti->temp_title != NULL)
983 free(noti->temp_title);
985 noti->temp_title = strdup(result_str);
987 *text = noti->temp_title;
989 case NOTIFICATION_TEXT_TYPE_CONTENT:
990 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
991 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
992 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
993 if (noti->temp_content !=
995 free(noti->temp_content);
997 noti->temp_content = strdup(result_str);
999 *text = noti->temp_content;
1011 return NOTIFICATION_ERROR_NONE;
1014 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
1018 /* check noti and domain is valid data */
1019 if (noti == NULL || domain == NULL) {
1020 return NOTIFICATION_ERROR_INVALID_DATA;
1025 /* Remove previous domain */
1029 noti->domain = strdup(domain);
1031 /* Check locale dir */
1033 /* Remove previous locale dir */
1036 /* Copy locale dir */
1037 noti->dir = strdup(dir);
1039 return NOTIFICATION_ERROR_NONE;
1042 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
1046 /* Check noti is valid data */
1048 return NOTIFICATION_ERROR_INVALID_DATA;
1052 if (domain != NULL && noti->domain != NULL) {
1053 *domain = noti->domain;
1056 /* Get locale dir */
1057 if (dir != NULL && noti->dir != NULL) {
1061 return NOTIFICATION_ERROR_NONE;
1064 EXPORT_API notification_error_e notification_set_time_to_text(notification_h noti, notification_text_type_e type,
1067 notification_error_e ret = NOTIFICATION_ERROR_NONE;
1068 char buf[256] = { 0, };
1069 char buf_tag[512] = { 0, };
1072 return NOTIFICATION_ERROR_INVALID_DATA;
1075 return NOTIFICATION_ERROR_INVALID_DATA;
1078 snprintf(buf, sizeof(buf), "%lu", time);
1079 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
1081 if (ret != NOTIFICATION_ERROR_NONE) {
1085 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1088 EXPORT_API notification_error_e notification_get_time_from_text(notification_h noti, notification_text_type_e type,
1091 notification_error_e ret = NOTIFICATION_ERROR_NONE;
1094 return NOTIFICATION_ERROR_INVALID_DATA;
1097 return NOTIFICATION_ERROR_INVALID_DATA;
1100 char *ret_text = NULL;
1101 ret = notification_get_text(noti, type, &ret_text);
1103 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
1104 return NOTIFICATION_ERROR_INVALID_DATA;
1107 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
1108 return NOTIFICATION_ERROR_INVALID_DATA;
1111 char *tag_value = NULL;
1112 tag_value = notification_noti_strip_tag(ret_text);
1113 if (tag_value == NULL) {
1114 return NOTIFICATION_ERROR_INVALID_DATA;
1117 *time = atol(tag_value);
1120 return NOTIFICATION_ERROR_NONE;
1123 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1124 notification_sound_type_e type,
1127 /* Check noti is valid data */
1129 return NOTIFICATION_ERROR_INVALID_DATA;
1132 /* Check type is valid */
1133 if (type < NOTIFICATION_SOUND_TYPE_NONE
1134 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1135 return NOTIFICATION_ERROR_INVALID_DATA;
1138 /* Save sound type */
1139 noti->sound_type = type;
1141 /* Save sound path if user data type */
1142 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1143 if (noti->sound_path != NULL) {
1144 free(noti->sound_path);
1147 noti->sound_path = strdup(path);
1149 if (noti->sound_path != NULL) {
1150 free(noti->sound_path);
1151 noti->sound_path = NULL;
1155 return NOTIFICATION_ERROR_NONE;
1158 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1159 notification_sound_type_e *type,
1162 /* check noti and type is valid data */
1163 if (noti == NULL || type == NULL) {
1164 return NOTIFICATION_ERROR_INVALID_DATA;
1167 /* Set sound type */
1168 *type = noti->sound_type;
1170 /* Set sound path if user data type */
1171 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1173 *path = noti->sound_path;
1176 return NOTIFICATION_ERROR_NONE;
1179 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1180 notification_vibration_type_e type,
1183 /* Check noti is valid data */
1185 return NOTIFICATION_ERROR_INVALID_DATA;
1188 /* Check type is valid */
1189 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1190 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1191 return NOTIFICATION_ERROR_INVALID_DATA;
1194 /* Save vibration type */
1195 noti->vibration_type = type;
1197 /* Save sound path if user data type */
1198 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1199 if (noti->vibration_path != NULL) {
1200 free(noti->vibration_path);
1203 noti->vibration_path = strdup(path);
1205 if (noti->vibration_path != NULL) {
1206 free(noti->vibration_path);
1207 noti->vibration_path = NULL;
1211 return NOTIFICATION_ERROR_NONE;
1215 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1216 notification_vibration_type_e *type,
1219 /* check noti and type is valid data */
1220 if (noti == NULL || type == NULL) {
1221 return NOTIFICATION_ERROR_INVALID_DATA;
1224 /* Set vibration type */
1225 *type = noti->vibration_type;
1227 /* Set sound path if user data type */
1228 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1230 *path = noti->vibration_path;
1233 return NOTIFICATION_ERROR_NONE;
1236 EXPORT_API notification_error_e notification_set_led(notification_h noti,
1237 notification_led_op_e operation,
1240 /* Check noti is valid data */
1242 return NOTIFICATION_ERROR_INVALID_DATA;
1245 /* Check operation is valid */
1246 if (operation < NOTIFICATION_LED_OP_OFF
1247 || operation >= NOTIFICATION_LED_OP_MAX) {
1248 return NOTIFICATION_ERROR_INVALID_DATA;
1251 /* Save led operation */
1252 noti->led_operation = operation;
1254 /* Save led argb if operation is turning on LED with custom color */
1255 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1256 noti->led_argb = led_argb;
1259 return NOTIFICATION_ERROR_NONE;
1262 EXPORT_API notification_error_e notification_get_led(notification_h noti,
1263 notification_led_op_e *operation,
1266 /* check noti and operation is valid data */
1267 if (noti == NULL || operation == NULL) {
1268 return NOTIFICATION_ERROR_INVALID_DATA;
1271 /* Set led operation */
1272 *operation = noti->led_operation;
1274 /* Save led argb if operation is turning on LED with custom color */
1275 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1276 && led_argb != NULL) {
1277 *led_argb = noti->led_argb;
1280 return NOTIFICATION_ERROR_NONE;
1283 EXPORT_API notification_error_e notification_set_led_time_period(notification_h noti,
1284 int on_ms, int off_ms)
1286 /* Check noti is valid data */
1288 return NOTIFICATION_ERROR_INVALID_DATA;
1291 /* Save led operation */
1292 noti->led_on_ms = on_ms;
1293 noti->led_off_ms = off_ms;
1295 return NOTIFICATION_ERROR_NONE;
1298 EXPORT_API notification_error_e notification_get_led_time_period(notification_h noti,
1299 int *on_ms, int *off_ms)
1301 /* check noti and operation is valid data */
1303 return NOTIFICATION_ERROR_INVALID_DATA;
1307 *(on_ms) = noti->led_on_ms;
1309 *(off_ms) = noti->led_off_ms;
1311 return NOTIFICATION_ERROR_NONE;
1314 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1315 const char *pkgname)
1317 if (noti == NULL || pkgname == NULL) {
1318 return NOTIFICATION_ERROR_INVALID_DATA;
1321 if (noti->launch_pkgname) {
1322 free(noti->launch_pkgname);
1325 noti->launch_pkgname = strdup(pkgname);
1327 return NOTIFICATION_ERROR_NONE;
1330 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1333 if (noti == NULL || pkgname == NULL) {
1334 return NOTIFICATION_ERROR_INVALID_DATA;
1337 if (noti->launch_pkgname) {
1338 *pkgname = noti->launch_pkgname;
1340 *pkgname = noti->caller_pkgname;
1343 return NOTIFICATION_ERROR_NONE;
1346 EXPORT_API notification_error_e notification_set_args(notification_h noti,
1348 bundle * group_args)
1350 if (noti == NULL || args == NULL) {
1351 return NOTIFICATION_ERROR_INVALID_DATA;
1355 bundle_free(noti->args);
1358 noti->args = bundle_dup(args);
1360 if (noti->group_args) {
1361 bundle_free(noti->group_args);
1362 noti->group_args = NULL;
1365 if (group_args != NULL) {
1366 noti->group_args = bundle_dup(group_args);
1369 return NOTIFICATION_ERROR_NONE;
1372 EXPORT_API notification_error_e notification_get_args(notification_h noti,
1374 bundle ** group_args)
1376 if (noti == NULL || args == NULL) {
1377 return NOTIFICATION_ERROR_INVALID_DATA;
1386 if (group_args != NULL && noti->group_args) {
1387 *group_args = noti->group_args;
1390 return NOTIFICATION_ERROR_NONE;
1393 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1394 notification_execute_type_e type,
1397 bundle *service_handle)
1399 char buf_key[32] = { 0, };
1400 const char *ret_val = NULL;
1404 return NOTIFICATION_ERROR_INVALID_DATA;
1407 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1408 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1409 return NOTIFICATION_ERROR_INVALID_DATA;
1412 /* Create execute option bundle if does not exist */
1413 if (noti->b_execute_option != NULL) {
1414 noti->b_execute_option = bundle_create();
1417 b = noti->b_execute_option;
1422 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1424 /* Check text key exist */
1425 ret_val = bundle_get_val(b, buf_key);
1426 if (ret_val != NULL) {
1427 /* Remove previous data */
1428 bundle_del(b, buf_key);
1432 bundle_add(b, buf_key, text);
1438 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1440 /* Check key key exist */
1441 ret_val = bundle_get_val(b, buf_key);
1442 if (ret_val != NULL) {
1443 /* Remove previous data */
1444 bundle_del(b, buf_key);
1448 bundle_add(b, buf_key, key);
1452 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1453 /* Remove previous data if exist */
1454 if (noti->b_service_responding != NULL) {
1455 bundle_free(noti->b_service_responding);
1456 noti->b_service_responding = NULL;
1459 /* Save service handle */
1460 if (service_handle != NULL) {
1461 noti->b_service_responding = bundle_dup(service_handle);
1464 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1465 /* Remove previous data if exist */
1466 if (noti->b_service_single_launch != NULL) {
1467 bundle_free(noti->b_service_single_launch);
1468 noti->b_service_single_launch = NULL;
1471 /* Save service handle */
1472 if (service_handle != NULL) {
1473 noti->b_service_single_launch =
1474 bundle_dup(service_handle);
1477 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1478 /* Remove previous data if exist */
1479 if (noti->b_service_multi_launch != NULL) {
1480 bundle_free(noti->b_service_multi_launch);
1481 noti->b_service_multi_launch = NULL;
1484 /* Save service handle */
1485 if (service_handle != NULL) {
1486 noti->b_service_multi_launch =
1487 bundle_dup(service_handle);
1490 case NOTIFICATION_EXECUTE_TYPE_NONE:
1491 case NOTIFICATION_EXECUTE_TYPE_MAX:
1492 NOTIFICATION_ERR("invalid execution type");
1496 return NOTIFICATION_ERROR_NONE;
1499 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1500 notification_execute_type_e type,
1502 bundle **service_handle)
1504 char buf_key[32] = { 0, };
1505 const char *ret_val = NULL;
1506 char *get_str = NULL;
1510 return NOTIFICATION_ERROR_INVALID_DATA;
1513 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1514 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1515 return NOTIFICATION_ERROR_INVALID_DATA;
1519 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1520 b = noti->b_service_responding;
1522 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1523 b = noti->b_service_single_launch;
1525 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1526 b = noti->b_service_multi_launch;
1536 // Get text domain and dir
1537 if (noti->domain == NULL || noti->dir == NULL) {
1538 _notification_get_text_domain(noti);
1542 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1544 /* Check key key exist */
1545 ret_val = bundle_get_val(b, buf_key);
1546 if (ret_val != NULL && noti->domain != NULL
1547 && noti->dir != NULL) {
1548 /* Get application string */
1549 bindtextdomain(noti->domain, noti->dir);
1551 get_str = dgettext(noti->domain, ret_val);
1554 } else if (ret_val != NULL) {
1555 /* Get system string */
1556 get_str = dgettext("sys_string", ret_val);
1560 /* Get basic text */
1561 snprintf(buf_key, sizeof(buf_key), "text%d",
1564 ret_val = bundle_get_val(b, buf_key);
1572 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1573 b = noti->b_service_responding;
1575 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1576 b = noti->b_service_single_launch;
1578 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1579 b = noti->b_service_multi_launch;
1586 if (service_handle != NULL) {
1587 *service_handle = b;
1590 return NOTIFICATION_ERROR_NONE;
1593 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1596 /* Check noti is valid data */
1598 return NOTIFICATION_ERROR_INVALID_DATA;
1602 noti->flags_for_property = flags;
1604 return NOTIFICATION_ERROR_NONE;
1607 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1610 /* Check noti and flags are valid data */
1611 if (noti == NULL || flags == NULL) {
1612 return NOTIFICATION_ERROR_INVALID_DATA;
1616 *flags = noti->flags_for_property;
1618 return NOTIFICATION_ERROR_NONE;
1621 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1624 /* Check noti is valid data */
1626 return NOTIFICATION_ERROR_INVALID_DATA;
1630 noti->display_applist = applist;
1632 return NOTIFICATION_ERROR_NONE;
1635 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1638 /* Check noti and applist are valid data */
1639 if (noti == NULL || applist == NULL) {
1640 return NOTIFICATION_ERROR_INVALID_DATA;
1644 *applist = noti->display_applist;
1646 return NOTIFICATION_ERROR_NONE;
1649 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1652 /* Check noti is valid data */
1654 return NOTIFICATION_ERROR_INVALID_DATA;
1657 /* Save progress size */
1658 noti->progress_size = size;
1660 return NOTIFICATION_ERROR_NONE;
1663 EXPORT_API notification_error_e notification_get_size(notification_h noti,
1666 /* Check noti and size is valid data */
1667 if (noti == NULL || size == NULL) {
1668 return NOTIFICATION_ERROR_INVALID_DATA;
1671 /* Set progress size */
1672 *size = noti->progress_size;
1674 return NOTIFICATION_ERROR_NONE;
1677 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
1680 /* Check noti is valid data */
1682 return NOTIFICATION_ERROR_INVALID_DATA;
1685 /* Save progress percentage */
1686 noti->progress_percentage = percentage;
1688 return NOTIFICATION_ERROR_NONE;
1691 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
1694 /* Check noti and percentage are valid data */
1695 if (noti == NULL || percentage == NULL) {
1696 return NOTIFICATION_ERROR_INVALID_DATA;
1699 /* Set progress percentage */
1700 *percentage = noti->progress_percentage;
1702 return NOTIFICATION_ERROR_NONE;
1705 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
1706 const char *pkgname)
1708 /* check noti and pkgname are valid data */
1709 if (noti == NULL || pkgname == NULL) {
1710 return NOTIFICATION_ERROR_INVALID_DATA;
1713 /* Remove previous caller pkgname */
1714 if (noti->caller_pkgname) {
1715 free(noti->caller_pkgname);
1716 noti->caller_pkgname = NULL;
1719 noti->caller_pkgname = strdup(pkgname);
1721 return NOTIFICATION_ERROR_NONE;
1724 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
1727 /* Check noti and pkgname are valid data */
1728 if (noti == NULL || pkgname == NULL) {
1729 return NOTIFICATION_ERROR_INVALID_DATA;
1732 /* Get caller pkgname */
1733 if (noti->caller_pkgname) {
1734 *pkgname = noti->caller_pkgname;
1739 return NOTIFICATION_ERROR_NONE;
1742 EXPORT_API notification_error_e notification_set_layout(notification_h noti,
1743 notification_ly_type_e layout)
1745 /* check noti and pkgname are valid data */
1746 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1747 return NOTIFICATION_ERROR_INVALID_DATA;
1750 noti->layout = layout;
1752 return NOTIFICATION_ERROR_NONE;
1755 EXPORT_API notification_error_e notification_get_layout(notification_h noti,
1756 notification_ly_type_e *layout)
1758 /* Check noti and pkgname are valid data */
1759 if (noti == NULL || layout == NULL) {
1760 return NOTIFICATION_ERROR_INVALID_DATA;
1763 *layout = noti->layout;
1765 return NOTIFICATION_ERROR_NONE;
1768 EXPORT_API notification_error_e notification_get_id(notification_h noti,
1769 int *group_id, int *priv_id)
1771 /* check noti is valid data */
1773 return NOTIFICATION_ERROR_INVALID_DATA;
1776 /* Check group_id is valid data */
1779 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1780 *group_id = NOTIFICATION_GROUP_ID_NONE;
1782 *group_id = noti->group_id;
1786 /* Check priv_id is valid data */
1789 *priv_id = noti->priv_id;
1792 return NOTIFICATION_ERROR_NONE;
1795 EXPORT_API notification_error_e notification_get_type(notification_h noti,
1796 notification_type_e *type)
1798 /* Check noti and type is valid data */
1799 if (noti == NULL || type == NULL) {
1800 return NOTIFICATION_ERROR_INVALID_DATA;
1806 return NOTIFICATION_ERROR_NONE;
1809 EXPORT_API notification_error_e notification_insert(notification_h noti,
1815 /* Check noti is vaild data */
1817 return NOTIFICATION_ERROR_INVALID_DATA;
1820 /* Check noti type is valid type */
1821 if (noti->type <= NOTIFICATION_TYPE_NONE
1822 || noti->type >= NOTIFICATION_TYPE_MAX) {
1823 return NOTIFICATION_ERROR_INVALID_DATA;
1826 /* Save insert time */
1827 noti->insert_time = time(NULL);
1828 ret = notification_ipc_request_insert(noti, &id);
1829 if (ret != NOTIFICATION_ERROR_NONE) {
1833 NOTIFICATION_DBG("from master:%d", id);
1835 /* If priv_id is valid data, set priv_id */
1836 if (priv_id != NULL) {
1837 *priv_id = noti->priv_id;
1840 return NOTIFICATION_ERROR_NONE;
1843 EXPORT_API notification_error_e notification_update(notification_h noti)
1847 /* Check noti is valid data */
1849 /* Update insert time ? */
1850 noti->insert_time = time(NULL);
1851 ret = notification_ipc_request_update(noti);
1852 if (ret != NOTIFICATION_ERROR_NONE) {
1856 ret = notification_ipc_request_refresh();
1857 if (ret != NOTIFICATION_ERROR_NONE) {
1861 return NOTIFICATION_ERROR_NONE;
1864 EXPORT_API notification_error_e notification_update_async(notification_h noti,
1865 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1869 /* Check noti is valid data */
1871 /* Update insert time ? */
1872 noti->insert_time = time(NULL);
1873 ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1874 if (ret != NOTIFICATION_ERROR_NONE) {
1878 return NOTIFICATION_ERROR_NONE;
1881 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
1885 ret = notification_ipc_request_delete_multiple(type, NULL);
1886 if (ret != NOTIFICATION_ERROR_NONE) {
1890 return NOTIFICATION_ERROR_NONE;
1893 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
1894 notification_type_e type)
1897 char *caller_pkgname = NULL;
1899 if (pkgname == NULL) {
1900 caller_pkgname = _notification_get_pkgname_by_pid();
1902 caller_pkgname = strdup(pkgname);
1905 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1906 if (ret != NOTIFICATION_ERROR_NONE) {
1907 if (caller_pkgname) {
1908 free(caller_pkgname);
1913 if (caller_pkgname) {
1914 free(caller_pkgname);
1916 return NOTIFICATION_ERROR_NONE;
1919 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
1920 notification_type_e type,
1924 char *caller_pkgname = NULL;
1926 if (pkgname == NULL) {
1927 caller_pkgname = _notification_get_pkgname_by_pid();
1929 caller_pkgname = strdup(pkgname);
1932 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1933 if (ret != NOTIFICATION_ERROR_NONE) {
1934 if (caller_pkgname) {
1935 free(caller_pkgname);
1940 if (caller_pkgname) {
1941 free(caller_pkgname);
1943 return NOTIFICATION_ERROR_NONE;
1946 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
1947 notification_type_e type,
1951 char *caller_pkgname = NULL;
1953 if (pkgname == NULL) {
1954 caller_pkgname = _notification_get_pkgname_by_pid();
1956 caller_pkgname = strdup(pkgname);
1959 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
1960 if (ret != NOTIFICATION_ERROR_NONE) {
1961 if (caller_pkgname) {
1962 free(caller_pkgname);
1967 if (caller_pkgname) {
1968 free(caller_pkgname);
1970 return NOTIFICATION_ERROR_NONE;
1973 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
1974 notification_type_e type,
1978 char *caller_pkgname = NULL;
1980 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1981 return NOTIFICATION_ERROR_INVALID_DATA;
1984 if (pkgname == NULL) {
1985 caller_pkgname = _notification_get_pkgname_by_pid();
1987 caller_pkgname = strdup(pkgname);
1990 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
1991 if (ret != NOTIFICATION_ERROR_NONE) {
1992 if (caller_pkgname) {
1993 free(caller_pkgname);
1998 if (caller_pkgname) {
1999 free(caller_pkgname);
2004 EXPORT_API notification_error_e notification_delete(notification_h noti)
2009 return NOTIFICATION_ERROR_INVALID_DATA;
2012 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
2013 if (ret != NOTIFICATION_ERROR_NONE) {
2017 return NOTIFICATION_ERROR_NONE;
2020 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
2024 char *caller_pkgname = NULL;
2025 int input_priv_id = 0;
2026 double input_progress = 0.0;
2028 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2030 return NOTIFICATION_ERROR_INVALID_DATA;
2032 input_priv_id = noti->priv_id;
2035 input_priv_id = priv_id;
2039 caller_pkgname = _notification_get_pkgname_by_pid();
2041 caller_pkgname = strdup(noti->caller_pkgname);
2044 if (progress < 0.0) {
2045 input_progress = 0.0;
2046 } else if (progress > 1.0) {
2047 input_progress = 1.0;
2049 input_progress = progress;
2052 notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2055 if (caller_pkgname) {
2056 free(caller_pkgname);
2059 return NOTIFICATION_ERROR_NONE;
2062 EXPORT_API notification_error_e notification_update_size(notification_h noti,
2066 char *caller_pkgname = NULL;
2067 int input_priv_id = 0;
2068 double input_size = 0.0;
2070 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2072 return NOTIFICATION_ERROR_INVALID_DATA;
2074 input_priv_id = noti->priv_id;
2077 input_priv_id = priv_id;
2081 caller_pkgname = _notification_get_pkgname_by_pid();
2083 caller_pkgname = strdup(noti->caller_pkgname);
2092 notification_ongoing_update_size(caller_pkgname, input_priv_id,
2095 if (caller_pkgname) {
2096 free(caller_pkgname);
2099 return NOTIFICATION_ERROR_NONE;
2102 EXPORT_API notification_error_e notification_update_content(notification_h noti,
2104 const char *content)
2106 char *caller_pkgname = NULL;
2107 int input_priv_id = 0;
2109 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2111 return NOTIFICATION_ERROR_INVALID_DATA;
2113 input_priv_id = noti->priv_id;
2116 input_priv_id = priv_id;
2120 caller_pkgname = _notification_get_pkgname_by_pid();
2122 caller_pkgname = strdup(noti->caller_pkgname);
2125 notification_ongoing_update_content(caller_pkgname, input_priv_id,
2128 if (caller_pkgname) {
2129 free(caller_pkgname);
2132 return NOTIFICATION_ERROR_NONE;
2135 static notification_h _notification_create(notification_type_e type)
2137 notification_h noti = NULL;
2139 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2140 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2144 noti = (notification_h) calloc(1, sizeof(struct _notification));
2146 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2152 if (type == NOTIFICATION_TYPE_NOTI)
2153 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2154 else if (type == NOTIFICATION_TYPE_ONGOING)
2155 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
2157 noti->caller_pkgname = _notification_get_pkgname_by_pid();
2158 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
2159 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
2160 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2161 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2162 noti->led_operation = NOTIFICATION_LED_OP_OFF;
2163 noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2166 * Other fields are already initialized with ZERO.
2171 EXPORT_API notification_h notification_new(notification_type_e type,
2172 int group_id, int priv_id)
2174 return _notification_create(type);
2177 EXPORT_API notification_h notification_create(notification_type_e type)
2179 return _notification_create(type);
2182 EXPORT_API notification_h notification_load(char *pkgname,
2186 notification_h noti = NULL;
2188 noti = (notification_h) calloc(1, sizeof(struct _notification));
2190 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2194 ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id);
2195 if (ret != NOTIFICATION_ERROR_NONE) {
2196 notification_free(noti);
2203 EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone)
2205 notification_h new_noti = NULL;
2207 if (noti == NULL || clone == NULL) {
2208 NOTIFICATION_ERR("INVALID PARAMETER.");
2209 return NOTIFICATION_ERROR_INVALID_DATA;
2212 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
2213 if (new_noti == NULL) {
2214 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2215 return NOTIFICATION_ERROR_NO_MEMORY;
2218 new_noti->type = noti->type;
2219 new_noti->layout = noti->layout;
2221 new_noti->group_id = noti->group_id;
2222 new_noti->internal_group_id = noti->internal_group_id;
2223 new_noti->priv_id = noti->priv_id;
2225 if(noti->caller_pkgname != NULL) {
2226 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2228 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2230 if(noti->launch_pkgname != NULL) {
2231 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2233 new_noti->launch_pkgname = NULL;
2236 if(noti->args != NULL) {
2237 new_noti->args = bundle_dup(noti->args);
2239 new_noti->args = NULL;
2241 if(noti->group_args != NULL) {
2242 new_noti->group_args = bundle_dup(noti->group_args);
2244 new_noti->group_args = NULL;
2247 if(noti->b_execute_option != NULL) {
2248 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2250 new_noti->b_execute_option = NULL;
2252 if(noti->b_service_responding != NULL) {
2253 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2255 new_noti->b_service_responding = NULL;
2257 if(noti->b_service_single_launch != NULL) {
2258 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2260 new_noti->b_service_single_launch = NULL;
2262 if(noti->b_service_multi_launch != NULL) {
2263 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2265 new_noti->b_service_multi_launch = NULL;
2268 new_noti->sound_type = noti->sound_type;
2269 if(noti->sound_path != NULL) {
2270 new_noti->sound_path = strdup(noti->sound_path);
2272 new_noti->sound_path = NULL;
2274 new_noti->vibration_type = noti->vibration_type;
2275 if(noti->vibration_path != NULL) {
2276 new_noti->vibration_path = strdup(noti->vibration_path);
2278 new_noti->vibration_path = NULL;
2280 new_noti->led_operation = noti->led_operation;
2281 new_noti->led_argb = noti->led_argb;
2282 new_noti->led_on_ms = noti->led_on_ms;
2283 new_noti->led_off_ms = noti->led_off_ms;
2285 if(noti->domain != NULL) {
2286 new_noti->domain = strdup(noti->domain);
2288 new_noti->domain = NULL;
2290 if(noti->dir != NULL) {
2291 new_noti->dir = strdup(noti->dir);
2293 new_noti->dir = NULL;
2296 if(noti->b_text != NULL) {
2297 new_noti->b_text = bundle_dup(noti->b_text);
2299 new_noti->b_text = NULL;
2301 if(noti->b_key != NULL) {
2302 new_noti->b_key = bundle_dup(noti->b_key);
2304 new_noti->b_key = NULL;
2306 if(noti->b_format_args != NULL) {
2307 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2309 new_noti->b_format_args = NULL;
2311 new_noti->num_format_args = noti->num_format_args;
2313 if(noti->b_image_path != NULL) {
2314 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2316 new_noti->b_image_path = NULL;
2319 new_noti->time = noti->time;
2320 new_noti->insert_time = noti->insert_time;
2322 new_noti->flags_for_property = noti->flags_for_property;
2323 new_noti->display_applist = noti->display_applist;
2325 new_noti->progress_size = noti->progress_size;
2326 new_noti->progress_percentage = noti->progress_percentage;
2328 new_noti->app_icon_path = NULL;
2329 new_noti->app_name = NULL;
2330 new_noti->temp_title = NULL;
2331 new_noti->temp_content = NULL;
2335 return NOTIFICATION_ERROR_NONE;
2339 EXPORT_API notification_error_e notification_free(notification_h noti)
2342 return NOTIFICATION_ERROR_INVALID_DATA;
2345 if (noti->caller_pkgname) {
2346 free(noti->caller_pkgname);
2348 if (noti->launch_pkgname) {
2349 free(noti->launch_pkgname);
2352 bundle_free(noti->args);
2354 if (noti->group_args) {
2355 bundle_free(noti->group_args);
2358 if (noti->b_execute_option) {
2359 bundle_free(noti->b_execute_option);
2361 if (noti->b_service_responding) {
2362 bundle_free(noti->b_service_responding);
2364 if (noti->b_service_single_launch) {
2365 bundle_free(noti->b_service_single_launch);
2367 if (noti->b_service_multi_launch) {
2368 bundle_free(noti->b_service_multi_launch);
2371 if (noti->sound_path) {
2372 free(noti->sound_path);
2374 if (noti->vibration_path) {
2375 free(noti->vibration_path);
2386 bundle_free(noti->b_text);
2389 bundle_free(noti->b_key);
2391 if (noti->b_format_args) {
2392 bundle_free(noti->b_format_args);
2395 if (noti->b_image_path) {
2396 bundle_free(noti->b_image_path);
2399 if (noti->app_icon_path) {
2400 free(noti->app_icon_path);
2402 if (noti->app_name) {
2403 free(noti->app_name);
2405 if (noti->temp_title) {
2406 free(noti->temp_title);
2408 if (noti->temp_content) {
2409 free(noti->temp_content);
2414 return NOTIFICATION_ERROR_NONE;
2417 EXPORT_API notification_error_e
2418 notification_resister_changed_cb(void (*changed_cb)
2419 (void *data, notification_type_e type),
2422 notification_cb_list_s *noti_cb_list_new = NULL;
2423 notification_cb_list_s *noti_cb_list = NULL;
2425 if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2426 return NOTIFICATION_ERROR_IO;
2430 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2432 noti_cb_list_new->next = NULL;
2433 noti_cb_list_new->prev = NULL;
2435 noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
2436 noti_cb_list_new->changed_cb = changed_cb;
2437 noti_cb_list_new->detailed_changed_cb = NULL;
2438 noti_cb_list_new->data = user_data;
2440 if (g_notification_cb_list == NULL) {
2441 g_notification_cb_list = noti_cb_list_new;
2443 noti_cb_list = g_notification_cb_list;
2445 while (noti_cb_list->next != NULL) {
2446 noti_cb_list = noti_cb_list->next;
2449 noti_cb_list->next = noti_cb_list_new;
2450 noti_cb_list_new->prev = noti_cb_list;
2452 return NOTIFICATION_ERROR_NONE;
2455 EXPORT_API notification_error_e
2456 notification_unresister_changed_cb(void (*changed_cb)
2457 (void *data, notification_type_e type))
2459 notification_cb_list_s *noti_cb_list = NULL;
2460 notification_cb_list_s *noti_cb_list_prev = NULL;
2461 notification_cb_list_s *noti_cb_list_next = NULL;
2463 noti_cb_list = g_notification_cb_list;
2465 if (noti_cb_list == NULL) {
2466 return NOTIFICATION_ERROR_INVALID_DATA;
2469 while (noti_cb_list->prev != NULL) {
2470 noti_cb_list = noti_cb_list->prev;
2474 if (noti_cb_list->changed_cb == changed_cb) {
2475 noti_cb_list_prev = noti_cb_list->prev;
2476 noti_cb_list_next = noti_cb_list->next;
2478 if (noti_cb_list_prev == NULL) {
2479 g_notification_cb_list = noti_cb_list_next;
2481 noti_cb_list_prev->next = noti_cb_list_next;
2484 if (noti_cb_list_next == NULL) {
2485 if (noti_cb_list_prev != NULL) {
2486 noti_cb_list_prev->next = NULL;
2489 noti_cb_list_next->prev = noti_cb_list_prev;
2494 if (g_notification_cb_list == NULL)
2495 notification_ipc_monitor_fini();
2497 return NOTIFICATION_ERROR_NONE;
2499 noti_cb_list = noti_cb_list->next;
2500 } while (noti_cb_list != NULL);
2502 return NOTIFICATION_ERROR_INVALID_DATA;
2505 EXPORT_API notification_error_e
2506 notification_register_detailed_changed_cb(
2507 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2510 notification_cb_list_s *noti_cb_list_new = NULL;
2511 notification_cb_list_s *noti_cb_list = NULL;
2513 if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2514 return NOTIFICATION_ERROR_IO;
2518 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2520 noti_cb_list_new->next = NULL;
2521 noti_cb_list_new->prev = NULL;
2523 noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
2524 noti_cb_list_new->changed_cb = NULL;
2525 noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
2526 noti_cb_list_new->data = user_data;
2528 if (g_notification_cb_list == NULL) {
2529 g_notification_cb_list = noti_cb_list_new;
2531 noti_cb_list = g_notification_cb_list;
2533 while (noti_cb_list->next != NULL) {
2534 noti_cb_list = noti_cb_list->next;
2537 noti_cb_list->next = noti_cb_list_new;
2538 noti_cb_list_new->prev = noti_cb_list;
2540 return NOTIFICATION_ERROR_NONE;
2543 EXPORT_API notification_error_e
2544 notification_unregister_detailed_changed_cb(
2545 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2548 notification_cb_list_s *noti_cb_list = NULL;
2549 notification_cb_list_s *noti_cb_list_prev = NULL;
2550 notification_cb_list_s *noti_cb_list_next = NULL;
2552 noti_cb_list = g_notification_cb_list;
2554 if (noti_cb_list == NULL) {
2555 return NOTIFICATION_ERROR_INVALID_DATA;
2558 while (noti_cb_list->prev != NULL) {
2559 noti_cb_list = noti_cb_list->prev;
2563 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
2564 noti_cb_list_prev = noti_cb_list->prev;
2565 noti_cb_list_next = noti_cb_list->next;
2567 if (noti_cb_list_prev == NULL) {
2568 g_notification_cb_list = noti_cb_list_next;
2570 noti_cb_list_prev->next = noti_cb_list_next;
2573 if (noti_cb_list_next == NULL) {
2574 if (noti_cb_list_prev != NULL) {
2575 noti_cb_list_prev->next = NULL;
2578 noti_cb_list_next->prev = noti_cb_list_prev;
2583 if (g_notification_cb_list == NULL)
2584 notification_ipc_monitor_fini();
2586 return NOTIFICATION_ERROR_NONE;
2588 noti_cb_list = noti_cb_list->next;
2589 } while (noti_cb_list != NULL);
2591 return NOTIFICATION_ERROR_INVALID_DATA;
2594 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
2595 const char *pkgname,
2597 int priv_id, int *count)
2603 notification_noti_get_count(type, pkgname, group_id, priv_id,
2605 if (ret != NOTIFICATION_ERROR_NONE) {
2609 if (count != NULL) {
2610 *count = noti_count;
2613 return NOTIFICATION_ERROR_NONE;
2616 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
2618 notification_list_h *list)
2620 notification_list_h get_list = NULL;
2623 ret = notification_noti_get_grouping_list(type, count, &get_list);
2624 if (ret != NOTIFICATION_ERROR_NONE) {
2630 return NOTIFICATION_ERROR_NONE;
2633 EXPORT_API notification_error_e
2634 notification_get_grouping_list(notification_type_e type, int count,
2635 notification_list_h * list)
2637 notification_list_h get_list = NULL;
2640 ret = notification_noti_get_grouping_list(type, count, &get_list);
2641 if (ret != NOTIFICATION_ERROR_NONE) {
2647 return NOTIFICATION_ERROR_NONE;
2650 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
2654 notification_list_h *list)
2656 notification_list_h get_list = NULL;
2660 notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2662 if (ret != NOTIFICATION_ERROR_NONE) {
2668 return NOTIFICATION_ERROR_NONE;
2671 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
2673 notification_list_h cur_list = NULL;
2674 notification_h noti = NULL;
2677 NOTIFICATION_ERR("INVALID DATA : list == NULL");
2678 return NOTIFICATION_ERROR_INVALID_DATA;
2681 cur_list = notification_list_get_head(list);
2683 while (cur_list != NULL) {
2684 noti = notification_list_get_data(cur_list);
2685 cur_list = notification_list_remove(cur_list, noti);
2687 notification_free(noti);
2690 return NOTIFICATION_ERROR_NONE;
2693 EXPORT_API notification_error_e notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
2696 if (noti_op == NULL || data == NULL) {
2697 return NOTIFICATION_ERROR_INVALID_DATA;
2701 case NOTIFICATION_OP_DATA_TYPE:
2702 *((int*)data) = noti_op->type;
2704 case NOTIFICATION_OP_DATA_PRIV_ID:
2705 *((int*)data) = noti_op->priv_id;
2707 case NOTIFICATION_OP_DATA_NOTI:
2708 *((notification_h *)data) = noti_op->noti;
2710 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
2711 *((int*)data) = noti_op->extra_info_1;
2713 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
2714 *((int*)data) = noti_op->extra_info_2;
2717 return NOTIFICATION_ERROR_INVALID_DATA;
2721 return NOTIFICATION_ERROR_NONE;
2724 void notification_call_changed_cb(notification_op *op_list, int op_num)
2726 notification_cb_list_s *noti_cb_list = NULL;
2729 if (g_notification_cb_list == NULL) {
2732 noti_cb_list = g_notification_cb_list;
2734 while (noti_cb_list->prev != NULL) {
2735 noti_cb_list = noti_cb_list->prev;
2738 if (op_list == NULL) {
2739 NOTIFICATION_ERR("invalid data");
2743 while (noti_cb_list != NULL) {
2744 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
2745 noti_cb_list->changed_cb(noti_cb_list->data,
2746 NOTIFICATION_TYPE_NOTI);
2748 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
2749 noti_cb_list->detailed_changed_cb(noti_cb_list->data,
2750 NOTIFICATION_TYPE_NOTI, op_list, op_num);
2753 noti_cb_list = noti_cb_list->next;
2757 EXPORT_API int notification_is_service_ready(void)
2759 return notification_ipc_is_master_ready();
2762 EXPORT_API notification_error_e
2763 notification_add_deffered_task(
2764 void (*deffered_task_cb)(void *data), void *user_data)
2766 return notification_ipc_add_deffered_task(deffered_task_cb, user_data);
2769 EXPORT_API notification_error_e
2770 notification_del_deffered_task(
2771 void (*deffered_task_cb)(void *data))
2773 return notification_ipc_del_deffered_task(deffered_task_cb);