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 return notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
339 /* notification_get_icon will be removed */
340 /* LCOV_EXCL_START */
341 EXPORT_API int notification_get_icon(notification_h noti,
344 int ret_err = NOTIFICATION_ERROR_NONE;
345 char *ret_image_path = NULL;
347 ret_err = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
350 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL)
351 *icon_path = ret_image_path;
357 EXPORT_API int notification_translate_localized_text(notification_h noti)
359 int noti_err = NOTIFICATION_ERROR_NONE;
360 char *ret_text = NULL;
362 char *bundle_val = NULL;
365 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
367 for (; type < NOTIFICATION_TEXT_TYPE_MAX; type++) {
368 noti_err = notification_get_text(noti, type, &ret_text);
369 if (noti_err == NOTIFICATION_ERROR_NONE && ret_text) {
370 if (noti->b_text == NULL) {
371 noti->b_text = bundle_create();
372 if (noti->b_text == NULL)
373 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
378 new_text = strdup(ret_text);
380 snprintf(buf_key, sizeof(buf_key), "%d", type);
381 bundle_get_str(b, buf_key, &bundle_val);
382 if (bundle_val != NULL)
383 bundle_del(b, buf_key);
385 bundle_add_str(b, buf_key, new_text);
389 noti->num_format_args = 0;
397 /* LCOV_EXCL_START */
398 EXPORT_API int notification_set_title(notification_h noti,
400 const char *loc_title)
402 return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
404 NOTIFICATION_VARIABLE_TYPE_NONE);;
408 /* LCOV_EXCL_START */
409 EXPORT_API int notification_get_title(notification_h noti,
413 int noti_err = NOTIFICATION_ERROR_NONE;
414 char *ret_text = NULL;
416 noti_err = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
422 if (loc_title != NULL)
429 /* LCOV_EXCL_START */
430 EXPORT_API int notification_set_content(notification_h noti,
432 const char *loc_content)
434 return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
435 content, loc_content,
436 NOTIFICATION_VARIABLE_TYPE_NONE);
440 /* LCOV_EXCL_START */
441 EXPORT_API int notification_get_content(notification_h noti,
445 int noti_err = NOTIFICATION_ERROR_NONE;
446 char *ret_text = NULL;
448 noti_err = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
454 if (loc_content != NULL)
461 /* LCOV_EXCL_START */
462 EXPORT_API int notification_set_application(notification_h noti,
465 if (noti == NULL || pkgname == NULL)
466 return NOTIFICATION_ERROR_INVALID_PARAMETER;
468 if (noti->launch_pkgname)
469 free(noti->launch_pkgname);
471 noti->launch_pkgname = strdup(pkgname);
473 return NOTIFICATION_ERROR_NONE;
477 /* LCOV_EXCL_START */
478 EXPORT_API int notification_get_application(notification_h noti,
481 if (noti == NULL || pkgname == NULL)
482 return NOTIFICATION_ERROR_INVALID_PARAMETER;
484 if (noti->launch_pkgname)
485 *pkgname = noti->launch_pkgname;
487 *pkgname = noti->caller_pkgname;
489 return NOTIFICATION_ERROR_NONE;
493 /* LCOV_EXCL_START */
494 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
497 if (noti == NULL || args == NULL)
498 return NOTIFICATION_ERROR_INVALID_PARAMETER;
501 bundle_free(noti->args);
503 noti->args = bundle_dup(args);
505 if (noti->group_args) {
506 bundle_free(noti->group_args);
507 noti->group_args = NULL;
510 if (group_args != NULL)
511 noti->group_args = bundle_dup(group_args);
513 return NOTIFICATION_ERROR_NONE;
517 /* LCOV_EXCL_START */
518 EXPORT_API int notification_get_args(notification_h noti,
522 if (noti == NULL || args == NULL)
523 return NOTIFICATION_ERROR_INVALID_PARAMETER;
530 if (group_args != NULL && noti->group_args)
531 *group_args = noti->group_args;
533 return NOTIFICATION_ERROR_NONE;
537 /* LCOV_EXCL_START */
538 int notification_get_grouping_list_for_uid(notification_type_e type, int count,
539 notification_list_h *list, uid_t uid)
541 notification_list_h get_list = NULL;
545 return NOTIFICATION_ERROR_INVALID_PARAMETER;
547 ret = notification_noti_get_grouping_list(type, count, &get_list, uid);
548 if (ret != NOTIFICATION_ERROR_NONE)
553 return NOTIFICATION_ERROR_NONE;
556 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
557 notification_list_h *list)
559 return notification_get_grouping_list_for_uid(type, count, list, getuid());
563 /* LCOV_EXCL_START */
564 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
565 notification_type_e type,
569 char *caller_pkgname = NULL;
572 caller_pkgname = notification_get_pkgname_by_pid();
574 caller_pkgname = strdup(pkgname);
576 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, getuid());
579 free(caller_pkgname);
585 /* LCOV_EXCL_START */
586 int notification_delete_group_by_priv_id_for_uid(const char *pkgname,
587 notification_type_e type,
588 int priv_id, uid_t uid)
591 char *caller_pkgname = NULL;
594 caller_pkgname = notification_get_pkgname_by_pid();
596 caller_pkgname = strdup(pkgname);
598 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
601 free(caller_pkgname);
607 /* LCOV_EXCL_START */
608 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
609 notification_type_e type,
612 return notification_delete_group_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
615 int notification_get_count_for_uid(notification_type_e type,
618 int priv_id, int *count,
622 char *caller_pkgname = NULL;
625 return NOTIFICATION_ERROR_INVALID_PARAMETER;
628 caller_pkgname = notification_get_pkgname_by_pid();
630 caller_pkgname = strdup(pkgname);
632 ret = notification_ipc_request_get_count(
641 free(caller_pkgname);
647 /* LCOV_EXCL_START */
648 EXPORT_API int notification_get_count(notification_type_e type,
651 int priv_id, int *count)
653 return notification_get_count_for_uid(type, pkgname, group_id, priv_id, count, getuid());
656 int notification_clear_for_uid(notification_type_e type, uid_t uid)
658 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
659 return NOTIFICATION_ERROR_INVALID_PARAMETER;
661 return notification_ipc_request_delete_multiple(type, NULL, uid);
665 /* LCOV_EXCL_START */
666 EXPORT_API int notification_clear(notification_type_e type)
668 return notification_clear_for_uid(type, getuid());
671 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
674 if (noti_op == NULL || data == NULL)
675 return NOTIFICATION_ERROR_INVALID_PARAMETER;
678 case NOTIFICATION_OP_DATA_TYPE:
679 *((int *)data) = noti_op->type;
681 case NOTIFICATION_OP_DATA_PRIV_ID:
682 *((int *)data) = noti_op->priv_id;
684 case NOTIFICATION_OP_DATA_NOTI:
685 *((notification_h *)data) = noti_op->noti;
687 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
688 *((int *)data) = noti_op->extra_info_1;
690 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
691 *((int *)data) = noti_op->extra_info_2;
694 return NOTIFICATION_ERROR_INVALID_PARAMETER;
698 return NOTIFICATION_ERROR_NONE;
702 /* LCOV_EXCL_START */
703 EXPORT_API int notification_set_pkgname(notification_h noti,
706 if (noti == NULL || pkgname == NULL)
707 return NOTIFICATION_ERROR_INVALID_PARAMETER;
709 /* Remove previous caller pkgname */
710 if (noti->caller_pkgname) {
711 free(noti->caller_pkgname);
712 noti->caller_pkgname = NULL;
715 noti->caller_pkgname = strdup(pkgname);
717 return NOTIFICATION_ERROR_NONE;
721 /* LCOV_EXCL_START */
722 int notification_delete_all_by_type_for_uid(const char *pkgname,
723 notification_type_e type, uid_t uid)
726 char *caller_pkgname = NULL;
728 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
729 return NOTIFICATION_ERROR_INVALID_PARAMETER;
732 caller_pkgname = notification_get_pkgname_by_pid();
734 caller_pkgname = strdup(pkgname);
736 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
739 free(caller_pkgname);
745 /* LCOV_EXCL_START */
746 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
747 notification_type_e type)
749 return notification_delete_all_by_type_for_uid(pkgname, type, getuid());
752 int notification_delete_by_priv_id_for_uid(const char *pkgname,
753 notification_type_e type,
758 char *caller_pkgname = NULL;
760 if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
761 return NOTIFICATION_ERROR_INVALID_PARAMETER;
764 caller_pkgname = notification_get_pkgname_by_pid();
766 caller_pkgname = strdup(pkgname);
768 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
771 free(caller_pkgname);
777 /* LCOV_EXCL_START */
778 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
779 notification_type_e type,
782 return notification_delete_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
785 EXPORT_API int notification_set_execute_option(notification_h noti,
786 notification_execute_type_e type,
789 bundle *service_handle)
791 char buf_key[32] = { 0, };
792 char *ret_val = NULL;
796 return NOTIFICATION_ERROR_INVALID_PARAMETER;
798 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
799 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
800 return NOTIFICATION_ERROR_INVALID_PARAMETER;
802 if (noti->b_execute_option == NULL)
803 noti->b_execute_option = bundle_create();
805 b = noti->b_execute_option;
808 snprintf(buf_key, sizeof(buf_key), "text%d", type);
810 bundle_get_str(b, buf_key, &ret_val);
812 bundle_del(b, buf_key);
814 bundle_add_str(b, buf_key, text);
818 snprintf(buf_key, sizeof(buf_key), "key%d", type);
820 bundle_get_str(b, buf_key, &ret_val);
822 bundle_del(b, buf_key);
824 bundle_add_str(b, buf_key, key);
828 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
829 if (noti->b_service_responding != NULL) {
830 bundle_free(noti->b_service_responding);
831 noti->b_service_responding = NULL;
834 if (service_handle != NULL)
835 noti->b_service_responding = bundle_dup(service_handle);
838 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
839 if (noti->b_service_single_launch != NULL) {
840 bundle_free(noti->b_service_single_launch);
841 noti->b_service_single_launch = NULL;
844 if (service_handle != NULL)
845 noti->b_service_single_launch =
846 bundle_dup(service_handle);
849 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
850 if (noti->b_service_multi_launch != NULL) {
851 bundle_free(noti->b_service_multi_launch);
852 noti->b_service_multi_launch = NULL;
855 if (service_handle != NULL)
856 noti->b_service_multi_launch =
857 bundle_dup(service_handle);
862 return NOTIFICATION_ERROR_NONE;
866 /* LCOV_EXCL_START */
867 EXPORT_API int notification_get_id(notification_h noti,
868 int *group_id, int *priv_id)
871 return NOTIFICATION_ERROR_INVALID_PARAMETER;
874 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
875 *group_id = NOTIFICATION_GROUP_ID_NONE;
877 *group_id = noti->group_id;
881 *priv_id = noti->priv_id;
883 return NOTIFICATION_ERROR_NONE;
887 /* LCOV_EXCL_START */
888 notification_h notification_load_for_uid(char *pkgname,
889 int priv_id, uid_t uid)
892 notification_h noti = NULL;
894 noti = (notification_h)calloc(1, sizeof(struct _notification));
896 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
900 ret = notification_ipc_request_load_noti_by_priv_id(noti, pkgname, priv_id, uid);
901 if (ret != NOTIFICATION_ERROR_NONE) {
902 notification_free(noti);
910 /* LCOV_EXCL_START */
911 EXPORT_API notification_h notification_load(char *pkgname,
914 return notification_load_for_uid(pkgname, priv_id, getuid());
918 /* LCOV_EXCL_START */
919 EXPORT_API notification_h notification_new(notification_type_e type,
920 int group_id, int priv_id)
922 return notification_create(type);
925 static void _notification_get_text_domain(notification_h noti)
930 /* LCOV_EXCL_START */
931 EXPORT_API int notification_get_execute_option(notification_h noti,
932 notification_execute_type_e type,
934 bundle **service_handle)
936 char buf_key[32] = { 0, };
937 char *ret_val = NULL;
938 char *get_str = NULL;
942 return NOTIFICATION_ERROR_INVALID_PARAMETER;
944 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
945 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
946 return NOTIFICATION_ERROR_INVALID_PARAMETER;
950 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
951 b = noti->b_service_responding;
953 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
954 b = noti->b_service_single_launch;
956 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
957 b = noti->b_service_multi_launch;
965 if (noti->domain == NULL || noti->dir == NULL)
966 _notification_get_text_domain(noti);
968 snprintf(buf_key, sizeof(buf_key), "key%d", type);
970 bundle_get_str(b, buf_key, &ret_val);
971 if (ret_val != NULL && noti->domain != NULL
972 && noti->dir != NULL) {
973 bindtextdomain(noti->domain, noti->dir);
975 get_str = dgettext(noti->domain, ret_val);
978 } else if (ret_val != NULL) {
979 get_str = dgettext("sys_string", ret_val);
983 snprintf(buf_key, sizeof(buf_key), "text%d",
986 bundle_get_str(b, buf_key, &ret_val);
993 if (service_handle != NULL)
996 return NOTIFICATION_ERROR_NONE;
1000 EXPORT_API int notification_insert_for_uid(notification_h noti,
1001 int *priv_id, uid_t uid)
1007 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1009 if (noti->type <= NOTIFICATION_TYPE_NONE
1010 || noti->type >= NOTIFICATION_TYPE_MAX)
1011 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1014 noti->insert_time = time(NULL);
1016 ret = notification_ipc_request_insert(noti, &id);
1017 if (ret != NOTIFICATION_ERROR_NONE)
1021 NOTIFICATION_DBG("from master:%d", id);
1023 /* If priv_id is valid data, set priv_id */
1024 if (priv_id != NULL)
1025 *priv_id = noti->priv_id;
1027 return NOTIFICATION_ERROR_NONE;
1030 EXPORT_API int notification_insert(notification_h noti,
1033 return notification_insert_for_uid(noti, priv_id, getuid());
1036 EXPORT_API int notification_update_async_for_uid(notification_h noti,
1037 void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
1040 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1043 /* Update insert time ? */
1044 noti->insert_time = time(NULL);
1046 return notification_ipc_request_update_async(noti, result_cb, user_data);
1049 EXPORT_API int notification_update_async(notification_h noti,
1050 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1052 return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
1055 EXPORT_API int notification_register_detailed_changed_cb_for_uid(
1056 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1057 void *user_data, uid_t uid)
1059 GList *noti_cb_list = NULL;
1060 notification_cb_info_s *noti_cb_info_new = NULL;
1062 if (detailed_changed_cb == NULL)
1063 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1065 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE)
1066 return NOTIFICATION_ERROR_IO_ERROR;
1068 if (_noti_cb_hash == NULL)
1069 _noti_cb_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __free_changed_cb_hash);
1071 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
1072 if (noti_cb_info_new == NULL) {
1073 NOTIFICATION_ERR("malloc failed");
1074 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1077 noti_cb_info_new->cb_type = NOTIFICATION_CB_DETAILED;
1078 noti_cb_info_new->changed_cb = NULL;
1079 noti_cb_info_new->detailed_changed_cb = detailed_changed_cb;
1080 noti_cb_info_new->data = user_data;
1082 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1084 if (noti_cb_list == NULL) {
1085 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1086 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1088 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1091 return NOTIFICATION_ERROR_NONE;
1094 EXPORT_API int notification_register_detailed_changed_cb(
1095 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1098 return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1101 EXPORT_API int notification_unregister_detailed_changed_cb_for_uid(
1102 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1103 void *user_data, uid_t uid)
1105 notification_cb_info_s *noti_cb_info = NULL;
1106 GList *noti_cb_list = NULL;
1108 if (detailed_changed_cb == NULL)
1109 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1111 if (_noti_cb_hash == NULL)
1112 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1114 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1116 if (noti_cb_list == NULL)
1117 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1119 noti_cb_list = g_list_first(noti_cb_list);
1121 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
1122 noti_cb_info = noti_cb_list->data;
1123 if (noti_cb_info->detailed_changed_cb == detailed_changed_cb) {
1124 noti_cb_list = g_list_remove(g_list_first(noti_cb_list), noti_cb_info);
1126 if (noti_cb_list == NULL)
1127 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
1129 if (g_hash_table_size(_noti_cb_hash) == 0)
1130 notification_ipc_monitor_fini();
1132 return NOTIFICATION_ERROR_NONE;
1136 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1139 EXPORT_API int notification_unregister_detailed_changed_cb(
1140 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1143 return notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1146 /* LCOV_EXCL_START */
1147 EXPORT_API int notification_is_service_ready(void)
1149 return notification_ipc_is_master_ready();
1151 /* LCOV_EXCL_STOP */
1153 EXPORT_API int notification_set_uid(notification_h noti,
1157 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1160 return NOTIFICATION_ERROR_NONE;
1163 EXPORT_API int notification_get_uid(notification_h noti,
1166 if (noti == NULL || uid == NULL)
1167 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1170 return NOTIFICATION_ERROR_NONE;
1173 EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
1179 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1181 if (noti->type <= NOTIFICATION_TYPE_NONE
1182 || noti->type >= NOTIFICATION_TYPE_MAX)
1183 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1185 /* Save insert time */
1186 noti->insert_time = time(NULL);
1189 ret = notification_ipc_request_insert(noti, &id);
1190 if (ret != NOTIFICATION_ERROR_NONE)
1194 NOTIFICATION_DBG("from master:%d", id);
1196 return NOTIFICATION_ERROR_NONE;
1199 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
1202 notification_ipc_request_refresh(uid);
1203 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1207 /* Update insert time ? */
1208 noti->insert_time = time(NULL);
1210 return notification_ipc_request_update(noti);
1213 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
1217 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1219 return notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE,
1220 noti->caller_pkgname, noti->priv_id, uid);
1223 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
1226 char *caller_pkgname = NULL;
1228 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
1229 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1231 caller_pkgname = notification_get_pkgname_by_pid();
1233 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
1236 free(caller_pkgname);
1241 EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
1244 notification_h noti = NULL;
1245 char *caller_pkgname = NULL;
1248 NOTIFICATION_ERR("Invalid parameter");
1249 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1253 caller_pkgname = notification_get_pkgname_by_pid();
1254 if (!caller_pkgname) {
1255 /* LCOV_EXCL_START */
1256 NOTIFICATION_ERR("Failed to get a package name");
1257 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1259 /* LCOV_EXCL_STOP */
1262 noti = (notification_h)calloc(1, sizeof(struct _notification));
1264 /* LCOV_EXCL_START */
1265 NOTIFICATION_ERR("Failed to alloc a new notification");
1266 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1267 free(caller_pkgname);
1270 /* LCOV_EXCL_STOP */
1273 ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char *)tag, uid);
1274 free(caller_pkgname);
1276 set_last_result(ret);
1277 if (ret != NOTIFICATION_ERROR_NONE) {
1278 notification_free(noti);
1285 EXPORT_API notification_h notification_create_from_package_template(const char *pkgname, const char *template_name)
1288 notification_h noti = NULL;
1290 if (pkgname == NULL || template_name == NULL) {
1291 NOTIFICATION_ERR("Invalid parameter");
1292 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1296 noti = (notification_h)calloc(1, sizeof(struct _notification));
1298 NOTIFICATION_ERR("Failed to alloc a new notification");
1299 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1303 ret = notification_ipc_request_create_from_package_template(noti, pkgname, template_name);
1305 set_last_result(ret);
1306 if (ret != NOTIFICATION_ERROR_NONE) {
1307 notification_free(noti);
1314 int notification_set_default_button(notification_h noti, notification_button_index_e index)
1317 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1319 if (index < 0 && index > NOTIFICATION_BUTTON_6)
1320 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1322 noti->default_button_index = index;
1324 return NOTIFICATION_ERROR_NONE;
1327 int notification_get_default_button(notification_h noti, notification_button_index_e *index)
1329 if (noti == NULL || index == NULL)
1330 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1332 *index = noti->default_button_index;
1334 return NOTIFICATION_ERROR_NONE;