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;
61 static void __free_changed_cb_info(gpointer data)
63 notification_cb_info_s *noti_cb_info = (notification_cb_info_s *)data;
68 static void __free_changed_cb_hash(gpointer data)
70 GList *changed_cb_list = (GList *)data;
72 g_list_free_full(changed_cb_list, __free_changed_cb_info);
75 void notification_call_changed_cb_for_uid(notification_op *op_list, int op_num, uid_t uid)
77 notification_type_e type = 0;
78 GList *noti_cb_list = NULL;
79 notification_cb_info_s *noti_cb_info = NULL;
81 if (_noti_cb_hash == NULL)
84 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
86 if (noti_cb_list == NULL)
89 if (op_list == NULL) {
90 NOTIFICATION_ERR("invalid data");
94 noti_cb_list = g_list_first(noti_cb_list);
95 notification_get_type(op_list->noti, &type);
97 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
98 noti_cb_info = noti_cb_list->data;
100 if (noti_cb_info->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_info->changed_cb) {
101 noti_cb_info->changed_cb(noti_cb_info->data, type);
103 if (noti_cb_info->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_info->detailed_changed_cb) {
104 noti_cb_info->detailed_changed_cb(noti_cb_info->data,
105 type, op_list, op_num);
110 EXPORT_API int notification_add_deferred_task(
111 void (*deferred_task_cb)(void *data), void *user_data)
113 if (deferred_task_cb == NULL)
114 return NOTIFICATION_ERROR_INVALID_PARAMETER;
116 return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
119 EXPORT_API int notification_del_deferred_task(
120 void (*deferred_task_cb)(void *data))
122 if (deferred_task_cb == NULL)
123 return NOTIFICATION_ERROR_INVALID_PARAMETER;
125 return notification_ipc_del_deffered_task(deferred_task_cb);
128 EXPORT_API int notification_resister_changed_cb_for_uid(
129 void (*changed_cb)(void *data, notification_type_e type),
130 void *user_data, uid_t uid)
132 GList *noti_cb_list = NULL;
133 notification_cb_info_s *noti_cb_info_new = NULL;
135 if (changed_cb == NULL)
136 return NOTIFICATION_ERROR_INVALID_PARAMETER;
138 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE)
139 return NOTIFICATION_ERROR_IO_ERROR;
141 if (_noti_cb_hash == NULL)
142 _noti_cb_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __free_changed_cb_hash);
144 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
145 if (noti_cb_info_new == NULL) {
146 NOTIFICATION_ERR("malloc failed");
147 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
150 noti_cb_info_new->cb_type = NOTIFICATION_CB_NORMAL;
151 noti_cb_info_new->changed_cb = changed_cb;
152 noti_cb_info_new->detailed_changed_cb = NULL;
153 noti_cb_info_new->data = user_data;
155 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
157 if (noti_cb_list == NULL) {
158 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
159 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
161 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
164 return NOTIFICATION_ERROR_NONE;
167 EXPORT_API int notification_resister_changed_cb(
168 void (*changed_cb)(void *data, notification_type_e type),
171 return notification_resister_changed_cb_for_uid(changed_cb, user_data, getuid());
174 EXPORT_API int notification_unresister_changed_cb_for_uid(
175 void (*changed_cb)(void *data, notification_type_e type), uid_t uid)
177 notification_cb_info_s *noti_cb_info = NULL;
178 GList *noti_cb_list = NULL;
180 if (changed_cb == NULL)
181 return NOTIFICATION_ERROR_INVALID_PARAMETER;
183 if (_noti_cb_hash == NULL)
184 return NOTIFICATION_ERROR_INVALID_PARAMETER;
186 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
188 if (noti_cb_list == NULL)
189 return NOTIFICATION_ERROR_INVALID_PARAMETER;
191 noti_cb_list = g_list_first(noti_cb_list);
193 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
194 noti_cb_info = noti_cb_list->data;
195 if (noti_cb_info->changed_cb == changed_cb) {
196 noti_cb_list = g_list_remove(g_list_first(noti_cb_list), noti_cb_info);
198 if (noti_cb_list == NULL)
199 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
201 if (g_hash_table_size(_noti_cb_hash) == 0)
202 notification_ipc_monitor_fini();
204 return NOTIFICATION_ERROR_NONE;
208 return NOTIFICATION_ERROR_INVALID_PARAMETER;
211 EXPORT_API int notification_unresister_changed_cb(
212 void (*changed_cb)(void *data, notification_type_e type))
214 return notification_unresister_changed_cb_for_uid(changed_cb, getuid());
217 EXPORT_API int notification_update_progress(notification_h noti,
221 char *caller_pkgname = NULL;
222 int input_priv_id = 0;
224 double input_progress = 0.0;
226 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
228 return NOTIFICATION_ERROR_INVALID_PARAMETER;
230 input_priv_id = noti->priv_id;
233 input_priv_id = priv_id;
237 caller_pkgname = notification_get_pkgname_by_pid();
239 caller_pkgname = strdup(noti->caller_pkgname);
242 input_progress = 0.0;
243 else if (progress > 1.0)
244 input_progress = 1.0;
246 input_progress = progress;
248 ret = notification_ongoing_update_progress(caller_pkgname, input_priv_id,
252 free(caller_pkgname);
257 EXPORT_API int notification_update_size(notification_h noti,
261 char *caller_pkgname = NULL;
262 int input_priv_id = 0;
264 double input_size = 0.0;
266 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
268 return NOTIFICATION_ERROR_INVALID_PARAMETER;
270 input_priv_id = noti->priv_id;
272 input_priv_id = priv_id;
276 caller_pkgname = notification_get_pkgname_by_pid();
278 caller_pkgname = strdup(noti->caller_pkgname);
285 ret = notification_ongoing_update_size(caller_pkgname, input_priv_id,
289 free(caller_pkgname);
294 EXPORT_API int notification_update_content(notification_h noti,
298 char *caller_pkgname = NULL;
299 int input_priv_id = 0;
302 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
304 return NOTIFICATION_ERROR_INVALID_PARAMETER;
306 input_priv_id = noti->priv_id;
309 input_priv_id = priv_id;
313 caller_pkgname = notification_get_pkgname_by_pid();
315 caller_pkgname = strdup(noti->caller_pkgname);
317 ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
321 free(caller_pkgname);
326 /* notification_set_icon will be removed */
327 /* LCOV_EXCL_START */
328 EXPORT_API int notification_set_icon(notification_h noti,
329 const char *icon_path)
331 int ret_err = NOTIFICATION_ERROR_NONE;
334 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
341 /* notification_get_icon will be removed */
342 /* LCOV_EXCL_START */
343 EXPORT_API int notification_get_icon(notification_h noti,
346 int ret_err = NOTIFICATION_ERROR_NONE;
347 char *ret_image_path = NULL;
350 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
353 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL)
354 *icon_path = ret_image_path;
360 EXPORT_API int notification_translate_localized_text(notification_h noti)
362 int noti_err = NOTIFICATION_ERROR_NONE;
363 char *ret_text = NULL;
365 char *bundle_val = NULL;
368 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
370 for (; type < NOTIFICATION_TEXT_TYPE_MAX; type++) {
371 noti_err = notification_get_text(noti, type, &ret_text);
372 if (noti_err == NOTIFICATION_ERROR_NONE && ret_text) {
373 if (noti->b_text == NULL) {
374 noti->b_text = bundle_create();
375 if (noti->b_text == NULL)
376 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
381 new_text = strdup(ret_text);
383 snprintf(buf_key, sizeof(buf_key), "%d", type);
384 bundle_get_str(b, buf_key, &bundle_val);
385 if (bundle_val != NULL)
386 bundle_del(b, buf_key);
388 bundle_add_str(b, buf_key, new_text);
392 noti->num_format_args = 0;
398 bundle_free(noti->b_key);
405 /* LCOV_EXCL_START */
406 EXPORT_API int notification_set_title(notification_h noti,
408 const char *loc_title)
410 int noti_err = NOTIFICATION_ERROR_NONE;
412 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
414 NOTIFICATION_VARIABLE_TYPE_NONE);
420 /* LCOV_EXCL_START */
421 EXPORT_API int notification_get_title(notification_h noti,
425 int noti_err = NOTIFICATION_ERROR_NONE;
426 char *ret_text = NULL;
429 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
435 if (loc_title != NULL)
442 /* LCOV_EXCL_START */
443 EXPORT_API int notification_set_content(notification_h noti,
445 const char *loc_content)
447 int noti_err = NOTIFICATION_ERROR_NONE;
449 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
450 content, loc_content,
451 NOTIFICATION_VARIABLE_TYPE_NONE);
457 /* LCOV_EXCL_START */
458 EXPORT_API int notification_get_content(notification_h noti,
462 int noti_err = NOTIFICATION_ERROR_NONE;
463 char *ret_text = NULL;
466 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
472 if (loc_content != NULL)
480 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
482 if (ret == -1 || boolval == 0) {
483 if (content != NULL && noti->default_content != NULL)
484 *content = noti->default_content;
486 if (loc_content != NULL && noti->loc_default_content != NULL)
487 *loc_content = noti->loc_default_content;
493 /* LCOV_EXCL_START */
494 EXPORT_API int notification_set_application(notification_h noti,
497 if (noti == NULL || pkgname == NULL)
498 return NOTIFICATION_ERROR_INVALID_PARAMETER;
500 if (noti->launch_pkgname)
501 free(noti->launch_pkgname);
503 noti->launch_pkgname = strdup(pkgname);
505 return NOTIFICATION_ERROR_NONE;
509 /* LCOV_EXCL_START */
510 EXPORT_API int notification_get_application(notification_h noti,
513 if (noti == NULL || pkgname == NULL)
514 return NOTIFICATION_ERROR_INVALID_PARAMETER;
516 if (noti->launch_pkgname)
517 *pkgname = noti->launch_pkgname;
519 *pkgname = noti->caller_pkgname;
521 return NOTIFICATION_ERROR_NONE;
525 /* LCOV_EXCL_START */
526 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
529 if (noti == NULL || args == NULL)
530 return NOTIFICATION_ERROR_INVALID_PARAMETER;
533 bundle_free(noti->args);
535 noti->args = bundle_dup(args);
537 if (noti->group_args) {
538 bundle_free(noti->group_args);
539 noti->group_args = NULL;
542 if (group_args != NULL)
543 noti->group_args = bundle_dup(group_args);
545 return NOTIFICATION_ERROR_NONE;
549 /* LCOV_EXCL_START */
550 EXPORT_API int notification_get_args(notification_h noti,
554 if (noti == NULL || args == NULL)
555 return NOTIFICATION_ERROR_INVALID_PARAMETER;
562 if (group_args != NULL && noti->group_args)
563 *group_args = noti->group_args;
565 return NOTIFICATION_ERROR_NONE;
569 /* LCOV_EXCL_START */
570 int notification_get_grouping_list_for_uid(notification_type_e type, int count,
571 notification_list_h *list, uid_t uid)
573 notification_list_h get_list = NULL;
577 return NOTIFICATION_ERROR_INVALID_PARAMETER;
579 ret = notification_noti_get_grouping_list(type, count, &get_list, uid);
580 if (ret != NOTIFICATION_ERROR_NONE)
585 return NOTIFICATION_ERROR_NONE;
588 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
589 notification_list_h *list)
591 return notification_get_grouping_list_for_uid(type, count, list, getuid());
595 /* LCOV_EXCL_START */
596 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
597 notification_type_e type,
601 char *caller_pkgname = NULL;
604 caller_pkgname = notification_get_pkgname_by_pid();
606 caller_pkgname = strdup(pkgname);
608 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, getuid());
611 free(caller_pkgname);
617 /* LCOV_EXCL_START */
618 int notification_delete_group_by_priv_id_for_uid(const char *pkgname,
619 notification_type_e type,
620 int priv_id, uid_t uid)
623 char *caller_pkgname = NULL;
626 caller_pkgname = notification_get_pkgname_by_pid();
628 caller_pkgname = strdup(pkgname);
630 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
633 free(caller_pkgname);
639 /* LCOV_EXCL_START */
640 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
641 notification_type_e type,
644 return notification_delete_group_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
647 int notification_get_count_for_uid(notification_type_e type,
650 int priv_id, int *count,
654 char *caller_pkgname = NULL;
657 return NOTIFICATION_ERROR_INVALID_PARAMETER;
660 caller_pkgname = notification_get_pkgname_by_pid();
662 caller_pkgname = strdup(pkgname);
664 ret = notification_ipc_request_get_count(
673 free(caller_pkgname);
679 /* LCOV_EXCL_START */
680 EXPORT_API int notification_get_count(notification_type_e type,
683 int priv_id, int *count)
685 return notification_get_count_for_uid(type, pkgname, group_id, priv_id, count, getuid());
688 int notification_clear_for_uid(notification_type_e type, uid_t uid)
692 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
693 return NOTIFICATION_ERROR_INVALID_PARAMETER;
695 ret = notification_ipc_request_delete_multiple(type, NULL, uid);
701 /* LCOV_EXCL_START */
702 EXPORT_API int notification_clear(notification_type_e type)
704 return notification_clear_for_uid(type, getuid());
707 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
710 if (noti_op == NULL || data == NULL)
711 return NOTIFICATION_ERROR_INVALID_PARAMETER;
714 case NOTIFICATION_OP_DATA_TYPE:
715 *((int *)data) = noti_op->type;
717 case NOTIFICATION_OP_DATA_PRIV_ID:
718 *((int *)data) = noti_op->priv_id;
720 case NOTIFICATION_OP_DATA_NOTI:
721 *((notification_h *)data) = noti_op->noti;
723 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
724 *((int *)data) = noti_op->extra_info_1;
726 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
727 *((int *)data) = noti_op->extra_info_2;
730 return NOTIFICATION_ERROR_INVALID_PARAMETER;
734 return NOTIFICATION_ERROR_NONE;
738 /* LCOV_EXCL_START */
739 EXPORT_API int notification_set_pkgname(notification_h noti,
742 /* check noti and pkgname are valid data */
743 if (noti == NULL || pkgname == NULL)
744 return NOTIFICATION_ERROR_INVALID_PARAMETER;
746 /* Remove previous caller pkgname */
747 if (noti->caller_pkgname) {
748 free(noti->caller_pkgname);
749 noti->caller_pkgname = NULL;
752 noti->caller_pkgname = strdup(pkgname);
754 return NOTIFICATION_ERROR_NONE;
758 /* LCOV_EXCL_START */
759 int notification_delete_all_by_type_for_uid(const char *pkgname,
760 notification_type_e type, uid_t uid)
763 char *caller_pkgname = NULL;
765 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
766 return NOTIFICATION_ERROR_INVALID_PARAMETER;
769 caller_pkgname = notification_get_pkgname_by_pid();
771 caller_pkgname = strdup(pkgname);
773 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
776 free(caller_pkgname);
782 /* LCOV_EXCL_START */
783 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
784 notification_type_e type)
786 return notification_delete_all_by_type_for_uid(pkgname, type, getuid());
789 int notification_delete_by_priv_id_for_uid(const char *pkgname,
790 notification_type_e type,
795 char *caller_pkgname = NULL;
797 if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
798 return NOTIFICATION_ERROR_INVALID_PARAMETER;
801 caller_pkgname = notification_get_pkgname_by_pid();
803 caller_pkgname = strdup(pkgname);
805 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
808 free(caller_pkgname);
814 /* LCOV_EXCL_START */
815 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
816 notification_type_e type,
819 return notification_delete_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
822 EXPORT_API int notification_set_execute_option(notification_h noti,
823 notification_execute_type_e type,
826 bundle *service_handle)
828 char buf_key[32] = { 0, };
829 char *ret_val = NULL;
833 return NOTIFICATION_ERROR_INVALID_PARAMETER;
835 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
836 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
837 return NOTIFICATION_ERROR_INVALID_PARAMETER;
839 /* Create execute option bundle if does not exist */
840 if (noti->b_execute_option == NULL)
841 noti->b_execute_option = bundle_create();
843 b = noti->b_execute_option;
848 snprintf(buf_key, sizeof(buf_key), "text%d", type);
850 /* Check text key exist */
851 bundle_get_str(b, buf_key, &ret_val);
853 /* Remove previous data */
854 bundle_del(b, buf_key);
857 bundle_add_str(b, buf_key, text);
863 snprintf(buf_key, sizeof(buf_key), "key%d", type);
865 /* Check key key exist */
866 bundle_get_str(b, buf_key, &ret_val);
868 /* Remove previous data */
869 bundle_del(b, buf_key);
872 bundle_add_str(b, buf_key, key);
876 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
877 /* Remove previous data if exist */
878 if (noti->b_service_responding != NULL) {
879 bundle_free(noti->b_service_responding);
880 noti->b_service_responding = NULL;
883 /* Save service handle */
884 if (service_handle != NULL)
885 noti->b_service_responding = bundle_dup(service_handle);
888 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
889 /* Remove previous data if exist */
890 if (noti->b_service_single_launch != NULL) {
891 bundle_free(noti->b_service_single_launch);
892 noti->b_service_single_launch = NULL;
895 /* Save service handle */
896 if (service_handle != NULL)
897 noti->b_service_single_launch =
898 bundle_dup(service_handle);
901 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
902 /* Remove previous data if exist */
903 if (noti->b_service_multi_launch != NULL) {
904 bundle_free(noti->b_service_multi_launch);
905 noti->b_service_multi_launch = NULL;
908 /* Save service handle */
909 if (service_handle != NULL)
910 noti->b_service_multi_launch =
911 bundle_dup(service_handle);
916 return NOTIFICATION_ERROR_NONE;
920 /* LCOV_EXCL_START */
921 EXPORT_API int notification_get_id(notification_h noti,
922 int *group_id, int *priv_id)
924 /* check noti is valid data */
926 return NOTIFICATION_ERROR_INVALID_PARAMETER;
928 /* Check group_id is valid data */
931 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
932 *group_id = NOTIFICATION_GROUP_ID_NONE;
934 *group_id = noti->group_id;
937 /* Check priv_id is valid data */
940 *priv_id = noti->priv_id;
942 return NOTIFICATION_ERROR_NONE;
946 /* LCOV_EXCL_START */
947 notification_h notification_load_for_uid(char *pkgname,
948 int priv_id, uid_t uid)
951 notification_h noti = NULL;
953 noti = (notification_h)calloc(1, sizeof(struct _notification));
955 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
959 ret = notification_ipc_request_load_noti_by_priv_id(noti, pkgname, priv_id, uid);
960 if (ret != NOTIFICATION_ERROR_NONE) {
961 notification_free(noti);
969 /* LCOV_EXCL_START */
970 EXPORT_API notification_h notification_load(char *pkgname,
973 return notification_load_for_uid(pkgname, priv_id, getuid());
977 /* LCOV_EXCL_START */
978 EXPORT_API notification_h notification_new(notification_type_e type,
979 int group_id, int priv_id)
981 return notification_create(type);
984 static void _notification_get_text_domain(notification_h noti)
989 /* LCOV_EXCL_START */
990 EXPORT_API int notification_get_execute_option(notification_h noti,
991 notification_execute_type_e type,
993 bundle **service_handle)
995 char buf_key[32] = { 0, };
996 char *ret_val = NULL;
997 char *get_str = NULL;
1001 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1003 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1004 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
1005 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1009 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1010 b = noti->b_service_responding;
1012 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1013 b = noti->b_service_single_launch;
1015 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1016 b = noti->b_service_multi_launch;
1025 /* Get text domain and dir */
1026 if (noti->domain == NULL || noti->dir == NULL)
1027 _notification_get_text_domain(noti);
1030 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1032 /* Check key key exist */
1033 bundle_get_str(b, buf_key, &ret_val);
1034 if (ret_val != NULL && noti->domain != NULL
1035 && noti->dir != NULL) {
1036 /* Get application string */
1037 bindtextdomain(noti->domain, noti->dir);
1039 get_str = dgettext(noti->domain, ret_val);
1042 } else if (ret_val != NULL) {
1043 /* Get system string */
1044 get_str = dgettext("sys_string", ret_val);
1048 /* Get basic text */
1049 snprintf(buf_key, sizeof(buf_key), "text%d",
1052 bundle_get_str(b, buf_key, &ret_val);
1059 if (service_handle != NULL)
1060 *service_handle = b;
1062 return NOTIFICATION_ERROR_NONE;
1064 /* LCOV_EXCL_STOP */
1066 EXPORT_API int notification_insert_for_uid(notification_h noti,
1067 int *priv_id, uid_t uid)
1072 /* Check noti is vaild data */
1074 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1076 /* Check noti type is valid type */
1077 if (noti->type <= NOTIFICATION_TYPE_NONE
1078 || noti->type >= NOTIFICATION_TYPE_MAX)
1079 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1082 /* Save insert time */
1083 noti->insert_time = time(NULL);
1084 ret = notification_ipc_request_insert(noti, &id);
1085 if (ret != NOTIFICATION_ERROR_NONE)
1089 NOTIFICATION_DBG("from master:%d", id);
1091 /* If priv_id is valid data, set priv_id */
1092 if (priv_id != NULL)
1093 *priv_id = noti->priv_id;
1095 return NOTIFICATION_ERROR_NONE;
1098 EXPORT_API int notification_insert(notification_h noti,
1101 return notification_insert_for_uid(noti, priv_id, getuid());
1104 EXPORT_API int notification_update_async_for_uid(notification_h noti,
1105 void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
1109 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1112 /* Update insert time ? */
1113 noti->insert_time = time(NULL);
1114 ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1119 EXPORT_API int notification_update_async(notification_h noti,
1120 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1122 return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
1125 EXPORT_API int notification_register_detailed_changed_cb_for_uid(
1126 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1127 void *user_data, uid_t uid)
1129 GList *noti_cb_list = NULL;
1130 notification_cb_info_s *noti_cb_info_new = NULL;
1132 if (detailed_changed_cb == NULL)
1133 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1135 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE)
1136 return NOTIFICATION_ERROR_IO_ERROR;
1138 if (_noti_cb_hash == NULL)
1139 _noti_cb_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __free_changed_cb_hash);
1141 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
1142 if (noti_cb_info_new == NULL) {
1143 NOTIFICATION_ERR("malloc failed");
1144 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1147 noti_cb_info_new->cb_type = NOTIFICATION_CB_DETAILED;
1148 noti_cb_info_new->changed_cb = NULL;
1149 noti_cb_info_new->detailed_changed_cb = detailed_changed_cb;
1150 noti_cb_info_new->data = user_data;
1152 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1154 if (noti_cb_list == NULL) {
1155 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1156 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1158 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1161 return NOTIFICATION_ERROR_NONE;
1164 EXPORT_API int notification_register_detailed_changed_cb(
1165 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1168 return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1171 EXPORT_API int notification_unregister_detailed_changed_cb_for_uid(
1172 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1173 void *user_data, uid_t uid)
1175 notification_cb_info_s *noti_cb_info = NULL;
1176 GList *noti_cb_list = NULL;
1178 if (detailed_changed_cb == NULL)
1179 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1181 if (_noti_cb_hash == NULL)
1182 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1184 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1186 if (noti_cb_list == NULL)
1187 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1189 noti_cb_list = g_list_first(noti_cb_list);
1191 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
1192 noti_cb_info = noti_cb_list->data;
1193 if (noti_cb_info->detailed_changed_cb == detailed_changed_cb) {
1194 noti_cb_list = g_list_remove(g_list_first(noti_cb_list), noti_cb_info);
1196 if (noti_cb_list == NULL)
1197 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
1199 if (g_hash_table_size(_noti_cb_hash) == 0)
1200 notification_ipc_monitor_fini();
1202 return NOTIFICATION_ERROR_NONE;
1206 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1209 EXPORT_API int notification_unregister_detailed_changed_cb(
1210 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1213 return notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1216 /* LCOV_EXCL_START */
1217 EXPORT_API int notification_is_service_ready(void)
1219 return notification_ipc_is_master_ready();
1221 /* LCOV_EXCL_STOP */
1223 EXPORT_API int notification_set_uid(notification_h noti,
1227 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1230 return NOTIFICATION_ERROR_NONE;
1233 EXPORT_API int notification_get_uid(notification_h noti,
1236 if (noti == NULL || uid == NULL)
1237 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1240 return NOTIFICATION_ERROR_NONE;
1243 EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
1248 /* Check noti is vaild data */
1250 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1252 /* Check noti type is valid type */
1253 if (noti->type <= NOTIFICATION_TYPE_NONE
1254 || noti->type >= NOTIFICATION_TYPE_MAX)
1255 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1257 /* Save insert time */
1258 noti->insert_time = time(NULL);
1261 ret = notification_ipc_request_insert(noti, &id);
1262 if (ret != NOTIFICATION_ERROR_NONE)
1266 NOTIFICATION_DBG("from master:%d", id);
1268 return NOTIFICATION_ERROR_NONE;
1271 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
1275 /* Check noti is valid data */
1278 /* Update insert time ? */
1279 noti->insert_time = time(NULL);
1280 ret = notification_ipc_request_update(noti);
1282 notification_ipc_request_refresh(uid);
1283 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1289 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
1294 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1296 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id, uid);
1301 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
1304 char *caller_pkgname = NULL;
1306 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
1307 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1309 caller_pkgname = notification_get_pkgname_by_pid();
1311 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
1314 free(caller_pkgname);
1319 EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
1322 notification_h noti = NULL;
1323 char *caller_pkgname = NULL;
1326 NOTIFICATION_ERR("Invalid parameter");
1327 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1331 caller_pkgname = notification_get_pkgname_by_pid();
1332 if (!caller_pkgname) {
1333 /* LCOV_EXCL_START */
1334 NOTIFICATION_ERR("Failed to get a package name");
1335 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1337 /* LCOV_EXCL_STOP */
1340 noti = (notification_h)calloc(1, sizeof(struct _notification));
1342 /* LCOV_EXCL_START */
1343 NOTIFICATION_ERR("Failed to alloc a new notification");
1344 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1345 free(caller_pkgname);
1348 /* LCOV_EXCL_STOP */
1351 ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char *)tag, uid);
1352 free(caller_pkgname);
1354 set_last_result(ret);
1355 if (ret != NOTIFICATION_ERROR_NONE) {
1356 notification_free(noti);