focus_server: Fix bug regarding update of reacquisition information within focus...
[platform/core/multimedia/libmm-sound.git] / mm_sound_client.c
index 6c46fe2..4ba6246 100644 (file)
@@ -72,6 +72,11 @@ struct callback_data {
        guint subs_id;
 };
 
+typedef struct _FocusSource {
+       GSource source;
+       GPollFD poll_fd;
+} FocusSource;
+
 #define GET_CB_DATA(_cb_data, _func, _userdata, _extradata) \
        do { \
                _cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)); \
@@ -85,17 +90,20 @@ typedef struct {
        int focus_tid;
        int handle;
        int focus_fd;
-       GSourceFuncs* g_src_funcs;
-       GPollFD* g_poll_fd;
-       GSource* focus_src;
+       FocusSource *fsrc;
        bool is_used;
        bool auto_reacquire;
        GMutex focus_lock;
+       GThread *focus_cb_thread;
+       GMainLoop *focus_loop;
        mm_sound_focus_changed_cb focus_callback;
        mm_sound_focus_changed_watch_cb watch_callback;
        void* user_data;
+       bool unset_watch_callback_requested;
 
-       bool is_for_session;    /* will be removed when the session concept is completely left out*/
+       /* will be removed when the session concept is completely left out*/
+       bool is_for_session;
+       bool is_for_monitor;
 } focus_sound_info_t;
 
 typedef struct {
@@ -109,18 +117,19 @@ typedef struct {
 } focus_cb_data_lib;
 
 typedef struct {
+       int watch_cb_id;
        mm_sound_focus_session_interrupt_cb user_cb;
        void* user_data;
 } focus_session_interrupt_info_t;
 
-typedef gboolean (*focus_gLoopPollHandler_t)(gpointer d);
+typedef gboolean (*focus_callback_handler_t)(gpointer user_data);
 
-GThread *g_focus_thread;
-GMainLoop *g_focus_loop;
 focus_sound_info_t g_focus_sound_handle[FOCUS_HANDLE_MAX];
-focus_session_interrupt_info_t g_focus_session_interrupt_info = {NULL, NULL};
+focus_session_interrupt_info_t g_focus_session_interrupt_info = {-1, NULL, NULL};
 static pthread_mutex_t g_index_mutex = PTHREAD_MUTEX_INITIALIZER;
-guint g_focus_signal_handle = 0;
+static pthread_mutex_t g_event_mutex = PTHREAD_MUTEX_INITIALIZER;
+guint g_focus_signal_handle;
+guint g_idle_event_src;
 #endif
 
 gboolean g_need_emergent_exit = FALSE;
@@ -132,7 +141,12 @@ typedef struct {
        unsigned subs_id;
 } play_sound_end_callback_data_t;
 
-void _system_signal_handler(int signo)
+typedef struct _focus_idle_event {
+       focus_idle_event_type_e type;
+       int data;
+} focus_idle_event_t;
+
+void _system_signal_handler(int signo, siginfo_t *siginfo, void *context)
 {
        int ret = MM_ERROR_NONE;
        sigset_t old_mask, all_mask;
@@ -147,9 +161,9 @@ void _system_signal_handler(int signo)
        if (g_need_emergent_exit) {
                ret = mm_sound_proxy_emergent_exit(getpid());
                if (ret == MM_ERROR_NONE)
-                       debug_msg("[Client] Success to emergnet_exit\n");
+                       debug_msg("Success to emergnet_exit");
                else
-                       debug_error("[Client] Error occurred : 0x%x \n",ret);
+                       debug_error("Error occurred : 0x%x", ret);
        }
 
        sigprocmask(SIG_SETMASK, &old_mask, NULL);
@@ -157,28 +171,40 @@ void _system_signal_handler(int signo)
 
        switch (signo) {
        case SIGINT:
-               sigaction(SIGINT, &system_int_old_action, NULL);
-               raise( signo);
+               if (system_int_old_action.sa_sigaction)
+                       system_int_old_action.sa_sigaction(signo, siginfo, context);
+               else
+                       sigaction(signo, &system_int_old_action, NULL);
                break;
        case SIGABRT:
-               sigaction(SIGABRT, &system_abrt_old_action, NULL);
-               raise( signo);
+               if (system_abrt_old_action.sa_sigaction)
+                       system_abrt_old_action.sa_sigaction(signo, siginfo, context);
+               else
+                       sigaction(signo, &system_abrt_old_action, NULL);
                break;
        case SIGSEGV:
-               sigaction(SIGSEGV, &system_segv_old_action, NULL);
-               raise( signo);
+               if (system_segv_old_action.sa_sigaction)
+                       system_segv_old_action.sa_sigaction(signo, siginfo, context);
+               else
+                       sigaction(signo, &system_segv_old_action, NULL);
                break;
        case SIGTERM:
-               sigaction(SIGTERM, &system_term_old_action, NULL);
-               raise( signo);
+               if (system_term_old_action.sa_sigaction)
+                       system_term_old_action.sa_sigaction(signo, siginfo, context);
+               else
+                       sigaction(signo, &system_term_old_action, NULL);
                break;
        case SIGSYS:
-               sigaction(SIGSYS, &system_sys_old_action, NULL);
-               raise( signo);
+               if (system_sys_old_action.sa_sigaction)
+                       system_sys_old_action.sa_sigaction(signo, siginfo, context);
+               else
+                       sigaction(signo, &system_sys_old_action, NULL);
                break;
        case SIGXCPU:
-               sigaction(SIGXCPU, &system_xcpu_old_action, NULL);
-               raise( signo);
+               if (system_xcpu_old_action.sa_sigaction)
+                       system_xcpu_old_action.sa_sigaction(signo, siginfo, context);
+               else
+                       sigaction(signo, &system_xcpu_old_action, NULL);
                break;
        default:
                break;
@@ -193,11 +219,12 @@ int mm_sound_client_initialize(void)
        debug_fenter();
 
        mm_sound_proxy_initialize();
+       g_idle_event_src = 0;
 
 
        struct sigaction system_action;
-       system_action.sa_handler = _system_signal_handler;
-       system_action.sa_flags = SA_NOCLDSTOP;
+       system_action.sa_sigaction = _system_signal_handler;
+       system_action.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
 
        sigemptyset(&system_action.sa_mask);
 
@@ -221,9 +248,9 @@ int mm_sound_client_finalize(void)
        if (g_need_emergent_exit) {
                ret = mm_sound_proxy_emergent_exit(getpid());
                if (ret == MM_ERROR_NONE)
-                       debug_msg("[Client] Success to emergnet_exit\n");
+                       debug_msg("Success to emergent_exit");
                else
-                       debug_error("[Client] Error occurred : 0x%x \n",ret);
+                       debug_error("Error occurred : 0x%x", ret);
        }
 
        sigaction(SIGINT, &system_int_old_action, NULL);
@@ -235,17 +262,12 @@ int mm_sound_client_finalize(void)
 
        ret = mm_sound_proxy_finalize();
 
-
 #ifdef USE_FOCUS
-
-       if (g_focus_thread) {
-               g_main_loop_quit(g_focus_loop);
-               g_thread_join(g_focus_thread);
-               debug_log("after thread join");
-               g_main_loop_unref(g_focus_loop);
-               g_focus_thread = NULL;
+       if (g_idle_event_src > 0) {
+               MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_event_mutex, MM_ERROR_SOUND_INTERNAL);
+               g_source_remove(g_idle_event_src);
+               MMSOUND_LEAVE_CRITICAL_SECTION(&g_event_mutex);
        }
-
 #endif
 
        debug_fleave();
@@ -256,31 +278,31 @@ void mm_sound_convert_volume_type_to_stream_type(int volume_type, char *stream_t
 {
        switch (volume_type) {
        case VOLUME_TYPE_SYSTEM:
-               MMSOUND_STRNCPY(stream_type, "system", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "system", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_NOTIFICATION:
-               MMSOUND_STRNCPY(stream_type, "notification", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "notification", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_ALARM:
-               MMSOUND_STRNCPY(stream_type, "alarm", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "alarm", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_RINGTONE:
-               MMSOUND_STRNCPY(stream_type, "ringtone-voip", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "ringtone-voip", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_MEDIA:
-               MMSOUND_STRNCPY(stream_type, "media", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "media", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_CALL:
-               MMSOUND_STRNCPY(stream_type, "call-voice", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "call-voice", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_VOIP:
-               MMSOUND_STRNCPY(stream_type, "voip", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "voip", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_VOICE:
-               MMSOUND_STRNCPY(stream_type, "voice-recognition", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "voice-information", MAX_STREAM_TYPE_LEN);
                break;
        default:
-               MMSOUND_STRNCPY(stream_type, "media", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "media", MAX_STREAM_TYPE_LEN);
                break;
        }
 
@@ -309,12 +331,13 @@ void _mm_sound_client_focus_signal_callback(mm_sound_signal_name_t signal, int v
 }
 #endif
 
-int mm_sound_client_play_tone(int number, int volume_config, double volume, int time, int *handle, bool enable_session)
+int mm_sound_client_play_tone(int number, int volume_config, double volume,
+                                                       int time, int *handle, bool enable_session)
 {
        int ret = MM_ERROR_NONE;
-//      int instance = -1;     /* instance is unique to communicate with server : client message queue filter type */
+//      int instance = -1; /* instance is unique to communicate with server : client message queue filter type */
        int volume_type = MM_SOUND_VOLUME_CONFIG_TYPE(volume_config);
-       char stream_type[MM_SOUND_STREAM_TYPE_LEN] = {0, };
+       char stream_type[MAX_STREAM_TYPE_LEN] = {0, };
 
         debug_fenter();
 
@@ -334,21 +357,21 @@ int mm_sound_client_play_tone(int number, int volume_config, double volume, int
 
        if (enable_session) {
                if (MM_ERROR_NONE != _mm_session_util_read_information(-1, &session_type, &session_options)) {
-                       debug_warning("[Client] Read Session Information failed. use default \"media\" type\n");
+                       debug_warning("Read Session Information failed. use default \"media\" type");
                        session_type = MM_SESSION_TYPE_MEDIA;
 
                        if(MM_ERROR_NONE != mm_session_init(session_type)) {
-                               debug_critical("[Client] MMSessionInit() failed\n");
+                               debug_critical("MMSessionInit() failed");
                                return MM_ERROR_POLICY_INTERNAL;
                        }
                }
        }
 
         // instance = getpid();
-        //debug_log("[Client] pid for client ::: [%d]\n", instance);
+        //debug_log("pid for client ::: [%d]", instance);
 
         /* Send msg */
-        debug_msg("[Client] Input number : %d\n", number);
+        debug_msg("Input number : %d", number);
         /* Send req memory */
 
        mm_sound_convert_volume_type_to_stream_type(volume_type, stream_type);
@@ -356,7 +379,8 @@ int mm_sound_client_play_tone(int number, int volume_config, double volume, int
                                        session_type, session_options, getpid(), enable_session, handle, stream_type, -1);
 #ifdef USE_FOCUS
        if (enable_session && !g_focus_signal_handle) {
-               ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle, _mm_sound_client_focus_signal_callback, NULL);
+               ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle,
+                                                                               _mm_sound_client_focus_signal_callback, NULL);
                if (ret) {
                        debug_error("mm_sound_subscribe_signal failed [0x%x]", ret);
                        return MM_ERROR_POLICY_INTERNAL;
@@ -368,7 +392,8 @@ int mm_sound_client_play_tone(int number, int volume_config, double volume, int
        return ret;
 }
 
-int mm_sound_client_play_tone_with_stream_info(int tone, char *stream_type, int stream_id, double volume, int duration, int *handle)
+int mm_sound_client_play_tone_with_stream_info(int tone, char *stream_type, int stream_id,
+                                                                                       double volume, int duration, int *handle)
 {
        int ret = MM_ERROR_NONE;
 
@@ -385,7 +410,7 @@ static void _mm_sound_stop_callback_wrapper_func(int ended_handle, void *userdat
        struct callback_data *cb_data = (struct callback_data*) userdata;
        play_sound_end_callback_data_t *end_cb_data;
 
-       debug_log("[Wrapper CB][Play Stop] ended_handle : %d", ended_handle);
+       debug_log("ended_handle : %d", ended_handle);
 
        if (cb_data == NULL) {
                debug_warning("stop callback data null");
@@ -422,7 +447,7 @@ int mm_sound_client_play_sound(MMSoundPlayParam *param, int tone, int *handle)
        int is_focus_registered = 0;
 //     int instance = -1;      /* instance is unique to communicate with server : client message queue filter type */
        int volume_type = MM_SOUND_VOLUME_CONFIG_TYPE(param->volume_config);
-       char stream_type[MM_SOUND_STREAM_TYPE_LEN] = {0, };
+       char stream_type[MAX_STREAM_TYPE_LEN] = {0, };
        struct callback_data *cb_data = NULL;
        play_sound_end_callback_data_t *end_cb_data;
 
@@ -441,11 +466,11 @@ int mm_sound_client_play_sound(MMSoundPlayParam *param, int tone, int *handle)
 
        if (param->skip_session == false) {
                if(MM_ERROR_NONE != _mm_session_util_read_information(-1, &session_type, &session_options)) {
-                       debug_warning("[Client] Read MMSession Type failed. use default \"media\" type\n");
+                       debug_warning("Read MMSession Type failed. use default \"media\" type");
                        session_type = MM_SESSION_TYPE_MEDIA;
 
                        if(MM_ERROR_NONE != mm_session_init(session_type)) {
-                               debug_critical("[Client] MMSessionInit() failed\n");
+                               debug_critical("MMSessionInit() failed");
                                return MM_ERROR_POLICY_INTERNAL;
                        }
                }
@@ -459,8 +484,7 @@ int mm_sound_client_play_sound(MMSoundPlayParam *param, int tone, int *handle)
 
        mm_sound_convert_volume_type_to_stream_type(volume_type, stream_type);
        ret = mm_sound_proxy_play_sound(param->filename, tone, param->loop, param->volume, param->volume_config,
-                                        param->priority, session_type, session_options, getpid(), param->handle_route,
-                                        !param->skip_session, handle, stream_type, -1);
+                                        session_type, session_options, getpid(), param->skip_session, handle, stream_type, -1);
        if (ret != MM_ERROR_NONE) {
                debug_error("Play Sound Failed");
                goto failed;
@@ -470,14 +494,16 @@ int mm_sound_client_play_sound(MMSoundPlayParam *param, int tone, int *handle)
                end_cb_data->watching_handle = *handle;
                GET_CB_DATA(cb_data, param->callback, param->data, end_cb_data);
 
-               ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data, play_end_callback_data_free_func, &end_cb_data->subs_id);
+               ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data,
+                                                                                                               play_end_callback_data_free_func, &end_cb_data->subs_id);
                if (ret != MM_ERROR_NONE) {
                        debug_error("Add callback for play sound(%d) Failed", *handle);
                }
        }
 #ifdef USE_FOCUS
        if (!param->skip_session && !g_focus_signal_handle) {
-               ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle, _mm_sound_client_focus_signal_callback, NULL);
+               ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle,
+                                                                               _mm_sound_client_focus_signal_callback, NULL);
                if (ret) {
                        debug_error("mm_sound_subscribe_signal failed [0x%x]", ret);
                        return MM_ERROR_POLICY_INTERNAL;
@@ -498,7 +524,7 @@ int mm_sound_client_play_sound_with_stream_info(MMSoundPlayParam *param, int *ha
        play_sound_end_callback_data_t *end_cb_data;
 
        ret = mm_sound_proxy_play_sound_with_stream_info(param->filename, param->loop, param->volume,
-                                        param->priority, getpid(), param->handle_route, handle, stream_type, stream_id);
+                                                                                                       getpid(), handle, stream_type, stream_id);
        if (ret != MM_ERROR_NONE) {
                debug_error("Play Sound Failed");
                goto failed;
@@ -508,7 +534,8 @@ int mm_sound_client_play_sound_with_stream_info(MMSoundPlayParam *param, int *ha
                end_cb_data->watching_handle = *handle;
                GET_CB_DATA(cb_data, param->callback, param->data, end_cb_data);
 
-               ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data, play_end_callback_data_free_func, &end_cb_data->subs_id);
+               ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data,
+                                                                                                               play_end_callback_data_free_func, &end_cb_data->subs_id);
                if (ret != MM_ERROR_NONE) {
                        debug_error("Add callback for play sound(%d) Failed", *handle);
                }
@@ -548,15 +575,16 @@ static int _mm_sound_client_device_list_dump (GList *device_list)
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       debug_log("======================== device list : start ==========================\n");
+       debug_log("======================== device list : start ==========================");
        for (list = device_list; list != NULL; list = list->next) {
                device_node = (mm_sound_device_t *)list->data;
                if (device_node) {
-                       debug_log(" list idx[%d]: type[%17s], id[%02d], io_direction[%d], state[%d], name[%s]\n",
-                                               count++, device_node->type, device_node->id, device_node->io_direction, device_node->state, device_node->name);
+                       debug_log(" list idx[%d]: type[%17s], id[%02d], io_direction[%d], state[%d], name[%s]",
+                                               count++, device_node->type, device_node->id, device_node->io_direction,
+                                               device_node->state, device_node->name);
                }
        }
-       debug_log("======================== device list : end ============================\n");
+       debug_log("======================== device list : end ============================");
 
        return ret;
 }
@@ -573,7 +601,7 @@ int mm_sound_client_get_current_connected_device_list(int device_flags, mm_sound
        }
 
        if ((ret = mm_sound_proxy_get_current_connected_device_list(device_flags, &device_list->list)) != MM_ERROR_NONE) {
-               debug_error("[Client] failed to get current connected device list with dbus, ret[0x%x]", ret);
+               debug_error("failed to get current connected device list with dbus, ret[0x%x]", ret);
                goto failed;
        }
        if (!device_list->list) {
@@ -588,6 +616,20 @@ failed:
        return ret;
 }
 
+int mm_sound_client_get_device_by_id(int device_id, mm_sound_device_t **device)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if ((ret = mm_sound_proxy_get_device_by_id(device_id, device)) != MM_ERROR_NONE)
+               debug_error("failed to get device by id");
+
+       debug_fleave();
+
+       return ret;
+}
+
 static bool device_is_match_direction(int direction, int mask)
 {
        if (mask == DEVICE_IO_DIRECTION_FLAGS || mask == 0)
@@ -645,7 +687,8 @@ static bool device_is_match_with_mask(const char *type, int direction, int state
 }
 
 static int _fill_sound_device(mm_sound_device_t *device_h, int device_id, const char *device_type,
-               int direction, int state, const char *name, int *stream_id, int stream_num)
+               int direction, int state, const char *name, int vendor_id, int product_id,
+               int *stream_id, int stream_num)
 {
        int i;
 
@@ -664,6 +707,8 @@ static int _fill_sound_device(mm_sound_device_t *device_h, int device_id, const
        device_h->state = state;
        MMSOUND_STRNCPY(device_h->name, name, MAX_DEVICE_NAME_NUM);
        MMSOUND_STRNCPY(device_h->type, device_type, MAX_DEVICE_TYPE_STR_LEN);
+       device_h->vendor_id = vendor_id;
+       device_h->product_id = product_id;
 
        if (stream_num > 0) {
                device_h->stream_num = stream_num;
@@ -681,15 +726,16 @@ static int _fill_sound_device(mm_sound_device_t *device_h, int device_id, const
 }
 
 static void _mm_sound_device_connected_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
-               int state, const char *name, int *stream_id, int stream_num, gboolean is_connected, void *userdata)
+                                                       int state, const char *name, int vendor_id, int product_id, int *stream_id, int stream_num,
+                                                       gboolean is_connected, void *userdata)
 {
        mm_sound_device_t device_h;
        struct callback_data *cb_data = (struct callback_data*) userdata;
        int device_flags;
 
-       debug_log("[Device %s] id(%d) type(%s) direction(%d) state(%d) name(%s)",
+       debug_log("[Device %s] id(%d) type(%s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
                          is_connected ? "Connected" : "Disconnected", device_id, device_type, io_direction,
-                         state, name, is_connected);
+                         state, name, vendor_id, product_id, is_connected);
 
        if (cb_data == NULL) {
                debug_warning("device connected changed callback data null");
@@ -700,7 +746,8 @@ static void _mm_sound_device_connected_callback_wrapper_func(int device_id, cons
        if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
                return;
 
-       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name, stream_id, stream_num) < 0) {
+       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
+                               vendor_id, product_id, stream_id, stream_num) < 0) {
                debug_error("Failed to fill sound device");
                return;
        }
@@ -708,7 +755,8 @@ static void _mm_sound_device_connected_callback_wrapper_func(int device_id, cons
        ((mm_sound_device_connected_cb)(cb_data->user_cb))(&device_h, is_connected, cb_data->user_data);
 }
 
-int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* userdata, unsigned int *subs_id)
+int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func,
+                                                                                               void* userdata, unsigned int *subs_id)
 {
        int ret = MM_ERROR_NONE;
        struct callback_data *cb_data = NULL;
@@ -717,7 +765,9 @@ int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_dev
 
        GET_CB_DATA(cb_data, func, userdata, (void*) device_flags);
 
-       ret = mm_sound_proxy_add_device_connected_callback(device_flags, _mm_sound_device_connected_callback_wrapper_func, cb_data, g_free, subs_id);
+       ret = mm_sound_proxy_add_device_connected_callback(device_flags,
+                                                                                                       _mm_sound_device_connected_callback_wrapper_func,
+                                                                                                       cb_data, g_free, subs_id);
        if (ret == MM_ERROR_NONE)
                g_need_emergent_exit = TRUE;
 
@@ -737,14 +787,16 @@ int mm_sound_client_remove_device_connected_callback(unsigned int subs_id)
 }
 
 static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
-               int state, const char *name, int *stream_id, int stream_num, int changed_device_info_type, void *userdata)
+                                                       int state, const char *name, int vendor_id, int product_id, int *stream_id, int stream_num,
+                                                       int changed_device_info_type, void *userdata)
 {
        mm_sound_device_t device_h;
        struct callback_data *cb_data = (struct callback_data*) userdata;
        int device_flags;
 
-       debug_log("[Device Info Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) changed_info_type(%d)",
-                         device_id, device_type, io_direction, state, name, changed_device_info_type);
+       debug_log("[Device Info Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) "
+                       "vendor-id(%04x) product-id(%04x) changed_info_type(%d)",
+                       device_id, device_type, io_direction, state, name, vendor_id, product_id, changed_device_info_type);
 
        if (cb_data == NULL) {
                debug_warning("device info changed callback data null");
@@ -755,7 +807,8 @@ static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, c
        if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
                return;
 
-       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name, stream_id, stream_num) < 0) {
+       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
+                               vendor_id, product_id, stream_id, stream_num) < 0) {
                debug_error("Failed to fill sound device");
                return;
        }
@@ -763,7 +816,8 @@ static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, c
        ((mm_sound_device_info_changed_cb)(cb_data->user_cb))(&device_h, changed_device_info_type, cb_data->user_data);
 }
 
-int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void *userdata, unsigned int *subs_id)
+int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func,
+                                                                                                       void *userdata, unsigned int *subs_id)
 {
        int ret = MM_ERROR_NONE;
        struct callback_data *cb_data = (struct callback_data*) userdata;
@@ -772,7 +826,9 @@ int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_
 
        GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
 
-       ret = mm_sound_proxy_add_device_info_changed_callback(device_flags, _mm_sound_device_info_changed_callback_wrapper_func, cb_data, g_free, subs_id);
+       ret = mm_sound_proxy_add_device_info_changed_callback(device_flags,
+                                                                                                               _mm_sound_device_info_changed_callback_wrapper_func,
+                                                                                                               cb_data, g_free, subs_id);
 
        debug_fleave();
        return ret;
@@ -790,15 +846,17 @@ int mm_sound_client_remove_device_info_changed_callback(unsigned int subs_id)
 
 }
 
-static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
-               int state, const char *name, int *stream_id, int stream_num, void *userdata)
+static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type,
+                                                               int io_direction, int state, const char *name, int vendor_id, int product_id,
+                                                               int *stream_id, int stream_num, void *userdata)
 {
        mm_sound_device_t device_h;
        struct callback_data *cb_data = (struct callback_data*) userdata;
        int device_flags;
 
-       debug_log("[Device State Changed] id(%d) type(%s) direction(%d) state(%d) name(%s)",
-                         device_id, device_type, io_direction, state, name);
+       debug_log("[Device State Changed] id(%d) type(%s) direction(%d) state(%d) name(%s)"
+                       "vendor-id(%04x), product-id(%04x)",
+                       device_id, device_type, io_direction, state, name, vendor_id, product_id);
 
        if (cb_data == NULL) {
                debug_warning("device state changed callback data null");
@@ -810,7 +868,8 @@ static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id,
        if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
                return;
 
-       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name, stream_id, stream_num) < 0) {
+       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
+                               vendor_id, product_id, stream_id, stream_num) < 0) {
                debug_error("Failed to fill sound device");
                return;
        }
@@ -818,7 +877,8 @@ static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id,
        ((mm_sound_device_state_changed_cb)(cb_data->user_cb))(&device_h, state, cb_data->user_data);
 }
 
-int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func, void *userdata, unsigned int *id)
+int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func,
+                                                                                                       void *userdata, unsigned int *id)
 {
        int ret = MM_ERROR_NONE;
        struct callback_data *cb_data = (struct callback_data*) userdata;
@@ -827,7 +887,9 @@ int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound
 
        GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
 
-       ret = mm_sound_proxy_add_device_state_changed_callback(device_flags, _mm_sound_device_state_changed_callback_wrapper_func, cb_data, g_free, id);
+       ret = mm_sound_proxy_add_device_state_changed_callback(device_flags,
+                                                                                                               _mm_sound_device_state_changed_callback_wrapper_func,
+                                                                                                               cb_data, g_free, id);
 
        debug_fleave();
        return ret;
@@ -856,7 +918,7 @@ int mm_sound_client_is_stream_on_device(int stream_id, int device_id, bool *is_o
        }
 
        if ((ret = mm_sound_proxy_is_stream_on_device(stream_id, device_id, is_on)) != MM_ERROR_NONE) {
-               debug_error("[Client] failed to query is stream on device, ret[0x%x]", ret);
+               debug_error("failed to query is stream on device, ret[0x%x]", ret);
                goto failed;
        }
 
@@ -958,12 +1020,14 @@ failed:
        return ret;
 }
 
