Fix double unlock of slot mutex in user stops scneario
[platform/core/multimedia/libmm-sound.git] / mm_sound_focus.c
index 86f677d..1b0fd5f 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <stdlib.h>
 #include <unistd.h>
-
 #include <mm_debug.h>
 
 #include "include/mm_sound.h"
@@ -31,7 +30,7 @@
 { \
        int ret = MM_ERROR_NONE; \
        bool result = false; \
-       ret = mm_sound_client_is_focus_cb_thread(x_thread, &result); \
+       ret = mm_sound_client_is_focus_cb_thread(x_thread, &result, NULL); \
        if (ret) \
                return ret; \
        if (result) { \
 } \
 
 EXPORT_API
-int mm_sound_focus_get_id(int *id)
+int mm_sound_focus_is_cb_thread(bool *result, bool *is_for_watching)
 {
        int ret = MM_ERROR_NONE;
 
        debug_fenter();
 
-       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
-
-       ret = mm_sound_client_get_unique_id(id);
-       if (ret)
-               debug_error("Failed to mm_sound_client_get_unique_id(), ret[0x%x]", ret);
-
-       debug_fleave();
-
-       return ret;
-}
-
-EXPORT_API
-int mm_sound_focus_is_cb_thread(bool *result)
-{
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
+       if (result == NULL) {
+               debug_error("argument is not valid");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
 
-       ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), result);
+       ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), result, is_for_watching);
        if (!ret) {
                if (*result)
                        debug_msg("it might be called in the thread of focus callback");
+               if (is_for_watching && *is_for_watching)
+                       debug_msg("it's in the focus watch callback");
        }
 
        debug_fleave();
@@ -77,7 +65,7 @@ int mm_sound_focus_is_cb_thread(bool *result)
 }
 
 EXPORT_API
-int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
+int mm_sound_register_focus(const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data, int *id)
 {
        int ret = MM_ERROR_NONE;
 
@@ -85,12 +73,12 @@ int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_chan
 
        RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
 
-       if (id < 0 || callback == NULL) {
+       if (id == NULL || callback == NULL) {
                debug_error("argument is not valid");
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = mm_sound_client_register_focus(id, getpid(), stream_type, callback, user_data);
+       ret = mm_sound_client_register_focus(getpid(), stream_type, callback, user_data, id);
        if (ret)
                debug_error("Could not register focus, ret[0x%x]", ret);
 
@@ -107,12 +95,12 @@ int mm_sound_unregister_focus(int id)
 
        debug_fenter();
 
-       if (id < 0) {
+       if (id <= 0) {
                debug_error("argument is not valid");
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       mm_sound_client_is_focus_cb_thread(g_thread_self(), &result);
+       mm_sound_client_is_focus_cb_thread(g_thread_self(), &result, NULL);
        if (!result) {
                if ((ret = mm_sound_client_unregister_focus(id)))
                        debug_error("Could not unregister focus, ret = %x", ret);
@@ -320,7 +308,7 @@ int mm_sound_deliver_focus(int src_id, int dst_id, mm_sound_focus_type_e focus_t
 {
        int ret = MM_ERROR_NONE;
 
-       if ((ret = mm_sound_client_deliver_focus(getpid(), src_id, dst_id, focus_type)))
+       if ((ret = mm_sound_client_deliver_focus(src_id, dst_id, focus_type)))
                debug_error("failed to mm_sound_client_deliver_focus(), ret[0x%x]", ret);
 
        return ret;
@@ -366,7 +354,7 @@ int mm_sound_unset_focus_watch_callback(int id)
                return ret;
        }
 
-       mm_sound_client_is_focus_cb_thread(g_thread_self(), &result);
+       mm_sound_client_is_focus_cb_thread(g_thread_self(), &result, NULL);
        if (!result) {
                if ((ret = mm_sound_client_unset_focus_watch_callback(id)))
                        debug_error("Could not unset focus watch callback, id(%d), ret[0x%x]", id, ret);