Add new function to check if it needs to trigger focus callback or not 40/213740/1 accepted/tizen/unified/20190916.043539 submit/tizen/20190911.081829
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 11 Sep 2019 02:32:26 +0000 (11:32 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 11 Sep 2019 02:32:26 +0000 (11:32 +0900)
It'll reduce cyclomatic complexity of SAM.

[Version] 0.12.49
[Issue Type] Refactoring

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

index 9179833..2fbec02 100644 (file)
@@ -886,6 +886,39 @@ static void update_reacquisition_with_released_state(focus_node_t *node, int dir
        }
 }
 
+static int determine_trigger_focus_cb(GList *glist, focus_node_t *my_node, focus_type_e request_type, bool *need_to_trigger)
+{
+       int ret = MM_ERROR_NONE;
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+
+       if (!glist || !need_to_trigger || !my_node)
+               return MM_ERROR_INVALID_ARGUMENT;
+
+       /* check if the priority of any node is higher than its based on io direction */
+       for (list = glist; list != NULL; list = list->next) {
+               SET_NODE_FROM_LIST_DATA(node, list);
+               if (my_node == node || node->is_for_watch)
+                       continue;
+               if (request_type == FOCUS_TYPE_BOTH || node->status == FOCUS_STATUS_ACTIVATED_BOTH ||
+                       (node->status & request_type)) {
+                       if (node->status <= FOCUS_STATUS_DEACTIVATED)
+                               continue;
+
+                       if ((my_node->priority < node->priority)) {
+                               debug_warning("policy blocked by priority(%d < %d)", my_node->priority, node->priority);
+                               ret = MM_ERROR_POLICY_BLOCKED;
+                               *need_to_trigger = false;
+                               break;
+                       } else {
+                               *need_to_trigger = true;
+                       }
+               }
+       }
+
+       return ret;
+}
+
 int mm_sound_mgr_focus_request_acquire(const _mm_sound_mgr_focus_param_t *param)
 {
        int ret = MM_ERROR_NONE;
@@ -910,25 +943,7 @@ int mm_sound_mgr_focus_request_acquire(const _mm_sound_mgr_focus_param_t *param)
                goto FINISH;
        }
 
-       /* 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) {
-               SET_NODE_FROM_LIST_DATA(node, list);
-               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)
-                               continue;
-
-                       if ((my_node->priority < node->priority)) {
-                               ret = MM_ERROR_POLICY_BLOCKED;
-                               need_to_trigger_cb = false;
-                               break;
-                       } else {
-                               need_to_trigger_cb = true;
-                       }
-               }
-       }
+       ret = determine_trigger_focus_cb(g_focus_node_list, my_node, param->request_type, &need_to_trigger_cb);
 
        if (need_to_trigger_cb) {
                _mm_sound_mgr_focus_param_t *param_s = (_mm_sound_mgr_focus_param_t *)param;
@@ -941,16 +956,16 @@ int mm_sound_mgr_focus_request_acquire(const _mm_sound_mgr_focus_param_t *param)
                                (node->status & param_s->request_type)) {
                                if (node->status <= FOCUS_STATUS_DEACTIVATED)
                                        continue;
-                               if (my_node->priority >= node->priority) {
-                                       /* do callback for interruption */
-                                       if ((ret = _mm_sound_mgr_focus_do_callback(FOCUS_COMMAND_RELEASE, node, param_s))) {
-                                               debug_error("Fail to _focus_do_callback for COMMAND RELEASE to node[%p], ret[0x%x]", node, ret);
-                                               /* but, keep going */
-                                               ret = MM_ERROR_NONE;
-                                       }
-                                       if (!strncmp(my_node->stream_type, node->stream_type, MAX_STREAM_TYPE_LEN))
-                                               need_to_trigger_watch_cb = false;
+                               if (my_node->priority < node->priority)
+                                       continue;
+                               /* do callback for interruption */
+                               if ((ret = _mm_sound_mgr_focus_do_callback(FOCUS_COMMAND_RELEASE, node, param_s))) {
+                                       debug_error("Fail to _focus_do_callback for COMMAND RELEASE to node[%p], ret[0x%x]", node, ret);
+                                       /* but, keep going */
+                                       ret = MM_ERROR_NONE;
                                }
+                               if (!strncmp(my_node->stream_type, node->stream_type, MAX_STREAM_TYPE_LEN))
+                                       need_to_trigger_watch_cb = false;
                        }
                }
        }
@@ -1023,15 +1038,15 @@ int mm_sound_mgr_focus_request_release(const _mm_sound_mgr_focus_param_t *param)
                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) {
-                                       /* do callback for resumption */
-                                       if ((ret = _mm_sound_mgr_focus_do_callback(FOCUS_COMMAND_ACQUIRE, node, param_s)))
-                                               debug_error("Fail to _focus_do_callback for COMMAND ACQUIRE to node[%p], ret[0x%x]", node, ret);
-                                       if (!strncmp(my_node->stream_type, node->stream_type, MAX_STREAM_TYPE_LEN))
-                                               need_to_trigger_watch_cb = false;
-                               }
+                       if (!(param_s->request_type & (i+1)))
+                               continue;
+                       if (node->taken_by_id[i].pid == param_s->pid &&
+                               node->taken_by_id[i].handle_id == param_s->handle_id) {
+                               /* do callback for resumption */
+                               if ((ret = _mm_sound_mgr_focus_do_callback(FOCUS_COMMAND_ACQUIRE, node, param_s)))
+                                       debug_error("Fail to _focus_do_callback for COMMAND ACQUIRE to node[%p], ret[0x%x]", node, ret);
+                               if (!strncmp(my_node->stream_type, node->stream_type, MAX_STREAM_TYPE_LEN))
+                                       need_to_trigger_watch_cb = false;
                        }
                }
        }
index f6eb591..fa7b8ec 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.12.48
+Version:    0.12.49
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0