focus_server: Fix bug regarding update of reacquisition information within focus... 81/151281/5 accepted/tizen/unified/20170925.151022 submit/tizen/20170925.071433
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 20 Sep 2017 09:45:12 +0000 (18:45 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 21 Sep 2017 04:04:19 +0000 (13:04 +0900)
It is also modified regarding conding convention

[Version] 0.11.25
[Issue Type] Bug fix

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

index 982144a..8d4863e 100644 (file)
@@ -39,8 +39,7 @@ static GList *g_focus_node_list = NULL;
 static pthread_mutex_t g_focus_node_list_mutex = PTHREAD_MUTEX_INITIALIZER;
 stream_list_t g_stream_list;
 
-static const char* focus_status_str[] =
-{
+static const char* focus_status_str[] = {
        "DEACTIVATED",
        "P ACTIVATED",
        "C ACTIVATED",
@@ -58,12 +57,12 @@ typedef struct {
 } focus_cb_data;
 
 #define CLEAR_DEAD_NODE_LIST(x)  do { \
-       debug_warning("list = %p, node = %p, pid=[%d]", x, node, (node)? node->pid : -1); \
+       debug_warning("list = %p, node = %p, pid=[%d]", x, node, (node) ? node->pid : -1); \
        if (x && node && (mm_sound_util_is_process_alive(node->pid) == FALSE)) { \
                debug_warning("PID:%d does not exist now! remove from device cb list", node->pid); \
                __clear_focus_pipe(node); \
-               x = g_list_remove (x, node); \
-               g_free (node); \
+               x = g_list_remove(x, node); \
+               g_free(node); \
        } \
 } while (0)
 
@@ -96,7 +95,7 @@ static char* __get_focus_pipe_path(int instance_id, int handle, const char* post
 
        if (postfix) {
                path2 = g_strconcat(path, postfix, NULL);
-               g_free (path);
+               g_free(path);
                path = NULL;
                return path2;
        }
@@ -269,7 +268,7 @@ static void _invoke_watch_callback(focus_node_t *node, const char *stream_type,
                debug_error("[RETCB] failed to get watch return pipe");
                goto RELEASE;
        }
-       if ((fd_FOCUS_R= open(filename2, O_RDONLY|O_NONBLOCK)) == -1) {
+       if ((fd_FOCUS_R = open(filename2, O_RDONLY|O_NONBLOCK)) == -1) {
                char str_error[256];
                strerror_r(errno, str_error, sizeof(str_error));
                debug_error("[RETCB] failed to open watch return pipe (%s, err:%s)", filename2, str_error);
@@ -279,7 +278,7 @@ static void _invoke_watch_callback(focus_node_t *node, const char *stream_type,
        /*******************************************
         * Write Callback msg
         *******************************************/
-       if (write(fd_FOCUS, &cb_data ,sizeof(cb_data)) == -1) {
+       if (write(fd_FOCUS, &cb_datasizeof(cb_data)) == -1) {
                char str_error[256];
                strerror_r(errno, str_error, sizeof(str_error));
                debug_error("[CB] failed to write (err:%s)", str_error);
@@ -466,12 +465,12 @@ int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victi
        debug_msg("for pid(%d) handle(%d)", victim_node->pid, victim_node->handle_id);
 
        memset(&cb_data, 0, sizeof(focus_cb_data));
-       cb_data.pid= victim_node->pid;
-       cb_data.handle= victim_node->handle_id;
+       cb_data.pid = victim_node->pid;
+       cb_data.handle = victim_node->handle_id;
        if (command == FOCUS_COMMAND_RELEASE) {
                /* client will lost the acquired focus */
-               cb_data.type= assaulter_param->request_type & victim_node->status;
-               cb_data.state= FOCUS_STATUS_DEACTIVATED;
+               cb_data.type = assaulter_param->request_type & victim_node->status;
+               cb_data.state = FOCUS_STATUS_DEACTIVATED;
                /* remove ext info. */
                for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
                        if (cb_data.type & (i+1)) {
@@ -535,7 +534,7 @@ int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victi
                res = -1;
                goto RELEASE;
        }
-       if ((fd_FOCUS_R = open(filename2,O_RDONLY|O_NONBLOCK)) == -1) {
+       if ((fd_FOCUS_R = open(filename2, O_RDONLY|O_NONBLOCK)) == -1) {
                char str_error[256];
                strerror_r(errno, str_error, sizeof(str_error));
                debug_error("[RETCB] failed to open return pipe (%s, err:%s)", filename2, str_error);
@@ -562,7 +561,7 @@ int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victi
        pfd.fd = fd_FOCUS_R;
        pfd.events = POLLIN;
        pfd.revents = 0;
-       debug_msg("[RETCB] wait CALLBACK (client pid=%d, handle=%d, cmd=%d, timeout=%d(ms))",cb_data.pid, cb_data.handle, command, CALLBACK_TIMEOUT);
+       debug_msg("[RETCB] wait CALLBACK (client pid=%d, handle=%d, cmd=%d, timeout=%d(ms))", cb_data.pid, cb_data.handle, command, CALLBACK_TIMEOUT);
        pret = poll(&pfd, 1, CALLBACK_TIMEOUT);
        if (pret < 0) {
                debug_error("[RETCB] poll failed (%d)", pret);
@@ -628,16 +627,8 @@ int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victi
                                                }
                                        }
                                } else {
-                                       for (list = g_focus_node_list; list != NULL; list = list->next) {
-                                               CONTINUE_IF_LIST_DATA_IS_NULL(node, list);
-                                               if (node->taken_backup[i].pid == victim_node->pid) {
-                                                       UPDATE_FOCUS_TAKEN_INFO(by_id, node, node->taken_backup[i].pid, node->taken_backup[i].handle_id, node->taken_backup[i].by_session);
-                                                       UPDATE_FOCUS_TAKEN_INFO(backup, node, 0, 0, false);
-                                               } else if (!list->next) {
-                                                       UPDATE_FOCUS_TAKEN_INFO(by_id, victim_node, taken_pid, taken_hid, taken_by_session);
-                                                       UPDATE_FOCUS_TAKEN_INFO(backup, victim_node, 0, 0, false);
-                                               }
-                                       }
+                                       UPDATE_FOCUS_TAKEN_INFO(by_id, victim_node, taken_pid, taken_hid, taken_by_session);
+                                       UPDATE_FOCUS_TAKEN_INFO(backup, victim_node, 0, 0, false);
                                }
                        } else {
                                if (victim_node->reacquisition)
@@ -669,14 +660,14 @@ RELEASE:
                fd_FOCUS = -1;
        }
        if (fd_FOCUS_R != -1) {
-               close (fd_FOCUS_R);
+               close(fd_FOCUS_R);
                fd_FOCUS_R = -1;
        }
 
        return res;
 }
 
-static int _mm_sound_mgr_focus_list_dump ()
+static int _mm_sound_mgr_focus_list_dump()
 {
        int ret = MM_ERROR_NONE;
        GList *list = NULL;
@@ -686,9 +677,9 @@ static int _mm_sound_mgr_focus_list_dump ()
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                if ((node = (focus_node_t *)list->data) && !node->is_for_watch) {
                        debug_msg("*** pid[%5d]/handle_id[%2d]/[%14s]:priority[%2d],status[%s],taken_by[P(%5d/%2d/%2d)C(%5d/%2d/%2d)],session[%d],option[0x%x/0x%x],ext_info[%s/%s]",
-                                 node->pid, node->handle_id, node->stream_type, node->priority, focus_status_str[node->status],
-                                 node->taken_by_id[0].pid, node->taken_by_id[0].handle_id, node->taken_by_id[0].by_session, node->taken_by_id[1].pid,
-                                 node->taken_by_id[1].handle_id, node->taken_by_id[1].by_session, node->is_for_session, node->option[0], node->option[1], node->ext_info[0], node->ext_info[1]);
+                               node->pid, node->handle_id, node->stream_type, node->priority, focus_status_str[node->status],
+                               node->taken_by_id[0].pid, node->taken_by_id[0].handle_id, node->taken_by_id[0].by_session, node->taken_by_id[1].pid,
+                               node->taken_by_id[1].handle_id, node->taken_by_id[1].by_session, node->is_for_session, node->option[0], node->option[1], node->ext_info[0], node->ext_info[1]);
                }
        }
        debug_msg("================================================ focus node list : end =====================================================");
@@ -706,7 +697,7 @@ static int _mm_sound_mgr_focus_watch_list_dump()
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                if ((node = (focus_node_t *)list->data) && node->is_for_watch)
                        debug_msg("*** pid[%5d]/handle_id[%d]/watch on focus status[%s]/for_session[%d]/for_monitor[%d]",
-                                 node->pid, node->handle_id, focus_status_str[node->status], node->is_for_session, node->is_for_monitor);
+                               node->pid, node->handle_id, focus_status_str[node->status], node->is_for_session, node->is_for_monitor);
        }
        debug_msg("============================================= focus watch node list : end ===================================================");
 
@@ -738,7 +729,7 @@ int mm_sound_mgr_focus_create_node(const _mm_sound_mgr_focus_param_t *param)
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                CONTINUE_IF_LIST_DATA_IS_NULL(node, list);
@@ -794,7 +785,7 @@ int mm_sound_mgr_focus_destroy_node(const _mm_sound_mgr_focus_param_t *param)
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                CONTINUE_IF_LIST_DATA_IS_NULL(node, list);
@@ -902,7 +893,7 @@ int mm_sound_mgr_focus_set_reacquisition(const _mm_sound_mgr_focus_param_t *para
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        /* Find node to set reacquisition */
        for (list = g_focus_node_list; list != NULL; list = list->next) {
@@ -979,7 +970,7 @@ int mm_sound_mgr_focus_get_stream_type_of_acquired_focus(focus_type_e focus_type
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        /* Find node to set reacquisition */
        for (list = g_focus_node_list; list != NULL; list = list->next) {
@@ -992,7 +983,7 @@ int mm_sound_mgr_focus_get_stream_type_of_acquired_focus(focus_type_e focus_type
                        int index = (focus_type == FOCUS_TYPE_BOTH) ? FOCUS_TYPE_PLAYBACK - 1 : focus_type - 1;
 
                        debug_msg("found a node : request_focus_type(%d), stream_type(%s)/ext info(%s) of acquired focus",
-                                 focus_type, node->stream_type, node->ext_info[index]);
+                               focus_type, node->stream_type, node->ext_info[index]);
 
                        *stream_type = node->stream_type;
                        *option = node->option[index];
@@ -1025,8 +1016,8 @@ static void update_reacquisition_with_released_state(focus_node_t *node, int dir
         When invoking focus state changed callback for acquiring, state of the node will not be updated rather updated
         when the next request to acquire. */
        if (!strncmp("audio-io acquire focus", node->ext_info[direction], MM_SOUND_NAME_NUM) ||
-           !strncmp("mm-player acquire focus", node->ext_info[direction], MM_SOUND_NAME_NUM) ||
-           !strncmp("mm-camcorder acquire focus", node->ext_info[direction], MM_SOUND_NAME_NUM)) {
+               !strncmp("mm-player acquire focus", node->ext_info[direction], MM_SOUND_NAME_NUM) ||
+               !strncmp("mm-camcorder acquire focus", node->ext_info[direction], MM_SOUND_NAME_NUM)) {
                debug_msg("this node[pid:%d, handle_id:%d] needs reacquisition with focus released state", node->pid, node->handle_id);
                node->reacquisition_with_released_state = true;
        }
@@ -1049,7 +1040,7 @@ int mm_sound_mgr_focus_request_acquire(const _mm_sound_mgr_focus_param_t *param)
                MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                CONTINUE_IF_LIST_DATA_IS_NULL(node, list);
@@ -1146,7 +1137,7 @@ int mm_sound_mgr_focus_request_acquire(const _mm_sound_mgr_focus_param_t *param)
        }
 
        _mm_sound_mgr_focus_list_dump();
-       _mm_sound_mgr_focus_watch_list_dump ();
+       _mm_sound_mgr_focus_watch_list_dump();
 FINISH:
        if (!param->is_in_thread)
                MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
@@ -1172,7 +1163,7 @@ int mm_sound_mgr_focus_request_release(const _mm_sound_mgr_focus_param_t *param)
                MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                CONTINUE_IF_LIST_DATA_IS_NULL(node, list);
@@ -1258,7 +1249,7 @@ int mm_sound_mgr_focus_request_release(const _mm_sound_mgr_focus_param_t *param)
                _mm_sound_mgr_focus_do_monitor_callback_outer((focus_type_e)param->request_type, FOCUS_COMMAND_ACQUIRE, my_node, param);
 
        _mm_sound_mgr_focus_list_dump();
-       _mm_sound_mgr_focus_watch_list_dump ();
+       _mm_sound_mgr_focus_watch_list_dump();
 FINISH:
        if (!param->is_in_thread)
                MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
@@ -1278,7 +1269,7 @@ int mm_sound_mgr_focus_set_watch_cb(const _mm_sound_mgr_focus_param_t *param)
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                CONTINUE_IF_LIST_DATA_IS_NULL(node, list);
@@ -1325,7 +1316,7 @@ int mm_sound_mgr_focus_unset_watch_cb(const _mm_sound_mgr_focus_param_t *param)
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                CONTINUE_IF_LIST_DATA_IS_NULL(node, list);
@@ -1365,26 +1356,26 @@ int mm_sound_mgr_focus_deliver(const _mm_sound_mgr_focus_param_t *param)
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                CONTINUE_IF_LIST_DATA_IS_NULL(src_node, list);
                if ((src_node->pid == param->pid) && (src_node->handle_id == param->handle_id)) {
                        debug_log("SRC: found the node of pid[%d]/handle_id[%d] for watch focus",
-                                 param->pid, param->handle_id);
+                               param->pid, param->handle_id);
                        break;
                }
        }
        if (src_node == NULL) {
                debug_error("could not find the source node of param, pid[%d]/handle_id[%d]",
-                           param->pid, param->handle_id);
+                       param->pid, param->handle_id);
                ret = MM_ERROR_INVALID_ARGUMENT;
                goto FINISH;
        }
 
        if (!(src_node->status & param->request_type)) {
                debug_error("invalid request type(0x%x), src_node->status(0x%x)",
-                           param->request_type, src_node->status);
+                       param->request_type, src_node->status);
                ret = MM_ERROR_SOUND_INVALID_STATE;
                goto FINISH;
        }
@@ -1393,13 +1384,13 @@ int mm_sound_mgr_focus_deliver(const _mm_sound_mgr_focus_param_t *param)
                CONTINUE_IF_LIST_DATA_IS_NULL(dst_node, list);
                if ((dst_node->pid == param->pid) && (dst_node->handle_id == param->handle_id_dst)) {
                        debug_log("DST: found the destination node of param, pid[%d]/handle_id[%d]",
-                                 param->pid, param->handle_id_dst);
+                               param->pid, param->handle_id_dst);
                        break;
                }
        }
        if (dst_node == NULL) {
                debug_error("could not find the destination node of param, pid[%d]/handle_id[%d]",
-                           param->pid, param->handle_id_dst);
+                       param->pid, param->handle_id_dst);
                ret = MM_ERROR_INVALID_ARGUMENT;
                goto FINISH;
        }
@@ -1412,17 +1403,17 @@ int mm_sound_mgr_focus_deliver(const _mm_sound_mgr_focus_param_t *param)
                for (list = g_focus_node_list; list != NULL; list = list->next) {
                        CONTINUE_IF_LIST_DATA_IS_NULL(node, list);
                        if ((node->taken_by_id[i].pid == src_node->pid) &&
-                           (node->taken_by_id[i].handle_id == src_node->handle_id) &&
-                           (node->taken_by_id[i].by_session == false)) {
+                               (node->taken_by_id[i].handle_id == src_node->handle_id) &&
+                               (node->taken_by_id[i].by_session == false)) {
                                debug_log("found the node that focus was taken by this src node, update it",
-                                         node->pid, node->handle_id);
+                                       node->pid, node->handle_id);
                                UPDATE_FOCUS_TAKEN_INFO(by_id, node, dst_node->pid, dst_node->handle_id, false);
                        }
                        if ((node->taken_backup[i].pid == src_node->pid) &&
-                           (node->taken_backup[i].handle_id == src_node->handle_id) &&
-                           (node->taken_backup[i].by_session == false)) {
+                               (node->taken_backup[i].handle_id == src_node->handle_id) &&
+                               (node->taken_backup[i].by_session == false)) {
                                debug_log("found the node that focus was taken by this src node and set reacquisition to false, update it",
-                                         node->pid, node->handle_id);
+                                       node->pid, node->handle_id);
                                UPDATE_FOCUS_TAKEN_INFO(backup, node, dst_node->pid, dst_node->handle_id, false);
                        }
                }