-static void _mm_sound_volume_changed_callback_wrapper_func(const char *direction, const char *volume_type_str, int volume_level, void *userdata)
+static void _mm_sound_volume_changed_callback_wrapper_func(const char *direction, const char *volume_type_str,
+                                                                                                               int volume_level, void *userdata)
 {
        volume_type_t volume_type = 0;
        struct callback_data *cb_data = (struct callback_data *) userdata;
 
-       debug_log("[Wrapper CB][Volume Changed] direction : %s, volume_type : %s, volume_level : %d", direction, volume_type_str, volume_level);
+       debug_log("direction : %s, volume_type : %s, volume_level : %d",
+                       direction, volume_type_str, volume_level);
 
        if (cb_data == NULL) {
                debug_warning("volume changed callback data null");
@@ -974,7 +1038,8 @@ static void _mm_sound_volume_changed_callback_wrapper_func(const char *direction
                debug_error("volume type convert failed");
                return;
        }
-       debug_log("Call volume changed user cb, direction : %s, vol_type : %s(%d), level : %u", direction, volume_type_str, volume_type, volume_level);
+       debug_log("Call volume changed user cb, direction : %s, vol_type : %s(%d), level : %u",
+                       direction, volume_type_str, volume_type, volume_level);
        ((mm_sound_volume_changed_cb)(cb_data->user_cb))(volume_type, volume_level, cb_data->user_data);
 }
 
@@ -1005,7 +1070,85 @@ int mm_sound_client_remove_volume_changed_callback(unsigned int subs_id)
        return ret;
 }
 
