2 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <dbus/dbus.h>
24 #include <dbus/dbus-glib-lowlevel.h>
27 #include <app_control_internal.h>
31 #include <vconf-keys.h>
34 #include <notification.h>
35 #include <notification_list.h>
36 #include <notification_debug.h>
37 #include <notification_private.h>
38 #include <notification_noti.h>
39 #include <notification_ongoing.h>
40 #include <notification_group.h>
41 #include <notification_ipc.h>
42 #include <notification_internal.h>
44 typedef struct _notification_cb_list notification_cb_list_s;
46 typedef enum __notification_cb_type {
47 NOTIFICATION_CB_NORMAL = 1,
48 NOTIFICATION_CB_DETAILED,
49 } _notification_cb_type_e;
51 struct _notification_cb_list {
52 notification_cb_list_s *prev;
53 notification_cb_list_s *next;
55 _notification_cb_type_e cb_type;
56 void (*changed_cb) (void *data, notification_type_e type);
57 void (*detailed_changed_cb) (void *data, notification_type_e type, notification_op *op_list, int num_op);
61 static notification_cb_list_s *g_notification_cb_list = NULL;
63 void notification_call_changed_cb(notification_op *op_list, int op_num)
65 notification_cb_list_s *noti_cb_list = NULL;
66 notification_type_e type = 0;
68 if (g_notification_cb_list == NULL)
71 noti_cb_list = g_notification_cb_list;
73 while (noti_cb_list->prev != NULL)
74 noti_cb_list = noti_cb_list->prev;
77 if (op_list == NULL) {
78 NOTIFICATION_ERR("invalid data");
82 notification_get_type(op_list->noti, &type);
84 while (noti_cb_list != NULL) {
85 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
86 noti_cb_list->changed_cb(noti_cb_list->data,
89 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
90 noti_cb_list->detailed_changed_cb(noti_cb_list->data,
91 type, op_list, op_num);
94 noti_cb_list = noti_cb_list->next;
98 EXPORT_API int notification_add_deferred_task(
99 void (*deferred_task_cb)(void *data), void *user_data)
101 if (deferred_task_cb == NULL)
102 return NOTIFICATION_ERROR_INVALID_PARAMETER;
104 return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
107 EXPORT_API int notification_del_deferred_task(
108 void (*deferred_task_cb)(void *data))
110 if (deferred_task_cb == NULL)
111 return NOTIFICATION_ERROR_INVALID_PARAMETER;
113 return notification_ipc_del_deffered_task(deferred_task_cb);
117 EXPORT_API int notification_resister_changed_cb_for_uid(
118 void (*changed_cb)(void *data, notification_type_e type),
119 void *user_data, uid_t uid)
121 notification_cb_list_s *noti_cb_list_new = NULL;
122 notification_cb_list_s *noti_cb_list = NULL;
124 if (changed_cb == NULL)
125 return NOTIFICATION_ERROR_INVALID_PARAMETER;
128 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
130 if (noti_cb_list_new == NULL) {
131 NOTIFICATION_ERR("malloc failed");
132 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
135 noti_cb_list_new->next = NULL;
136 noti_cb_list_new->prev = NULL;
138 noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
139 noti_cb_list_new->changed_cb = changed_cb;
140 noti_cb_list_new->detailed_changed_cb = NULL;
141 noti_cb_list_new->data = user_data;
143 if (g_notification_cb_list == NULL) {
144 g_notification_cb_list = noti_cb_list_new;
146 noti_cb_list = g_notification_cb_list;
148 while (noti_cb_list->next != NULL)
149 noti_cb_list = noti_cb_list->next;
152 noti_cb_list->next = noti_cb_list_new;
153 noti_cb_list_new->prev = noti_cb_list;
156 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
157 notification_unresister_changed_cb(changed_cb);
158 return NOTIFICATION_ERROR_IO_ERROR;
161 return NOTIFICATION_ERROR_NONE;
164 EXPORT_API int notification_resister_changed_cb(
165 void (*changed_cb)(void *data, notification_type_e type),
168 return notification_resister_changed_cb_for_uid(
169 changed_cb, user_data, getuid());
172 EXPORT_API int notification_unresister_changed_cb(
173 void (*changed_cb)(void *data, notification_type_e type))
175 notification_cb_list_s *noti_cb_list = NULL;
176 notification_cb_list_s *noti_cb_list_prev = NULL;
177 notification_cb_list_s *noti_cb_list_next = NULL;
179 noti_cb_list = g_notification_cb_list;
181 if (changed_cb == NULL)
182 return NOTIFICATION_ERROR_INVALID_PARAMETER;
184 if (noti_cb_list == NULL)
185 return NOTIFICATION_ERROR_INVALID_PARAMETER;
187 while (noti_cb_list->prev != NULL)
188 noti_cb_list = noti_cb_list->prev;
192 if (noti_cb_list->changed_cb == changed_cb) {
193 noti_cb_list_prev = noti_cb_list->prev;
194 noti_cb_list_next = noti_cb_list->next;
196 if (noti_cb_list_prev == NULL)
197 g_notification_cb_list = noti_cb_list_next;
199 noti_cb_list_prev->next = noti_cb_list_next;
201 if (noti_cb_list_next == NULL) {
202 if (noti_cb_list_prev != NULL)
203 noti_cb_list_prev->next = NULL;
206 noti_cb_list_next->prev = noti_cb_list_prev;
211 if (g_notification_cb_list == NULL)
212 notification_ipc_monitor_fini();
214 return NOTIFICATION_ERROR_NONE;
216 noti_cb_list = noti_cb_list->next;
217 } while (noti_cb_list != NULL);
219 return NOTIFICATION_ERROR_INVALID_PARAMETER;
222 EXPORT_API int notification_update_progress(notification_h noti,
226 char *caller_pkgname = NULL;
227 int input_priv_id = 0;
229 double input_progress = 0.0;
231 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
233 return NOTIFICATION_ERROR_INVALID_PARAMETER;
235 input_priv_id = noti->priv_id;
238 input_priv_id = priv_id;
242 caller_pkgname = notification_get_pkgname_by_pid();
244 caller_pkgname = strdup(noti->caller_pkgname);
247 input_progress = 0.0;
248 else if (progress > 1.0)
249 input_progress = 1.0;
251 input_progress = progress;
253 ret = notification_ongoing_update_progress(caller_pkgname, input_priv_id,
257 free(caller_pkgname);
262 EXPORT_API int notification_update_size(notification_h noti,
266 char *caller_pkgname = NULL;
267 int input_priv_id = 0;
269 double input_size = 0.0;
271 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
273 return NOTIFICATION_ERROR_INVALID_PARAMETER;
275 input_priv_id = noti->priv_id;
277 input_priv_id = priv_id;
281 caller_pkgname = notification_get_pkgname_by_pid();
283 caller_pkgname = strdup(noti->caller_pkgname);
290 ret = notification_ongoing_update_size(caller_pkgname, input_priv_id,
294 free(caller_pkgname);
299 EXPORT_API int notification_update_content(notification_h noti,
303 char *caller_pkgname = NULL;
304 int input_priv_id = 0;
307 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
309 return NOTIFICATION_ERROR_INVALID_PARAMETER;
311 input_priv_id = noti->priv_id;
314 input_priv_id = priv_id;
318 caller_pkgname = notification_get_pkgname_by_pid();
320 caller_pkgname = strdup(noti->caller_pkgname);
322 ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
326 free(caller_pkgname);
331 /* notification_set_icon will be removed */
332 /* LCOV_EXCL_START */
333 EXPORT_API int notification_set_icon(notification_h noti,
334 const char *icon_path)
336 int ret_err = NOTIFICATION_ERROR_NONE;
339 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
346 /* notification_get_icon will be removed */
347 /* LCOV_EXCL_START */
348 EXPORT_API int notification_get_icon(notification_h noti,
351 int ret_err = NOTIFICATION_ERROR_NONE;
352 char *ret_image_path = NULL;
355 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
358 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL)
359 *icon_path = ret_image_path;
365 EXPORT_API int notification_translate_localized_text(notification_h noti)
367 int noti_err = NOTIFICATION_ERROR_NONE;
368 char *ret_text = NULL;
370 char *bundle_val = NULL;
373 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
375 for (; type < NOTIFICATION_TEXT_TYPE_MAX; type++) {
376 noti_err = notification_get_text(noti, type, &ret_text);
377 if (noti_err == NOTIFICATION_ERROR_NONE && ret_text) {
378 if (noti->b_text == NULL) {
379 noti->b_text = bundle_create();
380 if (noti->b_text == NULL)
381 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
386 new_text = strdup(ret_text);
388 snprintf(buf_key, sizeof(buf_key), "%d", type);
389 bundle_get_str(b, buf_key, &bundle_val);
390 if (bundle_val != NULL)
391 bundle_del(b, buf_key);
393 bundle_add_str(b, buf_key, new_text);
397 noti->num_format_args = 0;
403 bundle_free(noti->b_key);
410 /* LCOV_EXCL_START */
411 EXPORT_API int notification_set_title(notification_h noti,
413 const char *loc_title)
415 int noti_err = NOTIFICATION_ERROR_NONE;
417 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
419 NOTIFICATION_VARIABLE_TYPE_NONE);
425 /* LCOV_EXCL_START */
426 EXPORT_API int notification_get_title(notification_h noti,
430 int noti_err = NOTIFICATION_ERROR_NONE;
431 char *ret_text = NULL;
434 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
440 if (loc_title != NULL)
447 /* LCOV_EXCL_START */
448 EXPORT_API int notification_set_content(notification_h noti,
450 const char *loc_content)
452 int noti_err = NOTIFICATION_ERROR_NONE;
454 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
455 content, loc_content,
456 NOTIFICATION_VARIABLE_TYPE_NONE);
462 /* LCOV_EXCL_START */
463 EXPORT_API int notification_get_content(notification_h noti,
467 int noti_err = NOTIFICATION_ERROR_NONE;
468 char *ret_text = NULL;
471 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
477 if (loc_content != NULL)
485 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
487 if (ret == -1 || boolval == 0) {
488 if (content != NULL && noti->default_content != NULL)
489 *content = noti->default_content;
491 if (loc_content != NULL && noti->loc_default_content != NULL)
492 *loc_content = noti->loc_default_content;
498 /* LCOV_EXCL_START */
499 EXPORT_API int notification_set_application(notification_h noti,
502 if (noti == NULL || pkgname == NULL)
503 return NOTIFICATION_ERROR_INVALID_PARAMETER;
505 if (noti->launch_pkgname)
506 free(noti->launch_pkgname);
508 noti->launch_pkgname = strdup(pkgname);
510 return NOTIFICATION_ERROR_NONE;
514 /* LCOV_EXCL_START */
515 EXPORT_API int notification_get_application(notification_h noti,
518 if (noti == NULL || pkgname == NULL)
519 return NOTIFICATION_ERROR_INVALID_PARAMETER;
521 if (noti->launch_pkgname)
522 *pkgname = noti->launch_pkgname;
524 *pkgname = noti->caller_pkgname;
526 return NOTIFICATION_ERROR_NONE;
530 /* LCOV_EXCL_START */
531 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
534 if (noti == NULL || args == NULL)
535 return NOTIFICATION_ERROR_INVALID_PARAMETER;
538 bundle_free(noti->args);
540 noti->args = bundle_dup(args);
542 if (noti->group_args) {
543 bundle_free(noti->group_args);
544 noti->group_args = NULL;
547 if (group_args != NULL)
548 noti->group_args = bundle_dup(group_args);
550 return NOTIFICATION_ERROR_NONE;
554 /* LCOV_EXCL_START */
555 EXPORT_API int notification_get_args(notification_h noti,
559 if (noti == NULL || args == NULL)
560 return NOTIFICATION_ERROR_INVALID_PARAMETER;
567 if (group_args != NULL && noti->group_args)
568 *group_args = noti->group_args;
570 return NOTIFICATION_ERROR_NONE;
574 /* LCOV_EXCL_START */
575 int notification_get_grouping_list_for_uid(notification_type_e type, int count,
576 notification_list_h *list, uid_t uid)
578 notification_list_h get_list = NULL;
582 return NOTIFICATION_ERROR_INVALID_PARAMETER;
584 ret = notification_noti_get_grouping_list(type, count, &get_list, uid);
585 if (ret != NOTIFICATION_ERROR_NONE)
590 return NOTIFICATION_ERROR_NONE;
593 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
594 notification_list_h *list)
596 return notification_get_grouping_list_for_uid(type, count, list, getuid());
600 /* LCOV_EXCL_START */
601 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
602 notification_type_e type,
606 char *caller_pkgname = NULL;
609 caller_pkgname = notification_get_pkgname_by_pid();
611 caller_pkgname = strdup(pkgname);
613 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, getuid());
616 free(caller_pkgname);
622 /* LCOV_EXCL_START */
623 int notification_delete_group_by_priv_id_for_uid(const char *pkgname,
624 notification_type_e type,
625 int priv_id, uid_t uid)
628 char *caller_pkgname = NULL;
631 caller_pkgname = notification_get_pkgname_by_pid();
633 caller_pkgname = strdup(pkgname);
635 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
638 free(caller_pkgname);
644 /* LCOV_EXCL_START */
645 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
646 notification_type_e type,
649 return notification_delete_group_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
652 int notification_get_count_for_uid(notification_type_e type,
655 int priv_id, int *count,
659 char *caller_pkgname = NULL;
662 return NOTIFICATION_ERROR_INVALID_PARAMETER;
665 caller_pkgname = notification_get_pkgname_by_pid();
667 caller_pkgname = strdup(pkgname);
669 ret = notification_ipc_request_get_count(
678 free(caller_pkgname);
684 /* LCOV_EXCL_START */
685 EXPORT_API int notification_get_count(notification_type_e type,
688 int priv_id, int *count)
690 return notification_get_count_for_uid(type, pkgname, group_id, priv_id, count, getuid());
693 int notification_clear_for_uid(notification_type_e type, uid_t uid)
697 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
698 return NOTIFICATION_ERROR_INVALID_PARAMETER;
700 ret = notification_ipc_request_delete_multiple(type, NULL, uid);
706 /* LCOV_EXCL_START */
707 EXPORT_API int notification_clear(notification_type_e type)
709 return notification_clear_for_uid(type, getuid());
712 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
715 if (noti_op == NULL || data == NULL)
716 return NOTIFICATION_ERROR_INVALID_PARAMETER;
719 case NOTIFICATION_OP_DATA_TYPE:
720 *((int *)data) = noti_op->type;
722 case NOTIFICATION_OP_DATA_PRIV_ID:
723 *((int *)data) = noti_op->priv_id;
725 case NOTIFICATION_OP_DATA_NOTI:
726 *((notification_h *)data) = noti_op->noti;
728 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
729 *((int *)data) = noti_op->extra_info_1;
731 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
732 *((int *)data) = noti_op->extra_info_2;
735 return NOTIFICATION_ERROR_INVALID_PARAMETER;
739 return NOTIFICATION_ERROR_NONE;
743 /* LCOV_EXCL_START */
744 EXPORT_API int notification_set_pkgname(notification_h noti,
747 /* check noti and pkgname are valid data */
748 if (noti == NULL || pkgname == NULL)
749 return NOTIFICATION_ERROR_INVALID_PARAMETER;
751 /* Remove previous caller pkgname */
752 if (noti->caller_pkgname) {
753 free(noti->caller_pkgname);
754 noti->caller_pkgname = NULL;
757 noti->caller_pkgname = strdup(pkgname);
759 return NOTIFICATION_ERROR_NONE;
763 /* LCOV_EXCL_START */
764 int notification_delete_all_by_type_for_uid(const char *pkgname,
765 notification_type_e type, uid_t uid)
768 char *caller_pkgname = NULL;
770 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
771 return NOTIFICATION_ERROR_INVALID_PARAMETER;
774 caller_pkgname = notification_get_pkgname_by_pid();
776 caller_pkgname = strdup(pkgname);
778 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
781 free(caller_pkgname);
787 /* LCOV_EXCL_START */
788 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
789 notification_type_e type)
791 return notification_delete_all_by_type_for_uid(pkgname, type, getuid());
794 int notification_delete_by_priv_id_for_uid(const char *pkgname,
795 notification_type_e type,
800 char *caller_pkgname = NULL;
802 if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
803 return NOTIFICATION_ERROR_INVALID_PARAMETER;
806 caller_pkgname = notification_get_pkgname_by_pid();
808 caller_pkgname = strdup(pkgname);
810 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
813 free(caller_pkgname);
819 /* LCOV_EXCL_START */
820 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
821 notification_type_e type,
824 return notification_delete_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
827 EXPORT_API int notification_set_execute_option(notification_h noti,
828 notification_execute_type_e type,
831 bundle *service_handle)
833 char buf_key[32] = { 0, };
834 char *ret_val = NULL;
838 return NOTIFICATION_ERROR_INVALID_PARAMETER;
840 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
841 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
842 return NOTIFICATION_ERROR_INVALID_PARAMETER;
844 /* Create execute option bundle if does not exist */
845 if (noti->b_execute_option == NULL)
846 noti->b_execute_option = bundle_create();
848 b = noti->b_execute_option;
853 snprintf(buf_key, sizeof(buf_key), "text%d", type);
855 /* Check text key exist */
856 bundle_get_str(b, buf_key, &ret_val);
858 /* Remove previous data */
859 bundle_del(b, buf_key);
862 bundle_add_str(b, buf_key, text);
868 snprintf(buf_key, sizeof(buf_key), "key%d", type);
870 /* Check key key exist */
871 bundle_get_str(b, buf_key, &ret_val);
873 /* Remove previous data */
874 bundle_del(b, buf_key);
877 bundle_add_str(b, buf_key, key);
881 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
882 /* Remove previous data if exist */
883 if (noti->b_service_responding != NULL) {
884 bundle_free(noti->b_service_responding);
885 noti->b_service_responding = NULL;
888 /* Save service handle */
889 if (service_handle != NULL)
890 noti->b_service_responding = bundle_dup(service_handle);
893 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
894 /* Remove previous data if exist */
895 if (noti->b_service_single_launch != NULL) {
896 bundle_free(noti->b_service_single_launch);
897 noti->b_service_single_launch = NULL;
900 /* Save service handle */
901 if (service_handle != NULL)
902 noti->b_service_single_launch =
903 bundle_dup(service_handle);
906 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
907 /* Remove previous data if exist */
908 if (noti->b_service_multi_launch != NULL) {
909 bundle_free(noti->b_service_multi_launch);
910 noti->b_service_multi_launch = NULL;
913 /* Save service handle */
914 if (service_handle != NULL)
915 noti->b_service_multi_launch =
916 bundle_dup(service_handle);
921 return NOTIFICATION_ERROR_NONE;
925 /* LCOV_EXCL_START */
926 EXPORT_API int notification_get_id(notification_h noti,
927 int *group_id, int *priv_id)
929 /* check noti is valid data */
931 return NOTIFICATION_ERROR_INVALID_PARAMETER;
933 /* Check group_id is valid data */
936 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
937 *group_id = NOTIFICATION_GROUP_ID_NONE;
939 *group_id = noti->group_id;
942 /* Check priv_id is valid data */
945 *priv_id = noti->priv_id;
947 return NOTIFICATION_ERROR_NONE;
951 /* LCOV_EXCL_START */
952 notification_h notification_load_for_uid(char *pkgname,
953 int priv_id, uid_t uid)
956 notification_h noti = NULL;
958 noti = (notification_h)calloc(1, sizeof(struct _notification));
960 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
964 ret = notification_ipc_request_load_noti_by_priv_id(noti, pkgname, priv_id, uid);
965 if (ret != NOTIFICATION_ERROR_NONE) {
966 notification_free(noti);
974 /* LCOV_EXCL_START */
975 EXPORT_API notification_h notification_load(char *pkgname,
978 return notification_load_for_uid(pkgname, priv_id, getuid());
982 /* LCOV_EXCL_START */
983 EXPORT_API notification_h notification_new(notification_type_e type,
984 int group_id, int priv_id)
986 return notification_create(type);
989 static void _notification_get_text_domain(notification_h noti)
994 /* LCOV_EXCL_START */
995 EXPORT_API int notification_get_execute_option(notification_h noti,
996 notification_execute_type_e type,
998 bundle **service_handle)
1000 char buf_key[32] = { 0, };
1001 char *ret_val = NULL;
1002 char *get_str = NULL;
1006 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1008 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1009 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
1010 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1014 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1015 b = noti->b_service_responding;
1017 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1018 b = noti->b_service_single_launch;
1020 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1021 b = noti->b_service_multi_launch;
1030 /* Get text domain and dir */
1031 if (noti->domain == NULL || noti->dir == NULL)
1032 _notification_get_text_domain(noti);
1035 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1037 /* Check key key exist */
1038 bundle_get_str(b, buf_key, &ret_val);
1039 if (ret_val != NULL && noti->domain != NULL
1040 && noti->dir != NULL) {
1041 /* Get application string */
1042 bindtextdomain(noti->domain, noti->dir);
1044 get_str = dgettext(noti->domain, ret_val);
1047 } else if (ret_val != NULL) {
1048 /* Get system string */
1049 get_str = dgettext("sys_string", ret_val);
1053 /* Get basic text */
1054 snprintf(buf_key, sizeof(buf_key), "text%d",
1057 bundle_get_str(b, buf_key, &ret_val);
1064 if (service_handle != NULL)
1065 *service_handle = b;
1067 return NOTIFICATION_ERROR_NONE;
1069 /* LCOV_EXCL_STOP */
1071 EXPORT_API int notification_insert_for_uid(notification_h noti,
1072 int *priv_id, uid_t uid)
1077 /* Check noti is vaild data */
1079 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1081 /* Check noti type is valid type */
1082 if (noti->type <= NOTIFICATION_TYPE_NONE
1083 || noti->type >= NOTIFICATION_TYPE_MAX)
1084 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1087 /* Save insert time */
1088 noti->insert_time = time(NULL);
1089 ret = notification_ipc_request_insert(noti, &id);
1090 if (ret != NOTIFICATION_ERROR_NONE)
1094 NOTIFICATION_DBG("from master:%d", id);
1096 /* If priv_id is valid data, set priv_id */
1097 if (priv_id != NULL)
1098 *priv_id = noti->priv_id;
1100 return NOTIFICATION_ERROR_NONE;
1103 EXPORT_API int notification_insert(notification_h noti,
1106 return notification_insert_for_uid(noti, priv_id, getuid());
1109 EXPORT_API int notification_update_async_for_uid(notification_h noti,
1110 void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
1114 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1117 /* Update insert time ? */
1118 noti->insert_time = time(NULL);
1119 ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1124 EXPORT_API int notification_update_async(notification_h noti,
1125 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1127 return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
1130 EXPORT_API int notification_register_detailed_changed_cb_for_uid(
1131 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1132 void *user_data, uid_t uid)
1134 notification_cb_list_s *noti_cb_list_new = NULL;
1135 notification_cb_list_s *noti_cb_list = NULL;
1137 if (detailed_changed_cb == NULL)
1138 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1140 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE)
1141 return NOTIFICATION_ERROR_IO_ERROR;
1144 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
1146 if (noti_cb_list_new == NULL) {
1147 NOTIFICATION_ERR("malloc failed");
1148 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1151 noti_cb_list_new->next = NULL;
1152 noti_cb_list_new->prev = NULL;
1154 noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
1155 noti_cb_list_new->changed_cb = NULL;
1156 noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
1157 noti_cb_list_new->data = user_data;
1159 if (g_notification_cb_list == NULL) {
1160 g_notification_cb_list = noti_cb_list_new;
1162 noti_cb_list = g_notification_cb_list;
1164 while (noti_cb_list->next != NULL)
1165 noti_cb_list = noti_cb_list->next;
1168 noti_cb_list->next = noti_cb_list_new;
1169 noti_cb_list_new->prev = noti_cb_list;
1171 return NOTIFICATION_ERROR_NONE;
1174 EXPORT_API int notification_register_detailed_changed_cb(
1175 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1178 return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1181 EXPORT_API int notification_unregister_detailed_changed_cb(
1182 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1185 notification_cb_list_s *noti_cb_list = NULL;
1186 notification_cb_list_s *noti_cb_list_prev = NULL;
1187 notification_cb_list_s *noti_cb_list_next = NULL;
1189 noti_cb_list = g_notification_cb_list;
1191 if (detailed_changed_cb == NULL)
1192 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1194 if (noti_cb_list == NULL)
1195 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1198 while (noti_cb_list->prev != NULL)
1199 noti_cb_list = noti_cb_list->prev;
1203 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
1204 noti_cb_list_prev = noti_cb_list->prev;
1205 noti_cb_list_next = noti_cb_list->next;
1207 if (noti_cb_list_prev == NULL)
1208 g_notification_cb_list = noti_cb_list_next;
1210 noti_cb_list_prev->next = noti_cb_list_next;
1212 if (noti_cb_list_next == NULL) {
1213 if (noti_cb_list_prev != NULL)
1214 noti_cb_list_prev->next = NULL;
1217 noti_cb_list_next->prev = noti_cb_list_prev;
1222 if (g_notification_cb_list == NULL)
1223 notification_ipc_monitor_fini();
1225 return NOTIFICATION_ERROR_NONE;
1227 noti_cb_list = noti_cb_list->next;
1228 } while (noti_cb_list != NULL);
1230 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1233 /* LCOV_EXCL_START */
1234 EXPORT_API int notification_is_service_ready(void)
1236 return notification_ipc_is_master_ready();
1238 /* LCOV_EXCL_STOP */
1240 EXPORT_API int notification_set_uid(notification_h noti,
1244 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1247 return NOTIFICATION_ERROR_NONE;
1250 EXPORT_API int notification_get_uid(notification_h noti,
1253 if (noti == NULL || uid == NULL)
1254 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1257 return NOTIFICATION_ERROR_NONE;
1260 EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
1265 /* Check noti is vaild data */
1267 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1269 /* Check noti type is valid type */
1270 if (noti->type <= NOTIFICATION_TYPE_NONE
1271 || noti->type >= NOTIFICATION_TYPE_MAX)
1272 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1274 /* Save insert time */
1275 noti->insert_time = time(NULL);
1278 ret = notification_ipc_request_insert(noti, &id);
1279 if (ret != NOTIFICATION_ERROR_NONE)
1283 NOTIFICATION_DBG("from master:%d", id);
1285 return NOTIFICATION_ERROR_NONE;
1288 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
1292 /* Check noti is valid data */
1295 /* Update insert time ? */
1296 noti->insert_time = time(NULL);
1297 ret = notification_ipc_request_update(noti);
1299 notification_ipc_request_refresh(uid);
1300 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1306 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
1311 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1313 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id, uid);
1318 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
1321 char *caller_pkgname = NULL;
1323 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
1324 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1326 caller_pkgname = notification_get_pkgname_by_pid();
1328 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
1331 free(caller_pkgname);
1336 EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
1339 notification_h noti = NULL;
1340 char *caller_pkgname = NULL;
1343 NOTIFICATION_ERR("Invalid parameter");
1344 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1348 caller_pkgname = notification_get_pkgname_by_pid();
1349 if (!caller_pkgname) {
1350 /* LCOV_EXCL_START */
1351 NOTIFICATION_ERR("Failed to get a package name");
1352 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1354 /* LCOV_EXCL_STOP */
1357 noti = (notification_h)calloc(1, sizeof(struct _notification));
1359 /* LCOV_EXCL_START */
1360 NOTIFICATION_ERR("Failed to alloc a new notification");
1361 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1362 free(caller_pkgname);
1365 /* LCOV_EXCL_STOP */
1368 ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char *)tag, uid);
1369 free(caller_pkgname);
1371 set_last_result(ret);
1372 if (ret != NOTIFICATION_ERROR_NONE) {
1373 notification_free(noti);