diff options
Diffstat (limited to 'src/notifications/noti_event_manager.c')
-rwxr-xr-x | src/notifications/noti_event_manager.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/notifications/noti_event_manager.c b/src/notifications/noti_event_manager.c new file mode 100755 index 0000000..609d7b6 --- /dev/null +++ b/src/notifications/noti_event_manager.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2013 - 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common/log.h" +#include "common/callback_handler.h" +#include "notifications/noti_event_manager.h" + +#include <stdlib.h> + +static struct __noti_event_s { + callback_h *changed_cb_handler; +} s_info = { + .changed_cb_handler = NULL, +}; + +static void __notification_changed_cb(void *data, notification_type_e type, notification_op *operation_list, int operation_count); + +bool noti_event_manager_init(void) +{ + _D("%s", __func__); + + int ret = NOTIFICATION_ERROR_NONE; + + ret = notification_register_detailed_changed_cb(__notification_changed_cb, NULL); + + if (ret != NOTIFICATION_ERROR_NONE) { + _E("notification_register_detailed_changed_cb failed [%d]", ret); + return false; + } + + return true; +} + +void noti_event_manager_fini(void) +{ + callback_handler_free(s_info.changed_cb_handler); + s_info.changed_cb_handler = NULL; + + int ret = NOTIFICATION_ERROR_NONE; + ret = notification_unregister_detailed_changed_cb(__notification_changed_cb, NULL); + + if (ret != NOTIFICATION_ERROR_NONE) { + _E("notification_unregister_detailed_changed_cb failed [%d]", ret); + } +} + +void noti_event_manager_add_changed_cb(void(*cb)(void *noti_info)) +{ + if (s_info.changed_cb_handler == NULL) { + s_info.changed_cb_handler = callback_handler_new("noti_manager"); + } + + callback_handler_add_cb(s_info.changed_cb_handler, cb); +} + +void noti_event_manager_del_changed_cb(void(*cb)(void *noti_info)) +{ + callback_handler_del_cb(s_info.changed_cb_handler, cb); +} + +static void __notification_changed_cb(void *data, notification_type_e type, notification_op *operation_list, int operation_count) +{ + if (operation_list == NULL || operation_count < 1) { + _E("Invalid parameter"); + return; + } + + int i = 0; + noti_message_t *info = (noti_message_t *)malloc(sizeof(noti_message_t)); + if (info == NULL) { + _E("failed to malloc"); + return ; + } + + info->id = 0; + info->noti_handler = NULL; + info->operation_type = NOTIFICATION_OP_NONE; + for (i = 0; i < operation_count; i++) { + notification_op_get_data(operation_list + i, NOTIFICATION_OP_DATA_NOTI, &info->noti_handler); + notification_op_get_data(operation_list + i, NOTIFICATION_OP_DATA_PRIV_ID, &info->id); + notification_op_get_data(operation_list + i, NOTIFICATION_OP_DATA_TYPE, &info->operation_type); + + _D("notification id [%d], operation type [%d]", info->id, info->operation_type); + callback_handler_execute_cb(s_info.changed_cb_handler, info); + } +} |