-EXPORT_API int notification_update_content(notification_h noti,
- int priv_id,
- const char *content)
-{
- char *caller_pkgname = NULL;
- int input_priv_id = 0;
- int ret = 0;
-
- if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
- if (noti == NULL) {
- return NOTIFICATION_ERROR_INVALID_PARAMETER;
- } else {
- input_priv_id = noti->priv_id;
- }
- } else {
- input_priv_id = priv_id;
- }
-
- if (noti == NULL) {
- caller_pkgname = _notification_get_pkgname_by_pid();
- } else {
- caller_pkgname = strdup(noti->caller_pkgname);
- }
-
- ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
- content);
-
- if (caller_pkgname) {
- free(caller_pkgname);
- }
-
- return ret;
-}
-
-static notification_h _notification_create(notification_type_e type)
-{
- notification_h noti = NULL;
-
- if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
- NOTIFICATION_ERR("INVALID TYPE : %d", type);
- set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- noti = (notification_h) calloc(1, sizeof(struct _notification));
- if (noti == NULL) {
- NOTIFICATION_ERR("NO MEMORY : noti == NULL");
- set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
- return NULL;
- }
-
- noti->type = type;
-
- if (type == NOTIFICATION_TYPE_NOTI)
- noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
- else if (type == NOTIFICATION_TYPE_ONGOING)
- noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
-
- noti->caller_pkgname = _notification_get_pkgname_by_pid();
- noti->group_id = NOTIFICATION_GROUP_ID_NONE;
- noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
- noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
- noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
- noti->led_operation = NOTIFICATION_LED_OP_OFF;
- noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
- /*!
- * \NOTE
- * Other fields are already initialized with ZERO.
- */
- set_last_result(NOTIFICATION_ERROR_NONE);
- return noti;
-}
-
-EXPORT_API notification_h notification_new(notification_type_e type,
- int group_id, int priv_id)
-{
- return _notification_create(type);
-}
-
-EXPORT_API notification_h notification_create(notification_type_e type)
-{
- return _notification_create(type);
-}
-
-EXPORT_API notification_h notification_load(char *pkgname,
- int priv_id)
-{
- int ret = 0;
- notification_h noti = NULL;
-
- noti = (notification_h) calloc(1, sizeof(struct _notification));
- if (noti == NULL) {
- NOTIFICATION_ERR("NO MEMORY : noti == NULL");
- return NULL;
- }
-
- ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id);
- if (ret != NOTIFICATION_ERROR_NONE) {
- notification_free(noti);
- return NULL;
- }
-
- return noti;
-}
-
-EXPORT_API notification_h notification_load_by_tag(const char *tag)
-{
- int ret = 0;
- notification_h noti = NULL;
- char *caller_pkgname = NULL;
-
- if (tag == NULL) {
- NOTIFICATION_ERR("Invalid parameter");
- set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- caller_pkgname = _notification_get_pkgname_by_pid();
- if (!caller_pkgname) {
- NOTIFICATION_ERR("Failed to get a package name");
- set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
-
- return NULL;
- }
-
- noti = (notification_h) calloc(1, sizeof(struct _notification));
- if (noti == NULL) {
- NOTIFICATION_ERR("Failed to alloc a new notification");
- set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
- free(caller_pkgname);
-
- return NULL;
- }
-
- ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, tag);
-
- free(caller_pkgname);
-
- set_last_result(ret);
-
- if (ret != NOTIFICATION_ERROR_NONE) {
- notification_free(noti);
- return NULL;
- }
-
- return noti;
-}
-
-EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
-{
- notification_h new_noti = NULL;
-
- if (noti == NULL || clone == NULL) {
- NOTIFICATION_ERR("INVALID PARAMETER.");
- return NOTIFICATION_ERROR_INVALID_PARAMETER;
- }
-
- new_noti = (notification_h) calloc(1, sizeof(struct _notification));
- if (new_noti == NULL) {
- NOTIFICATION_ERR("NO MEMORY : noti == NULL");
- return NOTIFICATION_ERROR_OUT_OF_MEMORY;
- }
-
- new_noti->type = noti->type;
- new_noti->layout = noti->layout;
-
- new_noti->group_id = noti->group_id;
- new_noti->internal_group_id = noti->internal_group_id;
- new_noti->priv_id = noti->priv_id;
-
- if(noti->caller_pkgname != NULL) {
- new_noti->caller_pkgname = strdup(noti->caller_pkgname);
- } else {
- new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
- }
- if(noti->launch_pkgname != NULL) {
- new_noti->launch_pkgname = strdup(noti->launch_pkgname);
- } else {
- new_noti->launch_pkgname = NULL;
- }
-
- if(noti->args != NULL) {
- new_noti->args = bundle_dup(noti->args);
- } else {
- new_noti->args = NULL;
- }
- if(noti->group_args != NULL) {
- new_noti->group_args = bundle_dup(noti->group_args);
- } else {
- new_noti->group_args = NULL;
- }
-
- if(noti->b_execute_option != NULL) {
- new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
- } else {
- new_noti->b_execute_option = NULL;
- }
- if(noti->b_service_responding != NULL) {
- new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
- } else {
- new_noti->b_service_responding = NULL;
- }
- if(noti->b_service_single_launch != NULL) {
- new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
- } else {
- new_noti->b_service_single_launch = NULL;
- }
- if(noti->b_service_multi_launch != NULL) {
- new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
- } else {
- new_noti->b_service_multi_launch = NULL;
- }
-
- new_noti->sound_type = noti->sound_type;
- if(noti->sound_path != NULL) {
- new_noti->sound_path = strdup(noti->sound_path);
- } else {
- new_noti->sound_path = NULL;
- }
- new_noti->vibration_type = noti->vibration_type;
- if(noti->vibration_path != NULL) {
- new_noti->vibration_path = strdup(noti->vibration_path);
- } else {
- new_noti->vibration_path = NULL;
- }
- new_noti->led_operation = noti->led_operation;
- new_noti->led_argb = noti->led_argb;
- new_noti->led_on_ms = noti->led_on_ms;
- new_noti->led_off_ms = noti->led_off_ms;
-
- if(noti->domain != NULL) {
- new_noti->domain = strdup(noti->domain);
- } else {
- new_noti->domain = NULL;
- }
- if(noti->dir != NULL) {
- new_noti->dir = strdup(noti->dir);
- } else {
- new_noti->dir = NULL;
- }
-
- if(noti->b_text != NULL) {
- new_noti->b_text = bundle_dup(noti->b_text);
- } else {
- new_noti->b_text = NULL;
- }
- if(noti->b_key != NULL) {
- new_noti->b_key = bundle_dup(noti->b_key);
- } else {
- new_noti->b_key = NULL;
- }
- if(noti->b_format_args != NULL) {
- new_noti->b_format_args = bundle_dup(noti->b_format_args);
- } else {
- new_noti->b_format_args = NULL;
- }
- new_noti->num_format_args = noti->num_format_args;
-
- if(noti->b_image_path != NULL) {
- new_noti->b_image_path = bundle_dup(noti->b_image_path);
- } else {
- new_noti->b_image_path = NULL;
- }
-
- new_noti->time = noti->time;
- new_noti->insert_time = noti->insert_time;
-
- new_noti->flags_for_property = noti->flags_for_property;
- new_noti->display_applist = noti->display_applist;
-
- new_noti->progress_size = noti->progress_size;
- new_noti->progress_percentage = noti->progress_percentage;
-
- new_noti->app_icon_path = NULL;
- new_noti->app_name = NULL;
- new_noti->temp_title = NULL;
- new_noti->temp_content = NULL;
-
- *clone = new_noti;
-
- return NOTIFICATION_ERROR_NONE;
-}
-
-
-EXPORT_API int notification_free(notification_h noti)
-{
- if (noti == NULL) {
- return NOTIFICATION_ERROR_INVALID_PARAMETER;
- }
-
- if (noti->caller_pkgname) {
- free(noti->caller_pkgname);
- }
- if (noti->launch_pkgname) {
- free(noti->launch_pkgname);
- }
- if (noti->args) {
- bundle_free(noti->args);
- }
- if (noti->group_args) {
- bundle_free(noti->group_args);
- }
-
- if (noti->b_execute_option) {
- bundle_free(noti->b_execute_option);
- }
- if (noti->b_service_responding) {
- bundle_free(noti->b_service_responding);
- }
- if (noti->b_service_single_launch) {
- bundle_free(noti->b_service_single_launch);
- }
- if (noti->b_service_multi_launch) {
- bundle_free(noti->b_service_multi_launch);
- }
-
- if (noti->sound_path) {
- free(noti->sound_path);
- }
- if (noti->vibration_path) {
- free(noti->vibration_path);
- }
-
- if (noti->domain) {
- free(noti->domain);
- }
- if (noti->dir) {
- free(noti->dir);
- }
-
- if (noti->b_text) {
- bundle_free(noti->b_text);
- }
- if (noti->b_key) {
- bundle_free(noti->b_key);
- }
- if (noti->b_format_args) {
- bundle_free(noti->b_format_args);
- }
-
- if (noti->b_image_path) {
- bundle_free(noti->b_image_path);
- }
-
- if (noti->app_icon_path) {
- free(noti->app_icon_path);
- }
- if (noti->app_name) {
- free(noti->app_name);
- }
- if (noti->temp_title) {
- free(noti->temp_title);
- }
- if (noti->temp_content) {
- free(noti->temp_content);
- }
-
- if (noti->tag) {
- free(noti->tag);
- }
-
- free(noti);
-
- return NOTIFICATION_ERROR_NONE;
-}
-
-EXPORT_API int
-notification_resister_changed_cb(void (*changed_cb)
- (void *data, notification_type_e type),
- void *user_data)
-{
- notification_cb_list_s *noti_cb_list_new = NULL;
- notification_cb_list_s *noti_cb_list = NULL;
-
- if (changed_cb == NULL) {
- return NOTIFICATION_ERROR_INVALID_PARAMETER;
- }
- if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
- return NOTIFICATION_ERROR_IO_ERROR;
- }
-
- noti_cb_list_new =
- (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
-
- noti_cb_list_new->next = NULL;
- noti_cb_list_new->prev = NULL;
-
- noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
- noti_cb_list_new->changed_cb = changed_cb;
- noti_cb_list_new->detailed_changed_cb = NULL;
- noti_cb_list_new->data = user_data;
-
- if (g_notification_cb_list == NULL) {
- g_notification_cb_list = noti_cb_list_new;
- } else {
- noti_cb_list = g_notification_cb_list;
-
- while (noti_cb_list->next != NULL) {
- noti_cb_list = noti_cb_list->next;
- }
-
- noti_cb_list->next = noti_cb_list_new;
- noti_cb_list_new->prev = noti_cb_list;
- }
- return NOTIFICATION_ERROR_NONE;
-}
-
-EXPORT_API int
-notification_unresister_changed_cb(void (*changed_cb)
- (void *data, notification_type_e type))
-{
- notification_cb_list_s *noti_cb_list = NULL;
- notification_cb_list_s *noti_cb_list_prev = NULL;
- notification_cb_list_s *noti_cb_list_next = NULL;
-
- noti_cb_list = g_notification_cb_list;
-
- if (changed_cb == NULL) {
- return NOTIFICATION_ERROR_INVALID_PARAMETER;
- }
- if (noti_cb_list == NULL) {
- return NOTIFICATION_ERROR_INVALID_PARAMETER;
- }
-
- while (noti_cb_list->prev != NULL) {
- noti_cb_list = noti_cb_list->prev;
- }
-
- do {
- if (noti_cb_list->changed_cb == changed_cb) {
- noti_cb_list_prev = noti_cb_list->prev;
- noti_cb_list_next = noti_cb_list->next;
-
- if (noti_cb_list_prev == NULL) {
- g_notification_cb_list = noti_cb_list_next;
- } else {
- noti_cb_list_prev->next = noti_cb_list_next;
- }
-
- if (noti_cb_list_next == NULL) {
- if (noti_cb_list_prev != NULL) {
- noti_cb_list_prev->next = NULL;
- }
- } else {
- noti_cb_list_next->prev = noti_cb_list_prev;
- }
-
- free(noti_cb_list);
-
- if (g_notification_cb_list == NULL)
- notification_ipc_monitor_fini();
-
- return NOTIFICATION_ERROR_NONE;
- }
- noti_cb_list = noti_cb_list->next;
- } while (noti_cb_list != NULL);