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>
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.
33 #include <vconf-keys.h>
36 #include <notification.h>
37 #include <notification_list.h>
38 #include <notification_debug.h>
39 #include <notification_internal.h>
40 #include <notification_noti.h>
41 #include <notification_ongoing.h>
42 #include <notification_group.h>
44 typedef struct _notification_cb_list notification_cb_list_s;
46 struct _notification_cb_list {
47 notification_cb_list_s *prev;
48 notification_cb_list_s *next;
50 void (*changed_cb) (void *data, notification_type_e type);
54 static notification_cb_list_s *g_notification_cb_list = NULL;
55 static int g_notification_heynoti_fd = -1;
57 #define NOTI_PKGNAME_LEN 512
58 #define NOTI_CHANGED_NOTI "notification_noti_changed"
59 #define NOTI_CHANGED_ONGOING "notification_ontoing_changed"
61 static char *_notification_get_pkgname_by_pid(void)
63 char buf[NOTI_PKGNAME_LEN] = { 0, };
64 char pkgname[NOTI_PKGNAME_LEN] = { 0, };
65 int pid = 0, ret = AUL_R_OK;
70 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
71 if (ret != AUL_R_OK) {
72 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
74 fd = open(buf, O_RDONLY);
79 ret = read(fd, pkgname, sizeof(pkgname) - 1);
90 if (pkgname == NULL || pkgname[0] == '\0') {
93 return strdup(pkgname);
97 static char *_notification_get_icon(const char *package)
104 ret = ail_package_get_appinfo(package, &handle);
105 if (ret != AIL_ERROR_OK) {
109 ret = ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &str);
110 if (ret != AIL_ERROR_OK) {
111 ail_package_destroy_appinfo(handle);
117 ret = ail_package_destroy_appinfo(handle);
118 if (ret != AIL_ERROR_OK) {
119 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
125 static char *_notification_get_name(const char *package)
127 ail_appinfo_h handle;
132 ret = ail_package_get_appinfo(package, &handle);
133 if (ret != AIL_ERROR_OK) {
137 ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
138 if (ret != AIL_ERROR_OK) {
139 ail_package_destroy_appinfo(handle);
145 ret = ail_package_destroy_appinfo(handle);
146 if (ret != AIL_ERROR_OK) {
147 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
153 static void _notification_get_text_domain(notification_h noti)
155 if (noti->domain != NULL) {
159 if (noti->dir != NULL) {
164 static void _notification_chagned_noti_cb(void *data)
166 notification_cb_list_s *noti_cb_list = NULL;
168 if (g_notification_cb_list == NULL) {
172 noti_cb_list = g_notification_cb_list;
174 while (noti_cb_list->prev != NULL) {
175 noti_cb_list = noti_cb_list->prev;
178 while (noti_cb_list != NULL) {
179 if (noti_cb_list->changed_cb) {
180 noti_cb_list->changed_cb(noti_cb_list->data,
181 NOTIFICATION_TYPE_NOTI);
184 noti_cb_list = noti_cb_list->next;
189 static void _notification_chagned_ongoing_cb(void *data)
191 notification_cb_list_s *noti_cb_list = NULL;
193 if (g_notification_cb_list == NULL) {
197 noti_cb_list = g_notification_cb_list;
199 while (noti_cb_list->prev != NULL) {
200 noti_cb_list = noti_cb_list->prev;
203 while (noti_cb_list != NULL) {
204 if (noti_cb_list->changed_cb) {
205 noti_cb_list->changed_cb(noti_cb_list->data,
206 NOTIFICATION_TYPE_ONGOING);
209 noti_cb_list = noti_cb_list->next;
214 static void _notification_changed(const char *type)
216 heynoti_publish(type);
219 /* notification_set_icon will be removed */
220 EXPORT_API notification_error_e notification_set_icon(notification_h noti,
221 const char *icon_path)
223 int ret_err = NOTIFICATION_ERROR_NONE;
226 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
232 /* notification_get_icon will be removed */
233 EXPORT_API notification_error_e notification_get_icon(notification_h noti,
236 int ret_err = NOTIFICATION_ERROR_NONE;
237 char *ret_image_path = NULL;
240 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
243 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
244 *icon_path = ret_image_path;
246 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
252 EXPORT_API notification_error_e notification_set_image(notification_h noti,
253 notification_image_type_e type,
254 const char *image_path)
257 char buf_key[32] = { 0, };
258 const char *ret_val = NULL;
260 /* Check noti and image_path are valid data */
261 if (noti == NULL || image_path == NULL) {
262 return NOTIFICATION_ERROR_INVALID_DATA;
265 /* Check image type is valid type */
266 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
267 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
268 return NOTIFICATION_ERROR_INVALID_DATA;
271 /* Check image path bundle is exist */
272 if (noti->b_image_path) {
273 /* If image path bundle is exist, store local bundle value */
274 b = noti->b_image_path;
276 /* Set image type to key as char string type */
277 snprintf(buf_key, sizeof(buf_key), "%d", type);
279 /* Get value using key */
280 ret_val = bundle_get_val(b, buf_key);
281 if (ret_val != NULL) {
282 /* If key is exist, remove this value to store new image path */
283 bundle_del(b, buf_key);
286 /* Add new image path with type key */
287 bundle_add(b, buf_key, image_path);
289 /* If image path bundle is not exist, create new one */
292 /* Set image type to key as char string type */
293 snprintf(buf_key, sizeof(buf_key), "%d", type);
295 /* Add new image path with type key */
296 bundle_add(b, buf_key, image_path);
298 /* Save to image path bundle */
299 noti->b_image_path = b;
302 return NOTIFICATION_ERROR_NONE;
305 EXPORT_API notification_error_e notification_get_image(notification_h noti,
306 notification_image_type_e type,
310 char buf_key[32] = { 0, };
311 const char *ret_val = NULL;
312 const char *pkgname = NULL;
314 /* Check noti and image_path is valid data */
315 if (noti == NULL || image_path == NULL) {
316 return NOTIFICATION_ERROR_INVALID_DATA;
319 /* Check image type is valid data */
320 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
321 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
322 return NOTIFICATION_ERROR_INVALID_DATA;
325 /* Check image path bundle exist */
326 if (noti->b_image_path) {
327 /* If image path bundle exist, store local bundle data */
328 b = noti->b_image_path;
330 /* Set image type to key as char string type */
331 snprintf(buf_key, sizeof(buf_key), "%d", type);
333 /* Get value of key */
334 ret_val = bundle_get_val(b, buf_key);
336 *image_path = (char *)ret_val;
338 /* If image path bundle does not exist, image path is NULL */
342 /* If image path is NULL and type is ICON, icon path set from AIL */
343 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
344 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
345 /* Check App icon path is already set */
346 if (noti->app_icon_path != NULL) {
347 /* image path will be app icon path */
348 *image_path = noti->app_icon_path;
350 /* Get image path using launch_pkgname */
351 if (noti->launch_pkgname != NULL) {
352 noti->app_icon_path =
353 _notification_get_icon(noti->launch_pkgname);
356 /* If app icon path is NULL, get image path using caller_pkgname */
357 if (noti->app_icon_path == NULL
358 && noti->caller_pkgname != NULL) {
359 noti->app_icon_path =
360 _notification_get_icon(noti->caller_pkgname);
363 /* If app icon path is NULL, get image path using service data */
364 if (noti->app_icon_path == NULL
365 && noti->b_service_single_launch != NULL) {
367 appsvc_get_pkgname(noti->b_service_single_launch);
368 if (pkgname != NULL) {
369 noti->app_icon_path =
370 _notification_get_icon(pkgname);
374 *image_path = noti->app_icon_path;
378 return NOTIFICATION_ERROR_NONE;
381 EXPORT_API notification_error_e notification_set_time(notification_h noti,
384 /* Check noti is valid data */
386 return NOTIFICATION_ERROR_INVALID_DATA;
389 if (input_time == 0) {
390 /* If input time is 0, set current time */
391 noti->time = time(NULL);
393 /* save input time */
394 noti->time = input_time;
397 return NOTIFICATION_ERROR_NONE;
400 EXPORT_API notification_error_e notification_get_time(notification_h noti,
403 /* Check noti and time is valid data */
404 if (noti == NULL || ret_time == NULL) {
405 return NOTIFICATION_ERROR_INVALID_DATA;
408 /* Set time infomation */
409 *ret_time = noti->time;
411 return NOTIFICATION_ERROR_NONE;
414 EXPORT_API notification_error_e notification_get_insert_time(notification_h noti,
417 /* Check noti and ret_time is valid data */
418 if (noti == NULL || ret_time == NULL) {
419 return NOTIFICATION_ERROR_INVALID_DATA;
422 /* Set insert time information */
423 *ret_time = noti->insert_time;
425 return NOTIFICATION_ERROR_NONE;
428 EXPORT_API notification_error_e notification_set_title(notification_h noti,
430 const char *loc_title)
432 int noti_err = NOTIFICATION_ERROR_NONE;
434 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
436 NOTIFICATION_VARIABLE_TYPE_NONE);
441 EXPORT_API notification_error_e notification_get_title(notification_h noti,
445 int noti_err = NOTIFICATION_ERROR_NONE;
446 char *ret_text = NULL;
449 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
456 if (loc_title != NULL) {
463 EXPORT_API notification_error_e notification_set_content(notification_h noti,
465 const char *loc_content)
467 int noti_err = NOTIFICATION_ERROR_NONE;
469 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
470 content, loc_content,
471 NOTIFICATION_VARIABLE_TYPE_NONE);
476 EXPORT_API notification_error_e notification_get_content(notification_h noti,
480 int noti_err = NOTIFICATION_ERROR_NONE;
481 char *ret_text = NULL;
484 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
487 if (content != NULL) {
491 if (loc_content != NULL) {
500 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
502 if (ret == -1 || boolval == 0) {
503 if (content != NULL && noti->default_content != NULL) {
504 *content = noti->default_content;
507 if (loc_content != NULL && noti->loc_default_content != NULL) {
508 *loc_content = noti->loc_default_content;
514 EXPORT_API notification_error_e notification_set_text(notification_h noti,
515 notification_text_type_e type,
521 char buf_key[32] = { 0, };
522 char buf_val[1024] = { 0, };
523 const char *ret_val = NULL;
525 notification_variable_type_e var_type;
527 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
528 int var_value_int = 0;
529 double var_value_double = 0.0;
530 char *var_value_string = NULL;
531 notification_count_pos_type_e var_value_count =
532 NOTIFICATION_COUNT_POS_NONE;
534 /* Check noti is valid data */
536 return NOTIFICATION_ERROR_INVALID_DATA;
539 /* Check text type is valid type */
540 if (type <= NOTIFICATION_TEXT_TYPE_NONE
541 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
542 return NOTIFICATION_ERROR_INVALID_DATA;
545 /* Check text bundle exist */
547 if (noti->b_text != NULL) {
548 /* If text bundle exist, store local bundle data */
551 /* Make type to key as char string */
552 snprintf(buf_key, sizeof(buf_key), "%d", type);
554 /* Get value using type key */
555 ret_val = bundle_get_val(b, buf_key);
556 if (ret_val != NULL) {
557 /* If value exist, remove this to add new value */
558 bundle_del(b, buf_key);
561 snprintf(buf_val, sizeof(buf_val), "%s", text);
563 /* Add new text value */
564 bundle_add(b, buf_key, buf_val);
566 /* If text bundle does not exist, create new one */
569 /* Make type to key as char string */
570 snprintf(buf_key, sizeof(buf_key), "%d", type);
572 snprintf(buf_val, sizeof(buf_val), "%s", text);
574 /* Add new text value */
575 bundle_add(b, buf_key, buf_val);
577 /* Save text bundle */
581 /* Reset if text is NULL */
582 if (noti->b_text != NULL) {
583 /* If text bundle exist, store local bundle data */
586 /* Make type to key as char string */
587 snprintf(buf_key, sizeof(buf_key), "%d", type);
589 /* Get value using type key */
590 ret_val = bundle_get_val(b, buf_key);
591 if (ret_val != NULL) {
592 /* If value exist, remove this */
593 bundle_del(b, buf_key);
598 /* Save key if key is valid data */
600 /* Check key bundle exist */
601 if (noti->b_key != NULL) {
602 /* If key bundle exist, store local bundle data */
605 /* Make type to key as char string */
606 snprintf(buf_key, sizeof(buf_key), "%d", type);
608 /* Get value using type key */
609 ret_val = bundle_get_val(b, buf_key);
610 if (ret_val != NULL) {
611 /* If value exist, remove this to add new value */
612 bundle_del(b, buf_key);
615 snprintf(buf_val, sizeof(buf_val), "%s", key);
617 /* Add new key value */
618 bundle_add(b, buf_key, buf_val);
620 /* If key bundle does not exist, create new one */
623 /* Make type to key as char string */
624 snprintf(buf_key, sizeof(buf_key), "%d", type);
626 snprintf(buf_val, sizeof(buf_val), "%s", key);
628 /* Add new key value */
629 bundle_add(b, buf_key, buf_val);
631 /* Save key bundle */
635 /* Reset if key is NULL */
636 if (noti->b_key != NULL) {
637 /* If key bundle exist, store local bundle data */
640 /* Make type to key as char string */
641 snprintf(buf_key, sizeof(buf_key), "%d", type);
643 /* Get value using type key */
644 ret_val = bundle_get_val(b, buf_key);
645 if (ret_val != NULL) {
646 /* If value exist, remove this */
647 bundle_del(b, buf_key);
652 if (noti->b_format_args != NULL) {
653 b = noti->b_format_args;
658 va_start(var_args, args_type);
660 var_type = args_type;
663 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
665 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
666 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
668 ret_val = bundle_get_val(b, buf_key);
669 if (ret_val != NULL) {
670 bundle_del(b, buf_key);
673 bundle_add(b, buf_key, buf_val);
676 case NOTIFICATION_VARIABLE_TYPE_INT:
677 var_value_int = va_arg(var_args, int);
680 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
682 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
684 ret_val = bundle_get_val(b, buf_key);
685 if (ret_val != NULL) {
686 bundle_del(b, buf_key);
689 bundle_add(b, buf_key, buf_val);
691 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
692 var_value_double = va_arg(var_args, double);
695 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
697 snprintf(buf_val, sizeof(buf_val), "%.2f",
700 ret_val = bundle_get_val(b, buf_key);
701 if (ret_val != NULL) {
702 bundle_del(b, buf_key);
705 bundle_add(b, buf_key, buf_val);
707 case NOTIFICATION_VARIABLE_TYPE_STRING:
708 var_value_string = va_arg(var_args, char *);
711 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
713 snprintf(buf_val, sizeof(buf_val), "%s",
716 ret_val = bundle_get_val(b, buf_key);
717 if (ret_val != NULL) {
718 bundle_del(b, buf_key);
721 bundle_add(b, buf_key, buf_val);
723 case NOTIFICATION_VARIABLE_TYPE_COUNT:
725 va_arg(var_args, notification_count_pos_type_e);
728 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
730 snprintf(buf_val, sizeof(buf_val), "%d",
733 ret_val = bundle_get_val(b, buf_key);
734 if (ret_val != NULL) {
735 bundle_del(b, buf_key);
738 bundle_add(b, buf_key, buf_val);
741 NOTIFICATION_ERR("Error. invalid variable type. : %d",
743 noti_err = NOTIFICATION_ERROR_INVALID_DATA;
748 var_type = va_arg(var_args, notification_variable_type_e);
752 if (noti_err == NOTIFICATION_ERROR_NONE) {
753 noti->num_format_args = num_args;
755 noti->num_format_args = 0;
758 snprintf(buf_key, sizeof(buf_key), "num%d", type);
759 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
761 ret_val = bundle_get_val(b, buf_key);
762 if (ret_val != NULL) {
763 bundle_del(b, buf_key);
766 bundle_add(b, buf_key, buf_val);
768 noti->b_format_args = b;
773 EXPORT_API notification_error_e notification_get_text(notification_h noti,
774 notification_text_type_e type,
778 char buf_key[32] = { 0, };
779 const char *ret_val = NULL;
780 const char *pkgname = NULL;
781 const char *get_str = NULL;
782 const char *get_check_type_str = NULL;
785 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
786 int display_option_flag = 0;
788 char *temp_str = NULL;
789 char result_str[1024] = { 0, };
790 char buf_str[1024] = { 0, };
792 notification_variable_type_e ret_var_type = 0;
793 int ret_variable_int = 0;
794 double ret_variable_double = 0.0;
796 /* Check noti is valid data */
797 if (noti == NULL || text == NULL) {
798 return NOTIFICATION_ERROR_INVALID_DATA;
801 /* Check text type is valid type */
802 if (type <= NOTIFICATION_TEXT_TYPE_NONE
803 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
804 return NOTIFICATION_ERROR_INVALID_DATA;
807 /* Check content display option of setting */
808 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
809 || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
812 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL,
814 if (ret == -1 || boolval == 0) {
815 /* Set flag as display option is OFF */
816 //display_option_flag = 1;
821 if (noti->b_key != NULL) {
824 /* Get text domain and dir */
825 _notification_get_text_domain(noti);
827 snprintf(buf_key, sizeof(buf_key), "%d", type);
829 ret_val = bundle_get_val(b, buf_key);
830 if (ret_val != NULL && noti->domain != NULL
831 && noti->dir != NULL) {
832 /* Get application string */
833 bindtextdomain(noti->domain, noti->dir);
835 get_str = dgettext(noti->domain, ret_val);
836 } else if (ret_val != NULL) {
837 /* Get system string */
838 get_str = dgettext("sys_string", ret_val);
844 if (get_str == NULL && noti->b_text != NULL) {
847 snprintf(buf_key, sizeof(buf_key), "%d", type);
849 get_str = bundle_get_val(b, buf_key);
854 /* Set display option is off type when option is off, type is noti */
855 if (get_str != NULL && display_option_flag == 1
856 && noti->type == NOTIFICATION_TYPE_NOTI) {
857 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
858 || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
859 /* Set check_type to option content string */
860 if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
862 NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
863 } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
865 NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
869 if (noti->b_key != NULL) {
872 /* Get text domain and dir */
873 _notification_get_text_domain(noti);
875 snprintf(buf_key, sizeof(buf_key), "%d",
878 ret_val = bundle_get_val(b, buf_key);
879 if (ret_val != NULL && noti->domain != NULL
880 && noti->dir != NULL) {
881 /* Get application string */
882 bindtextdomain(noti->domain, noti->dir);
885 dgettext(noti->domain, ret_val);
886 } else if (ret_val != NULL) {
887 /* Get system string */
889 dgettext("sys_string", ret_val);
891 get_check_type_str = NULL;
895 if (get_check_type_str == NULL && noti->b_text != NULL) {
898 snprintf(buf_key, sizeof(buf_key), "%d",
901 get_check_type_str = bundle_get_val(b, buf_key);
905 if (get_check_type_str != NULL) {
906 /* Replace option off type string */
907 get_str = get_check_type_str;
909 /* Set default string */
911 dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
915 if (get_str != NULL) {
916 /* Get number format args */
917 b = noti->b_format_args;
918 noti->num_format_args = 0;
921 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
922 ret_val = bundle_get_val(b, buf_key);
923 if (ret_val != NULL) {
924 noti->num_format_args = atoi(ret_val);
928 if (noti->num_format_args == 0) {
929 *text = (char *)get_str;
931 /* Check first variable is count, LEFT pos */
932 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
933 check_type, num_args);
934 ret_val = bundle_get_val(b, buf_key);
935 ret_var_type = atoi(ret_val);
937 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
939 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
940 check_type, num_args);
941 ret_val = bundle_get_val(b, buf_key);
942 ret_variable_int = atoi(ret_val);
944 if (ret_variable_int ==
945 NOTIFICATION_COUNT_POS_LEFT) {
946 notification_noti_get_count(noti->type,
947 noti->caller_pkgname,
951 snprintf(buf_str, sizeof(buf_str),
952 "%d ", ret_variable_int);
953 strncat(result_str, buf_str,
961 /* Check variable IN pos */
962 for (temp_str = (char *)get_str; *temp_str != '\0';
964 if (*temp_str != '%') {
965 strncat(result_str, temp_str, 1);
967 if (*(temp_str + 1) == '%') {
968 strncat(result_str, temp_str,
970 } else if (*(temp_str + 1) == 'd') {
972 ret_variable_int = 0;
976 "%dtype%d", check_type,
979 bundle_get_val(b, buf_key);
980 ret_var_type = atoi(ret_val);
982 NOTIFICATION_VARIABLE_TYPE_COUNT)
984 /* Get notification count */
985 notification_noti_get_count
987 noti->caller_pkgname,
1007 sizeof(buf_str), "%d",
1009 strncat(result_str, buf_str,
1010 sizeof(result_str));
1015 } else if (*(temp_str + 1) == 's') {
1020 check_type, num_args);
1022 bundle_get_val(b, buf_key);
1025 sizeof(buf_str), "%s",
1027 strncat(result_str, buf_str,
1028 sizeof(result_str));
1033 } else if (*(temp_str + 1) == 'f') {
1038 check_type, num_args);
1040 bundle_get_val(b, buf_key);
1041 ret_variable_double =
1047 ret_variable_double);
1048 strncat(result_str, buf_str,
1049 sizeof(result_str));
1059 /* Check last variable is count, LEFT pos */
1060 if (num_args < noti->num_format_args) {
1061 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1062 check_type, num_args);
1063 ret_val = bundle_get_val(b, buf_key);
1064 ret_var_type = atoi(ret_val);
1066 NOTIFICATION_VARIABLE_TYPE_COUNT) {
1068 snprintf(buf_key, sizeof(buf_key),
1069 "%dvalue%d", check_type,
1071 ret_val = bundle_get_val(b, buf_key);
1072 ret_variable_int = atoi(ret_val);
1074 if (ret_variable_int ==
1075 NOTIFICATION_COUNT_POS_RIGHT) {
1076 notification_noti_get_count
1078 noti->caller_pkgname,
1083 sizeof(buf_str), " %d",
1085 strncat(result_str, buf_str,
1086 sizeof(result_str));
1094 switch (check_type) {
1095 case NOTIFICATION_TEXT_TYPE_TITLE:
1096 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
1097 if (noti->temp_title != NULL)
1098 free(noti->temp_title);
1100 noti->temp_title = strdup(result_str);
1102 *text = noti->temp_title;
1104 case NOTIFICATION_TEXT_TYPE_CONTENT:
1105 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1106 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
1107 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1108 if (noti->temp_content !=
1110 free(noti->temp_content);
1112 noti->temp_content = strdup(result_str);
1114 *text = noti->temp_content;
1123 if (check_type == NOTIFICATION_TEXT_TYPE_TITLE
1124 || check_type == NOTIFICATION_TEXT_TYPE_GROUP_TITLE) {
1125 /* Remove app name if exist, because pkgname is changed according to language setting */
1126 if (noti->app_name != NULL) {
1127 free(noti->app_name);
1128 noti->app_name = NULL;
1131 /* First, get app name from launch_pkgname */
1132 if (noti->launch_pkgname != NULL) {
1134 _notification_get_name(noti->
1138 /* Second, get app name from caller_pkgname */
1139 if (noti->app_name == NULL
1140 && noti->caller_pkgname != NULL) {
1142 _notification_get_name(noti->
1146 /* Third, get app name from service data */
1147 if (noti->app_name == NULL
1148 && noti->b_service_single_launch != NULL) {
1150 appsvc_get_pkgname(noti->
1151 b_service_single_launch);
1153 if (pkgname != NULL) {
1155 _notification_get_name(pkgname);
1159 *text = noti->app_name;
1165 NOTIFICATION_INFO("Get text : %s", *text);
1167 return NOTIFICATION_ERROR_NONE;
1170 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
1174 /* check noti and domain is valid data */
1175 if (noti == NULL || domain == NULL) {
1176 return NOTIFICATION_ERROR_INVALID_DATA;
1181 /* Remove previous domain */
1185 noti->domain = strdup(domain);
1187 /* Check locale dir */
1189 /* Remove previous locale dir */
1192 /* Copy locale dir */
1193 noti->dir = strdup(dir);
1195 return NOTIFICATION_ERROR_NONE;
1198 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
1202 /* Check noti is valid data */
1204 return NOTIFICATION_ERROR_INVALID_DATA;
1208 if (domain != NULL && noti->domain != NULL) {
1209 *domain = noti->domain;
1212 /* Get locale dir */
1213 if (dir != NULL && noti->dir != NULL) {
1217 return NOTIFICATION_ERROR_NONE;
1220 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1221 notification_sound_type_e type,
1224 /* Check noti is valid data */
1226 return NOTIFICATION_ERROR_INVALID_DATA;
1229 /* Check type is valid */
1230 if (type < NOTIFICATION_SOUND_TYPE_NONE
1231 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1232 return NOTIFICATION_ERROR_INVALID_DATA;
1235 /* Save sound type */
1236 noti->sound_type = type;
1238 /* Save sound path if user data type */
1239 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1240 if (noti->sound_path != NULL) {
1241 free(noti->sound_path);
1244 noti->sound_path = strdup(path);
1246 if (noti->sound_path != NULL) {
1247 free(noti->sound_path);
1248 noti->sound_path = NULL;
1252 return NOTIFICATION_ERROR_NONE;
1255 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1256 notification_sound_type_e *type,
1259 /* check noti and type is valid data */
1260 if (noti == NULL || type == NULL) {
1261 return NOTIFICATION_ERROR_INVALID_DATA;
1264 /* Set sound type */
1265 *type = noti->sound_type;
1267 /* Set sound path if user data type */
1268 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1270 *path = noti->sound_path;
1273 return NOTIFICATION_ERROR_NONE;
1276 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1277 notification_vibration_type_e type,
1280 /* Check noti is valid data */
1282 return NOTIFICATION_ERROR_INVALID_DATA;
1285 /* Check type is valid */
1286 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1287 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1288 return NOTIFICATION_ERROR_INVALID_DATA;
1291 /* Save vibration type */
1292 noti->vibration_type = type;
1294 /* Save sound path if user data type */
1295 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1296 if (noti->vibration_path != NULL) {
1297 free(noti->vibration_path);
1300 noti->vibration_path = strdup(path);
1302 if (noti->vibration_path != NULL) {
1303 free(noti->vibration_path);
1304 noti->vibration_path = NULL;
1308 return NOTIFICATION_ERROR_NONE;
1312 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1313 notification_vibration_type_e *type,
1316 /* check noti and type is valid data */
1317 if (noti == NULL || type == NULL) {
1318 return NOTIFICATION_ERROR_INVALID_DATA;
1321 /* Set vibration type */
1322 *type = noti->vibration_type;
1324 /* Set sound path if user data type */
1325 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1327 *path = noti->vibration_path;
1330 return NOTIFICATION_ERROR_NONE;
1333 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1334 const char *pkgname)
1336 if (noti == NULL || pkgname == NULL) {
1337 return NOTIFICATION_ERROR_INVALID_DATA;
1340 if (noti->launch_pkgname) {
1341 free(noti->launch_pkgname);
1344 noti->launch_pkgname = strdup(pkgname);
1346 return NOTIFICATION_ERROR_NONE;
1349 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1352 if (noti == NULL || pkgname == NULL) {
1353 return NOTIFICATION_ERROR_INVALID_DATA;
1356 if (noti->launch_pkgname) {
1357 *pkgname = noti->launch_pkgname;
1359 *pkgname = noti->caller_pkgname;
1362 return NOTIFICATION_ERROR_NONE;
1365 EXPORT_API notification_error_e notification_set_args(notification_h noti,
1367 bundle * group_args)
1369 if (noti == NULL || args == NULL) {
1370 return NOTIFICATION_ERROR_INVALID_DATA;
1374 bundle_free(noti->args);
1377 noti->args = bundle_dup(args);
1379 if (noti->group_args) {
1380 bundle_free(noti->group_args);
1381 noti->group_args = NULL;
1384 if (group_args != NULL) {
1385 noti->group_args = bundle_dup(group_args);
1388 return NOTIFICATION_ERROR_NONE;
1391 EXPORT_API notification_error_e notification_get_args(notification_h noti,
1393 bundle ** group_args)
1395 if (noti == NULL || args == NULL) {
1396 return NOTIFICATION_ERROR_INVALID_DATA;
1405 if (group_args != NULL && noti->group_args) {
1406 *group_args = noti->group_args;
1409 return NOTIFICATION_ERROR_NONE;
1412 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1413 notification_execute_type_e type,
1416 bundle *service_handle)
1418 char buf_key[32] = { 0, };
1419 const char *ret_val = NULL;
1423 return NOTIFICATION_ERROR_INVALID_DATA;
1426 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1427 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1428 return NOTIFICATION_ERROR_INVALID_DATA;
1431 /* Create execute option bundle if does not exist */
1432 if (noti->b_execute_option != NULL) {
1433 noti->b_execute_option = bundle_create();
1436 b = noti->b_execute_option;
1441 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1443 /* Check text key exist */
1444 ret_val = bundle_get_val(b, buf_key);
1445 if (ret_val != NULL) {
1446 /* Remove previous data */
1447 bundle_del(b, buf_key);
1451 bundle_add(b, buf_key, text);
1457 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1459 /* Check key key exist */
1460 ret_val = bundle_get_val(b, buf_key);
1461 if (ret_val != NULL) {
1462 /* Remove previous data */
1463 bundle_del(b, buf_key);
1467 bundle_add(b, buf_key, key);
1471 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1472 /* Remove previous data if exist */
1473 if (noti->b_service_responding != NULL) {
1474 bundle_free(noti->b_service_responding);
1475 noti->b_service_responding = NULL;
1478 /* Save service handle */
1479 if (service_handle != NULL) {
1480 noti->b_service_responding = bundle_dup(service_handle);
1483 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1484 /* Remove previous data if exist */
1485 if (noti->b_service_single_launch != NULL) {
1486 bundle_free(noti->b_service_single_launch);
1487 noti->b_service_single_launch = NULL;
1490 /* Save service handle */
1491 if (service_handle != NULL) {
1492 noti->b_service_single_launch =
1493 bundle_dup(service_handle);
1496 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1497 /* Remove previous data if exist */
1498 if (noti->b_service_multi_launch != NULL) {
1499 bundle_free(noti->b_service_multi_launch);
1500 noti->b_service_multi_launch = NULL;
1503 /* Save service handle */
1504 if (service_handle != NULL) {
1505 noti->b_service_multi_launch =
1506 bundle_dup(service_handle);
1513 return NOTIFICATION_ERROR_NONE;
1516 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1517 notification_execute_type_e type,
1519 bundle **service_handle)
1521 char buf_key[32] = { 0, };
1522 const char *ret_val = NULL;
1523 char *get_str = NULL;
1527 return NOTIFICATION_ERROR_INVALID_DATA;
1530 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1531 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1532 return NOTIFICATION_ERROR_INVALID_DATA;
1536 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1537 b = noti->b_service_responding;
1539 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1540 b = noti->b_service_single_launch;
1542 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1543 b = noti->b_service_multi_launch;
1553 // Get text domain and dir
1554 if (noti->domain == NULL || noti->dir == NULL) {
1555 _notification_get_text_domain(noti);
1559 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1561 /* Check key key exist */
1562 ret_val = bundle_get_val(b, buf_key);
1563 if (ret_val != NULL && noti->domain != NULL
1564 && noti->dir != NULL) {
1565 /* Get application string */
1566 bindtextdomain(noti->domain, noti->dir);
1568 get_str = dgettext(noti->domain, ret_val);
1571 } else if (ret_val != NULL) {
1572 /* Get system string */
1573 get_str = dgettext("sys_string", ret_val);
1577 /* Get basic text */
1578 snprintf(buf_key, sizeof(buf_key), "text%d",
1581 ret_val = bundle_get_val(b, buf_key);
1589 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1590 b = noti->b_service_responding;
1592 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1593 b = noti->b_service_single_launch;
1595 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1596 b = noti->b_service_multi_launch;
1603 if (service_handle != NULL) {
1604 *service_handle = b;
1607 return NOTIFICATION_ERROR_NONE;
1610 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1613 /* Check noti is valid data */
1615 return NOTIFICATION_ERROR_INVALID_DATA;
1619 noti->flags_for_property = flags;
1621 return NOTIFICATION_ERROR_NONE;
1624 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1627 /* Check noti and flags are valid data */
1628 if (noti == NULL || flags == NULL) {
1629 return NOTIFICATION_ERROR_INVALID_DATA;
1633 *flags = noti->flags_for_property;
1635 return NOTIFICATION_ERROR_NONE;
1638 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1641 /* Check noti is valid data */
1643 return NOTIFICATION_ERROR_INVALID_DATA;
1647 noti->display_applist = applist;
1649 return NOTIFICATION_ERROR_NONE;
1652 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1655 /* Check noti and applist are valid data */
1656 if (noti == NULL || applist == NULL) {
1657 return NOTIFICATION_ERROR_INVALID_DATA;
1661 *applist = noti->display_applist;
1663 return NOTIFICATION_ERROR_NONE;
1666 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1669 /* Check noti is valid data */
1671 return NOTIFICATION_ERROR_INVALID_DATA;
1674 /* Save progress size */
1675 noti->progress_size = size;
1677 return NOTIFICATION_ERROR_NONE;
1680 EXPORT_API notification_error_e notification_get_size(notification_h noti,
1683 /* Check noti and size is valid data */
1684 if (noti == NULL || size == NULL) {
1685 return NOTIFICATION_ERROR_INVALID_DATA;
1688 /* Set progress size */
1689 *size = noti->progress_size;
1691 return NOTIFICATION_ERROR_NONE;
1694 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
1697 /* Check noti is valid data */
1699 return NOTIFICATION_ERROR_INVALID_DATA;
1702 /* Save progress percentage */
1703 noti->progress_percentage = percentage;
1705 return NOTIFICATION_ERROR_NONE;
1708 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
1711 /* Check noti and percentage are valid data */
1712 if (noti == NULL || percentage == NULL) {
1713 return NOTIFICATION_ERROR_INVALID_DATA;
1716 /* Set progress percentage */
1717 *percentage = noti->progress_percentage;
1719 return NOTIFICATION_ERROR_NONE;
1722 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
1723 const char *pkgname)
1725 /* check noti and pkgname are valid data */
1726 if (noti == NULL || pkgname == NULL) {
1727 return NOTIFICATION_ERROR_INVALID_DATA;
1730 /* Remove previous caller pkgname */
1731 if (noti->caller_pkgname) {
1732 free(noti->caller_pkgname);
1733 noti->caller_pkgname = NULL;
1736 noti->caller_pkgname = strdup(pkgname);
1738 return NOTIFICATION_ERROR_NONE;
1741 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
1744 /* Check noti and pkgname are valid data */
1745 if (noti == NULL || pkgname == NULL) {
1746 return NOTIFICATION_ERROR_INVALID_DATA;
1749 /* Get caller pkgname */
1750 if (noti->caller_pkgname) {
1751 *pkgname = noti->caller_pkgname;
1756 return NOTIFICATION_ERROR_NONE;
1759 EXPORT_API notification_error_e notification_set_badge(const char *pkgname,
1760 int group_id, int count)
1762 char *caller_pkgname = NULL;
1763 int ret = NOTIFICATION_ERROR_NONE;
1765 /* Check count is valid count */
1767 return NOTIFICATION_ERROR_INVALID_DATA;
1771 if (pkgname == NULL) {
1772 caller_pkgname = _notification_get_pkgname_by_pid();
1774 /* Set count into Group DB */
1776 notification_group_set_badge(caller_pkgname, group_id,
1779 if (caller_pkgname != NULL) {
1780 free(caller_pkgname);
1783 /* Set count into Group DB */
1784 ret = notification_group_set_badge(pkgname, group_id, count);
1790 EXPORT_API notification_error_e notification_get_badge(const char *pkgname,
1791 int group_id, int *count)
1793 char *caller_pkgname = NULL;
1794 int ret = NOTIFICATION_ERROR_NONE;
1795 int ret_unread_count = 0;
1798 if (pkgname == NULL) {
1799 caller_pkgname = _notification_get_pkgname_by_pid();
1801 /* Get count from Group DB */
1803 notification_group_get_badge(caller_pkgname, group_id,
1806 if (caller_pkgname != NULL) {
1807 free(caller_pkgname);
1810 /* Get count from Group DB */
1812 notification_group_get_badge(pkgname, group_id,
1816 if (ret != NOTIFICATION_ERROR_NONE) {
1821 if (count != NULL) {
1822 *count = ret_unread_count;
1825 return NOTIFICATION_ERROR_NONE;
1828 EXPORT_API notification_error_e notification_get_id(notification_h noti,
1829 int *group_id, int *priv_id)
1831 /* check noti is valid data */
1833 return NOTIFICATION_ERROR_INVALID_DATA;
1836 /* Check group_id is valid data */
1839 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1840 *group_id = NOTIFICATION_GROUP_ID_NONE;
1842 *group_id = noti->group_id;
1846 /* Check priv_id is valid data */
1849 *priv_id = noti->priv_id;
1852 return NOTIFICATION_ERROR_NONE;
1855 EXPORT_API notification_error_e notification_get_type(notification_h noti,
1856 notification_type_e *type)
1858 /* Check noti and type is valid data */
1859 if (noti == NULL || type == NULL) {
1860 return NOTIFICATION_ERROR_INVALID_DATA;
1866 return NOTIFICATION_ERROR_NONE;
1869 EXPORT_API notification_error_e notification_insert(notification_h noti,
1874 /* Check noti is vaild data */
1876 return NOTIFICATION_ERROR_INVALID_DATA;
1879 /* Check noti type is valid type */
1880 if (noti->type <= NOTIFICATION_TYPE_NONE
1881 || noti->type >= NOTIFICATION_TYPE_MAX) {
1882 return NOTIFICATION_ERROR_INVALID_DATA;
1885 /* Save insert time */
1886 noti->insert_time = time(NULL);
1888 /* Insert into DB */
1889 ret = notification_noti_insert(noti);
1890 if (ret != NOTIFICATION_ERROR_NONE) {
1894 /* Check disable update on insert property */
1895 if (noti->flags_for_property
1896 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
1897 /* Disable changed cb */
1899 /* Enable changed cb */
1900 _notification_changed(NOTI_CHANGED_NOTI);
1903 /* If priv_id is valid data, set priv_id */
1904 if (priv_id != NULL) {
1905 *priv_id = noti->priv_id;
1908 return NOTIFICATION_ERROR_NONE;
1911 EXPORT_API notification_error_e notification_update(notification_h noti)
1915 /* Check noti is valid data */
1917 /* Update insert time ? */
1918 noti->insert_time = time(NULL);
1920 ret = notification_noti_update(noti);
1921 if (ret != NOTIFICATION_ERROR_NONE) {
1926 /* Send changed notification */
1927 _notification_changed(NOTI_CHANGED_NOTI);
1929 return NOTIFICATION_ERROR_NONE;
1932 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
1936 /* Delete all notification of type */
1937 ret = notification_noti_delete_all(type, NULL);
1938 if (ret != NOTIFICATION_ERROR_NONE) {
1942 /* Send chagned notification */
1943 _notification_changed(NOTI_CHANGED_NOTI);
1945 return NOTIFICATION_ERROR_NONE;
1948 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
1949 notification_type_e type)
1952 char *caller_pkgname = NULL;
1954 if (pkgname == NULL) {
1955 caller_pkgname = _notification_get_pkgname_by_pid();
1957 caller_pkgname = strdup(pkgname);
1960 ret = notification_noti_delete_all(type, caller_pkgname);
1961 if (ret != NOTIFICATION_ERROR_NONE) {
1962 free(caller_pkgname);
1966 _notification_changed(NOTI_CHANGED_NOTI);
1968 free(caller_pkgname);
1973 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
1974 notification_type_e type,
1978 char *caller_pkgname = NULL;
1980 if (group_id < NOTIFICATION_GROUP_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);
1991 notification_noti_delete_group_by_group_id(caller_pkgname,
1993 if (ret != NOTIFICATION_ERROR_NONE) {
1994 free(caller_pkgname);
1998 _notification_changed(NOTI_CHANGED_NOTI);
2000 free(caller_pkgname);
2005 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2006 notification_type_e type,
2010 char *caller_pkgname = NULL;
2012 if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2013 return NOTIFICATION_ERROR_INVALID_DATA;
2016 if (pkgname == NULL) {
2017 caller_pkgname = _notification_get_pkgname_by_pid();
2019 caller_pkgname = strdup(pkgname);
2023 notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id);
2024 if (ret != NOTIFICATION_ERROR_NONE) {
2025 free(caller_pkgname);
2029 _notification_changed(NOTI_CHANGED_NOTI);
2031 free(caller_pkgname);
2036 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
2037 notification_type_e type,
2041 char *caller_pkgname = NULL;
2043 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2044 return NOTIFICATION_ERROR_INVALID_DATA;
2047 if (pkgname == NULL) {
2048 caller_pkgname = _notification_get_pkgname_by_pid();
2050 caller_pkgname = strdup(pkgname);
2053 ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id);
2054 if (ret != NOTIFICATION_ERROR_NONE) {
2055 free(caller_pkgname);
2059 _notification_changed(NOTI_CHANGED_NOTI);
2061 free(caller_pkgname);
2066 EXPORT_API notification_error_e notification_delete(notification_h noti)
2071 return NOTIFICATION_ERROR_INVALID_DATA;
2075 notification_noti_delete_by_priv_id(noti->caller_pkgname,
2077 if (ret != NOTIFICATION_ERROR_NONE) {
2081 if (noti->flags_for_property
2082 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) {
2083 NOTIFICATION_INFO("Disabled update while delete.");
2085 _notification_changed(NOTI_CHANGED_NOTI);
2088 return NOTIFICATION_ERROR_NONE;
2091 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
2095 char *caller_pkgname = NULL;
2096 int input_priv_id = 0;
2097 double input_progress = 0.0;
2099 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2101 return NOTIFICATION_ERROR_INVALID_DATA;
2103 input_priv_id = noti->priv_id;
2106 input_priv_id = priv_id;
2110 caller_pkgname = _notification_get_pkgname_by_pid();
2112 caller_pkgname = strdup(noti->caller_pkgname);
2115 if (progress < 0.0) {
2116 input_progress = 0.0;
2117 } else if (progress > 1.0) {
2118 input_progress = 1.0;
2120 input_progress = progress;
2123 notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2126 if (caller_pkgname) {
2127 free(caller_pkgname);
2130 return NOTIFICATION_ERROR_NONE;
2133 EXPORT_API notification_error_e notification_update_size(notification_h noti,
2137 char *caller_pkgname = NULL;
2138 int input_priv_id = 0;
2139 double input_size = 0.0;
2141 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2143 return NOTIFICATION_ERROR_INVALID_DATA;
2145 input_priv_id = noti->priv_id;
2148 input_priv_id = priv_id;
2152 caller_pkgname = _notification_get_pkgname_by_pid();
2154 caller_pkgname = strdup(noti->caller_pkgname);
2163 notification_ongoing_update_size(caller_pkgname, input_priv_id,
2166 if (caller_pkgname) {
2167 free(caller_pkgname);
2170 return NOTIFICATION_ERROR_NONE;
2173 EXPORT_API notification_error_e notification_update_content(notification_h noti,
2175 const char *content)
2177 char *caller_pkgname = NULL;
2178 int input_priv_id = 0;
2180 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2182 return NOTIFICATION_ERROR_INVALID_DATA;
2184 input_priv_id = noti->priv_id;
2187 input_priv_id = priv_id;
2191 caller_pkgname = _notification_get_pkgname_by_pid();
2193 caller_pkgname = strdup(noti->caller_pkgname);
2196 notification_ongoing_update_content(caller_pkgname, input_priv_id,
2199 if (caller_pkgname) {
2200 free(caller_pkgname);
2203 return NOTIFICATION_ERROR_NONE;
2206 EXPORT_API notification_h notification_new(notification_type_e type,
2207 int group_id, int priv_id)
2209 notification_h noti = NULL;
2211 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2212 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2216 if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2217 NOTIFICATION_ERR("INVALID GROUP ID : %d", group_id);
2221 if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2222 NOTIFICATION_ERR("INVALID PRIV ID : %d", priv_id);
2226 noti = (notification_h) malloc(sizeof(struct _notification));
2228 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2231 memset(noti, 0x00, sizeof(struct _notification));
2235 noti->group_id = group_id;
2236 noti->internal_group_id = 0;
2237 noti->priv_id = priv_id;
2239 noti->caller_pkgname = _notification_get_pkgname_by_pid();
2240 noti->launch_pkgname = NULL;
2242 noti->group_args = NULL;
2244 noti->b_execute_option = NULL;
2245 noti->b_service_responding = NULL;
2246 noti->b_service_single_launch = NULL;
2247 noti->b_service_multi_launch = NULL;
2249 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2250 noti->sound_path = NULL;
2252 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2253 noti->vibration_path = NULL;
2255 noti->domain = NULL;
2258 noti->b_text = NULL;
2260 noti->b_format_args = NULL;
2261 noti->num_format_args = 0;
2263 noti->b_image_path = NULL;
2266 noti->insert_time = 0;
2268 noti->flags_for_property = 0;
2269 noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2271 noti->progress_size = 0.0;
2272 noti->progress_percentage = 0.0;
2274 noti->app_icon_path = NULL;
2275 noti->app_name = NULL;
2276 noti->temp_title = NULL;
2277 noti->temp_content = NULL;
2282 EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone)
2284 notification_h new_noti = NULL;
2286 if (noti == NULL || clone == NULL) {
2287 NOTIFICATION_ERR("INVALID PARAMETER.");
2288 return NOTIFICATION_ERROR_INVALID_DATA;
2291 new_noti = (notification_h) malloc(sizeof(struct _notification));
2292 if (new_noti == NULL) {
2293 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2294 return NOTIFICATION_ERROR_NO_MEMORY;
2296 memset(new_noti, 0x00, sizeof(struct _notification));
2298 new_noti->type = noti->type;
2300 new_noti->group_id = noti->group_id;
2301 new_noti->internal_group_id = noti->internal_group_id;
2302 new_noti->priv_id = noti->priv_id;
2304 if(noti->caller_pkgname != NULL) {
2305 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2307 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2309 if(noti->launch_pkgname != NULL) {
2310 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2312 new_noti->launch_pkgname = NULL;
2315 if(noti->args != NULL) {
2316 new_noti->args = bundle_dup(noti->args);
2318 new_noti->args = NULL;
2320 if(noti->group_args != NULL) {
2321 new_noti->group_args = bundle_dup(noti->group_args);
2323 new_noti->group_args = NULL;
2326 if(noti->b_execute_option != NULL) {
2327 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2329 new_noti->b_execute_option = NULL;
2331 if(noti->b_service_responding != NULL) {
2332 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2334 new_noti->b_service_responding = NULL;
2336 if(noti->b_service_single_launch != NULL) {
2337 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2339 new_noti->b_service_single_launch = NULL;
2341 if(noti->b_service_multi_launch != NULL) {
2342 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2344 new_noti->b_service_multi_launch = NULL;
2347 new_noti->sound_type = noti->sound_type;
2348 if(noti->sound_path != NULL) {
2349 new_noti->sound_path = strdup(noti->sound_path);
2351 new_noti->sound_path = NULL;
2353 new_noti->vibration_type = noti->vibration_type;
2354 if(noti->vibration_path != NULL) {
2355 new_noti->vibration_path = strdup(noti->vibration_path);
2357 new_noti->vibration_path = NULL;
2360 if(noti->domain != NULL) {
2361 new_noti->domain = strdup(noti->domain);
2363 new_noti->domain = NULL;
2365 if(noti->dir != NULL) {
2366 new_noti->dir = strdup(noti->dir);
2368 new_noti->dir = NULL;
2371 if(noti->b_text != NULL) {
2372 new_noti->b_text = bundle_dup(noti->b_text);
2374 new_noti->b_text = NULL;
2376 if(noti->b_key != NULL) {
2377 new_noti->b_key = bundle_dup(noti->b_key);
2379 new_noti->b_key = NULL;
2381 if(noti->b_format_args != NULL) {
2382 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2384 new_noti->b_format_args = NULL;
2386 new_noti->num_format_args = noti->num_format_args;
2388 if(noti->b_image_path != NULL) {
2389 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2391 new_noti->b_image_path = NULL;
2394 new_noti->time = noti->time;
2395 new_noti->insert_time = noti->insert_time;
2397 new_noti->flags_for_property = noti->flags_for_property;
2398 new_noti->display_applist = noti->display_applist;
2400 new_noti->progress_size = noti->progress_size;
2401 new_noti->progress_percentage = noti->progress_percentage;
2403 new_noti->app_icon_path = NULL;
2404 new_noti->app_name = NULL;
2405 new_noti->temp_title = NULL;
2406 new_noti->temp_content = NULL;
2410 return NOTIFICATION_ERROR_NONE;
2414 EXPORT_API notification_error_e notification_free(notification_h noti)
2417 return NOTIFICATION_ERROR_INVALID_DATA;
2420 if (noti->caller_pkgname) {
2421 free(noti->caller_pkgname);
2423 if (noti->launch_pkgname) {
2424 free(noti->launch_pkgname);
2427 bundle_free(noti->args);
2429 if (noti->group_args) {
2430 bundle_free(noti->group_args);
2433 if (noti->b_execute_option) {
2434 bundle_free(noti->b_execute_option);
2436 if (noti->b_service_responding) {
2437 bundle_free(noti->b_service_responding);
2439 if (noti->b_service_single_launch) {
2440 bundle_free(noti->b_service_single_launch);
2442 if (noti->b_service_multi_launch) {
2443 bundle_free(noti->b_service_multi_launch);
2446 if (noti->sound_path) {
2447 free(noti->sound_path);
2449 if (noti->vibration_path) {
2450 free(noti->vibration_path);
2461 bundle_free(noti->b_text);
2464 bundle_free(noti->b_key);
2466 if (noti->b_format_args) {
2467 bundle_free(noti->b_format_args);
2470 if (noti->b_image_path) {
2471 bundle_free(noti->b_image_path);
2474 if (noti->app_icon_path) {
2475 free(noti->app_icon_path);
2477 if (noti->app_name) {
2478 free(noti->app_name);
2480 if (noti->temp_title) {
2481 free(noti->temp_title);
2483 if (noti->temp_content) {
2484 free(noti->temp_content);
2489 return NOTIFICATION_ERROR_NONE;
2492 EXPORT_API notification_error_e
2493 notification_resister_changed_cb(void (*changed_cb)
2494 (void *data, notification_type_e type),
2497 notification_cb_list_s *noti_cb_list_new = NULL;
2498 notification_cb_list_s *noti_cb_list = NULL;
2501 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2503 noti_cb_list_new->next = NULL;
2504 noti_cb_list_new->prev = NULL;
2506 noti_cb_list_new->changed_cb = changed_cb;
2507 noti_cb_list_new->data = user_data;
2509 if (g_notification_cb_list == NULL) {
2510 g_notification_cb_list = noti_cb_list_new;
2512 noti_cb_list = g_notification_cb_list;
2514 while (noti_cb_list->next != NULL) {
2515 noti_cb_list = noti_cb_list->next;
2518 noti_cb_list->next = noti_cb_list_new;
2519 noti_cb_list_new->prev = noti_cb_list;
2522 if (g_notification_heynoti_fd < 0) {
2523 g_notification_heynoti_fd = heynoti_init();
2525 heynoti_subscribe(g_notification_heynoti_fd, NOTI_CHANGED_NOTI,
2526 _notification_chagned_noti_cb, NULL);
2528 heynoti_attach_handler(g_notification_heynoti_fd);
2531 return NOTIFICATION_ERROR_NONE;
2534 EXPORT_API notification_error_e
2535 notification_unresister_changed_cb(void (*changed_cb)
2536 (void *data, notification_type_e type))
2538 notification_cb_list_s *noti_cb_list = NULL;
2539 notification_cb_list_s *noti_cb_list_prev = NULL;
2540 notification_cb_list_s *noti_cb_list_next = NULL;
2542 noti_cb_list = g_notification_cb_list;
2544 if (noti_cb_list == NULL) {
2545 return NOTIFICATION_ERROR_INVALID_DATA;
2548 while (noti_cb_list->prev != NULL) {
2549 noti_cb_list = noti_cb_list->prev;
2553 if (noti_cb_list->changed_cb == changed_cb) {
2554 noti_cb_list_prev = noti_cb_list->prev;
2555 noti_cb_list_next = noti_cb_list->next;
2557 if (noti_cb_list_prev == NULL) {
2558 g_notification_cb_list = noti_cb_list_next;
2560 noti_cb_list_prev->next = noti_cb_list_next;
2563 if (noti_cb_list_next == NULL) {
2564 if (noti_cb_list_prev != NULL) {
2565 noti_cb_list_prev->next = NULL;
2568 noti_cb_list_next->prev = noti_cb_list_prev;
2573 if (g_notification_cb_list == NULL) {
2574 heynoti_detach_handler
2575 (g_notification_heynoti_fd);
2576 heynoti_close(g_notification_heynoti_fd);
2577 g_notification_heynoti_fd = -1;
2580 return NOTIFICATION_ERROR_NONE;
2582 noti_cb_list = noti_cb_list->next;
2583 } while (noti_cb_list != NULL);
2585 return NOTIFICATION_ERROR_INVALID_DATA;
2588 EXPORT_API notification_error_e
2589 notification_resister_badge_changed_cb(void (*changed_cb)
2590 (void *data, const char *pkgname,
2591 int group_id), void *user_data)
2593 // Add DBus signal handler
2594 return NOTIFICATION_ERROR_NONE;
2597 EXPORT_API notification_error_e
2598 notification_unresister_badge_changed_cb(void (*changed_cb)
2599 (void *data, const char *pkgname,
2602 // Del DBus signal handler
2603 return NOTIFICATION_ERROR_NONE;
2606 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
2607 const char *pkgname,
2609 int priv_id, int *count)
2615 notification_noti_get_count(type, pkgname, group_id, priv_id,
2617 if (ret != NOTIFICATION_ERROR_NONE) {
2621 if (count != NULL) {
2622 *count = noti_count;
2625 return NOTIFICATION_ERROR_NONE;
2628 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
2630 notification_list_h *list)
2632 notification_list_h get_list = NULL;
2635 ret = notification_noti_get_grouping_list(type, count, &get_list);
2636 if (ret != NOTIFICATION_ERROR_NONE) {
2642 return NOTIFICATION_ERROR_NONE;
2645 EXPORT_API notification_error_e
2646 notification_get_grouping_list(notification_type_e type, int count,
2647 notification_list_h * list)
2649 notification_list_h get_list = NULL;
2652 ret = notification_noti_get_grouping_list(type, count, &get_list);
2653 if (ret != NOTIFICATION_ERROR_NONE) {
2659 return NOTIFICATION_ERROR_NONE;
2662 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
2666 notification_list_h *list)
2668 notification_list_h get_list = NULL;
2672 notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2674 if (ret != NOTIFICATION_ERROR_NONE) {
2680 return NOTIFICATION_ERROR_NONE;
2683 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
2685 notification_list_h cur_list = NULL;
2686 notification_h noti = NULL;
2689 NOTIFICATION_ERR("INVALID DATA : list == NULL");
2690 return NOTIFICATION_ERROR_INVALID_DATA;
2693 cur_list = notification_list_get_head(list);
2695 while (cur_list != NULL) {
2696 noti = notification_list_get_data(cur_list);
2697 cur_list = notification_list_remove(cur_list, noti);
2699 notification_free(noti);
2702 return NOTIFICATION_ERROR_NONE;