+int mm_sound_client_set_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       ret = mm_sound_proxy_set_filter_by_type(stream_type, filter_name, filter_parameters, filter_group);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_unset_filter_by_type(const char *stream_type)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       ret = mm_sound_proxy_unset_filter_by_type(stream_type);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       ret = mm_sound_proxy_control_filter_by_type(stream_type, filter_name, filter_controls);
+
+       debug_fleave();
+       return ret;
+}
+
 #ifdef USE_FOCUS
+static gboolean _interrupted_completed(gpointer *data)
+{
+       if (!data) {
+               debug_error("data is null");
+               return false;
+       }
+       if (!g_focus_session_interrupt_info.user_cb) {
+               debug_error("user_cb is null");
+               free(data);
+               return false;
+       }
+
+       debug_msg("invoke user_cb(%p)", g_focus_session_interrupt_info.user_cb);
+       (g_focus_session_interrupt_info.user_cb)(FOCUS_IS_RELEASED, (const char *)data, g_focus_session_interrupt_info.user_data);
+       debug_msg("invoked");
+
+       free(data);
+       return false;
+}
+
+static void _session_interrupted_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state,
+                                    const char *reason_for_change, const char *ext_info, void *user_data)
+{
+       debug_msg("id(%d), focus_type(%d), state(%d), reason(%s)", id, focus_type, state, reason_for_change);
+
+       if (id != g_focus_session_interrupt_info.watch_cb_id) {
+               debug_error("id is not valid(param id:%d, g_focus_session_interrupt_watch_cb_id:%d)",
+                           id, g_focus_session_interrupt_info.watch_cb_id);
+               return;
+       }
+       if (!g_focus_session_interrupt_info.user_cb) {
+               debug_error("user callback is null");
+               return;
+       }
+
+       debug_msg("  >>> invoking session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
+       if (state == FOCUS_IS_RELEASED)
+               (g_focus_session_interrupt_info.user_cb)(FOCUS_IS_ACQUIRED, reason_for_change, g_focus_session_interrupt_info.user_data);
+       else {
+               debug_msg("INTERRUPTED COMPLETED case, append it to idle");
+               g_idle_add((GSourceFunc)_interrupted_completed, strdup(reason_for_change));
+       }
+       debug_msg("  <<< session interrupt callback finished");
+}
+
 int mm_sound_client_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void* user_data)
 {
        int ret = MM_ERROR_NONE;
@@ -1015,6 +1158,14 @@ int mm_sound_client_set_session_interrupt_callback(mm_sound_focus_session_interr
        if (!callback)
                return MM_ERROR_INVALID_ARGUMENT;
 
+       /* add internal focus watch callback */
+       if (g_focus_session_interrupt_info.watch_cb_id == -1) {
+               if ((ret = mm_sound_client_set_focus_watch_callback(getpid(), FOCUS_FOR_BOTH, true, true, _session_interrupted_cb, NULL,
+                                                                   &g_focus_session_interrupt_info.watch_cb_id))) {
+                       debug_error("failed to mm_sound_client_set_focus_watch_callback(), ret(0x%x)", ret);
+                       return ret;
+               }
+       }
        g_focus_session_interrupt_info.user_cb = callback;
        g_focus_session_interrupt_info.user_data = user_data;
 
@@ -1028,11 +1179,18 @@ int mm_sound_client_unset_session_interrupt_callback(void)
 
        debug_fenter();
 
-       if (!g_focus_session_interrupt_info.user_cb) {
+       if (!g_focus_session_interrupt_info.user_cb || g_focus_session_interrupt_info.watch_cb_id == -1) {
                debug_error("no callback to unset");
                return MM_ERROR_SOUND_INTERNAL;
        }
 
+       /* remove internal focus watch callback */
+       if ((ret = mm_sound_client_unset_focus_watch_callback(g_focus_session_interrupt_info.watch_cb_id))) {
+               debug_error("failed to mm_sound_client_unset_focus_watch_callback(), id(%d), ret(0x%x)",
+                           g_focus_session_interrupt_info.watch_cb_id, ret);
+               return ret;
+       }
+       g_focus_session_interrupt_info.watch_cb_id = -1;
        g_focus_session_interrupt_info.user_cb = NULL;
        g_focus_session_interrupt_info.user_data = NULL;
 
@@ -1043,52 +1201,50 @@ int mm_sound_client_unset_session_interrupt_callback(void)
 static gpointer _focus_thread_func(gpointer data)
 {
        unsigned int thread_id = (unsigned int)pthread_self();
-       debug_warning(">>> thread func..ID of this thread(%u), mainloop(%p)", thread_id, g_focus_loop);
-       if (g_focus_loop)
-               g_main_loop_run(g_focus_loop);
+       GMainLoop *focus_loop = (GMainLoop*)data;
+
+       debug_warning(">>> thread id(%u), mainloop[%p]", thread_id, focus_loop);
+       if (focus_loop)
+               g_main_loop_run(focus_loop);
+       debug_warning("<<< quit : thread id(%u), mainloop[%p]", thread_id, focus_loop);
 
-       debug_warning("<<< quit thread func..(%u), mainloop(%p)", thread_id, g_focus_loop);
        return NULL;
 }
 
+static gboolean _focus_fd_prepare(GSource *source, gint *timeout)
+{
+#ifdef __DEBUG__
+       debug_warning("[ PREPARE : %p, (%p, %d)", source, timeout, timeout? *timeout : -1);
+#endif
+       return FALSE;
+}
+
 static gboolean _focus_fd_check(GSource * source)
 {
-       GSList *fd_list;
-       GPollFD *temp;
+       FocusSource* fsource = (FocusSource *)source;
 
-       if (!source) {
+       if (!fsource) {
                debug_error("GSource is null");
                return FALSE;
        }
-       fd_list = source->poll_fds;
-       if (!fd_list) {
-               debug_error("fd_list is null");
+#ifdef __DEBUG__
+       debug_warning("CHECK : %p, 0x%x ]", source, fsource->pollfd.revents);
+#endif
+       if (fsource->poll_fd.revents & (POLLIN | POLLPRI))
+               return TRUE;
+       else
                return FALSE;
-       }
-       do {
-               temp = (GPollFD*)fd_list->data;
-               if (!temp) {
-                       debug_error("fd_list->data is null");
-                       return FALSE;
-               }
-               if (temp->revents & (POLLIN | POLLPRI)) {
-                       return TRUE;
-               }
-               fd_list = fd_list->next;
-       } while (fd_list);
-
-       return FALSE; /* there is no change in any fd state */
 }
 
-static gboolean _focus_fd_prepare(GSource *source, gint *timeout)
+static gboolean _focus_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
 {
-       return FALSE;
+       debug_warning("*** DISPATCH : %p, (%p, %p)", source, callback, user_data);
+       return callback(user_data);
 }
 
-static gboolean _focus_fd_dispatch(GSource *source,    GSourceFunc callback, gpointer user_data)
+static void _focus_fd_finalize(GSource *source)
 {
-       callback(user_data);
-       return TRUE;
+       debug_warning("### FINALIZE : %p", source);
 }
 
 static int _focus_find_index_by_handle(int handle)
@@ -1115,142 +1271,141 @@ static int _focus_watch_find_index_by_handle(int handle)
        return -1;
 }
 
-static gboolean _focus_callback_handler(gpointer d)
+static gboolean _focus_callback_handler(gpointer user_data)
 {
-       GPollFD *data = (GPollFD*)d;
+       focus_sound_info_t *focus_handle = (focus_sound_info_t *)user_data;
+       GPollFD *poll_fd;
        int count;
        int tid = 0;
-       int focus_index = 0;
        focus_cb_data_lib cb_data;
-       debug_log(">>> focus_callback_handler()..ID of this thread(%u)\n", (unsigned int)pthread_self());
 
-       memset(&cb_data, 0, sizeof(focus_cb_data_lib));
+       debug_log(">>> thread id(%u)", (unsigned int)pthread_self());
 
-       if (!data) {
-               debug_error("GPollFd is null");
-               return FALSE;
+       if (!focus_handle) {
+               debug_error("focus_handle is null");
+               return G_SOURCE_CONTINUE;
        }
-       if (data->revents & (POLLIN | POLLPRI)) {
+       poll_fd = &focus_handle->fsrc->poll_fd;
+       debug_log("focus_handle(%p), poll_fd(%p)", focus_handle, poll_fd);
+
+       memset(&cb_data, 0, sizeof(focus_cb_data_lib));
+
+       if (poll_fd->revents & (POLLIN | POLLPRI)) {
                int changed_state = -1;
 
-               count = read(data->fd, &cb_data, sizeof(cb_data));
+               count = read(poll_fd->fd, &cb_data, sizeof(cb_data));
                if (count < 0){
                        char str_error[256];
                        strerror_r(errno, str_error, sizeof(str_error));
                        debug_error("GpollFD read fail, errno=%d(%s)",errno, str_error);
-                       return FALSE;
+                       return G_SOURCE_CONTINUE;
                }
                changed_state = cb_data.state;
-               focus_index = _focus_find_index_by_handle(cb_data.handle);
-               if (focus_index == -1) {
-                       debug_error("Could not find index");
-                       return FALSE;
-               }
 
-               g_mutex_lock(&g_focus_sound_handle[focus_index].focus_lock);
+               g_mutex_lock(&focus_handle->focus_lock);
 
-               tid = g_focus_sound_handle[focus_index].focus_tid;
+               tid = focus_handle->focus_tid;
 
                if (changed_state != -1) {
-                       debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
-                       if (g_focus_sound_handle[focus_index].focus_callback == NULL) {
-                                       debug_error("callback is null..");
-                                       g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
-                                       return FALSE;
+                       debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)",
+                                       tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
+                       if (focus_handle->focus_callback == NULL) {
+                                       debug_error("focus callback is null..");
+                                       g_mutex_unlock(&focus_handle->focus_lock);
+                                       return G_SOURCE_CONTINUE;
                        }
-                       debug_msg("[CALLBACK(%p) START]",g_focus_sound_handle[focus_index].focus_callback);
-                       (g_focus_sound_handle[focus_index].focus_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.option, cb_data.ext_info, g_focus_sound_handle[focus_index].user_data);
+                       debug_msg("[CALLBACK(%p) START]", focus_handle->focus_callback);
+                       (focus_handle->focus_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type,
+                                                                               cb_data.option, cb_data.ext_info, focus_handle->user_data);
                        debug_msg("[CALLBACK END]");
-                       if (g_focus_session_interrupt_info.user_cb) {
-                               debug_msg("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
-                               (g_focus_session_interrupt_info.user_cb)(cb_data.state, cb_data.stream_type, false, g_focus_session_interrupt_info.user_data);
-                       }
                }
 #ifdef CONFIG_ENABLE_RETCB
                {
                        int rett = 0;
                        int tmpfd = -1;
                        unsigned int buf = 0;
-                       char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[focus_index].focus_tid, cb_data.handle);
+                       char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", focus_handle->focus_tid, cb_data.handle);
                        tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
                        if (tmpfd < 0) {
                                char str_error[256];
                                strerror_r(errno, str_error, sizeof(str_error));
-                               debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
+                               debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)",
+                                                       tid, tmpfd, filename2, errno, str_error);
                                g_free(filename2);
-                               g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
-                               return FALSE;
+                               g_mutex_unlock(&focus_handle->focus_lock);
+                               return G_SOURCE_CONTINUE;
                        }
                        /* buf contains data as below,
                         * |<--12bits--><--4bits (reacquisition)--><--16bits (handle)-->| */
-                       buf = (unsigned int)((0x0000ffff & cb_data.handle) | (g_focus_sound_handle[focus_index].auto_reacquire << 16));
+                       buf = (unsigned int)((0x0000ffff & cb_data.handle) | (focus_handle->auto_reacquire << 16));
                        rett = write(tmpfd, &buf, sizeof(buf));
                        close(tmpfd);
                        g_free(filename2);
-                       debug_msg("[RETCB] tid(%d) finishing CB (write=%d)\n", tid, rett);
+                       debug_msg("[RETCB] tid(%d) finishing CB (write=%d)", tid, rett);
                }
 #endif
        }
 
-       g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
+       g_mutex_unlock(&focus_handle->focus_lock);
+
+       debug_fleave();
 
-       return TRUE;
+       return G_SOURCE_CONTINUE;
 }
 
-static gboolean _focus_watch_callback_handler(gpointer d)
+static gboolean _focus_watch_callback_handler(gpointer user_data)
 {
-       GPollFD *data = (GPollFD*)d;
+       focus_sound_info_t *focus_handle = (focus_sound_info_t *)user_data;
+       GPollFD *poll_fd;
        int count;
        int tid = 0;
-       int focus_index = 0;
        focus_cb_data_lib cb_data;
 
-       debug_fenter();
+       debug_log(">>> thread id(%u)", (unsigned int)pthread_self());
+
+       if (!focus_handle) {
+               debug_error("focus_handle is null");
+               return G_SOURCE_CONTINUE;
+       }
+       poll_fd = &focus_handle->fsrc->poll_fd;
+       debug_log("focus_handle(%p), poll_fd(%p)", focus_handle, poll_fd);
 
        memset(&cb_data, 0, sizeof(focus_cb_data_lib));
 
-       if (!data) {
-               debug_error("GPollFd is null");
-               return FALSE;
-       }
-       if (data->revents & (POLLIN | POLLPRI)) {
-               count = read(data->fd, &cb_data, sizeof(cb_data));
+       if (poll_fd->revents & (POLLIN | POLLPRI)) {
+               count = read(poll_fd->fd, &cb_data, sizeof(cb_data));
                if (count < 0){
                        char str_error[256];
                        strerror_r(errno, str_error, sizeof(str_error));
                        debug_error("GpollFD read fail, errno=%d(%s)",errno, str_error);
-                       return FALSE;
+                       return G_SOURCE_CONTINUE;
                }
 
-               focus_index = _focus_watch_find_index_by_handle(cb_data.handle);
-               if (focus_index == -1) {
-                       debug_error("Could not find index");
-                       return FALSE;
-               }
-
-               if (!g_focus_sound_handle[focus_index].is_used) {
+               if (!focus_handle->is_used) {
                        debug_warning("unsetting watch calllback has been already requested");
                        goto SKIP_CB_AND_RET;
                }
 
-               debug_msg("lock focus_lock = %p", &g_focus_sound_handle[focus_index].focus_lock);
-               g_mutex_lock(&g_focus_sound_handle[focus_index].focus_lock);
+               g_mutex_lock(&focus_handle->focus_lock);
 
-               tid = g_focus_sound_handle[focus_index].focus_tid;
+               tid = focus_handle->focus_tid;
 
-               debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle,  cb_data.type, cb_data.state, cb_data.stream_type);
+               debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)",
+                               tid, cb_data.handle,  cb_data.type, cb_data.state, cb_data.stream_type);
 
-               if (g_focus_sound_handle[focus_index].watch_callback == NULL) {
-                       debug_msg("callback is null..");
-               } else {
-                       debug_msg("[CALLBACK(%p) START]",g_focus_sound_handle[focus_index].watch_callback);
-                       (g_focus_sound_handle[focus_index].watch_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.ext_info, g_focus_sound_handle[focus_index].user_data);
-                       debug_msg("[CALLBACK END]");
-                       if (g_focus_session_interrupt_info.user_cb) {
-                               debug_msg("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
-                               (g_focus_session_interrupt_info.user_cb)(cb_data.state, cb_data.stream_type, true, g_focus_session_interrupt_info.user_data);
-                       }
+               if (focus_handle->watch_callback == NULL) {
+                       debug_warning("watch callback is null..");
+                       goto SKIP_CB_AND_RET;
                }
+               if (focus_handle->unset_watch_callback_requested == true) {
+                       debug_warning("unset_watch_callback_requested..");
+                       goto SKIP_CB_AND_RET;
+               }
+
+               debug_msg("[CALLBACK(%p) START]", focus_handle->watch_callback);
+               (focus_handle->watch_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type,
+                                                                       cb_data.ext_info, focus_handle->user_data);
+               debug_msg("[CALLBACK END]");
 
 SKIP_CB_AND_RET:
 #ifdef CONFIG_ENABLE_RETCB
@@ -1258,33 +1413,34 @@ SKIP_CB_AND_RET:
                        int rett = 0;
                        int tmpfd = -1;
                        int buf = -1;
-                       char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", g_focus_sound_handle[focus_index].focus_tid, cb_data.handle);
+                       char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", focus_handle->focus_tid, cb_data.handle);
                        tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
                        if (tmpfd < 0) {
                                char str_error[256];
                                strerror_r(errno, str_error, sizeof(str_error));
-                               debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
+                               debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)",
+                                                       tid, tmpfd, filename2, errno, str_error);
                                g_free(filename2);
-                               g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
-                               return FALSE;
+                               g_mutex_unlock(&focus_handle->focus_lock);
+                               return G_SOURCE_CONTINUE;
                        }
                        buf = cb_data.handle;
                        rett = write(tmpfd, &buf, sizeof(buf));
                        close(tmpfd);
                        g_free(filename2);
-                       debug_msg("[RETCB] tid(%d) finishing CB (write=%d)\n", tid, rett);
+                       debug_msg("[RETCB] tid(%d) finishing CB (write=%d)", tid, rett);
                }
 #endif
        }
 
-       if (g_focus_sound_handle[focus_index].is_used) {
-               debug_msg("unlock focus_lock = %p", &g_focus_sound_handle[focus_index].focus_lock);
-               g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
+       if (focus_handle->is_used) {
+               debug_msg("unlock focus_lock = %p", &focus_handle->focus_lock);
+               g_mutex_unlock(&focus_handle->focus_lock);
        }
 
        debug_fleave();
 
-       return TRUE;
+       return G_SOURCE_CONTINUE;
 }
 
 static void _focus_open_callback(int index, bool is_for_watching)
@@ -1300,9 +1456,13 @@ static void _focus_open_callback(int index, bool is_for_watching)
        }
 
        if (is_for_watching) {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+               filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch",
+                                                               g_focus_sound_handle[index].focus_tid,
+                                                               g_focus_sound_handle[index].handle);
        } else {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+               filename = g_strdup_printf("/tmp/FOCUS.%d.%d",
+                                                               g_focus_sound_handle[index].focus_tid,
+                                                               g_focus_sound_handle[index].handle);
        }
        pre_mask = umask(0);
        if (mknod(filename, S_IFIFO|0666, 0)) {
@@ -1313,7 +1473,8 @@ static void _focus_open_callback(int index, bool is_for_watching)
        if (g_focus_sound_handle[index].focus_fd == -1) {
                debug_error("Open fail : index(%d), file open error(%d)", index, errno);
        } else {
-               debug_log("Open success : index(%d), filename(%s), fd(%d)", index, filename, g_focus_sound_handle[index].focus_fd);
+               debug_log("Open success : index(%d), filename(%s), fd(%d)",
+                               index, filename, g_focus_sound_handle[index].focus_fd);
        }
        g_free(filename);
        filename = NULL;
@@ -1322,9 +1483,13 @@ static void _focus_open_callback(int index, bool is_for_watching)
        char *filename2;
 
        if (is_for_watching) {
-               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr",
+                                                                       g_focus_sound_handle[index].focus_tid,
+                                                                       g_focus_sound_handle[index].handle);
        } else {
-               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr",
+                                                                       g_focus_sound_handle[index].focus_tid,
+                                                                       g_focus_sound_handle[index].handle);
        }
        pre_mask = umask(0);
        if (mknod(filename2, S_IFIFO | 0666, 0)) {
@@ -1357,12 +1522,17 @@ void _focus_close_callback(int index, bool is_for_watching)
        }
 
        if (is_for_watching) {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+               filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch",
+                                                               g_focus_sound_handle[index].focus_tid,
+                                                               g_focus_sound_handle[index].handle);
        } else {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+               filename = g_strdup_printf("/tmp/FOCUS.%d.%d",
+                                                               g_focus_sound_handle[index].focus_tid,
+                                                               g_focus_sound_handle[index].handle);
        }
        if (remove(filename)) {
-               debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)", filename, errno);
+               debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)",
+                                       filename, errno);
        }
        g_free(filename);
        filename = NULL;
