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>
28 #include <app_control_internal.h>
32 #include <vconf-keys.h>
35 #include <notification.h>
36 #include <notification_list.h>
37 #include <notification_debug.h>
38 #include <notification_private.h>
39 #include <notification_noti.h>
40 #include <notification_ongoing.h>
41 #include <notification_group.h>
42 #include <notification_ipc.h>
43 #include <notification_internal.h>
45 typedef struct _notification_cb_info notification_cb_info_s;
47 typedef enum __notification_cb_type {
48 NOTIFICATION_CB_NORMAL = 1,
49 NOTIFICATION_CB_DETAILED,
50 } _notification_cb_type_e;
52 struct _notification_cb_info {
53 _notification_cb_type_e cb_type;
54 void (*changed_cb) (void *data, notification_type_e type);
55 void (*detailed_changed_cb) (void *data, notification_type_e type, notification_op *op_list, int num_op);
59 static GHashTable *_noti_cb_hash = NULL;
62 static void __free_changed_cb_info(gpointer data)
64 notification_cb_info_s *noti_cb_info = (notification_cb_info_s *)data;
71 static void __free_changed_cb_hash(gpointer data)
73 GList *changed_cb_list = (GList *)data;
75 g_list_free_full(changed_cb_list, __free_changed_cb_info);
79 void notification_call_changed_cb_for_uid(notification_op *op_list, int op_num, uid_t uid)
81 notification_type_e type = 0;
82 GList *noti_cb_list = NULL;
83 notification_cb_info_s *noti_cb_info = NULL;
85 if (_noti_cb_hash == NULL)
88 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
90 if (noti_cb_list == NULL)
93 if (op_list == NULL) {
94 NOTIFICATION_ERR("invalid data");
98 noti_cb_list = g_list_first(noti_cb_list);
99 notification_get_type(op_list->noti, &type);
101 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
102 noti_cb_info = noti_cb_list->data;
104 if (noti_cb_info->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_info->changed_cb) {
105 noti_cb_info->changed_cb(noti_cb_info->data, type);
107 if (noti_cb_info->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_info->detailed_changed_cb) {
108 noti_cb_info->detailed_changed_cb(noti_cb_info->data,
109 type, op_list, op_num);
114 EXPORT_API int notification_add_deferred_task(
115 void (*deferred_task_cb)(void *data), void *user_data)
117 if (deferred_task_cb == NULL)
118 return NOTIFICATION_ERROR_INVALID_PARAMETER;
120 return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
123 EXPORT_API int notification_del_deferred_task(
124 void (*deferred_task_cb)(void *data))
126 if (deferred_task_cb == NULL)
127 return NOTIFICATION_ERROR_INVALID_PARAMETER;
129 return notification_ipc_del_deffered_task(deferred_task_cb);
132 EXPORT_API int notification_resister_changed_cb_for_uid(
133 void (*changed_cb)(void *data, notification_type_e type),
134 void *user_data, uid_t uid)
136 GList *noti_cb_list = NULL;
137 notification_cb_info_s *noti_cb_info_new = NULL;
139 if (changed_cb == NULL)
140 return NOTIFICATION_ERROR_INVALID_PARAMETER;
142 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE)
143 return NOTIFICATION_ERROR_IO_ERROR;
145 if (_noti_cb_hash == NULL)
146 _noti_cb_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __free_changed_cb_hash);
148 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
149 if (noti_cb_info_new == NULL) {
150 NOTIFICATION_ERR("malloc failed");
151 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
154 noti_cb_info_new->cb_type = NOTIFICATION_CB_NORMAL;
155 noti_cb_info_new->changed_cb = changed_cb;
156 noti_cb_info_new->detailed_changed_cb = NULL;
157 noti_cb_info_new->data = user_data;
159 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
161 if (noti_cb_list == NULL) {
162 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
163 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
165 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
168 return NOTIFICATION_ERROR_NONE;
171 EXPORT_API int notification_resister_changed_cb(
172 void (*changed_cb)(void *data, notification_type_e type),
175 return notification_resister_changed_cb_for_uid(changed_cb, user_data, getuid());
178 EXPORT_API int notification_unresister_changed_cb_for_uid(
179 void (*changed_cb)(void *data, notification_type_e type), uid_t uid)
181 notification_cb_info_s *noti_cb_info = NULL;
182 GList *noti_cb_list = NULL;
184 if (changed_cb == NULL)
185 return NOTIFICATION_ERROR_INVALID_PARAMETER;
187 if (_noti_cb_hash == NULL)
188 return NOTIFICATION_ERROR_INVALID_PARAMETER;
190 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
192 if (noti_cb_list == NULL)
193 return NOTIFICATION_ERROR_INVALID_PARAMETER;
195 noti_cb_list = g_list_first(noti_cb_list);
197 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
198 noti_cb_info = noti_cb_list->data;
199 if (noti_cb_info->changed_cb == changed_cb) {
200 noti_cb_list = g_list_remove(g_list_first(noti_cb_list), noti_cb_info);
202 if (noti_cb_list == NULL)
203 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
205 if (g_hash_table_size(_noti_cb_hash) == 0)
206 notification_ipc_monitor_fini();
208 return NOTIFICATION_ERROR_NONE;
212 return NOTIFICATION_ERROR_INVALID_PARAMETER;
215 EXPORT_API int notification_unresister_changed_cb(
216 void (*changed_cb)(void *data, notification_type_e type))
218 return notification_unresister_changed_cb_for_uid(changed_cb, getuid());
221 EXPORT_API int notification_update_progress(notification_h noti,
225 char *caller_pkgname = NULL;
226 int input_priv_id = 0;
228 double input_progress = 0.0;
230 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
232 return NOTIFICATION_ERROR_INVALID_PARAMETER;
234 input_priv_id = noti->priv_id;
237 input_priv_id = priv_id;
241 caller_pkgname = notification_get_pkgname_by_pid();
243 caller_pkgname = strdup(noti->caller_pkgname);
246 input_progress = 0.0;
247 else if (progress > 1.0)
248 input_progress = 1.0;
250 input_progress = progress;
252 ret = notification_ongoing_update_progress(caller_pkgname, input_priv_id,
256 free(caller_pkgname);
261 EXPORT_API int notification_update_size(notification_h noti,
265 char *caller_pkgname = NULL;
266 int input_priv_id = 0;
268 double input_size = 0.0;
270 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
272 return NOTIFICATION_ERROR_INVALID_PARAMETER;
274 input_priv_id = noti->priv_id;
276 input_priv_id = priv_id;
280 caller_pkgname = notification_get_pkgname_by_pid();
282 caller_pkgname = strdup(noti->caller_pkgname);
289 ret = notification_ongoing_update_size(caller_pkgname, input_priv_id,
293 free(caller_pkgname);
298 EXPORT_API int notification_update_content(notification_h noti,
302 char *caller_pkgname = NULL;
303 int input_priv_id = 0;
306 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
308 return NOTIFICATION_ERROR_INVALID_PARAMETER;
310 input_priv_id = noti->priv_id;
313 input_priv_id = priv_id;
317 caller_pkgname = notification_get_pkgname_by_pid();
319 caller_pkgname = strdup(noti->caller_pkgname);
321 ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
325 free(caller_pkgname);
330 /* notification_set_icon will be removed */
331 /* LCOV_EXCL_START */
332 EXPORT_API int notification_set_icon(notification_h noti,
333 const char *icon_path)
335 int ret_err = NOTIFICATION_ERROR_NONE;
338 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
345 /* notification_get_icon will be removed */
346 /* LCOV_EXCL_START */
347 EXPORT_API int notification_get_icon(notification_h noti,
350 int ret_err = NOTIFICATION_ERROR_NONE;
351 char *ret_image_path = NULL;
354 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
357 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL)
358 *icon_path = ret_image_path;
364 EXPORT_API int notification_translate_localized_text(notification_h noti)
366 int noti_err = NOTIFICATION_ERROR_NONE;
367 char *ret_text = NULL;
369 char *bundle_val = NULL;
372 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
374 for (; type < NOTIFICATION_TEXT_TYPE_MAX; type++) {
375 noti_err = notification_get_text(noti, type, &ret_text);
376 if (noti_err == NOTIFICATION_ERROR_NONE && ret_text) {
377 if (noti->b_text == NULL) {
378 noti->b_text = bundle_create();
379 if (noti->b_text == NULL)
380 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
385 new_text = strdup(ret_text);
387 snprintf(buf_key, sizeof(buf_key), "%d", type);
388 bundle_get_str(b, buf_key, &bundle_val);
389 if (bundle_val != NULL)
390 bundle_del(b, buf_key);
392 bundle_add_str(b, buf_key, new_text);
396 noti->num_format_args = 0;
404 /* LCOV_EXCL_START */
405 EXPORT_API int notification_set_title(notification_h noti,
407 const char *loc_title)
409 int noti_err = NOTIFICATION_ERROR_NONE;
411 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
413 NOTIFICATION_VARIABLE_TYPE_NONE);
419 /* LCOV_EXCL_START */
420 EXPORT_API int notification_get_title(notification_h noti,
424 int noti_err = NOTIFICATION_ERROR_NONE;
425 char *ret_text = NULL;
428 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
434 if (loc_title != NULL)
441 /* LCOV_EXCL_START */
442 EXPORT_API int notification_set_content(notification_h noti,
444 const char *loc_content)
446 int noti_err = NOTIFICATION_ERROR_NONE;
448 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
449 content, loc_content,
450 NOTIFICATION_VARIABLE_TYPE_NONE);
456 /* LCOV_EXCL_START */
457 EXPORT_API int notification_get_content(notification_h noti,
461 int noti_err = NOTIFICATION_ERROR_NONE;
462 char *ret_text = NULL;
465 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
471 if (loc_content != NULL)
479 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
481 if (ret == -1 || boolval == 0) {
482 if (content != NULL && noti->default_content != NULL)
483 *content = noti->default_content;
485 if (loc_content != NULL && noti->loc_default_content != NULL)
486 *loc_content = noti->loc_default_content;
492 /* LCOV_EXCL_START */
493 EXPORT_API int notification_set_application(notification_h noti,
496 if (noti == NULL || pkgname == NULL)
497 return NOTIFICATION_ERROR_INVALID_PARAMETER;
499 if (noti->launch_pkgname)
500 free(noti->launch_pkgname);
502 noti->launch_pkgname = strdup(pkgname);
504 return NOTIFICATION_ERROR_NONE;
508 /* LCOV_EXCL_START */
509 EXPORT_API int notification_get_application(notification_h noti,
512 if (noti == NULL || pkgname == NULL)
513 return NOTIFICATION_ERROR_INVALID_PARAMETER;
515 if (noti->launch_pkgname)
516 *pkgname = noti->launch_pkgname;
518 *pkgname = noti->caller_pkgname;
520 return NOTIFICATION_ERROR_NONE;
524 /* LCOV_EXCL_START */
525 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
528 if (noti == NULL || args == NULL)
529 return NOTIFICATION_ERROR_INVALID_PARAMETER;
532 bundle_free(noti->args);
534 noti->args = bundle_dup(args);
536 if (noti->group_args) {
537 bundle_free(noti->group_args);
538 noti->group_args = NULL;
541 if (group_args != NULL)
542 noti->group_args = bundle_dup(group_args);
544 return NOTIFICATION_ERROR_NONE;
548 /* LCOV_EXCL_START */
549 EXPORT_API int notification_get_args(notification_h noti,
553 if (noti == NULL || args == NULL)
554 return NOTIFICATION_ERROR_INVALID_PARAMETER;
561 if (group_args != NULL && noti->group_args)
562 *group_args = noti->group_args;
564 return NOTIFICATION_ERROR_NONE;
568 /* LCOV_EXCL_START */
569 int notification_get_grouping_list_for_uid(notification_type_e type, int count,
570 notification_list_h *list, uid_t uid)
572 notification_list_h get_list = NULL;
576 return NOTIFICATION_ERROR_INVALID_PARAMETER;
578 ret = notification_noti_get_grouping_list(type, count, &get_list, uid);
579 if (ret != NOTIFICATION_ERROR_NONE)
584 return NOTIFICATION_ERROR_NONE;
587 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
588 notification_list_h *list)
590 return notification_get_grouping_list_for_uid(type, count, list, getuid());
594 /* LCOV_EXCL_START */
595 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
596 notification_type_e type,
600 char *caller_pkgname = NULL;
603 caller_pkgname = notification_get_pkgname_by_pid();
605 caller_pkgname = strdup(pkgname);
607 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, getuid());
610 free(caller_pkgname);
616 /* LCOV_EXCL_START */
617 int notification_delete_group_by_priv_id_for_uid(const char *pkgname,
618 notification_type_e type,
619 int priv_id, uid_t uid)
622 char *caller_pkgname = NULL;
625 caller_pkgname = notification_get_pkgname_by_pid();
627 caller_pkgname = strdup(pkgname);
629 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
632 free(caller_pkgname);
638 /* LCOV_EXCL_START */
639 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
640 notification_type_e type,
643 return notification_delete_group_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
646 int notification_get_count_for_uid(notification_type_e type,
649 int priv_id, int *count,
653 char *caller_pkgname = NULL;
656 return NOTIFICATION_ERROR_INVALID_PARAMETER;
659 caller_pkgname = notification_get_pkgname_by_pid();
661 caller_pkgname = strdup(pkgname);
663 ret = notification_ipc_request_get_count(
672 free(caller_pkgname);
678 /* LCOV_EXCL_START */
679 EXPORT_API int notification_get_count(notification_type_e type,
682 int priv_id, int *count)
684 return notification_get_count_for_uid(type, pkgname, group_id, priv_id, count, getuid());
687 int notification_clear_for_uid(notification_type_e type, uid_t uid)
691 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
692 return NOTIFICATION_ERROR_INVALID_PARAMETER;
694 ret = notification_ipc_request_delete_multiple(type, NULL, uid);
700 /* LCOV_EXCL_START */
701 EXPORT_API int notification_clear(notification_type_e type)
703 return notification_clear_for_uid(type, getuid());
706 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
709 if (noti_op == NULL || data == NULL)
710 return NOTIFICATION_ERROR_INVALID_PARAMETER;
713 case NOTIFICATION_OP_DATA_TYPE:
714 *((int *)data) = noti_op->type;
716 case NOTIFICATION_OP_DATA_PRIV_ID:
717 *((int *)data) = noti_op->priv_id;
719 case NOTIFICATION_OP_DATA_NOTI:
720 *((notification_h *)data) = noti_op->noti;
722 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
723 *((int *)data) = noti_op->extra_info_1;
725 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
726 *((int *)data) = noti_op->extra_info_2;
729 return NOTIFICATION_ERROR_INVALID_PARAMETER;
733 return NOTIFICATION_ERROR_NONE;
737 /* LCOV_EXCL_START */
738 EXPORT_API int notification_set_pkgname(notification_h noti,
741 /* check noti and pkgname are valid data */
742 if (noti == NULL || pkgname == NULL)
743 return NOTIFICATION_ERROR_INVALID_PARAMETER;
745 /* Remove previous caller pkgname */
746 if (noti->caller_pkgname) {
747 free(noti->caller_pkgname);
748 noti->caller_pkgname = NULL;
751 noti->caller_pkgname = strdup(pkgname);
753 return NOTIFICATION_ERROR_NONE;
757 /* LCOV_EXCL_START */
758 int notification_delete_all_by_type_for_uid(const char *pkgname,
759 notification_type_e type, uid_t uid)
762 char *caller_pkgname = NULL;
764 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
765 return NOTIFICATION_ERROR_INVALID_PARAMETER;
768 caller_pkgname = notification_get_pkgname_by_pid();
770 caller_pkgname = strdup(pkgname);
772 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
775 free(caller_pkgname);
781 /* LCOV_EXCL_START */
782 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
783 notification_type_e type)
785 return notification_delete_all_by_type_for_uid(pkgname, type, getuid());
788 int notification_delete_by_priv_id_for_uid(const char *pkgname,
789 notification_type_e type,
794 char *caller_pkgname = NULL;
796 if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
797 return NOTIFICATION_ERROR_INVALID_PARAMETER;
800 caller_pkgname = notification_get_pkgname_by_pid();
802 caller_pkgname = strdup(pkgname);
804 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
807 free(caller_pkgname);
813 /* LCOV_EXCL_START */
814 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
815 notification_type_e type,
818 return notification_delete_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
821 EXPORT_API int notification_set_execute_option(notification_h noti,
822 notification_execute_type_e type,
825 bundle *service_handle)
827 char buf_key[32] = { 0, };
828 char *ret_val = NULL;
832 return NOTIFICATION_ERROR_INVALID_PARAMETER;
834 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
835 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
836 return NOTIFICATION_ERROR_INVALID_PARAMETER;
838 /* Create execute option bundle if does not exist */
839 if (noti->b_execute_option == NULL)
840 noti->b_execute_option = bundle_create();
842 b = noti->b_execute_option;
847 snprintf(buf_key, sizeof(buf_key), "text%d", type);
849 /* Check text key exist */
850 bundle_get_str(b, buf_key, &ret_val);
852 /* Remove previous data */
853 bundle_del(b, buf_key);
856 bundle_add_str(b, buf_key, text);
862 snprintf(buf_key, sizeof(buf_key), "key%d", type);
864 /* Check key key exist */
865 bundle_get_str(b, buf_key, &ret_val);
867 /* Remove previous data */
868 bundle_del(b, buf_key);
871 bundle_add_str(b, buf_key, key);
875 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
876 /* Remove previous data if exist */
877 if (noti->b_service_responding != NULL) {
878 bundle_free(noti->b_service_responding);
879 noti->b_service_responding = NULL;
882 /* Save service handle */
883 if (service_handle != NULL)
884 noti->b_service_responding = bundle_dup(service_handle);
887 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
888 /* Remove previous data if exist */
889 if (noti->b_service_single_launch != NULL) {
890 bundle_free(noti->b_service_single_launch);
891 noti->b_service_single_launch = NULL;
894 /* Save service handle */
895 if (service_handle != NULL)
896 noti->b_service_single_launch =
897 bundle_dup(service_handle);
900 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
901 /* Remove previous data if exist */
902 if (noti->b_service_multi_launch != NULL) {
903 bundle_free(noti->b_service_multi_launch);
904 noti->b_service_multi_launch = NULL;
907 /* Save service handle */
908 if (service_handle != NULL)
909 noti->b_service_multi_launch =
910 bundle_dup(service_handle);
915 return NOTIFICATION_ERROR_NONE;
919 /* LCOV_EXCL_START */
920 EXPORT_API int notification_get_id(notification_h noti,
921 int *group_id, int *priv_id)
923 /* check noti is valid data */
925 return NOTIFICATION_ERROR_INVALID_PARAMETER;
927 /* Check group_id is valid data */
930 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
931 *group_id = NOTIFICATION_GROUP_ID_NONE;
933 *group_id = noti->group_id;
936 /* Check priv_id is valid data */
939 *priv_id = noti->priv_id;
941 return NOTIFICATION_ERROR_NONE;
945 /* LCOV_EXCL_START */
946 notification_h notification_load_for_uid(char *pkgname,
947 int priv_id, uid_t uid)
950 notification_h noti = NULL;
952 noti = (notification_h)calloc(1, sizeof(struct _notification));
954 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
958 ret = notification_ipc_request_load_noti_by_priv_id(noti, pkgname, priv_id, uid);
959 if (ret != NOTIFICATION_ERROR_NONE) {
960 notification_free(noti);
968 /* LCOV_EXCL_START */
969 EXPORT_API notification_h notification_load(char *pkgname,
972 return notification_load_for_uid(pkgname, priv_id, getuid());
976 /* LCOV_EXCL_START */
977 EXPORT_API notification_h notification_new(notification_type_e type,
978 int group_id, int priv_id)
980 return notification_create(type);
983 static void _notification_get_text_domain(notification_h noti)
988 /* LCOV_EXCL_START */
989 EXPORT_API int notification_get_execute_option(notification_h noti,
990 notification_execute_type_e type,
992 bundle **service_handle)
994 char buf_key[32] = { 0, };
995 char *ret_val = NULL;
996 char *get_str = NULL;
1000 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1002 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1003 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
1004 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1008 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1009 b = noti->b_service_responding;
1011 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1012 b = noti->b_service_single_launch;
1014 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1015 b = noti->b_service_multi_launch;
1024 /* Get text domain and dir */
1025 if (noti->domain == NULL || noti->dir == NULL)
1026 _notification_get_text_domain(noti);
1029 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1031 /* Check key key exist */
1032 bundle_get_str(b, buf_key, &ret_val);
1033 if (ret_val != NULL && noti->domain != NULL
1034 && noti->dir != NULL) {
1035 /* Get application string */
1036 bindtextdomain(noti->domain, noti->dir);
1038 get_str = dgettext(noti->domain, ret_val);
1041 } else if (ret_val != NULL) {
1042 /* Get system string */
1043 get_str = dgettext("sys_string", ret_val);
1047 /* Get basic text */
1048 snprintf(buf_key, sizeof(buf_key), "text%d",
1051 bundle_get_str(b, buf_key, &ret_val);
1058 if (service_handle != NULL)
1059 *service_handle = b;
1061 return NOTIFICATION_ERROR_NONE;
1063 /* LCOV_EXCL_STOP */
1065 EXPORT_API int notification_insert_for_uid(notification_h noti,
1066 int *priv_id, uid_t uid)
1071 /* Check noti is vaild data */
1073 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1075 /* Check noti type is valid type */
1076 if (noti->type <= NOTIFICATION_TYPE_NONE
1077 || noti->type >= NOTIFICATION_TYPE_MAX)
1078 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1081 /* Save insert time */
1082 noti->insert_time = time(NULL);
1083 ret = notification_ipc_request_insert(noti, &id);
1084 if (ret != NOTIFICATION_ERROR_NONE)
1088 NOTIFICATION_DBG("from master:%d", id);
1090 /* If priv_id is valid data, set priv_id */
1091 if (priv_id != NULL)
1092 *priv_id = noti->priv_id;
1094 return NOTIFICATION_ERROR_NONE;
1097 EXPORT_API int notification_insert(notification_h noti,
1100 return notification_insert_for_uid(noti, priv_id, getuid());
1103 EXPORT_API int notification_update_async_for_uid(notification_h noti,
1104 void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
1108 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1111 /* Update insert time ? */
1112 noti->insert_time = time(NULL);
1113 ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1118 EXPORT_API int notification_update_async(notification_h noti,
1119 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1121 return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
1124 EXPORT_API int notification_register_detailed_changed_cb_for_uid(
1125 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1126 void *user_data, uid_t uid)
1128 GList *noti_cb_list = NULL;
1129 notification_cb_info_s *noti_cb_info_new = NULL;
1131 if (detailed_changed_cb == NULL)
1132 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1134 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE)
1135 return NOTIFICATION_ERROR_IO_ERROR;
1137 if (_noti_cb_hash == NULL)
1138 _noti_cb_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __free_changed_cb_hash);
1140 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
1141 if (noti_cb_info_new == NULL) {
1142 NOTIFICATION_ERR("malloc failed");
1143 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1146 noti_cb_info_new->cb_type = NOTIFICATION_CB_DETAILED;
1147 noti_cb_info_new->changed_cb = NULL;
1148 noti_cb_info_new->detailed_changed_cb = detailed_changed_cb;
1149 noti_cb_info_new->data = user_data;
1151 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1153 if (noti_cb_list == NULL) {
1154 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1155 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1157 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1160 return NOTIFICATION_ERROR_NONE;
1163 EXPORT_API int notification_register_detailed_changed_cb(
1164 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1167 return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1170 EXPORT_API int notification_unregister_detailed_changed_cb_for_uid(
1171 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1172 void *user_data, uid_t uid)
1174 notification_cb_info_s *noti_cb_info = NULL;
1175 GList *noti_cb_list = NULL;
1177 if (detailed_changed_cb == NULL)
1178 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1180 if (_noti_cb_hash == NULL)
1181 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1183 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1185 if (noti_cb_list == NULL)
1186 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1188 noti_cb_list = g_list_first(noti_cb_list);
1190 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
1191 noti_cb_info = noti_cb_list->data;
1192 if (noti_cb_info->detailed_changed_cb == detailed_changed_cb) {
1193 noti_cb_list = g_list_remove(g_list_first(noti_cb_list), noti_cb_info);
1195 if (noti_cb_list == NULL)
1196 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
1198 if (g_hash_table_size(_noti_cb_hash) == 0)
1199 notification_ipc_monitor_fini();
1201 return NOTIFICATION_ERROR_NONE;
1205 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1208 EXPORT_API int notification_unregister_detailed_changed_cb(
1209 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1212 return notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1215 /* LCOV_EXCL_START */
1216 EXPORT_API int notification_is_service_ready(void)
1218 return notification_ipc_is_master_ready();
1220 /* LCOV_EXCL_STOP */
1222 EXPORT_API int notification_set_uid(notification_h noti,
1226 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1229 return NOTIFICATION_ERROR_NONE;
1232 EXPORT_API int notification_get_uid(notification_h noti,
1235 if (noti == NULL || uid == NULL)
1236 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1239 return NOTIFICATION_ERROR_NONE;
1242 EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
1247 /* Check noti is vaild data */
1249 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1251 /* Check noti type is valid type */
1252 if (noti->type <= NOTIFICATION_TYPE_NONE
1253 || noti->type >= NOTIFICATION_TYPE_MAX)
1254 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1256 /* Save insert time */
1257 noti->insert_time = time(NULL);
1260 ret = notification_ipc_request_insert(noti, &id);
1261 if (ret != NOTIFICATION_ERROR_NONE)
1265 NOTIFICATION_DBG("from master:%d", id);
1267 return NOTIFICATION_ERROR_NONE;
1270 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
1274 /* Check noti is valid data */
1277 /* Update insert time ? */
1278 noti->insert_time = time(NULL);
1279 ret = notification_ipc_request_update(noti);
1281 notification_ipc_request_refresh(uid);
1282 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1288 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
1293 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1295 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id, uid);
1300 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
1303 char *caller_pkgname = NULL;
1305 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
1306 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1308 caller_pkgname = notification_get_pkgname_by_pid();
1310 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
1313 free(caller_pkgname);
1318 EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
1321 notification_h noti = NULL;
1322 char *caller_pkgname = NULL;
1325 NOTIFICATION_ERR("Invalid parameter");
1326 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1330 caller_pkgname = notification_get_pkgname_by_pid();
1331 if (!caller_pkgname) {
1332 /* LCOV_EXCL_START */
1333 NOTIFICATION_ERR("Failed to get a package name");
1334 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1336 /* LCOV_EXCL_STOP */
1339 noti = (notification_h)calloc(1, sizeof(struct _notification));
1341 /* LCOV_EXCL_START */
1342 NOTIFICATION_ERR("Failed to alloc a new notification");
1343 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1344 free(caller_pkgname);
1347 /* LCOV_EXCL_STOP */
1350 ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char *)tag, uid);
1351 free(caller_pkgname);
1353 set_last_result(ret);
1354 if (ret != NOTIFICATION_ERROR_NONE) {
1355 notification_free(noti);