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.
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 EXPORT_API notification_error_e notification_set_image(notification_h noti,
126 notification_image_type_e type,
127 const char *image_path)
130 char buf_key[32] = { 0, };
131 const char *ret_val = NULL;
133 /* Check noti and image_path are valid data */
134 if (noti == NULL || image_path == NULL) {
135 return NOTIFICATION_ERROR_INVALID_DATA;
138 /* Check image type is valid type */
139 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
140 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
141 return NOTIFICATION_ERROR_INVALID_DATA;
144 /* Check image path bundle is exist */
145 if (noti->b_image_path) {
146 /* If image path bundle is exist, store local bundle value */
147 b = noti->b_image_path;
149 /* Set image type to key as char string type */
150 snprintf(buf_key, sizeof(buf_key), "%d", type);
152 /* Get value using key */
153 ret_val = bundle_get_val(b, buf_key);
154 if (ret_val != NULL) {
155 /* If key is exist, remove this value to store new image path */
156 bundle_del(b, buf_key);
159 /* Add new image path with type key */
160 bundle_add(b, buf_key, image_path);
162 /* If image path bundle is not exist, create new one */
165 /* Set image type to key as char string type */
166 snprintf(buf_key, sizeof(buf_key), "%d", type);
168 /* Add new image path with type key */
169 bundle_add(b, buf_key, image_path);
171 /* Save to image path bundle */
172 noti->b_image_path = b;
175 return NOTIFICATION_ERROR_NONE;
178 EXPORT_API notification_error_e notification_get_image(notification_h noti,
179 notification_image_type_e type,
183 char buf_key[32] = { 0, };
184 const char *ret_val = NULL;
186 /* Check noti and image_path is valid data */
187 if (noti == NULL || image_path == NULL) {
188 return NOTIFICATION_ERROR_INVALID_DATA;
191 /* Check image type is valid data */
192 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
193 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
194 return NOTIFICATION_ERROR_INVALID_DATA;
197 /* Check image path bundle exist */
198 if (noti->b_image_path) {
199 /* If image path bundle exist, store local bundle data */
200 b = noti->b_image_path;
202 /* Set image type to key as char string type */
203 snprintf(buf_key, sizeof(buf_key), "%d", type);
205 /* Get value of key */
206 ret_val = bundle_get_val(b, buf_key);
208 *image_path = (char *)ret_val;
210 /* If image path bundle does not exist, image path is NULL */
214 /* If image path is NULL and type is ICON, icon path set from AIL */
215 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
216 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
217 /* Check App icon path is already set */
218 if (noti->app_icon_path != NULL) {
219 /* image path will be app icon path */
220 *image_path = noti->app_icon_path;
226 return NOTIFICATION_ERROR_NONE;
229 EXPORT_API notification_error_e notification_set_time(notification_h noti,
232 /* Check noti is valid data */
234 return NOTIFICATION_ERROR_INVALID_DATA;
237 if (input_time == 0) {
238 /* If input time is 0, set current time */
239 noti->time = time(NULL);
241 /* save input time */
242 noti->time = input_time;
245 return NOTIFICATION_ERROR_NONE;
248 EXPORT_API notification_error_e notification_get_time(notification_h noti,
251 /* Check noti and time is valid data */
252 if (noti == NULL || ret_time == NULL) {
253 return NOTIFICATION_ERROR_INVALID_DATA;
256 /* Set time infomation */
257 *ret_time = noti->time;
259 return NOTIFICATION_ERROR_NONE;
262 EXPORT_API notification_error_e notification_get_insert_time(notification_h noti,
265 /* Check noti and ret_time is valid data */
266 if (noti == NULL || ret_time == NULL) {
267 return NOTIFICATION_ERROR_INVALID_DATA;
270 /* Set insert time information */
271 *ret_time = noti->insert_time;
273 return NOTIFICATION_ERROR_NONE;
276 EXPORT_API notification_error_e notification_set_text(notification_h noti,
277 notification_text_type_e type,
283 char buf_key[32] = { 0, };
284 char buf_val[1024] = { 0, };
285 const char *ret_val = NULL;
287 notification_variable_type_e var_type;
289 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
290 int var_value_int = 0;
291 double var_value_double = 0.0;
292 char *var_value_string = NULL;
293 notification_count_pos_type_e var_value_count =
294 NOTIFICATION_COUNT_POS_NONE;
296 /* Check noti is valid data */
298 return NOTIFICATION_ERROR_INVALID_DATA;
301 /* Check text type is valid type */
302 if (type <= NOTIFICATION_TEXT_TYPE_NONE
303 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
304 return NOTIFICATION_ERROR_INVALID_DATA;
307 /* Check text bundle exist */
309 if (noti->b_text != NULL) {
310 /* If text bundle exist, store local bundle data */
313 /* Make type to key as char string */
314 snprintf(buf_key, sizeof(buf_key), "%d", type);
316 /* Get value using type key */
317 ret_val = bundle_get_val(b, buf_key);
318 if (ret_val != NULL) {
319 /* If value exist, remove this to add new value */
320 bundle_del(b, buf_key);
323 snprintf(buf_val, sizeof(buf_val), "%s", text);
325 /* Add new text value */
326 bundle_add(b, buf_key, buf_val);
328 /* If text bundle does not exist, create new one */
331 /* Make type to key as char string */
332 snprintf(buf_key, sizeof(buf_key), "%d", type);
334 snprintf(buf_val, sizeof(buf_val), "%s", text);
336 /* Add new text value */
337 bundle_add(b, buf_key, buf_val);
339 /* Save text bundle */
343 /* Reset if text is NULL */
344 if (noti->b_text != NULL) {
345 /* If text bundle exist, store local bundle data */
348 /* Make type to key as char string */
349 snprintf(buf_key, sizeof(buf_key), "%d", type);
351 /* Get value using type key */
352 ret_val = bundle_get_val(b, buf_key);
353 if (ret_val != NULL) {
354 /* If value exist, remove this */
355 bundle_del(b, buf_key);
360 /* Save key if key is valid data */
362 /* Check key bundle exist */
363 if (noti->b_key != NULL) {
364 /* If key bundle exist, store local bundle data */
367 /* Make type to key as char string */
368 snprintf(buf_key, sizeof(buf_key), "%d", type);
370 /* Get value using type key */
371 ret_val = bundle_get_val(b, buf_key);
372 if (ret_val != NULL) {
373 /* If value exist, remove this to add new value */
374 bundle_del(b, buf_key);
377 snprintf(buf_val, sizeof(buf_val), "%s", key);
379 /* Add new key value */
380 bundle_add(b, buf_key, buf_val);
382 /* If key bundle does not exist, create new one */
385 /* Make type to key as char string */
386 snprintf(buf_key, sizeof(buf_key), "%d", type);
388 snprintf(buf_val, sizeof(buf_val), "%s", key);
390 /* Add new key value */
391 bundle_add(b, buf_key, buf_val);
393 /* Save key bundle */
397 /* Reset if key is NULL */
398 if (noti->b_key != NULL) {
399 /* If key bundle exist, store local bundle data */
402 /* Make type to key as char string */
403 snprintf(buf_key, sizeof(buf_key), "%d", type);
405 /* Get value using type key */
406 ret_val = bundle_get_val(b, buf_key);
407 if (ret_val != NULL) {
408 /* If value exist, remove this */
409 bundle_del(b, buf_key);
414 if (noti->b_format_args != NULL) {
415 b = noti->b_format_args;
420 va_start(var_args, args_type);
422 var_type = args_type;
425 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
427 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
428 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
430 ret_val = bundle_get_val(b, buf_key);
431 if (ret_val != NULL) {
432 bundle_del(b, buf_key);
435 bundle_add(b, buf_key, buf_val);
438 case NOTIFICATION_VARIABLE_TYPE_INT:
439 var_value_int = va_arg(var_args, int);
442 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
444 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
446 ret_val = bundle_get_val(b, buf_key);
447 if (ret_val != NULL) {
448 bundle_del(b, buf_key);
451 bundle_add(b, buf_key, buf_val);
453 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
454 var_value_double = va_arg(var_args, double);
457 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
459 snprintf(buf_val, sizeof(buf_val), "%.2f",
462 ret_val = bundle_get_val(b, buf_key);
463 if (ret_val != NULL) {
464 bundle_del(b, buf_key);
467 bundle_add(b, buf_key, buf_val);
469 case NOTIFICATION_VARIABLE_TYPE_STRING:
470 var_value_string = va_arg(var_args, char *);
473 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
475 snprintf(buf_val, sizeof(buf_val), "%s",
478 ret_val = bundle_get_val(b, buf_key);
479 if (ret_val != NULL) {
480 bundle_del(b, buf_key);
483 bundle_add(b, buf_key, buf_val);
485 case NOTIFICATION_VARIABLE_TYPE_COUNT:
487 va_arg(var_args, notification_count_pos_type_e);
490 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
492 snprintf(buf_val, sizeof(buf_val), "%d",
495 ret_val = bundle_get_val(b, buf_key);
496 if (ret_val != NULL) {
497 bundle_del(b, buf_key);
500 bundle_add(b, buf_key, buf_val);
503 NOTIFICATION_ERR("Error. invalid variable type. : %d",
505 noti_err = NOTIFICATION_ERROR_INVALID_DATA;
510 var_type = va_arg(var_args, notification_variable_type_e);
514 if (noti_err == NOTIFICATION_ERROR_NONE) {
515 noti->num_format_args = num_args;
517 noti->num_format_args = 0;
520 snprintf(buf_key, sizeof(buf_key), "num%d", type);
521 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
523 ret_val = bundle_get_val(b, buf_key);
524 if (ret_val != NULL) {
525 bundle_del(b, buf_key);
528 bundle_add(b, buf_key, buf_val);
530 noti->b_format_args = b;
535 EXPORT_API notification_error_e notification_get_text(notification_h noti,
536 notification_text_type_e type,
540 char buf_key[32] = { 0, };
541 const char *ret_val = NULL;
542 const char *get_str = NULL;
543 const char *get_check_type_str = NULL;
544 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
545 int display_option_flag = 0;
547 char *temp_str = NULL;
548 char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
549 char buf_str[1024] = { 0, };
551 notification_variable_type_e ret_var_type = 0;
552 int ret_variable_int = 0;
553 double ret_variable_double = 0.0;
555 /* Check noti is valid data */
556 if (noti == NULL || text == NULL) {
557 return NOTIFICATION_ERROR_INVALID_DATA;
560 /* Check text type is valid type */
561 if (type <= NOTIFICATION_TEXT_TYPE_NONE
562 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
563 return NOTIFICATION_ERROR_INVALID_DATA;
567 if (noti->b_key != NULL) {
570 /* Get text domain and dir */
571 _notification_get_text_domain(noti);
573 snprintf(buf_key, sizeof(buf_key), "%d", type);
575 ret_val = bundle_get_val(b, buf_key);
576 if (ret_val != NULL && noti->domain != NULL
577 && noti->dir != NULL) {
578 /* Get application string */
579 bindtextdomain(noti->domain, noti->dir);
581 get_str = dgettext(noti->domain, ret_val);
582 } else if (ret_val != NULL) {
583 /* Get system string */
584 get_str = dgettext("sys_string", ret_val);
590 if (get_str == NULL && noti->b_text != NULL) {
593 snprintf(buf_key, sizeof(buf_key), "%d", type);
595 get_str = bundle_get_val(b, buf_key);
600 /* Set display option is off type when option is off, type is noti */
601 if (get_str != NULL && display_option_flag == 1
602 && noti->type == NOTIFICATION_TYPE_NOTI) {
603 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
604 || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
605 /* Set check_type to option content string */
606 if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
608 NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
609 } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
611 NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
615 if (noti->b_key != NULL) {
618 /* Get text domain and dir */
619 _notification_get_text_domain(noti);
621 snprintf(buf_key, sizeof(buf_key), "%d",
624 ret_val = bundle_get_val(b, buf_key);
625 if (ret_val != NULL && noti->domain != NULL
626 && noti->dir != NULL) {
627 /* Get application string */
628 bindtextdomain(noti->domain, noti->dir);
631 dgettext(noti->domain, ret_val);
632 } else if (ret_val != NULL) {
633 /* Get system string */
635 dgettext("sys_string", ret_val);
637 get_check_type_str = NULL;
641 if (get_check_type_str == NULL && noti->b_text != NULL) {
644 snprintf(buf_key, sizeof(buf_key), "%d",
647 get_check_type_str = bundle_get_val(b, buf_key);
651 if (get_check_type_str != NULL) {
652 /* Replace option off type string */
653 get_str = get_check_type_str;
655 /* Set default string */
657 dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
661 if (get_str != NULL) {
662 /* Get number format args */
663 b = noti->b_format_args;
664 noti->num_format_args = 0;
667 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
668 ret_val = bundle_get_val(b, buf_key);
669 if (ret_val != NULL) {
670 noti->num_format_args = atoi(ret_val);
674 if (noti->num_format_args == 0) {
675 *text = (char *)get_str;
677 /* Check first variable is count, LEFT pos */
678 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
679 check_type, num_args);
680 ret_val = bundle_get_val(b, buf_key);
681 ret_var_type = atoi(ret_val);
683 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
685 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
686 check_type, num_args);
687 ret_val = bundle_get_val(b, buf_key);
688 ret_variable_int = atoi(ret_val);
690 if (ret_variable_int ==
691 NOTIFICATION_COUNT_POS_LEFT) {
692 notification_noti_get_count(noti->type,
693 noti->caller_pkgname,
697 snprintf(buf_str, sizeof(buf_str),
698 "%d ", ret_variable_int);
700 int src_len = strlen(result_str);
701 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
703 strncat(result_str, buf_str,
711 /* Check variable IN pos */
712 for (temp_str = (char *)get_str; *temp_str != '\0';
714 if (*temp_str != '%') {
715 strncat(result_str, temp_str, 1);
717 if (*(temp_str + 1) == '%') {
718 strncat(result_str, temp_str,
720 } else if (*(temp_str + 1) == 'd') {
722 ret_variable_int = 0;
726 "%dtype%d", check_type,
729 bundle_get_val(b, buf_key);
730 ret_var_type = atoi(ret_val);
732 NOTIFICATION_VARIABLE_TYPE_COUNT)
734 /* Get notification count */
735 notification_noti_get_count
737 noti->caller_pkgname,
757 sizeof(buf_str), "%d",
760 int src_len = strlen(result_str);
761 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
763 strncat(result_str, buf_str,
769 } else if (*(temp_str + 1) == 's') {
774 check_type, num_args);
776 bundle_get_val(b, buf_key);
779 sizeof(buf_str), "%s",
782 int src_len = strlen(result_str);
783 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
785 strncat(result_str, buf_str,
791 } else if (*(temp_str + 1) == 'f') {
796 check_type, num_args);
798 bundle_get_val(b, buf_key);
799 ret_variable_double =
805 ret_variable_double);
807 int src_len = strlen(result_str);
808 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
810 strncat(result_str, buf_str,
821 /* Check last variable is count, LEFT pos */
822 if (num_args < noti->num_format_args) {
823 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
824 check_type, num_args);
825 ret_val = bundle_get_val(b, buf_key);
826 ret_var_type = atoi(ret_val);
828 NOTIFICATION_VARIABLE_TYPE_COUNT) {
830 snprintf(buf_key, sizeof(buf_key),
831 "%dvalue%d", check_type,
833 ret_val = bundle_get_val(b, buf_key);
834 ret_variable_int = atoi(ret_val);
836 if (ret_variable_int ==
837 NOTIFICATION_COUNT_POS_RIGHT) {
838 notification_noti_get_count
840 noti->caller_pkgname,
845 sizeof(buf_str), " %d",
848 int src_len = strlen(result_str);
849 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
851 strncat(result_str, buf_str,
860 switch (check_type) {
861 case NOTIFICATION_TEXT_TYPE_TITLE:
862 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
863 if (noti->temp_title != NULL)
864 free(noti->temp_title);
866 noti->temp_title = strdup(result_str);
868 *text = noti->temp_title;
870 case NOTIFICATION_TEXT_TYPE_CONTENT:
871 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
872 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
873 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
874 if (noti->temp_content !=
876 free(noti->temp_content);
878 noti->temp_content = strdup(result_str);
880 *text = noti->temp_content;
892 return NOTIFICATION_ERROR_NONE;
895 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
899 /* check noti and domain is valid data */
900 if (noti == NULL || domain == NULL) {
901 return NOTIFICATION_ERROR_INVALID_DATA;
906 /* Remove previous domain */
910 noti->domain = strdup(domain);
912 /* Check locale dir */
914 /* Remove previous locale dir */
917 /* Copy locale dir */
918 noti->dir = strdup(dir);
920 return NOTIFICATION_ERROR_NONE;
923 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
927 /* Check noti is valid data */
929 return NOTIFICATION_ERROR_INVALID_DATA;
933 if (domain != NULL && noti->domain != NULL) {
934 *domain = noti->domain;
938 if (dir != NULL && noti->dir != NULL) {
942 return NOTIFICATION_ERROR_NONE;
945 EXPORT_API notification_error_e notification_set_time_to_text(notification_h noti, notification_text_type_e type,
948 notification_error_e ret = NOTIFICATION_ERROR_NONE;
949 char buf[256] = { 0, };
950 char buf_tag[512] = { 0, };
953 return NOTIFICATION_ERROR_INVALID_DATA;
956 return NOTIFICATION_ERROR_INVALID_DATA;
959 snprintf(buf, sizeof(buf), "%lu", time);
960 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
962 if (ret != NOTIFICATION_ERROR_NONE) {
966 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
969 EXPORT_API notification_error_e notification_get_time_from_text(notification_h noti, notification_text_type_e type,
972 notification_error_e ret = NOTIFICATION_ERROR_NONE;
975 return NOTIFICATION_ERROR_INVALID_DATA;
978 return NOTIFICATION_ERROR_INVALID_DATA;
981 char *ret_text = NULL;
982 ret = notification_get_text(noti, type, &ret_text);
984 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
985 return NOTIFICATION_ERROR_INVALID_DATA;
988 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
989 return NOTIFICATION_ERROR_INVALID_DATA;
992 char *tag_value = NULL;
993 tag_value = notification_noti_strip_tag(ret_text);
994 if (tag_value == NULL) {
995 return NOTIFICATION_ERROR_INVALID_DATA;
998 *time = atol(tag_value);
1001 return NOTIFICATION_ERROR_NONE;
1004 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1005 notification_sound_type_e type,
1008 /* Check noti is valid data */
1010 return NOTIFICATION_ERROR_INVALID_DATA;
1013 /* Check type is valid */
1014 if (type < NOTIFICATION_SOUND_TYPE_NONE
1015 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1016 return NOTIFICATION_ERROR_INVALID_DATA;
1019 /* Save sound type */
1020 noti->sound_type = type;
1022 /* Save sound path if user data type */
1023 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1024 if (noti->sound_path != NULL) {
1025 free(noti->sound_path);
1028 noti->sound_path = strdup(path);
1030 if (noti->sound_path != NULL) {
1031 free(noti->sound_path);
1032 noti->sound_path = NULL;
1036 return NOTIFICATION_ERROR_NONE;
1039 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1040 notification_sound_type_e *type,
1043 /* check noti and type is valid data */
1044 if (noti == NULL || type == NULL) {
1045 return NOTIFICATION_ERROR_INVALID_DATA;
1048 /* Set sound type */
1049 *type = noti->sound_type;
1051 /* Set sound path if user data type */
1052 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1054 *path = noti->sound_path;
1057 return NOTIFICATION_ERROR_NONE;
1060 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1061 notification_vibration_type_e type,
1064 /* Check noti is valid data */
1066 return NOTIFICATION_ERROR_INVALID_DATA;
1069 /* Check type is valid */
1070 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1071 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1072 return NOTIFICATION_ERROR_INVALID_DATA;
1075 /* Save vibration type */
1076 noti->vibration_type = type;
1078 /* Save sound path if user data type */
1079 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1080 if (noti->vibration_path != NULL) {
1081 free(noti->vibration_path);
1084 noti->vibration_path = strdup(path);
1086 if (noti->vibration_path != NULL) {
1087 free(noti->vibration_path);
1088 noti->vibration_path = NULL;
1092 return NOTIFICATION_ERROR_NONE;
1096 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1097 notification_vibration_type_e *type,
1100 /* check noti and type is valid data */
1101 if (noti == NULL || type == NULL) {
1102 return NOTIFICATION_ERROR_INVALID_DATA;
1105 /* Set vibration type */
1106 *type = noti->vibration_type;
1108 /* Set sound path if user data type */
1109 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1111 *path = noti->vibration_path;
1114 return NOTIFICATION_ERROR_NONE;
1117 EXPORT_API notification_error_e notification_set_led(notification_h noti,
1118 notification_led_op_e operation,
1121 /* Check noti is valid data */
1123 return NOTIFICATION_ERROR_INVALID_DATA;
1126 /* Check operation is valid */
1127 if (operation < NOTIFICATION_LED_OP_OFF
1128 || operation >= NOTIFICATION_LED_OP_MAX) {
1129 return NOTIFICATION_ERROR_INVALID_DATA;
1132 /* Save led operation */
1133 noti->led_operation = operation;
1135 /* Save led argb if operation is turning on LED with custom color */
1136 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1137 noti->led_argb = led_argb;
1140 return NOTIFICATION_ERROR_NONE;
1143 EXPORT_API notification_error_e notification_get_led(notification_h noti,
1144 notification_led_op_e *operation,
1147 /* check noti and operation is valid data */
1148 if (noti == NULL || operation == NULL) {
1149 return NOTIFICATION_ERROR_INVALID_DATA;
1152 /* Set led operation */
1153 *operation = noti->led_operation;
1155 /* Save led argb if operation is turning on LED with custom color */
1156 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1157 && led_argb != NULL) {
1158 *led_argb = noti->led_argb;
1161 return NOTIFICATION_ERROR_NONE;
1164 EXPORT_API notification_error_e notification_set_led_time_period(notification_h noti,
1165 int on_ms, int off_ms)
1167 /* Check noti is valid data */
1169 return NOTIFICATION_ERROR_INVALID_DATA;
1172 /* Save led operation */
1173 noti->led_on_ms = on_ms;
1174 noti->led_off_ms = off_ms;
1176 return NOTIFICATION_ERROR_NONE;
1179 EXPORT_API notification_error_e notification_get_led_time_period(notification_h noti,
1180 int *on_ms, int *off_ms)
1182 /* check noti and operation is valid data */
1184 return NOTIFICATION_ERROR_INVALID_DATA;
1188 *(on_ms) = noti->led_on_ms;
1190 *(off_ms) = noti->led_off_ms;
1192 return NOTIFICATION_ERROR_NONE;
1195 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1196 const char *pkgname)
1198 if (noti == NULL || pkgname == NULL) {
1199 return NOTIFICATION_ERROR_INVALID_DATA;
1202 if (noti->launch_pkgname) {
1203 free(noti->launch_pkgname);
1206 noti->launch_pkgname = strdup(pkgname);
1208 return NOTIFICATION_ERROR_NONE;
1211 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1214 if (noti == NULL || pkgname == NULL) {
1215 return NOTIFICATION_ERROR_INVALID_DATA;
1218 if (noti->launch_pkgname) {
1219 *pkgname = noti->launch_pkgname;
1221 *pkgname = noti->caller_pkgname;
1224 return NOTIFICATION_ERROR_NONE;
1227 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1228 notification_execute_type_e type,
1231 bundle *service_handle)
1233 char buf_key[32] = { 0, };
1234 const char *ret_val = NULL;
1238 return NOTIFICATION_ERROR_INVALID_DATA;
1241 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1242 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1243 return NOTIFICATION_ERROR_INVALID_DATA;
1246 /* Create execute option bundle if does not exist */
1247 if (noti->b_execute_option != NULL) {
1248 noti->b_execute_option = bundle_create();
1251 b = noti->b_execute_option;
1256 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1258 /* Check text key exist */
1259 ret_val = bundle_get_val(b, buf_key);
1260 if (ret_val != NULL) {
1261 /* Remove previous data */
1262 bundle_del(b, buf_key);
1266 bundle_add(b, buf_key, text);
1272 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1274 /* Check key key exist */
1275 ret_val = bundle_get_val(b, buf_key);
1276 if (ret_val != NULL) {
1277 /* Remove previous data */
1278 bundle_del(b, buf_key);
1282 bundle_add(b, buf_key, key);
1285 switch ((int)type) {
1286 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1287 /* Remove previous data if exist */
1288 if (noti->b_service_responding != NULL) {
1289 bundle_free(noti->b_service_responding);
1290 noti->b_service_responding = NULL;
1293 /* Save service handle */
1294 if (service_handle != NULL) {
1295 noti->b_service_responding = bundle_dup(service_handle);
1298 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1299 /* Remove previous data if exist */
1300 if (noti->b_service_single_launch != NULL) {
1301 bundle_free(noti->b_service_single_launch);
1302 noti->b_service_single_launch = NULL;
1305 /* Save service handle */
1306 if (service_handle != NULL) {
1307 noti->b_service_single_launch =
1308 bundle_dup(service_handle);
1311 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1312 /* Remove previous data if exist */
1313 if (noti->b_service_multi_launch != NULL) {
1314 bundle_free(noti->b_service_multi_launch);
1315 noti->b_service_multi_launch = NULL;
1318 /* Save service handle */
1319 if (service_handle != NULL) {
1320 noti->b_service_multi_launch =
1321 bundle_dup(service_handle);
1326 return NOTIFICATION_ERROR_NONE;
1329 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1330 notification_execute_type_e type,
1332 bundle **service_handle)
1334 char buf_key[32] = { 0, };
1335 const char *ret_val = NULL;
1336 char *get_str = NULL;
1340 return NOTIFICATION_ERROR_INVALID_DATA;
1343 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1344 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1345 return NOTIFICATION_ERROR_INVALID_DATA;
1349 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1350 b = noti->b_service_responding;
1352 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1353 b = noti->b_service_single_launch;
1355 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1356 b = noti->b_service_multi_launch;
1366 // Get text domain and dir
1367 if (noti->domain == NULL || noti->dir == NULL) {
1368 _notification_get_text_domain(noti);
1372 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1374 /* Check key key exist */
1375 ret_val = bundle_get_val(b, buf_key);
1376 if (ret_val != NULL && noti->domain != NULL
1377 && noti->dir != NULL) {
1378 /* Get application string */
1379 bindtextdomain(noti->domain, noti->dir);
1381 get_str = dgettext(noti->domain, ret_val);
1384 } else if (ret_val != NULL) {
1385 /* Get system string */
1386 get_str = dgettext("sys_string", ret_val);
1390 /* Get basic text */
1391 snprintf(buf_key, sizeof(buf_key), "text%d",
1394 ret_val = bundle_get_val(b, buf_key);
1402 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1403 b = noti->b_service_responding;
1405 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1406 b = noti->b_service_single_launch;
1408 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1409 b = noti->b_service_multi_launch;
1416 if (service_handle != NULL) {
1417 *service_handle = b;
1420 return NOTIFICATION_ERROR_NONE;
1423 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1426 /* Check noti is valid data */
1428 return NOTIFICATION_ERROR_INVALID_DATA;
1432 noti->flags_for_property = flags;
1434 return NOTIFICATION_ERROR_NONE;
1437 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1440 /* Check noti and flags are valid data */
1441 if (noti == NULL || flags == NULL) {
1442 return NOTIFICATION_ERROR_INVALID_DATA;
1446 *flags = noti->flags_for_property;
1448 return NOTIFICATION_ERROR_NONE;
1451 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1454 /* Check noti is valid data */
1456 return NOTIFICATION_ERROR_INVALID_DATA;
1460 noti->display_applist = applist;
1462 return NOTIFICATION_ERROR_NONE;
1465 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1468 /* Check noti and applist are valid data */
1469 if (noti == NULL || applist == NULL) {
1470 return NOTIFICATION_ERROR_INVALID_DATA;
1474 *applist = noti->display_applist;
1476 return NOTIFICATION_ERROR_NONE;
1479 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1482 /* Check noti is valid data */
1484 return NOTIFICATION_ERROR_INVALID_DATA;
1487 /* Save progress size */
1488 noti->progress_size = size;
1490 return NOTIFICATION_ERROR_NONE;
1493 EXPORT_API notification_error_e notification_get_size(notification_h noti,
1496 /* Check noti and size is valid data */
1497 if (noti == NULL || size == NULL) {
1498 return NOTIFICATION_ERROR_INVALID_DATA;
1501 /* Set progress size */
1502 *size = noti->progress_size;
1504 return NOTIFICATION_ERROR_NONE;
1507 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
1510 /* Check noti is valid data */
1512 return NOTIFICATION_ERROR_INVALID_DATA;
1515 /* Save progress percentage */
1516 noti->progress_percentage = percentage;
1518 return NOTIFICATION_ERROR_NONE;
1521 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
1524 /* Check noti and percentage are valid data */
1525 if (noti == NULL || percentage == NULL) {
1526 return NOTIFICATION_ERROR_INVALID_DATA;
1529 /* Set progress percentage */
1530 *percentage = noti->progress_percentage;
1532 return NOTIFICATION_ERROR_NONE;
1535 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
1536 const char *pkgname)
1538 /* check noti and pkgname are valid data */
1539 if (noti == NULL || pkgname == NULL) {
1540 return NOTIFICATION_ERROR_INVALID_DATA;
1543 /* Remove previous caller pkgname */
1544 if (noti->caller_pkgname) {
1545 free(noti->caller_pkgname);
1546 noti->caller_pkgname = NULL;
1549 noti->caller_pkgname = strdup(pkgname);
1551 return NOTIFICATION_ERROR_NONE;
1554 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
1557 /* Check noti and pkgname are valid data */
1558 if (noti == NULL || pkgname == NULL) {
1559 return NOTIFICATION_ERROR_INVALID_DATA;
1562 /* Get caller pkgname */
1563 if (noti->caller_pkgname) {
1564 *pkgname = noti->caller_pkgname;
1569 return NOTIFICATION_ERROR_NONE;
1572 EXPORT_API notification_error_e notification_set_layout(notification_h noti,
1573 notification_ly_type_e layout)
1575 /* check noti and pkgname are valid data */
1576 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1577 return NOTIFICATION_ERROR_INVALID_DATA;
1580 noti->layout = layout;
1582 return NOTIFICATION_ERROR_NONE;
1585 EXPORT_API notification_error_e notification_get_layout(notification_h noti,
1586 notification_ly_type_e *layout)
1588 /* Check noti and pkgname are valid data */
1589 if (noti == NULL || layout == NULL) {
1590 return NOTIFICATION_ERROR_INVALID_DATA;
1593 *layout = noti->layout;
1595 return NOTIFICATION_ERROR_NONE;
1598 EXPORT_API notification_error_e notification_get_id(notification_h noti,
1599 int *group_id, int *priv_id)
1601 /* check noti is valid data */
1603 return NOTIFICATION_ERROR_INVALID_DATA;
1606 /* Check group_id is valid data */
1609 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1610 *group_id = NOTIFICATION_GROUP_ID_NONE;
1612 *group_id = noti->group_id;
1616 /* Check priv_id is valid data */
1619 *priv_id = noti->priv_id;
1622 return NOTIFICATION_ERROR_NONE;
1625 EXPORT_API notification_error_e notification_get_type(notification_h noti,
1626 notification_type_e *type)
1628 /* Check noti and type is valid data */
1629 if (noti == NULL || type == NULL) {
1630 return NOTIFICATION_ERROR_INVALID_DATA;
1636 return NOTIFICATION_ERROR_NONE;
1639 EXPORT_API notification_error_e notification_insert(notification_h noti,
1645 /* Check noti is vaild data */
1647 return NOTIFICATION_ERROR_INVALID_DATA;
1650 /* Check noti type is valid type */
1651 if (noti->type <= NOTIFICATION_TYPE_NONE
1652 || noti->type >= NOTIFICATION_TYPE_MAX) {
1653 return NOTIFICATION_ERROR_INVALID_DATA;
1656 /* Save insert time */
1657 noti->insert_time = time(NULL);
1658 ret = notification_ipc_request_insert(noti, &id);
1659 if (ret != NOTIFICATION_ERROR_NONE) {
1663 NOTIFICATION_DBG("from master:%d", id);
1665 /* If priv_id is valid data, set priv_id */
1666 if (priv_id != NULL) {
1667 *priv_id = noti->priv_id;
1670 return NOTIFICATION_ERROR_NONE;
1673 EXPORT_API notification_error_e notification_update(notification_h noti)
1677 /* Check noti is valid data */
1679 /* Update insert time ? */
1680 noti->insert_time = time(NULL);
1681 ret = notification_ipc_request_update(noti);
1682 if (ret != NOTIFICATION_ERROR_NONE) {
1686 ret = notification_ipc_request_refresh();
1687 if (ret != NOTIFICATION_ERROR_NONE) {
1691 return NOTIFICATION_ERROR_NONE;
1694 EXPORT_API notification_error_e notification_update_async(notification_h noti,
1695 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1699 /* Check noti is valid data */
1701 /* Update insert time ? */
1702 noti->insert_time = time(NULL);
1703 ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1704 if (ret != NOTIFICATION_ERROR_NONE) {
1708 return NOTIFICATION_ERROR_NONE;
1711 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
1715 ret = notification_ipc_request_delete_multiple(type, NULL);
1716 if (ret != NOTIFICATION_ERROR_NONE) {
1720 return NOTIFICATION_ERROR_NONE;
1723 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
1724 notification_type_e type)
1727 char *caller_pkgname = NULL;
1729 if (pkgname == NULL) {
1730 caller_pkgname = _notification_get_pkgname_by_pid();
1732 caller_pkgname = strdup(pkgname);
1735 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1736 if (ret != NOTIFICATION_ERROR_NONE) {
1737 if (caller_pkgname) {
1738 free(caller_pkgname);
1743 if (caller_pkgname) {
1744 free(caller_pkgname);
1746 return NOTIFICATION_ERROR_NONE;
1749 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
1750 notification_type_e type,
1754 char *caller_pkgname = NULL;
1756 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1757 return NOTIFICATION_ERROR_INVALID_DATA;
1760 if (pkgname == NULL) {
1761 caller_pkgname = _notification_get_pkgname_by_pid();
1763 caller_pkgname = strdup(pkgname);
1766 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
1767 if (ret != NOTIFICATION_ERROR_NONE) {
1768 if (caller_pkgname) {
1769 free(caller_pkgname);
1774 if (caller_pkgname) {
1775 free(caller_pkgname);
1780 EXPORT_API notification_error_e notification_delete(notification_h noti)
1785 return NOTIFICATION_ERROR_INVALID_DATA;
1788 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1789 if (ret != NOTIFICATION_ERROR_NONE) {
1793 return NOTIFICATION_ERROR_NONE;
1796 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
1800 char *caller_pkgname = NULL;
1801 int input_priv_id = 0;
1802 double input_progress = 0.0;
1804 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1806 return NOTIFICATION_ERROR_INVALID_DATA;
1808 input_priv_id = noti->priv_id;
1811 input_priv_id = priv_id;
1815 caller_pkgname = _notification_get_pkgname_by_pid();
1817 caller_pkgname = strdup(noti->caller_pkgname);
1820 if (progress < 0.0) {
1821 input_progress = 0.0;
1822 } else if (progress > 1.0) {
1823 input_progress = 1.0;
1825 input_progress = progress;
1828 notification_ongoing_update_progress(caller_pkgname, input_priv_id,
1831 if (caller_pkgname) {
1832 free(caller_pkgname);
1835 return NOTIFICATION_ERROR_NONE;
1838 EXPORT_API notification_error_e notification_update_size(notification_h noti,
1842 char *caller_pkgname = NULL;
1843 int input_priv_id = 0;
1844 double input_size = 0.0;
1846 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1848 return NOTIFICATION_ERROR_INVALID_DATA;
1850 input_priv_id = noti->priv_id;
1853 input_priv_id = priv_id;
1857 caller_pkgname = _notification_get_pkgname_by_pid();
1859 caller_pkgname = strdup(noti->caller_pkgname);
1868 notification_ongoing_update_size(caller_pkgname, input_priv_id,
1871 if (caller_pkgname) {
1872 free(caller_pkgname);
1875 return NOTIFICATION_ERROR_NONE;
1878 EXPORT_API notification_error_e notification_update_content(notification_h noti,
1880 const char *content)
1882 char *caller_pkgname = NULL;
1883 int input_priv_id = 0;
1885 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1887 return NOTIFICATION_ERROR_INVALID_DATA;
1889 input_priv_id = noti->priv_id;
1892 input_priv_id = priv_id;
1896 caller_pkgname = _notification_get_pkgname_by_pid();
1898 caller_pkgname = strdup(noti->caller_pkgname);
1901 notification_ongoing_update_content(caller_pkgname, input_priv_id,
1904 if (caller_pkgname) {
1905 free(caller_pkgname);
1908 return NOTIFICATION_ERROR_NONE;
1911 static notification_h _notification_create(notification_type_e type)
1913 notification_h noti = NULL;
1915 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1916 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1920 noti = (notification_h) calloc(1, sizeof(struct _notification));
1922 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1928 if (type == NOTIFICATION_TYPE_NOTI)
1929 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1930 else if (type == NOTIFICATION_TYPE_ONGOING)
1931 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1933 noti->caller_pkgname = _notification_get_pkgname_by_pid();
1934 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1935 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1936 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1937 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1938 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1939 noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
1942 * Other fields are already initialized with ZERO.
1947 EXPORT_API notification_h notification_new(notification_type_e type,
1948 int group_id, int priv_id)
1950 return _notification_create(type);
1953 EXPORT_API notification_h notification_create(notification_type_e type)
1955 return _notification_create(type);
1958 EXPORT_API notification_h notification_load(char *pkgname,
1962 notification_h noti = NULL;
1964 noti = (notification_h) calloc(1, sizeof(struct _notification));
1966 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1970 ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id);
1971 if (ret != NOTIFICATION_ERROR_NONE) {
1972 notification_free(noti);
1979 EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone)
1981 notification_h new_noti = NULL;
1983 if (noti == NULL || clone == NULL) {
1984 NOTIFICATION_ERR("INVALID PARAMETER.");
1985 return NOTIFICATION_ERROR_INVALID_DATA;
1988 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1989 if (new_noti == NULL) {
1990 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1991 return NOTIFICATION_ERROR_NO_MEMORY;
1994 new_noti->type = noti->type;
1995 new_noti->layout = noti->layout;
1997 new_noti->group_id = noti->group_id;
1998 new_noti->internal_group_id = noti->internal_group_id;
1999 new_noti->priv_id = noti->priv_id;
2001 if(noti->caller_pkgname != NULL) {
2002 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2004 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2006 if(noti->launch_pkgname != NULL) {
2007 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2009 new_noti->launch_pkgname = NULL;
2012 if(noti->args != NULL) {
2013 new_noti->args = bundle_dup(noti->args);
2015 new_noti->args = NULL;
2017 if(noti->group_args != NULL) {
2018 new_noti->group_args = bundle_dup(noti->group_args);
2020 new_noti->group_args = NULL;
2023 if(noti->b_execute_option != NULL) {
2024 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2026 new_noti->b_execute_option = NULL;
2028 if(noti->b_service_responding != NULL) {
2029 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2031 new_noti->b_service_responding = NULL;
2033 if(noti->b_service_single_launch != NULL) {
2034 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2036 new_noti->b_service_single_launch = NULL;
2038 if(noti->b_service_multi_launch != NULL) {
2039 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2041 new_noti->b_service_multi_launch = NULL;
2044 new_noti->sound_type = noti->sound_type;
2045 if(noti->sound_path != NULL) {
2046 new_noti->sound_path = strdup(noti->sound_path);
2048 new_noti->sound_path = NULL;
2050 new_noti->vibration_type = noti->vibration_type;
2051 if(noti->vibration_path != NULL) {
2052 new_noti->vibration_path = strdup(noti->vibration_path);
2054 new_noti->vibration_path = NULL;
2056 new_noti->led_operation = noti->led_operation;
2057 new_noti->led_argb = noti->led_argb;
2058 new_noti->led_on_ms = noti->led_on_ms;
2059 new_noti->led_off_ms = noti->led_off_ms;
2061 if(noti->domain != NULL) {
2062 new_noti->domain = strdup(noti->domain);
2064 new_noti->domain = NULL;
2066 if(noti->dir != NULL) {
2067 new_noti->dir = strdup(noti->dir);
2069 new_noti->dir = NULL;
2072 if(noti->b_text != NULL) {
2073 new_noti->b_text = bundle_dup(noti->b_text);
2075 new_noti->b_text = NULL;
2077 if(noti->b_key != NULL) {
2078 new_noti->b_key = bundle_dup(noti->b_key);
2080 new_noti->b_key = NULL;
2082 if(noti->b_format_args != NULL) {
2083 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2085 new_noti->b_format_args = NULL;
2087 new_noti->num_format_args = noti->num_format_args;
2089 if(noti->b_image_path != NULL) {
2090 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2092 new_noti->b_image_path = NULL;
2095 new_noti->time = noti->time;
2096 new_noti->insert_time = noti->insert_time;
2098 new_noti->flags_for_property = noti->flags_for_property;
2099 new_noti->display_applist = noti->display_applist;
2101 new_noti->progress_size = noti->progress_size;
2102 new_noti->progress_percentage = noti->progress_percentage;
2104 new_noti->app_icon_path = NULL;
2105 new_noti->app_name = NULL;
2106 new_noti->temp_title = NULL;
2107 new_noti->temp_content = NULL;
2111 return NOTIFICATION_ERROR_NONE;
2115 EXPORT_API notification_error_e notification_free(notification_h noti)
2118 return NOTIFICATION_ERROR_INVALID_DATA;
2121 if (noti->caller_pkgname) {
2122 free(noti->caller_pkgname);
2124 if (noti->launch_pkgname) {
2125 free(noti->launch_pkgname);
2128 bundle_free(noti->args);
2130 if (noti->group_args) {
2131 bundle_free(noti->group_args);
2134 if (noti->b_execute_option) {
2135 bundle_free(noti->b_execute_option);
2137 if (noti->b_service_responding) {
2138 bundle_free(noti->b_service_responding);
2140 if (noti->b_service_single_launch) {
2141 bundle_free(noti->b_service_single_launch);
2143 if (noti->b_service_multi_launch) {
2144 bundle_free(noti->b_service_multi_launch);
2147 if (noti->sound_path) {
2148 free(noti->sound_path);
2150 if (noti->vibration_path) {
2151 free(noti->vibration_path);
2162 bundle_free(noti->b_text);
2165 bundle_free(noti->b_key);
2167 if (noti->b_format_args) {
2168 bundle_free(noti->b_format_args);
2171 if (noti->b_image_path) {
2172 bundle_free(noti->b_image_path);
2175 if (noti->app_icon_path) {
2176 free(noti->app_icon_path);
2178 if (noti->app_name) {
2179 free(noti->app_name);
2181 if (noti->temp_title) {
2182 free(noti->temp_title);
2184 if (noti->temp_content) {
2185 free(noti->temp_content);
2190 return NOTIFICATION_ERROR_NONE;
2193 EXPORT_API notification_error_e
2194 notification_resister_changed_cb(void (*changed_cb)
2195 (void *data, notification_type_e type),
2198 notification_cb_list_s *noti_cb_list_new = NULL;
2199 notification_cb_list_s *noti_cb_list = NULL;
2201 if (changed_cb == NULL) {
2202 return NOTIFICATION_ERROR_INVALID_DATA;
2204 if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2205 return NOTIFICATION_ERROR_IO;
2209 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2211 noti_cb_list_new->next = NULL;
2212 noti_cb_list_new->prev = NULL;
2214 noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
2215 noti_cb_list_new->changed_cb = changed_cb;
2216 noti_cb_list_new->detailed_changed_cb = NULL;
2217 noti_cb_list_new->data = user_data;
2219 if (g_notification_cb_list == NULL) {
2220 g_notification_cb_list = noti_cb_list_new;
2222 noti_cb_list = g_notification_cb_list;
2224 while (noti_cb_list->next != NULL) {
2225 noti_cb_list = noti_cb_list->next;
2228 noti_cb_list->next = noti_cb_list_new;
2229 noti_cb_list_new->prev = noti_cb_list;
2231 return NOTIFICATION_ERROR_NONE;
2234 EXPORT_API notification_error_e
2235 notification_unresister_changed_cb(void (*changed_cb)
2236 (void *data, notification_type_e type))
2238 notification_cb_list_s *noti_cb_list = NULL;
2239 notification_cb_list_s *noti_cb_list_prev = NULL;
2240 notification_cb_list_s *noti_cb_list_next = NULL;
2242 noti_cb_list = g_notification_cb_list;
2244 if (changed_cb == NULL) {
2245 return NOTIFICATION_ERROR_INVALID_DATA;
2247 if (noti_cb_list == NULL) {
2248 return NOTIFICATION_ERROR_INVALID_DATA;
2251 while (noti_cb_list->prev != NULL) {
2252 noti_cb_list = noti_cb_list->prev;
2256 if (noti_cb_list->changed_cb == changed_cb) {
2257 noti_cb_list_prev = noti_cb_list->prev;
2258 noti_cb_list_next = noti_cb_list->next;
2260 if (noti_cb_list_prev == NULL) {
2261 g_notification_cb_list = noti_cb_list_next;
2263 noti_cb_list_prev->next = noti_cb_list_next;
2266 if (noti_cb_list_next == NULL) {
2267 if (noti_cb_list_prev != NULL) {
2268 noti_cb_list_prev->next = NULL;
2271 noti_cb_list_next->prev = noti_cb_list_prev;
2276 if (g_notification_cb_list == NULL)
2277 notification_ipc_monitor_fini();
2279 return NOTIFICATION_ERROR_NONE;
2281 noti_cb_list = noti_cb_list->next;
2282 } while (noti_cb_list != NULL);
2284 return NOTIFICATION_ERROR_INVALID_DATA;
2287 EXPORT_API notification_error_e
2288 notification_register_detailed_changed_cb(
2289 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2292 notification_cb_list_s *noti_cb_list_new = NULL;
2293 notification_cb_list_s *noti_cb_list = NULL;
2295 if (detailed_changed_cb == NULL) {
2296 return NOTIFICATION_ERROR_INVALID_DATA;
2298 if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2299 return NOTIFICATION_ERROR_IO;
2303 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2305 noti_cb_list_new->next = NULL;
2306 noti_cb_list_new->prev = NULL;
2308 noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
2309 noti_cb_list_new->changed_cb = NULL;
2310 noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
2311 noti_cb_list_new->data = user_data;
2313 if (g_notification_cb_list == NULL) {
2314 g_notification_cb_list = noti_cb_list_new;
2316 noti_cb_list = g_notification_cb_list;
2318 while (noti_cb_list->next != NULL) {
2319 noti_cb_list = noti_cb_list->next;
2322 noti_cb_list->next = noti_cb_list_new;
2323 noti_cb_list_new->prev = noti_cb_list;
2325 return NOTIFICATION_ERROR_NONE;
2328 EXPORT_API notification_error_e
2329 notification_unregister_detailed_changed_cb(
2330 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2333 notification_cb_list_s *noti_cb_list = NULL;
2334 notification_cb_list_s *noti_cb_list_prev = NULL;
2335 notification_cb_list_s *noti_cb_list_next = NULL;
2337 noti_cb_list = g_notification_cb_list;
2339 if (detailed_changed_cb == NULL) {
2340 return NOTIFICATION_ERROR_INVALID_DATA;
2342 if (noti_cb_list == NULL) {
2343 return NOTIFICATION_ERROR_INVALID_DATA;
2346 while (noti_cb_list->prev != NULL) {
2347 noti_cb_list = noti_cb_list->prev;
2351 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
2352 noti_cb_list_prev = noti_cb_list->prev;
2353 noti_cb_list_next = noti_cb_list->next;
2355 if (noti_cb_list_prev == NULL) {
2356 g_notification_cb_list = noti_cb_list_next;
2358 noti_cb_list_prev->next = noti_cb_list_next;
2361 if (noti_cb_list_next == NULL) {
2362 if (noti_cb_list_prev != NULL) {
2363 noti_cb_list_prev->next = NULL;
2366 noti_cb_list_next->prev = noti_cb_list_prev;
2371 if (g_notification_cb_list == NULL)
2372 notification_ipc_monitor_fini();
2374 return NOTIFICATION_ERROR_NONE;
2376 noti_cb_list = noti_cb_list->next;
2377 } while (noti_cb_list != NULL);
2379 return NOTIFICATION_ERROR_INVALID_DATA;
2382 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
2383 const char *pkgname,
2385 int priv_id, int *count)
2390 if (count == NULL) {
2391 return NOTIFICATION_ERROR_INVALID_DATA;
2395 notification_noti_get_count(type, pkgname, group_id, priv_id,
2397 if (ret != NOTIFICATION_ERROR_NONE) {
2401 *count = noti_count;
2403 return NOTIFICATION_ERROR_NONE;
2406 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
2408 notification_list_h *list)
2410 notification_list_h get_list = NULL;
2414 return NOTIFICATION_ERROR_INVALID_DATA;
2417 ret = notification_noti_get_grouping_list(type, count, &get_list);
2418 if (ret != NOTIFICATION_ERROR_NONE) {
2424 return NOTIFICATION_ERROR_NONE;
2427 EXPORT_API notification_error_e
2428 notification_get_grouping_list(notification_type_e type, int count,
2429 notification_list_h * list)
2431 notification_list_h get_list = NULL;
2435 return NOTIFICATION_ERROR_INVALID_DATA;
2438 ret = notification_noti_get_grouping_list(type, count, &get_list);
2439 if (ret != NOTIFICATION_ERROR_NONE) {
2445 return NOTIFICATION_ERROR_NONE;
2448 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
2452 notification_list_h *list)
2454 notification_list_h get_list = NULL;
2458 return NOTIFICATION_ERROR_INVALID_DATA;
2462 notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2464 if (ret != NOTIFICATION_ERROR_NONE) {
2470 return NOTIFICATION_ERROR_NONE;
2473 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
2475 notification_list_h cur_list = NULL;
2476 notification_h noti = NULL;
2479 return NOTIFICATION_ERROR_INVALID_DATA;
2482 cur_list = notification_list_get_head(list);
2484 while (cur_list != NULL) {
2485 noti = notification_list_get_data(cur_list);
2486 cur_list = notification_list_remove(cur_list, noti);
2488 notification_free(noti);
2491 return NOTIFICATION_ERROR_NONE;
2494 EXPORT_API notification_error_e notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
2497 if (noti_op == NULL || data == NULL) {
2498 return NOTIFICATION_ERROR_INVALID_DATA;
2502 case NOTIFICATION_OP_DATA_TYPE:
2503 *((int*)data) = noti_op->type;
2505 case NOTIFICATION_OP_DATA_PRIV_ID:
2506 *((int*)data) = noti_op->priv_id;
2508 case NOTIFICATION_OP_DATA_NOTI:
2509 *((notification_h *)data) = noti_op->noti;
2511 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
2512 *((int*)data) = noti_op->extra_info_1;
2514 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
2515 *((int*)data) = noti_op->extra_info_2;
2518 return NOTIFICATION_ERROR_INVALID_DATA;
2522 return NOTIFICATION_ERROR_NONE;
2525 void notification_call_changed_cb(notification_op *op_list, int op_num)
2527 notification_cb_list_s *noti_cb_list = NULL;
2530 if (g_notification_cb_list == NULL) {
2533 noti_cb_list = g_notification_cb_list;
2535 while (noti_cb_list->prev != NULL) {
2536 noti_cb_list = noti_cb_list->prev;
2539 if (op_list == NULL) {
2540 NOTIFICATION_ERR("invalid data");
2544 while (noti_cb_list != NULL) {
2545 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
2546 noti_cb_list->changed_cb(noti_cb_list->data,
2547 NOTIFICATION_TYPE_NOTI);
2549 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
2550 noti_cb_list->detailed_changed_cb(noti_cb_list->data,
2551 NOTIFICATION_TYPE_NOTI, op_list, op_num);
2554 noti_cb_list = noti_cb_list->next;
2558 EXPORT_API int notification_is_service_ready(void)
2560 return notification_ipc_is_master_ready();
2563 EXPORT_API notification_error_e
2564 notification_add_deffered_task(
2565 void (*deffered_task_cb)(void *data), void *user_data)
2567 if (deffered_task_cb == NULL) {
2568 return NOTIFICATION_ERROR_INVALID_DATA;
2571 return notification_ipc_add_deffered_task(deffered_task_cb, user_data);
2574 EXPORT_API notification_error_e
2575 notification_del_deffered_task(
2576 void (*deffered_task_cb)(void *data))
2578 if (deffered_task_cb == NULL) {
2579 return NOTIFICATION_ERROR_INVALID_DATA;
2582 return notification_ipc_del_deffered_task(deffered_task_cb);
2585 /* notification_set_icon will be removed */
2586 EXPORT_API notification_error_e notification_set_icon(notification_h noti,
2587 const char *icon_path)
2589 int ret_err = NOTIFICATION_ERROR_NONE;
2592 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2598 /* notification_get_icon will be removed */
2599 EXPORT_API notification_error_e notification_get_icon(notification_h noti,
2602 int ret_err = NOTIFICATION_ERROR_NONE;
2603 char *ret_image_path = NULL;
2606 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2609 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
2610 *icon_path = ret_image_path;
2612 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
2618 EXPORT_API notification_error_e notification_set_title(notification_h noti,
2620 const char *loc_title)
2622 int noti_err = NOTIFICATION_ERROR_NONE;
2624 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2626 NOTIFICATION_VARIABLE_TYPE_NONE);
2631 EXPORT_API notification_error_e notification_get_title(notification_h noti,
2635 int noti_err = NOTIFICATION_ERROR_NONE;
2636 char *ret_text = NULL;
2639 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2642 if (title != NULL) {
2646 if (loc_title != NULL) {
2653 EXPORT_API notification_error_e notification_set_content(notification_h noti,
2654 const char *content,
2655 const char *loc_content)
2657 int noti_err = NOTIFICATION_ERROR_NONE;
2659 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2660 content, loc_content,
2661 NOTIFICATION_VARIABLE_TYPE_NONE);
2666 EXPORT_API notification_error_e notification_get_content(notification_h noti,
2670 int noti_err = NOTIFICATION_ERROR_NONE;
2671 char *ret_text = NULL;
2674 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2677 if (content != NULL) {
2678 *content = ret_text;
2681 if (loc_content != NULL) {
2682 *loc_content = NULL;
2690 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
2692 if (ret == -1 || boolval == 0) {
2693 if (content != NULL && noti->default_content != NULL) {
2694 *content = noti->default_content;
2697 if (loc_content != NULL && noti->loc_default_content != NULL) {
2698 *loc_content = noti->loc_default_content;
2704 EXPORT_API notification_error_e notification_set_args(notification_h noti,
2706 bundle * group_args)
2708 if (noti == NULL || args == NULL) {
2709 return NOTIFICATION_ERROR_INVALID_DATA;
2713 bundle_free(noti->args);
2716 noti->args = bundle_dup(args);
2718 if (noti->group_args) {
2719 bundle_free(noti->group_args);
2720 noti->group_args = NULL;
2723 if (group_args != NULL) {
2724 noti->group_args = bundle_dup(group_args);
2727 return NOTIFICATION_ERROR_NONE;
2730 EXPORT_API notification_error_e notification_get_args(notification_h noti,
2732 bundle ** group_args)
2734 if (noti == NULL || args == NULL) {
2735 return NOTIFICATION_ERROR_INVALID_DATA;
2744 if (group_args != NULL && noti->group_args) {
2745 *group_args = noti->group_args;
2748 return NOTIFICATION_ERROR_NONE;
2751 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
2752 notification_type_e type,
2756 char *caller_pkgname = NULL;
2758 if (pkgname == NULL) {
2759 caller_pkgname = _notification_get_pkgname_by_pid();
2761 caller_pkgname = strdup(pkgname);
2764 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
2765 if (ret != NOTIFICATION_ERROR_NONE) {
2766 if (caller_pkgname) {
2767 free(caller_pkgname);
2772 if (caller_pkgname) {
2773 free(caller_pkgname);
2775 return NOTIFICATION_ERROR_NONE;
2778 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2779 notification_type_e type,
2783 char *caller_pkgname = NULL;
2785 if (pkgname == NULL) {
2786 caller_pkgname = _notification_get_pkgname_by_pid();
2788 caller_pkgname = strdup(pkgname);
2791 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
2792 if (ret != NOTIFICATION_ERROR_NONE) {
2793 if (caller_pkgname) {
2794 free(caller_pkgname);
2799 if (caller_pkgname) {
2800 free(caller_pkgname);
2802 return NOTIFICATION_ERROR_NONE;