@@ -1451,7 +1442,7 @@ int mm_sound_mgr_focus_emergent_exit(const _mm_sound_mgr_focus_param_t *param)
 {
        int ret = MM_ERROR_NONE;
        GList *list = NULL;
-       GList *list_s =NULL;
+       GList *list_s = NULL;
        focus_node_t *node = NULL;
        focus_node_t *my_node = NULL;
        int i;
@@ -1461,14 +1452,14 @@ int mm_sound_mgr_focus_emergent_exit(const _mm_sound_mgr_focus_param_t *param)
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
        /* Update list for dead process */
-       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+       g_list_foreach(g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        list = g_focus_node_list;
        while (list) {
                CONTINUE_IF_LIST_DATA_IS_NULL(node, list);
                if (node->pid != param->pid) {
                        list = list->next;
-                       debug_log("node not found, next list = %p",list);
+                       debug_log("node not found, next list = %p", list);
                        continue;
                }
                if (node->is_for_watch) {
@@ -1538,7 +1529,7 @@ int mm_sound_mgr_focus_emergent_exit(const _mm_sound_mgr_focus_param_t *param)
        }
 
        _mm_sound_mgr_focus_list_dump();
-       _mm_sound_mgr_focus_watch_list_dump ();
+       _mm_sound_mgr_focus_watch_list_dump();
 
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
 
index 942b47c..22d6334 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.11.24
+Version:    0.11.25
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0