Add to check if a focus API is called in the same thread with focus callback's 89/50989/7 accepted/tizen/mobile/20151106.045847 accepted/tizen/tv/20151106.045858 accepted/tizen/wearable/20151106.045912 submit/tizen/20151105.120840
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 4 Nov 2015 08:37:02 +0000 (17:37 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 5 Nov 2015 06:22:25 +0000 (15:22 +0900)
[Version] Release 0.9.270
[Profile] Common
[Issue Type] Code enhancement

Change-Id: I994d66580957bb7c7aa22bd80f7b38c9d3f3fe62
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
focus_server/mm_sound_focus_server.c
include/mm_sound_client.h
include/mm_sound_focus.h
mm_sound.c
mm_sound_client.c
mm_sound_client_dbus.c
mm_sound_focus.c
packaging/libmm-sound.spec

index 4260b01..393047c 100644 (file)
@@ -57,7 +57,7 @@ typedef struct {
     int testmode;
 } server_arg;
 
-static int getOption(int argc, char **argv, server_arg *arg);
+static int get_option(int argc, char **argv, server_arg *arg);
 static int usage(int argc, char **argv);
 
 static struct sigaction sigint_action;  /* Backup pointer of SIGINT handler */
@@ -92,7 +92,7 @@ int main(int argc, char **argv)
        action.sa_flags = 0;
        sigemptyset(&action.sa_mask);
 
-       if (getOption(argc, argv, &serveropt))
+       if (get_option(argc, argv, &serveropt))
                return 1;
 
        debug_warning("focus_server [%d] init \n", getpid());
@@ -159,7 +159,7 @@ int main(int argc, char **argv)
        return 0;
 }
 
-static int getOption(int argc, char **argv, server_arg *arg)
+static int get_option(int argc, char **argv, server_arg *arg)
 {
        int c;
        static struct option long_options[] = {
index 9e39e45..35ddb81 100644 (file)
@@ -58,6 +58,7 @@ int mm_sound_client_remove_device_info_changed_callback(unsigned int subs_id);
 int mm_sound_client_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void* user_data);
 int mm_sound_client_unset_session_interrupt_callback(void);
 int mm_sound_client_get_uniq_id(int *id);
+int mm_sound_client_is_focus_cb_thread(GThread *mine, bool *result);
 int mm_sound_client_register_focus(int id, int pid, const char *stream_type, mm_sound_focus_changed_cb callback, bool is_for_session, void* user_data);
 int mm_sound_client_unregister_focus(int id);
 int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, const char *option);
index 1de4c5a..7f8e31c 100644 (file)
@@ -47,6 +47,7 @@ typedef enum {
 } mm_sound_focus_type_e;
 
 int mm_sound_focus_get_id(int *id);
+int mm_sound_focus_is_cb_thread(bool *result);
 
 typedef void (*mm_sound_focus_changed_cb) (int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data);
 int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data);
index 813eee5..1786855 100644 (file)
@@ -222,7 +222,7 @@ int mm_sound_remove_volume_changed_callback(unsigned int subs_id)
 EXPORT_API
 int mm_sound_volume_get_step(volume_type_t type, int *step)
 {
-       return MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 EXPORT_API
index 4f19d32..cc6d6ac 100644 (file)
@@ -1526,6 +1526,22 @@ int mm_sound_client_get_unique_id(int *id)
        return ret;
 }
 
+int mm_sound_client_is_focus_cb_thread(GThread *mine, bool *result)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (!mine || !result)
+               ret = MM_ERROR_INVALID_ARGUMENT;
+       else {
+               if (mine == g_focus_thread)
+                       *result = true;
+               else
+                       *result = false;
+       }
+
+       return ret;
+}
+
 int mm_sound_client_register_focus(int id, int pid, const char *stream_type, mm_sound_focus_changed_cb callback, bool is_for_session, void* user_data)
 {
        int ret = MM_ERROR_NONE;
@@ -1625,6 +1641,7 @@ int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, const char
        int ret = MM_ERROR_NONE;
        int instance;
        int index = -1;
+
        debug_fenter();
 
        index = _focus_find_index_by_handle(id);
index 874d0f1..1ea6ecb 100644 (file)
@@ -1136,46 +1136,22 @@ int mm_sound_client_dbus_clear_focus(int pid)
 
 int mm_sound_client_dbus_is_route_available(mm_sound_route route, bool *is_available)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 int mm_sound_client_dbus_foreach_available_route_cb(mm_sound_available_route_cb avail_cb, void *user_data)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 int mm_sound_client_dbus_set_active_route(mm_sound_route route, bool need_broadcast)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 int mm_sound_client_dbus_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 int mm_sound_client_dbus_add_play_sound_end_callback(mm_sound_stop_callback_wrapper_func stop_cb, void* userdata, unsigned int *subs_id)
@@ -1208,68 +1184,32 @@ int mm_sound_client_dbus_remove_play_sound_end_callback(unsigned int subs_id)
 
 int mm_sound_client_dbus_add_active_device_changed_callback(const char *name, mm_sound_active_device_changed_cb func, void* user_data)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 int mm_sound_client_dbus_remove_active_device_changed_callback(const char *name)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 int mm_sound_client_dbus_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void* user_data)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 int mm_sound_client_dbus_remove_available_route_changed_callback(void)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 int mm_sound_client_dbus_set_sound_path_for_active_device(mm_sound_device_out device_out, mm_sound_device_in device_in)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 int mm_sound_client_dbus_set_active_route_auto(void)
 {
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
-       debug_fleave();
-
-       return ret;
+       return MM_ERROR_NOT_SUPPORT_API;
 }
 
 /*------------------------------------------ FOCUS --------------------------------------------------*/