@@ -1371,12 +1541,17 @@ void _focus_close_callback(int index, bool is_for_watching)
        char *filename2;
 
        if (is_for_watching) {
-               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr",
+                                                                       g_focus_sound_handle[index].focus_tid,
+                                                                       g_focus_sound_handle[index].handle);
        } else {
-               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr",
+                                                                       g_focus_sound_handle[index].focus_tid,
+                                                                       g_focus_sound_handle[index].handle);
        }
        if (remove(filename2)) {
-               debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)", filename2, errno);
+               debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)",
+                                       filename2, errno);
        }
        g_free(filename2);
        filename2 = NULL;
@@ -1386,76 +1561,61 @@ void _focus_close_callback(int index, bool is_for_watching)
 
 }
 
-static bool _focus_add_sound_callback(int index, int fd, gushort events, focus_gLoopPollHandler_t p_gloop_poll_handler )
+static GSourceFuncs event_funcs = {
+       .prepare = _focus_fd_prepare,
+       .check = _focus_fd_check,
+       .dispatch = _focus_fd_dispatch,
+       .finalize = _focus_fd_finalize,
+};
+
+static bool _focus_add_sound_callback(int index, focus_callback_handler_t focus_cb_handler)
 {
-       GSource* g_src = NULL;
-       GSourceFuncs *g_src_funcs = NULL;               /* handler function */
-       guint g_src_id = 0;
-       GPollFD *g_poll_fd = NULL;                      /* file descriptor */
+       FocusSource *fsrc = NULL;
+       GSource *src = NULL;
+       guint fsrc_id = 0;
 
        debug_fenter();
 
        g_mutex_init(&g_focus_sound_handle[index].focus_lock);
 
-       /* 1. make GSource Object */
-       g_src_funcs = (GSourceFuncs *)g_malloc(sizeof(GSourceFuncs));
-       if (!g_src_funcs) {
-               debug_error("failed to g_malloc for g_src_funcs");
+       src = g_source_new(&event_funcs, sizeof(FocusSource));
+       if (!src) {
+               debug_error("failed to g_source_new for focus source");
                goto ERROR;
        }
 
-       g_src_funcs->prepare = _focus_fd_prepare;
-       g_src_funcs->check = _focus_fd_check;
-       g_src_funcs->dispatch = _focus_fd_dispatch;
-       g_src_funcs->finalize = NULL;
-       g_src = g_source_new(g_src_funcs, sizeof(GSource));
-       if (!g_src) {
-               debug_error("failed to g_source_new for g_src");
-               goto ERROR;
-       }
+       fsrc = (FocusSource*) src;
 
-       /* 2. add file description which used in g_loop() */
-       g_poll_fd = (GPollFD *)g_malloc(sizeof(GPollFD));
-       if (!g_poll_fd) {
-               debug_error("failed to g_malloc for g_poll_fd");
-               goto ERROR;
-       }
-       g_poll_fd->fd = fd;
-       g_poll_fd->events = events;
+       fsrc->poll_fd.fd = g_focus_sound_handle[index].focus_fd;
+       fsrc->poll_fd.events = (gushort)(POLLIN | POLLPRI);
+       g_source_add_poll(src, &fsrc->poll_fd);
+
+       g_source_set_callback(src, focus_cb_handler, (gpointer)&g_focus_sound_handle[index], NULL);
 
-       /* 3. combine g_source object and file descriptor */
-       g_source_add_poll(g_src, g_poll_fd);
-       g_src_id = g_source_attach(g_src, g_main_loop_get_context(g_focus_loop));
-       if (!g_src_id) {
+       debug_warning("fsrc(%p), src_funcs(%p), pollfd(%p), fd(%d)",
+                               fsrc, &event_funcs, &fsrc->poll_fd, fsrc->poll_fd.fd);
+
+       fsrc_id = g_source_attach(src, g_main_loop_get_context(g_focus_sound_handle[index].focus_loop));
+       if (!fsrc_id) {
                debug_error("failed to attach the source to context");
                goto ERROR;
        }
+       g_source_unref(src);
 
-       /* 4. set callback */
-       g_source_set_callback(g_src, p_gloop_poll_handler,(gpointer)g_poll_fd, NULL);
-
-       debug_log("g_malloc : g_src_funcs(%p), g_poll_fd(%p)", g_src_funcs, g_poll_fd);
-
-       /* 5. store to global handle */
-       g_focus_sound_handle[index].focus_src = g_src;
-       g_focus_sound_handle[index].g_src_funcs = g_src_funcs;
-       g_focus_sound_handle[index].g_poll_fd = g_poll_fd;
+       g_focus_sound_handle[index].fsrc = fsrc;
 
        debug_fleave();
        return true;
 
 ERROR:
-       g_free(g_src_funcs);
-       g_free(g_poll_fd);
-       if (g_src)
-               g_source_unref(g_src);
+       if (src)
+               g_source_unref(src);
 
        return false;
 }
 
 static bool _focus_remove_sound_callback(int index)
 {
-       bool ret = true;
        focus_sound_info_t *h = NULL;
 
        debug_fenter();
@@ -1466,32 +1626,11 @@ static bool _focus_remove_sound_callback(int index)
        }
 
        h = &g_focus_sound_handle[index];
-
-       if (h->focus_src && h->g_poll_fd) {
-               debug_log("g_source_remove_poll : fd(%d), event(0x%x)",
-                               h->g_poll_fd->fd, h->g_poll_fd->events);
-               g_source_remove_poll(h->focus_src, h->g_poll_fd);
-       } else {
-               debug_error("[%d] focus_src[%p], g_poll_fd[%p]",
-                                       index, h->focus_src, h->g_poll_fd);
-               ret = false;
+       if (h->fsrc) {
+               g_source_destroy((GSource *)h->fsrc);
+               h->fsrc = NULL;
        }
 
-       if (h->focus_src) {
-               g_source_destroy(h->focus_src);
-               g_source_unref(h->focus_src);
-               h->focus_src = NULL;
-       }
-
-       debug_log("g_free : g_src_funcs(%p), g_poll_fd(%p)",
-                       h->g_src_funcs, h->g_poll_fd);
-
-       g_free(h->g_src_funcs);
-       h->g_src_funcs = NULL;
-
-       g_free(h->g_poll_fd);
-       h->g_poll_fd = NULL;
-
        h->focus_callback = NULL;
        h->watch_callback = NULL;
 
@@ -1499,10 +1638,9 @@ static bool _focus_remove_sound_callback(int index)
 
        debug_fleave();
 
-       return ret;
+       return true;
 }
 
-
 static void _focus_add_callback(int index, bool is_for_watching)
 {
        debug_fenter();
@@ -1513,12 +1651,10 @@ static void _focus_add_callback(int index, bool is_for_watching)
        }
 
        if (!is_for_watching) {
-               if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd,
-                                                                       (gushort)POLLIN | POLLPRI, _focus_callback_handler))
+               if (!_focus_add_sound_callback(index, _focus_callback_handler))
                        debug_error("failed to _focus_add_sound_callback(%p)", _focus_callback_handler);
        } else { // need to check if it's necessary
-               if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd,
-                                                                       (gushort)POLLIN | POLLPRI, _focus_watch_callback_handler))
+               if (!_focus_add_sound_callback(index, _focus_watch_callback_handler))
                        debug_error("failed to _focus_add_sound_callback(%p)", _focus_watch_callback_handler);
        }
        debug_fleave();
