focus-server: Call focus callbacks in case of destroying focus node with acquisition... 04/109604/2 submit/tizen_3.0/20170112.101943
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 10 Jan 2017 06:07:14 +0000 (15:07 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 11 Jan 2017 02:04:56 +0000 (11:04 +0900)
[Version] 0.10.80
[Profile] Common
[Issue Type] Feature enhancement

Change-Id: Iada33c749a33bc8a2e06d4b4925d4f67511ad737
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
focus_server/mm_sound_mgr_focus.c
packaging/libmm-sound.spec

index 432a854..47b634a 100644 (file)
@@ -677,61 +677,72 @@ int mm_sound_mgr_focus_destroy_node(const _mm_sound_mgr_focus_param_t *param)
                goto FINISH;
        }
 
-       /* Check if there's remaining focus for session for the same PID of incomming param*/
+       /* Check if there's remaining focus for session for the same PID of incomming param */
        if (my_node->is_for_session) {
                for (list = g_focus_node_list; list != NULL; list = list->next) {
-                       node = (focus_node_t *)list->data;
-                       if (!node) {
-                               /* skip */
-                       } else if (my_node == node || node->is_for_watch) {
-                               /* skip */
-                       } else {
-                               if (node->pid == my_node->pid && node->is_for_session) {
-                                       debug_error("focus for session for this pid still remains, skip updating victim focus nodes");
-                                       need_to_trigger = false;
-                                       break;
-                               }
+                       if (!(node = (focus_node_t *)list->data))
+                               continue;
+                       if (my_node == node || node->is_for_watch)
+                               continue;
+                       if (node->pid == my_node->pid && node->is_for_session) {
+                               debug_error("focus for session for this pid still remains, skip updating victim focus nodes");
+                               need_to_trigger = false;
+                               break;
                        }
                }
        }
 
        if (need_to_trigger) {
                for (list = g_focus_node_list; list != NULL; list = list->next) {
-                       node = (focus_node_t *)list->data;
-                       if (!node) {
-                               /* skip */
-                       } else if (my_node == node || node->is_for_watch) {
-                               /* skip */
-                       } else {
-                               for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
-                                       if (node->taken_by_id[i].pid == param->pid) {
-                                               if (my_node->taken_by_id[i].pid) {
-                                               /* If exists update the taken focus info to my victim node */
-                                                       if (node->taken_by_id[i].by_session && !node->status) {
-                                                               UPDATE_FOCUS_TAKEN_INFO(by_id, node, my_node->taken_by_id[i].pid, my_node->taken_by_id[i].handle_id, my_node->taken_by_id[i].by_session);
-                                                       } else if (node->taken_by_id[i].handle_id == param->handle_id) {
-                                                               UPDATE_FOCUS_TAKEN_INFO(by_id, node, my_node->taken_by_id[i].pid, my_node->taken_by_id[i].handle_id, false);
-                                                       }
-                                               } else {
-                                                       if (node->taken_by_id[i].by_session && !node->status) {
-                                                               UPDATE_FOCUS_TAKEN_INFO(by_id, node, 0, 0, false);
-                                                       } else if (node->taken_by_id[i].handle_id == param->handle_id) {
-                                                               UPDATE_FOCUS_TAKEN_INFO(by_id, node, 0, 0, false);
+                       if (!(node = (focus_node_t *)list->data))
+                               continue;
+                       if (my_node == node || node->is_for_watch)
+                               continue;
+                       for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
+                               if (node->taken_by_id[i].pid == param->pid) {
+                                       if (my_node->taken_by_id[i].pid) {
+                                       /* If exists update the taken focus info to my victim node */
+                                               if (node->taken_by_id[i].by_session && !node->status) {
+                                                       UPDATE_FOCUS_TAKEN_INFO(by_id, node, my_node->taken_by_id[i].pid, my_node->taken_by_id[i].handle_id, my_node->taken_by_id[i].by_session);
+                                               } else if (node->taken_by_id[i].handle_id == param->handle_id) {
+                                                       UPDATE_FOCUS_TAKEN_INFO(by_id, node, my_node->taken_by_id[i].pid, my_node->taken_by_id[i].handle_id, false);
+                                               }
+                                       } else if (my_node->status & (i+1)) {
+                                               _mm_sound_mgr_focus_param_t *new_param = g_malloc0(sizeof(_mm_sound_mgr_focus_param_t));
+                                               if (!new_param) {
+                                                       debug_warning("Fail to g_malloc0 for new_param, but keep going\n");
+                                                       goto CLEAR_NODE;
+                                               }
+                                               new_param->pid = param->pid;
+                                               new_param->handle_id = param->handle_id;
+                                               new_param->is_for_session = my_node->is_for_session;
+                                               new_param->request_type = my_node->status;
+                                               new_param->option = my_node->option[i];
+                                               MMSOUND_STRNCPY(new_param->ext_info, my_node->ext_info[i], MM_SOUND_NAME_NUM);
+
+                                               if (node->taken_by_id[i].handle_id == new_param->handle_id || node->taken_by_id[i].by_session) {
+                                                       /* do callback for resumption */
+                                                       if ((ret = _mm_sound_mgr_focus_do_callback(FOCUS_COMMAND_ACQUIRE, node, new_param, my_node->stream_type)))
+                                                               debug_error("Fail to _focus_do_callback for COMMAND ACQUIRE to node[%x], ret[0x%x]\n", node, ret);
+                                                       if (!strncmp(my_node->stream_type, node->stream_type, MAX_STREAM_TYPE_LEN)) {
+                                                               my_node->status &= ~(new_param->request_type);
+                                                               _mm_sound_mgr_focus_do_watch_callback((focus_type_e)new_param->request_type, FOCUS_COMMAND_RELEASE, my_node, new_param);
                                                        }
                                                }
+                                               g_free(new_param);
                                        }
                                }
                        }
                }
        }
 
+CLEAR_NODE:
        /* Destroy my node  */
        __clear_focus_pipe(my_node);
        g_focus_node_list = g_list_remove(g_focus_node_list, my_node);
        g_free(my_node);
-
-       _mm_sound_mgr_focus_list_dump();
 FINISH:
+       _mm_sound_mgr_focus_list_dump();
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
 
        debug_fleave();
@@ -890,13 +901,12 @@ int mm_sound_mgr_focus_request_acquire(const _mm_sound_mgr_focus_param_t *param)
 
        /* check if the priority of any node is higher than its based on io direction */
        for (list = g_focus_node_list; list != NULL; list = list->next) {
-               node = (focus_node_t *)list->data;
-               if (!node) {
-                       /* skip */
-               } else if (my_node == node || node->is_for_watch) {
-                       /* skip */
-               } else if (param->request_type == FOCUS_TYPE_BOTH || node->status == FOCUS_STATUS_ACTIVATED_BOTH ||
-                                       (node->status & param->request_type)) {
+               if (!(node = (focus_node_t *)list->data))
+                       continue;
+               if (my_node == node || node->is_for_watch)
+                       continue;
+               if (param->request_type == FOCUS_TYPE_BOTH || node->status == FOCUS_STATUS_ACTIVATED_BOTH ||
+                       (node->status & param->request_type)) {
                        if (node->status > FOCUS_STATUS_DEACTIVATED) {
                                if ((my_node->priority < node->priority)) {
                                        ret = MM_ERROR_POLICY_BLOCKED;
@@ -913,13 +923,12 @@ int mm_sound_mgr_focus_request_acquire(const _mm_sound_mgr_focus_param_t *param)
                _mm_sound_mgr_focus_param_t *param_s = (_mm_sound_mgr_focus_param_t *)param;
                param_s->is_for_session = my_node->is_for_session;
                for (list = g_focus_node_list; list != NULL; list = list->next) {
-                       node = (focus_node_t *)list->data;
-                       if (!node) {
-                               /* skip */
-                       } else if (node == my_node || node->is_for_watch || (node->pid == my_node->pid && node->is_for_session && my_node->is_for_session)) {
-                               /* skip */
-                       } else if (param_s->request_type == FOCUS_TYPE_BOTH || node->status == FOCUS_STATUS_ACTIVATED_BOTH ||
-                                       (node->status & param_s->request_type)) {
+                       if (!(node = (focus_node_t *)list->data))
+                               continue;
+                       if (node == my_node || node->is_for_watch || (node->pid == my_node->pid && node->is_for_session && my_node->is_for_session))
+                               continue;
+                       if (param_s->request_type == FOCUS_TYPE_BOTH || node->status == FOCUS_STATUS_ACTIVATED_BOTH ||
+                               (node->status & param_s->request_type)) {
                                if (node->status > FOCUS_STATUS_DEACTIVATED) {
                                        if (my_node->priority >= node->priority) {
                                                /* do callback for interruption */
@@ -1013,11 +1022,11 @@ int mm_sound_mgr_focus_request_release(const _mm_sound_mgr_focus_param_t *param)
        /* Check if there's activating focus for session for the same PID of incomming param*/
        if (my_node->is_for_session) {
                for (list = g_focus_node_list; list != NULL; list = list->next) {
-                       node = (focus_node_t *)list->data;
-                       if (!node) {
-                               /* skip */
-                       } else if (node != my_node && node->pid == my_node->pid && node->is_for_session && !node->is_for_watch
-                               && my_node->status & node->status) {
+                       if (!(node = (focus_node_t *)list->data))
+                               continue;
+                       if (node == my_node || node->is_for_watch)
+                               continue;
+                       if (node->pid == my_node->pid && node->is_for_session && my_node->status & node->status) {
                                debug_error("focus for session for this pid is active, skip callbacks");
                                need_to_trigger_watch_cb = false;
                                need_to_trigger_cb = false;
@@ -1030,23 +1039,20 @@ int mm_sound_mgr_focus_request_release(const _mm_sound_mgr_focus_param_t *param)
                _mm_sound_mgr_focus_param_t *param_s = (_mm_sound_mgr_focus_param_t *)param;
                param_s->is_for_session = my_node->is_for_session;
                for (list = g_focus_node_list; list != NULL; list = list->next) {
-                       node = (focus_node_t *)list->data;
-                       if (!node) {
-                               /* skip */
-                       } else if (node == my_node || node->is_for_watch) {
-                               /* skip */
-                       } else {
-                               for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
-                                       if (param_s->request_type & (i+1)) {
-                                               if (node->taken_by_id[i].pid == param_s->pid && (node->taken_by_id[i].handle_id == param_s->handle_id || node->taken_by_id[i].by_session)) {
-                                                       /* do callback for resumption */
-                                                       ret = _mm_sound_mgr_focus_do_callback(FOCUS_COMMAND_ACQUIRE, node, param_s, my_node->stream_type);
-                                                       if (ret) {
-                                                               debug_error("Fail to _focus_do_callback for COMMAND ACQUIRE to node[%x], ret[0x%x]\n", node, ret);
-                                                       }
-                                                       if (!strncmp(my_node->stream_type, node->stream_type, MAX_STREAM_TYPE_LEN)) {
-                                                               need_to_trigger_watch_cb = false;
-                                                       }
+                       if (!(node = (focus_node_t *)list->data))
+                               continue;
+                       if (node == my_node || node->is_for_watch)
+                               continue;
+                       for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
+                               if (param_s->request_type & (i+1)) {
+                                       if (node->taken_by_id[i].pid == param_s->pid && (node->taken_by_id[i].handle_id == param_s->handle_id || node->taken_by_id[i].by_session)) {
+                                               /* do callback for resumption */
+                                               ret = _mm_sound_mgr_focus_do_callback(FOCUS_COMMAND_ACQUIRE, node, param_s, my_node->stream_type);
+                                               if (ret) {
+                                                       debug_error("Fail to _focus_do_callback for COMMAND ACQUIRE to node[%x], ret[0x%x]\n", node, ret);
+                                               }
+                                               if (!strncmp(my_node->stream_type, node->stream_type, MAX_STREAM_TYPE_LEN)) {
+                                                       need_to_trigger_watch_cb = false;
                                                }
                                        }
                                }
@@ -1290,4 +1296,3 @@ int MMSoundMgrFocusFini(void)
        debug_fleave();
        return MM_ERROR_NONE;
 }
-
index a2073e8..81c53cb 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.10.79
+Version:    0.10.80
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0