index f4e9883..d24bff3 100644 (file)
 #include "include/mm_sound_focus.h"
 #include "focus_server/include/mm_sound_mgr_focus.h"
 
+#define RETURN_ERROR_IF_FOCUS_CB_THREAD(x_thread) \
+{ \
+       int ret = MM_ERROR_NONE; \
+       bool result = false; \
+       ret = mm_sound_client_is_focus_cb_thread(x_thread, &result); \
+       if (ret) \
+               return ret; \
+       else if (result) { \
+               debug_error("it might be called in the thread of focus callback, it is not allowed\n"); \
+               return MM_ERROR_SOUND_INVALID_OPERATION; \
+       } \
+} \
+
 EXPORT_API
 int mm_sound_focus_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void *user_data)
 {
        int ret = MM_ERROR_NONE;
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        if (!callback)
                return MM_ERROR_INVALID_ARGUMENT;
 
@@ -53,6 +68,8 @@ int mm_sound_focus_unset_session_interrupt_callback(void)
        int ret = MM_ERROR_NONE;
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        ret = mm_sound_client_unset_session_interrupt_callback ();
        if (ret) {
                debug_error("Failed to mm_sound_client_unset_session_interrupt_callback(), ret[0x%x]\n", ret);
@@ -70,6 +87,8 @@ int mm_sound_focus_get_id(int *id)
 
        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]\n", ret);
@@ -81,12 +100,32 @@ int mm_sound_focus_get_id(int *id)
 }
 
 EXPORT_API
+int mm_sound_focus_is_cb_thread(bool *result)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), result);
+       if (!ret) {
+               if (*result)
+                       debug_error("it might be called in the thread of focus callback, it is not allowed\n");
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+EXPORT_API
 int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
 {
        int ret = MM_ERROR_NONE;
 
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        if (id < 0 || callback == NULL) {
                debug_error("argument is not valid\n");
                return MM_ERROR_INVALID_ARGUMENT;
@@ -109,6 +148,8 @@ int mm_sound_register_focus_for_session(int id, int pid, const char *stream_type
 
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        if (id < 0 || callback == NULL) {
                debug_error("argument is not valid\n");
                return MM_ERROR_INVALID_ARGUMENT;
@@ -124,7 +165,6 @@ int mm_sound_register_focus_for_session(int id, int pid, const char *stream_type
        return ret;
 }
 
-
 EXPORT_API
 int mm_sound_unregister_focus(int id)
 {
@@ -132,6 +172,8 @@ int mm_sound_unregister_focus(int id)
 
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        if (id < 0) {
                debug_error("argument is not valid\n");
                return MM_ERROR_INVALID_ARGUMENT;
@@ -154,6 +196,8 @@ int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char
 
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        if (id < 0) {
                debug_error("argument is not valid\n");
                return MM_ERROR_INVALID_ARGUMENT;
@@ -180,6 +224,8 @@ int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char
 
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        if (id < 0) {
                debug_error("argument is not valid\n");
                return MM_ERROR_INVALID_ARGUMENT;
@@ -206,6 +252,8 @@ int mm_sound_set_focus_watch_callback(mm_sound_focus_type_e focus_type, mm_sound
 
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        if (callback == NULL || id == NULL) {
                debug_error("argument is not valid\n");
                return MM_ERROR_INVALID_ARGUMENT;
@@ -227,6 +275,8 @@ int mm_sound_set_focus_watch_callback_for_session(int pid, mm_sound_focus_type_e
 
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        if (callback == NULL || id == NULL) {
                debug_error("argument is not valid\n");
                return MM_ERROR_INVALID_ARGUMENT;
@@ -248,6 +298,8 @@ int mm_sound_unset_focus_watch_callback(int id)
 
        debug_fenter();
 
+       RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
+
        ret = mm_sound_client_unset_focus_watch_callback(id);
        if (ret) {
                debug_error("Could not unset focus watch callback, id(%d), ret = %x\n", id, ret);
index 520509b..35adda7 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.9.270
+Version:    0.9.271
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0