@@ -1540,7 +1676,7 @@ static void _focus_init_callback(int index, bool is_for_watching)
        debug_fleave();
 }
 
-static void _focus_destroy_callback(int index, bool is_for_watching)
+static void _focus_deinit_callback(int index, bool is_for_watching)
 {
        debug_fenter();
        _focus_remove_callback(index);
@@ -1548,6 +1684,104 @@ static void _focus_destroy_callback(int index, bool is_for_watching)
        debug_fleave();
 }
 
+#define INTERVAL_MS 20
+static int _focus_loop_is_running_timed_wait(GMainLoop *focus_loop, int timeout_ms)
+{
+       int reduced_time_ms = timeout_ms;
+       if (!focus_loop || timeout_ms < 0) {
+               debug_error("invalid argument, focus_loop(%p), timeout_ms(%d)", focus_loop, timeout_ms);
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       do {
+               if (g_main_loop_is_running(focus_loop))
+                       return MM_ERROR_NONE;
+
+               usleep(INTERVAL_MS * 1000);
+               if (reduced_time_ms < timeout_ms)
+                       debug_warning("reduced_time_ms(%d)", reduced_time_ms);
+       } while ((reduced_time_ms -= INTERVAL_MS) >= 0);
+
+       debug_error("focus_loop is not running for timeout_ms(%d), focus_loop(%p) ", timeout_ms, focus_loop);
+
+       return MM_ERROR_SOUND_INTERNAL;
+}
+
+#define LOOP_RUNNING_WAIT_TIME_MS 200
+static int _focus_init_context(int index)
+{
+       int ret = MM_ERROR_NONE;
+       GMainContext *focus_context;
+
+       debug_fenter();
+
+       if (index < 0 || index >= FOCUS_HANDLE_MAX) {
+               debug_error("index(%d) is not valid", index);
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       focus_context = g_main_context_new();
+       g_focus_sound_handle[index].focus_loop = g_main_loop_new(focus_context, FALSE);
+       g_main_context_unref(focus_context);
+       if (g_focus_sound_handle[index].focus_loop == NULL) {
+               debug_error("could not create mainloop..");
+               goto ERROR;
+       }
+
+       g_focus_sound_handle[index].focus_cb_thread = g_thread_new("focus-cb-thread",
+                                                                       _focus_thread_func,
+                                                                       g_focus_sound_handle[index].focus_loop);
+       if (g_focus_sound_handle[index].focus_cb_thread == NULL) {
+               debug_error("could not create thread..");
+               goto ERROR;
+       }
+
+       debug_warning("focus cb thread[%p] with mainloop[%p] is created for index(%d)",
+                               g_focus_sound_handle[index].focus_cb_thread, g_focus_sound_handle[index].focus_loop, index);
+
+       if ((ret = _focus_loop_is_running_timed_wait(g_focus_sound_handle[index].focus_loop, LOOP_RUNNING_WAIT_TIME_MS))) {
+               debug_error("failed to _focus_loop_is_running_timed_wait(), ret[0x%x]", ret);
+               goto ERROR;
+       }
+
+       debug_fleave();
+
+       return MM_ERROR_NONE;
+
+ERROR:
+       if (g_focus_sound_handle[index].focus_loop) {
+               g_main_loop_unref(g_focus_sound_handle[index].focus_loop);
+               g_focus_sound_handle[index].focus_loop = NULL;
+       }
+       return MM_ERROR_SOUND_INTERNAL;
+}
+
+static void _focus_deinit_context(int index)
+{
+       debug_fenter();
+
+       if (index < 0 || index >= FOCUS_HANDLE_MAX) {
+               debug_error("index(%d) is not valid", index);
+               return;
+       }
+
+       if (!g_focus_sound_handle[index].focus_loop || !g_focus_sound_handle[index].focus_cb_thread) {
+               debug_error("focus_loop[%p] or focus_cb_thread[%p] is null",
+                               g_focus_sound_handle[index].focus_loop, g_focus_sound_handle[index].focus_cb_thread);
+               return;
+       }
+
+       g_main_loop_quit(g_focus_sound_handle[index].focus_loop);
+       g_thread_join(g_focus_sound_handle[index].focus_cb_thread);
+       debug_warning("after thread join, thread[%p], mainloop[%p] for index(%d)",
+                       g_focus_sound_handle[index].focus_cb_thread, g_focus_sound_handle[index].focus_loop, index);
+       g_main_loop_unref(g_focus_sound_handle[index].focus_loop);
+       g_focus_sound_handle[index].focus_loop = NULL;
+       g_focus_sound_handle[index].focus_cb_thread = NULL;
+
+       debug_fleave();
+}
+
 int mm_sound_client_get_unique_id(int *id)
 {
        int ret = MM_ERROR_NONE;
@@ -1567,20 +1801,27 @@ int mm_sound_client_get_unique_id(int *id)
 int mm_sound_client_is_focus_cb_thread(GThread *mine, bool *result)
 {
        int ret = MM_ERROR_NONE;
+       int i = 0;
 
        if (!mine || !result)
                ret = MM_ERROR_INVALID_ARGUMENT;
        else {
-               if (mine == g_focus_thread)
-                       *result = true;
-               else
-                       *result = false;
+               *result = false;
+               for (i = 0; i < FOCUS_HANDLE_MAX; i++) {
+                       if (!g_focus_sound_handle[i].is_used)
+                               continue;
+                       if (g_focus_sound_handle[i].focus_cb_thread == mine) {
+                               *result = true;
+                               break;
+                       }
+               }
        }
 
        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 mm_sound_client_register_focus(int id, int pid, const char *stream_type, bool is_for_session,
+                                   mm_sound_focus_changed_cb callback, void* user_data)
 {
        int ret = MM_ERROR_NONE;
        int instance;
@@ -1606,40 +1847,21 @@ int mm_sound_client_register_focus(int id, int pid, const char *stream_type, mm_
        g_focus_sound_handle[index].auto_reacquire = true;
 
        ret = mm_sound_proxy_register_focus(id, pid, stream_type, callback, is_for_session, user_data);
-
        if (ret == MM_ERROR_NONE) {
-               debug_msg("[Client] Success to register focus\n");
+               debug_msg("Success to register focus");
                g_need_emergent_exit = TRUE;
-               if (!g_focus_thread) {
-                       GMainContext* focus_context = g_main_context_new ();
-                       g_focus_loop = g_main_loop_new (focus_context, FALSE);
-                       g_main_context_unref(focus_context);
-                       if (g_focus_loop == NULL) {
-                               debug_error("could not create mainloop..");
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
-
-                       g_focus_thread = g_thread_new("focus-cb-thread", _focus_thread_func, NULL);
-                       if (g_focus_thread == NULL) {
-                               debug_error("could not create thread..");
-                               g_main_loop_unref(g_focus_loop);
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
-               } else {
-                       debug_warning("focus thread(%p) with mainloop(%p) exists, skip thread creation",
-                                               g_focus_thread, g_focus_loop);
+               if (_focus_init_context(index)) {
+                       ret = MM_ERROR_SOUND_INTERNAL;
+                       goto cleanup;
                }
        } else {
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x",ret);
                goto cleanup;
        }
 
        _focus_init_callback(index, false);
 
 cleanup:
-
        if (ret) {
                g_focus_sound_handle[index].is_used = false;
        }
@@ -1676,26 +1898,28 @@ int mm_sound_client_unregister_focus(int id)
        }
 
        ret = mm_sound_proxy_unregister_focus(instance, id, g_focus_sound_handle[index].is_for_session);
-
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to unregister focus\n");
+               debug_msg("Success to unregister focus");
        else
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x", ret);
 
        g_mutex_unlock(&g_focus_sound_handle[index].focus_lock);
 
-       _focus_destroy_callback(index, false);
+       _focus_deinit_callback(index, false);
        g_focus_sound_handle[index].focus_fd = 0;
        g_focus_sound_handle[index].focus_tid = 0;
        g_focus_sound_handle[index].handle = 0;
        g_focus_sound_handle[index].is_used = false;
+       _focus_deinit_context(index);
+
+
 cleanup:
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
        return ret;
 }
 
-int mm_sound_client_set_focus_reacquisition(int id, bool reacquisition)
+int mm_sound_client_set_focus_reacquisition(int id, bool reacquisition, bool is_for_session)
 {
        int ret = MM_ERROR_NONE;
        int instance;
@@ -1703,7 +1927,11 @@ int mm_sound_client_set_focus_reacquisition(int id, bool reacquisition)
        bool result;
 
        debug_fenter();
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       /* Since the muse server which uses this library for multiple handles executes requests from clients serially,
+        * we can skip locking/unlocking the mutex for this case. */
+       if (!is_for_session)
+               MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
 
        index = _focus_find_index_by_handle(id);
        if (index == -1) {
@@ -1715,24 +1943,26 @@ int mm_sound_client_set_focus_reacquisition(int id, bool reacquisition)
 
        ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), &result);
        if (ret) {
-               debug_error("[Client] mm_sound_client_is_focus_cb_thread failed");
+               debug_error("mm_sound_client_is_focus_cb_thread failed");
                goto cleanup;
        } else if (!result) {
-               ret = mm_sound_proxy_set_foucs_reacquisition(instance, id, reacquisition);
+               ret = mm_sound_proxy_set_focus_reacquisition(instance, id, reacquisition, is_for_session);
                if (ret == MM_ERROR_NONE) {
-                       debug_msg("[Client] Success to set focus reacquisition to [%d]\n", reacquisition);
+                       debug_msg("Success to set focus reacquisition to [%d]", reacquisition);
                } else {
-                       debug_error("[Client] Error occurred : 0x%x \n",ret);
+                       debug_error("Error occurred : 0x%x",ret);
                        goto cleanup;
                }
        } else {
-               debug_warning("[Client] Inside the focus cb thread, set focus reacquisition to [%d]\n", reacquisition);
+               debug_warning("Inside the focus cb thread, set focus reacquisition to [%d]", reacquisition);
        }
 
        g_focus_sound_handle[index].auto_reacquire = reacquisition;
+       debug_msg("set focus reacquisition(%d) for id(%d)", reacquisition, id);
 
 cleanup:
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
+       if (!is_for_session)
+               MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
        return ret;
 }
@@ -1759,6 +1989,7 @@ int mm_sound_client_get_focus_reacquisition(int id, bool *reacquisition)
        }
 
        *reacquisition = g_focus_sound_handle[index].auto_reacquire;
+       debug_msg("get focus reacquisition(%d) for id(%d)", *reacquisition, id);
 
 cleanup:
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
@@ -1769,17 +2000,21 @@ cleanup:
 int mm_sound_client_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
 {
        int ret = MM_ERROR_NONE;
-       char *ext_str = NULL;
+       char *stream_type_str = NULL;
+       char *ext_info_str = NULL;
 
        debug_fenter();
 
-       ret = mm_sound_proxy_get_acquired_focus_stream_type(focus_type, stream_type, option, &ext_str);
+       ret = mm_sound_proxy_get_acquired_focus_stream_type(focus_type, &stream_type_str, option, &ext_info_str);
        if (ret == MM_ERROR_NONE) {
-               debug_msg("[Client] Success to get stream type of acquired focus, stream_type(%s), ext_info(%s)\n", *stream_type, ext_str);
-               *ext_info = strdup(ext_str);
-               g_free(ext_str);
+               debug_msg("Success to get stream type of acquired focus, stream_type(%s), ext_info(%s)",
+                         stream_type_str, ext_info_str);
+               *stream_type = strdup(stream_type_str);
+               *ext_info = strdup(ext_info_str);
+               g_free(stream_type_str);
+               g_free(ext_info_str);
        } else {
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x",ret);
        }
 
        debug_fleave();
@@ -1805,9 +2040,9 @@ int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, int option
 
        ret = mm_sound_proxy_acquire_focus(instance, id, type, option, ext_info, g_focus_sound_handle[index].is_for_session);
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to acquire focus\n");
+               debug_msg("Success to acquire focus");
        else
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x", ret);
 
 cleanup:
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
@@ -1834,9 +2069,9 @@ int mm_sound_client_release_focus(int id, mm_sound_focus_type_e type, int option
 
        ret = mm_sound_proxy_release_focus(instance, id, type, option, ext_info, g_focus_sound_handle[index].is_for_session);
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to release focus\n");
+               debug_msg("Success to release focus");
        else
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x",ret);
 
 cleanup:
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
@@ -1844,7 +2079,32 @@ cleanup:
        return ret;
 }
 
-int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, bool is_for_session, void* user_data, int *id)
+int mm_sound_client_update_stream_focus_status(int id, unsigned int status)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if ((ret = mm_sound_proxy_update_stream_focus_status(id, status)) != MM_ERROR_NONE)
+               debug_error("failed to update stream focus status, ret[0x%x]", ret);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_deliver_focus(int pid, int src_id, int dst_id, mm_sound_focus_type_e focus_type)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if ((ret = mm_sound_proxy_deliver_focus(pid, src_id, dst_id, focus_type)) != MM_ERROR_NONE)
+               debug_error("failed to deliver focus, ret[0x%x]", ret);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e focus_type, bool is_for_session, bool is_for_monitor,
+                                             mm_sound_focus_changed_watch_cb callback, void* user_data, int *id)
 {
        int ret = MM_ERROR_NONE;
        int instance;
@@ -1877,42 +2137,27 @@ int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e focu
        g_focus_sound_handle[index].watch_callback = callback;
        g_focus_sound_handle[index].user_data = user_data;
        g_focus_sound_handle[index].is_for_session = is_for_session;
+       g_focus_sound_handle[index].is_for_monitor = is_for_monitor;
+       g_focus_sound_handle[index].unset_watch_callback_requested = false;
 
-       ret = mm_sound_proxy_set_focus_watch_callback(pid, g_focus_sound_handle[index].handle, focus_type, callback, is_for_session, user_data);
+       ret = mm_sound_proxy_set_focus_watch_callback(pid, g_focus_sound_handle[index].handle, focus_type,
+                                                     is_for_session, is_for_monitor, callback, user_data);
 
        if (ret == MM_ERROR_NONE) {
-               debug_msg("[Client] Success to watch focus");
+               debug_msg("Success to watch focus");
                g_need_emergent_exit = TRUE;
-               if (!g_focus_thread) {
-                       GMainContext* focus_context = g_main_context_new ();
-                       g_focus_loop = g_main_loop_new (focus_context, FALSE);
-                       g_main_context_unref(focus_context);
-                       if (g_focus_loop == NULL) {
-                               debug_error("could not create mainloop..");
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
-
-                       g_focus_thread = g_thread_new("focus-cb-thread", _focus_thread_func, NULL);
-                       if (g_focus_thread == NULL) {
-                               debug_error ("could not create thread..");
-                               g_main_loop_unref(g_focus_loop);
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
-               } else {
-                       debug_warning("focus thread(%p) with mainloop(%p) exists, skip thread creation",
-                                               g_focus_thread, g_focus_loop);
+               if (_focus_init_context(index)) {
+                       ret = MM_ERROR_SOUND_INTERNAL;
+                       goto cleanup;
                }
        } else {
-               debug_error("[Client] Error occurred : 0x%x",ret);
+               debug_error("Error occurred : 0x%x",ret);
                goto cleanup;
        }
 
        _focus_init_callback(index, true);
 
 cleanup:
-
        if (ret) {
                g_focus_sound_handle[index].is_used = false;
        }
@@ -1922,10 +2167,33 @@ cleanup:
        return ret;
 }
 
+int mm_sound_client_request_unset_focus_watch_callback(int id)
+{
+       int ret = MM_ERROR_NONE;
+       int index = -1;
+
+       debug_fenter();
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       index = _focus_watch_find_index_by_handle(id);
+       if (index == -1) {
+               debug_error("Could not find index");
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
+       }
+       g_focus_sound_handle[index].unset_watch_callback_requested = true;
+
+cleanup:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
+       debug_fleave();
+       return ret;
+}
+
 int mm_sound_client_unset_focus_watch_callback(int id)
 {
        int ret = MM_ERROR_NONE;
        int index = -1;
+
        debug_fenter();
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
 
@@ -1940,25 +2208,86 @@ int mm_sound_client_unset_focus_watch_callback(int id)
 
        g_focus_sound_handle[index].is_used = false;
 
-       ret = mm_sound_proxy_unset_focus_watch_callback(g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle, g_focus_sound_handle[index].is_for_session);
+       ret = mm_sound_proxy_unset_focus_watch_callback(g_focus_sound_handle[index].focus_tid,
+                                                       g_focus_sound_handle[index].handle,
+                                                       g_focus_sound_handle[index].is_for_session);
 
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to unwatch focus\n");
+               debug_msg("Success to unwatch focus");
        else
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x",ret);
 
 
        g_mutex_unlock(&g_focus_sound_handle[index].focus_lock);
 
-       _focus_destroy_callback(index, true);
+       _focus_deinit_callback(index, true);
        g_focus_sound_handle[index].focus_fd = 0;
        g_focus_sound_handle[index].focus_tid = 0;
        g_focus_sound_handle[index].handle = 0;
+       _focus_deinit_context(index);
+
 cleanup:
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
        return ret;
 }
+
+static gboolean _idle_event_callback(void *data)
+{
+       focus_idle_event_t *idle_event_data = (focus_idle_event_t*)data;
+       int ret = MM_ERROR_NONE;
+
+       if (data == NULL) {
+               debug_error("data is null");
+               return FALSE;
+       }
+
+       debug_msg("idle_event_data(%p): type(%d), data(%d)",
+               idle_event_data, idle_event_data->type, idle_event_data->data);
+
+       switch (idle_event_data->type) {
+       case IDLE_EVENT_TYPE_UNSET_FOCUS_WATCH_CB:
+               if ((ret = mm_sound_client_unset_focus_watch_callback(idle_event_data->data)))
+                       debug_error("Could not unset focus watch callback, id(%d), ret = %x", idle_event_data->data, ret);
+               break;
+       case IDLE_EVENT_TYPE_UNREGISTER_FOCUS:
+               if ((ret = mm_sound_client_unregister_focus(idle_event_data->data)))
+                       debug_error("Could not unregister focus, id(%d), ret = %x", idle_event_data->data, ret);
+               break;
+       default:
+               debug_warning("invalid type(%d)", idle_event_data->type);
+               break;
+       }
+
+       g_free(idle_event_data);
+
+       g_idle_event_src = 0;
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_event_mutex);
+
+       return FALSE;
+}
+
+int mm_sound_client_execute_focus_func_in_main_context(focus_idle_event_type_e type, int data)
+{
+       focus_idle_event_t *idle_event_data = NULL;
+
+       if (IDLE_EVENT_TYPE_MAX < type)
+               return MM_ERROR_INVALID_ARGUMENT;
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_event_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       idle_event_data = g_new0(focus_idle_event_t, 1);
+       idle_event_data->type = type;
+       idle_event_data->data = data;
+
+       g_idle_event_src = g_idle_add_full(G_PRIORITY_HIGH,
+                               (GSourceFunc)_idle_event_callback,
+                               (gpointer)idle_event_data,
+                               NULL);
+
+       return MM_ERROR_NONE;
+}
 #endif