#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"
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);
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;
}
-