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;
402 bundle_free(noti->b_key);
409 /* LCOV_EXCL_START */
410 EXPORT_API int notification_set_title(notification_h noti,
412 const char *loc_title)
414 int noti_err = NOTIFICATION_ERROR_NONE;
416 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
418 NOTIFICATION_VARIABLE_TYPE_NONE);
424 /* LCOV_EXCL_START */
425 EXPORT_API int notification_get_title(notification_h noti,
429 int noti_err = NOTIFICATION_ERROR_NONE;
430 char *ret_text = NULL;
433 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
439 if (loc_title != NULL)
446 /* LCOV_EXCL_START */
447 EXPORT_API int notification_set_content(notification_h noti,
449 const char *loc_content)
451 int noti_err = NOTIFICATION_ERROR_NONE;
453 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
454 content, loc_content,
455 NOTIFICATION_VARIABLE_TYPE_NONE);
461 /* LCOV_EXCL_START */
462 EXPORT_API int notification_get_content(notification_h noti,
466 int noti_err = NOTIFICATION_ERROR_NONE;
467 char *ret_text = NULL;
470 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
476 if (loc_content != NULL)
484 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
486 if (ret == -1 || boolval == 0) {
487 if (content != NULL && noti->default_content != NULL)
488 *content = noti->default_content;
490 if (loc_content != NULL && noti->loc_default_content != NULL)
491 *loc_content = noti->loc_default_content;
497 /* LCOV_EXCL_START */
498 EXPORT_API int notification_set_application(notification_h noti,
501 if (noti == NULL || pkgname == NULL)
502 return NOTIFICATION_ERROR_INVALID_PARAMETER;
504 if (noti->launch_pkgname)
505 free(noti->launch_pkgname);
507 noti->launch_pkgname = strdup(pkgname);
509 return NOTIFICATION_ERROR_NONE;
513 /* LCOV_EXCL_START */
514 EXPORT_API int notification_get_application(notification_h noti,
517 if (noti == NULL || pkgname == NULL)
518 return NOTIFICATION_ERROR_INVALID_PARAMETER;
520 if (noti->launch_pkgname)
521 *pkgname = noti->launch_pkgname;
523 *pkgname = noti->caller_pkgname;
525 return NOTIFICATION_ERROR_NONE;
529 /* LCOV_EXCL_START */
530 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
533 if (noti == NULL || args == NULL)
534 return NOTIFICATION_ERROR_INVALID_PARAMETER;
537 bundle_free(noti->args);
539 noti->args = bundle_dup(args);
541 if (noti->group_args) {
542 bundle_free(noti->group_args);
543 noti->group_args = NULL;
546 if (group_args != NULL)
547 noti->group_args = bundle_dup(group_args);
549 return NOTIFICATION_ERROR_NONE;
553 /* LCOV_EXCL_START */
554 EXPORT_API int notification_get_args(notification_h noti,
558 if (noti == NULL || args == NULL)
559 return NOTIFICATION_ERROR_INVALID_PARAMETER;
566 if (group_args != NULL && noti->group_args)
567 *group_args = noti->group_args;
569 return NOTIFICATION_ERROR_NONE;
573 /* LCOV_EXCL_START */
574 int notification_get_grouping_list_for_uid(notification_type_e type, int count,
575 notification_list_h *list, uid_t uid)
577 notification_list_h get_list = NULL;
581 return NOTIFICATION_ERROR_INVALID_PARAMETER;
583 ret = notification_noti_get_grouping_list(type, count, &get_list, uid);
584 if (ret != NOTIFICATION_ERROR_NONE)
589 return NOTIFICATION_ERROR_NONE;
592 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
593 notification_list_h *list)
595 return notification_get_grouping_list_for_uid(type, count, list, getuid());
599 /* LCOV_EXCL_START */
600 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
601 notification_type_e type,
605 char *caller_pkgname = NULL;
608 caller_pkgname = notification_get_pkgname_by_pid();
610 caller_pkgname = strdup(pkgname);
612 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, getuid());
615 free(caller_pkgname);
621 /* LCOV_EXCL_START */
622 int notification_delete_group_by_priv_id_for_uid(const char *pkgname,
623 notification_type_e type,
624 int priv_id, uid_t uid)
627 char *caller_pkgname = NULL;
630 caller_pkgname = notification_get_pkgname_by_pid();
632 caller_pkgname = strdup(pkgname);
634 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
637 free(caller_pkgname);
643 /* LCOV_EXCL_START */
644 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
645 notification_type_e type,
648 return notification_delete_group_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
651 int notification_get_count_for_uid(notification_type_e type,
654 int priv_id, int *count,
658 char *caller_pkgname = NULL;
661 return NOTIFICATION_ERROR_INVALID_PARAMETER;
664 caller_pkgname = notification_get_pkgname_by_pid();
666 caller_pkgname = strdup(pkgname);
668 ret = notification_ipc_request_get_count(
677 free(caller_pkgname);
683 /* LCOV_EXCL_START */
684 EXPORT_API int notification_get_count(notification_type_e type,
687 int priv_id, int *count)
689 return notification_get_count_for_uid(type, pkgname, group_id, priv_id, count, getuid());
692 int notification_clear_for_uid(notification_type_e type, uid_t uid)
696 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
697 return NOTIFICATION_ERROR_INVALID_PARAMETER;
699 ret = notification_ipc_request_delete_multiple(type, NULL, uid);
705 /* LCOV_EXCL_START */
706 EXPORT_API int notification_clear(notification_type_e type)
708 return notification_clear_for_uid(type, getuid());
711 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
714 if (noti_op == NULL || data == NULL)
715 return NOTIFICATION_ERROR_INVALID_PARAMETER;
718 case NOTIFICATION_OP_DATA_TYPE:
719 *((int *)data) = noti_op->type;
721 case NOTIFICATION_OP_DATA_PRIV_ID:
722 *((int *)data) = noti_op->priv_id;
724 case NOTIFICATION_OP_DATA_NOTI:
725 *((notification_h *)data) = noti_op->noti;
727 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
728 *((int *)data) = noti_op->extra_info_1;
730 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
731 *((int *)data) = noti_op->extra_info_2;
734 return NOTIFICATION_ERROR_INVALID_PARAMETER;
738 return NOTIFICATION_ERROR_NONE;
742 /* LCOV_EXCL_START */
743 EXPORT_API int notification_set_pkgname(notification_h noti,
746 /* check noti and pkgname are valid data */
747 if (noti == NULL || pkgname == NULL)
748 return NOTIFICATION_ERROR_INVALID_PARAMETER;
750 /* Remove previous caller pkgname */
751 if (noti->caller_pkgname) {
752 free(noti->caller_pkgname);
753 noti->caller_pkgname = NULL;
756 noti->caller_pkgname = strdup(pkgname);
758 return NOTIFICATION_ERROR_NONE;
762 /* LCOV_EXCL_START */
763 int notification_delete_all_by_type_for_uid(const char *pkgname,
764 notification_type_e type, uid_t uid)
767 char *caller_pkgname = NULL;
769 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
770 return NOTIFICATION_ERROR_INVALID_PARAMETER;
773 caller_pkgname = notification_get_pkgname_by_pid();
775 caller_pkgname = strdup(pkgname);
777 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
780 free(caller_pkgname);
786 /* LCOV_EXCL_START */
787 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
788 notification_type_e type)
790 return notification_delete_all_by_type_for_uid(pkgname, type, getuid());
793 int notification_delete_by_priv_id_for_uid(const char *pkgname,
794 notification_type_e type,
799 char *caller_pkgname = NULL;
801 if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
802 return NOTIFICATION_ERROR_INVALID_PARAMETER;
805 caller_pkgname = notification_get_pkgname_by_pid();
807 caller_pkgname = strdup(pkgname);
809 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
812 free(caller_pkgname);
818 /* LCOV_EXCL_START */
819 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
820 notification_type_e type,
823 return notification_delete_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
826 EXPORT_API int notification_set_execute_option(notification_h noti,
827 notification_execute_type_e type,
830 bundle *service_handle)
832 char buf_key[32] = { 0, };
833 char *ret_val = NULL;
837 return NOTIFICATION_ERROR_INVALID_PARAMETER;
839 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
840 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
841 return NOTIFICATION_ERROR_INVALID_PARAMETER;
843 /* Create execute option bundle if does not exist */
844 if (noti->b_execute_option == NULL)
845 noti->b_execute_option = bundle_create();
847 b = noti->b_execute_option;
852 snprintf(buf_key, sizeof(buf_key), "text%d", type);
854 /* Check text key exist */
855 bundle_get_str(b, buf_key, &ret_val);
857 /* Remove previous data */
858 bundle_del(b, buf_key);
861 bundle_add_str(b, buf_key, text);
867 snprintf(buf_key, sizeof(buf_key), "key%d", type);
869 /* Check key key exist */
870 bundle_get_str(b, buf_key, &ret_val);
872 /* Remove previous data */
873 bundle_del(b, buf_key);
876 bundle_add_str(b, buf_key, key);
880 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
881 /* Remove previous data if exist */
882 if (noti->b_service_responding != NULL) {
883 bundle_free(noti->b_service_responding);
884 noti->b_service_responding = NULL;
887 /* Save service handle */
888 if (service_handle != NULL)
889 noti->b_service_responding = bundle_dup(service_handle);
892 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
893 /* Remove previous data if exist */
894 if (noti->b_service_single_launch != NULL) {
895 bundle_free(noti->b_service_single_launch);
896 noti->b_service_single_launch = NULL;
899 /* Save service handle */
900 if (service_handle != NULL)
901 noti->b_service_single_launch =
902 bundle_dup(service_handle);
905 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
906 /* Remove previous data if exist */
907 if (noti->b_service_multi_launch != NULL) {
908 bundle_free(noti->b_service_multi_launch);
909 noti->b_service_multi_launch = NULL;
912 /* Save service handle */
913 if (service_handle != NULL)
914 noti->b_service_multi_launch =
915 bundle_dup(service_handle);
920 return NOTIFICATION_ERROR_NONE;
924 /* LCOV_EXCL_START */
925 EXPORT_API int notification_get_id(notification_h noti,
926 int *group_id, int *priv_id)
928 /* check noti is valid data */
930 return NOTIFICATION_ERROR_INVALID_PARAMETER;
932 /* Check group_id is valid data */
935 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
936 *group_id = NOTIFICATION_GROUP_ID_NONE;
938 *group_id = noti->group_id;
941 /* Check priv_id is valid data */
944 *priv_id = noti->priv_id;
946 return NOTIFICATION_ERROR_NONE;
950 /* LCOV_EXCL_START */
951 notification_h notification_load_for_uid(char *pkgname,
952 int priv_id, uid_t uid)
955 notification_h noti = NULL;
957 noti = (notification_h)calloc(1, sizeof(struct _notification));
959 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
963 ret = notification_ipc_request_load_noti_by_priv_id(noti, pkgname, priv_id, uid);
964 if (ret != NOTIFICATION_ERROR_NONE) {
965 notification_free(noti);
973 /* LCOV_EXCL_START */
974 EXPORT_API notification_h notification_load(char *pkgname,
977 return notification_load_for_uid(pkgname, priv_id, getuid());
981 /* LCOV_EXCL_START */
982 EXPORT_API notification_h notification_new(notification_type_e type,
983 int group_id, int priv_id)
985 return notification_create(type);
988 static void _notification_get_text_domain(notification_h noti)
993 /* LCOV_EXCL_START */
994 EXPORT_API int notification_get_execute_option(notification_h noti,
995 notification_execute_type_e type,
997 bundle **service_handle)
999 char buf_key[32] = { 0, };
1000 char *ret_val = NULL;
1001 char *get_str = NULL;
1005 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1007 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1008 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
1009 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1013 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1014 b = noti->b_service_responding;
1016 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1017 b = noti->b_service_single_launch;
1019 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1020 b = noti->b_service_multi_launch;
1029 /* Get text domain and dir */
1030 if (noti->domain == NULL || noti->dir == NULL)
1031 _notification_get_text_domain(noti);
1034 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1036 /* Check key key exist */
1037 bundle_get_str(b, buf_key, &ret_val);
1038 if (ret_val != NULL && noti->domain != NULL
1039 && noti->dir != NULL) {
1040 /* Get application string */
1041 bindtextdomain(noti->domain, noti->dir);
1043 get_str = dgettext(noti->domain, ret_val);
1046 } else if (ret_val != NULL) {
1047 /* Get system string */
1048 get_str = dgettext("sys_string", ret_val);
1052 /* Get basic text */
1053 snprintf(buf_key, sizeof(buf_key), "text%d",
1056 bundle_get_str(b, buf_key, &ret_val);
1063 if (service_handle != NULL)
1064 *service_handle = b;
1066 return NOTIFICATION_ERROR_NONE;
1068 /* LCOV_EXCL_STOP */
1070 EXPORT_API int notification_insert_for_uid(notification_h noti,
1071 int *priv_id, uid_t uid)
1076 /* Check noti is vaild data */
1078 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1080 /* Check noti type is valid type */
1081 if (noti->type <= NOTIFICATION_TYPE_NONE
1082 || noti->type >= NOTIFICATION_TYPE_MAX)
1083 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1086 /* Save insert time */
1087 noti->insert_time = time(NULL);
1088 ret = notification_ipc_request_insert(noti, &id);
1089 if (ret != NOTIFICATION_ERROR_NONE)
1093 NOTIFICATION_DBG("from master:%d", id);
1095 /* If priv_id is valid data, set priv_id */
1096 if (priv_id != NULL)
1097 *priv_id = noti->priv_id;
1099 return NOTIFICATION_ERROR_NONE;
1102 EXPORT_API int notification_insert(notification_h noti,
1105 return notification_insert_for_uid(noti, priv_id, getuid());
1108 EXPORT_API int notification_update_async_for_uid(notification_h noti,
1109 void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
1113 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1116 /* Update insert time ? */
1117 noti->insert_time = time(NULL);
1118 ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1123 EXPORT_API int notification_update_async(notification_h noti,
1124 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1126 return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
1129 EXPORT_API int notification_register_detailed_changed_cb_for_uid(
1130 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1131 void *user_data, uid_t uid)
1133 GList *noti_cb_list = NULL;
1134 notification_cb_info_s *noti_cb_info_new = NULL;
1136 if (detailed_changed_cb == NULL)
1137 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1139 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE)
1140 return NOTIFICATION_ERROR_IO_ERROR;
1142 if (_noti_cb_hash == NULL)
1143 _noti_cb_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __free_changed_cb_hash);
1145 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
1146 if (noti_cb_info_new == NULL) {
1147 NOTIFICATION_ERR("malloc failed");
1148 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1151 noti_cb_info_new->cb_type = NOTIFICATION_CB_DETAILED;
1152 noti_cb_info_new->changed_cb = NULL;
1153 noti_cb_info_new->detailed_changed_cb = detailed_changed_cb;
1154 noti_cb_info_new->data = user_data;
1156 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1158 if (noti_cb_list == NULL) {
1159 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1160 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1162 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1165 return NOTIFICATION_ERROR_NONE;
1168 EXPORT_API int notification_register_detailed_changed_cb(
1169 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1172 return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1175 EXPORT_API int notification_unregister_detailed_changed_cb_for_uid(
1176 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1177 void *user_data, uid_t uid)
1179 notification_cb_info_s *noti_cb_info = NULL;
1180 GList *noti_cb_list = NULL;
1182 if (detailed_changed_cb == NULL)
1183 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1185 if (_noti_cb_hash == NULL)
1186 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1188 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1190 if (noti_cb_list == NULL)
1191 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1193 noti_cb_list = g_list_first(noti_cb_list);
1195 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
1196 noti_cb_info = noti_cb_list->data;
1197 if (noti_cb_info->detailed_changed_cb == detailed_changed_cb) {
1198 noti_cb_list = g_list_remove(g_list_first(noti_cb_list), noti_cb_info);
1200 if (noti_cb_list == NULL)
1201 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
1203 if (g_hash_table_size(_noti_cb_hash) == 0)
1204 notification_ipc_monitor_fini();
1206 return NOTIFICATION_ERROR_NONE;
1210 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1213 EXPORT_API int notification_unregister_detailed_changed_cb(
1214 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1217 return notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1220 /* LCOV_EXCL_START */
1221 EXPORT_API int notification_is_service_ready(void)
1223 return notification_ipc_is_master_ready();
1225 /* LCOV_EXCL_STOP */
1227 EXPORT_API int notification_set_uid(notification_h noti,
1231 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1234 return NOTIFICATION_ERROR_NONE;
1237 EXPORT_API int notification_get_uid(notification_h noti,
1240 if (noti == NULL || uid == NULL)
1241 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1244 return NOTIFICATION_ERROR_NONE;
1247 EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
1252 /* Check noti is vaild data */
1254 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1256 /* Check noti type is valid type */
1257 if (noti->type <= NOTIFICATION_TYPE_NONE
1258 || noti->type >= NOTIFICATION_TYPE_MAX)
1259 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1261 /* Save insert time */
1262 noti->insert_time = time(NULL);
1265 ret = notification_ipc_request_insert(noti, &id);
1266 if (ret != NOTIFICATION_ERROR_NONE)
1270 NOTIFICATION_DBG("from master:%d", id);
1272 return NOTIFICATION_ERROR_NONE;
1275 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
1279 /* Check noti is valid data */
1282 /* Update insert time ? */
1283 noti->insert_time = time(NULL);
1284 ret = notification_ipc_request_update(noti);
1286 notification_ipc_request_refresh(uid);
1287 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1293 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
1298 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1300 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id, uid);
1305 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
1308 char *caller_pkgname = NULL;
1310 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
1311 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1313 caller_pkgname = notification_get_pkgname_by_pid();
1315 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
1318 free(caller_pkgname);
1323 EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
1326 notification_h noti = NULL;
1327 char *caller_pkgname = NULL;
1330 NOTIFICATION_ERR("Invalid parameter");
1331 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1335 caller_pkgname = notification_get_pkgname_by_pid();
1336 if (!caller_pkgname) {
1337 /* LCOV_EXCL_START */
1338 NOTIFICATION_ERR("Failed to get a package name");
1339 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1341 /* LCOV_EXCL_STOP */
1344 noti = (notification_h)calloc(1, sizeof(struct _notification));
1346 /* LCOV_EXCL_START */
1347 NOTIFICATION_ERR("Failed to alloc a new notification");
1348 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1349 free(caller_pkgname);
1352 /* LCOV_EXCL_STOP */
1355 ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char *)tag, uid);
1356 free(caller_pkgname);
1358 set_last_result(ret);
1359 if (ret != NOTIFICATION_ERROR_NONE) {
1360 notification_free(noti);