Improve notification-related functions 65/229265/2
authorMinje Ahn <minje.ahn@samsung.com>
Tue, 31 Mar 2020 00:54:03 +0000 (09:54 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Tue, 31 Mar 2020 06:02:51 +0000 (15:02 +0900)
Change-Id: I8b4d856bc63fbacd091f0f9882d5d069d4278aba
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
lib/include/media-util-noti-internal.h
lib/media-util-noti-internal.c

index 906f548..d516dfe 100755 (executable)
@@ -63,8 +63,6 @@ typedef void (*db_update_cb)(int pid, /* mandatory */
                                                        char *mime_type, /* optional */
                                                        void *user_data);
 
-typedef void (*clear_user_data_cb)(void * user_data);
-
 typedef void *MediaNotiHandle;         /**< Handle */
 
 #define MS_MEDIA_DBUS_PATH "/com/mediaserver/dbus/notify"
@@ -83,7 +81,7 @@ int media_db_update_send_internal(int pid, /* mandatory */
 
 int media_db_update_subscribe_internal(MediaNotiHandle *handle, db_update_cb user_cb, void *user_data);
 
-int media_db_update_unsubscribe_internal(MediaNotiHandle handle, clear_user_data_cb clear_cb);
+int media_db_update_unsubscribe_internal(MediaNotiHandle handle);
 
 
 /**
index a651bff..f9d8f23 100755 (executable)
@@ -36,7 +36,7 @@
 #include "media-util.h"
 #include "private.h"
 
-static GArray *handle_list_internal;
+static GList *handle_list;
 static GMutex mutex_internal;
 
 #define MS_MEDIA_DBUS_NAME_INTERNAL "ms_db_updated_internal"
@@ -224,16 +224,7 @@ int media_db_update_subscribe_internal(MediaNotiHandle *handle, db_update_cb use
 
        g_mutex_lock(&mutex_internal);
 
-       if (handle_list_internal == NULL) {
-               handle_list_internal = g_array_new(FALSE, FALSE, sizeof(MediaNotiHandle));
-               if (handle_list_internal == NULL) {
-                       g_mutex_unlock(&mutex_internal);
-                       ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
-                       goto ERROR;
-               }
-       }
-
-       g_array_append_val(handle_list_internal, *handle);
+       handle_list = g_list_append(handle_list, *handle);
 
        g_mutex_unlock(&mutex_internal);
 
@@ -251,72 +242,32 @@ ERROR:
        return ret;
 }
 
-static int _find_handle(MediaNotiHandle handle, int *idx)
+int media_db_update_unsubscribe_internal(MediaNotiHandle handle)
 {
-       unsigned int i;
-       int ret = MS_MEDIA_ERR_NONE;
-       bool find_flag = false;
-       MediaNotiHandle data;
-
-       /*delete all node*/
-       if (handle_list_internal != NULL) {
-               for (i = 0; i < handle_list_internal->len; i++) {
-                       data = g_array_index(handle_list_internal , MediaNotiHandle, i);
-                       MSAPI_DBG_INFO("%p %p", handle, data);
-                       if (data == handle) {
-                               MSAPI_DBG("FIND HANDLE");
-                               *idx = i;
-                               find_flag = true;
-                               break;
-                       }
-               }
-       } else {
-               ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       if (find_flag == false)
-               ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+       internal_noti_cb_data *_handle = (internal_noti_cb_data *)handle;
+       GList *found = NULL;
 
-       return ret;
-}
+       MSAPI_RETVM_IF(!handle, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid parameter");
 
-int media_db_update_unsubscribe_internal(MediaNotiHandle handle, clear_user_data_cb clear_cb)
-{
-       int idx = -1;
-       int ret = MS_MEDIA_ERR_NONE;
-       int err;
+       g_mutex_lock(&mutex_internal);
 
-       if (handle == NULL) {
-               MSAPI_DBG_ERR("INVALID PARAMETER");
+       found = g_list_find(handle_list, handle);
+       if (!found) {
+               g_mutex_unlock(&mutex_internal);
+               MSAPI_DBG_ERR("Does not found handle");
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       g_mutex_lock(&mutex_internal);
-
-       err = _find_handle(handle, &idx);
-       if (err == MS_MEDIA_ERR_NONE) {
-               GDBusConnection *gdbus = ((internal_noti_cb_data*)handle)->gdbus;
-               g_dbus_connection_signal_unsubscribe(gdbus, ((internal_noti_cb_data*)handle)->handler);
-               g_object_unref(gdbus);
-               g_array_remove_index(handle_list_internal, idx);
+       handle_list = g_list_delete_link(handle_list, found);
 
-               if (clear_cb != NULL)
-                       clear_cb(((internal_noti_cb_data*)handle)->user_data);
+       g_dbus_connection_signal_unsubscribe(_handle->gdbus, _handle->handler);
+       g_object_unref(_handle->gdbus);
 
-               MS_SAFE_FREE(handle);
-
-               if ((handle_list_internal != NULL) && (handle_list_internal->len == 0)) {
-                       g_array_free(handle_list_internal, FALSE);
-                       handle_list_internal = NULL;
-               }
-       } else {
-               MSAPI_DBG_ERR("PARAMETER DOES NOT FIND");
-               ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
+       MS_SAFE_FREE(_handle->user_data);
+       MS_SAFE_FREE(_handle);
 
        g_mutex_unlock(&mutex_internal);
 
-       return ret;
+       return MS_MEDIA_ERR_NONE;
 }
 
-