Change emergent exit from method call to signal 19/60419/4
authorMok Jeongho <jho.mok@samsung.com>
Fri, 26 Feb 2016 05:40:27 +0000 (14:40 +0900)
committerMok Jeongho <jho.mok@samsung.com>
Fri, 26 Feb 2016 08:50:18 +0000 (17:50 +0900)
[Version] Release 0.10.9
[Profile] Common
[Issue Type] Feature enhancement

Change-Id: Ie3e528a1def32cc77e492a277e9e446b8574e5bc

common/mm_sound_dbus.c
focus_server/mm_sound_mgr_focus.c
focus_server/mm_sound_mgr_focus_dbus.c
include/mm_sound_intf.h
include/mm_sound_proxy.h
mm_sound_client.c
mm_sound_proxy.c
packaging/libmm-sound.spec

index dfa30c3..e5ec0c3 100644 (file)
@@ -110,9 +110,6 @@ const mm_sound_dbus_method_info_t g_methods[AUDIO_METHOD_MAX] = {
        [AUDIO_METHOD_UNWATCH_FOCUS] = {
                .name = "UnwatchFocus",
        },
-       [AUDIO_METHOD_EMERGENT_EXIT_FOCUS] = {
-               .name = "EmergentExitFocus",
-       },
 };
 
 const mm_sound_dbus_signal_info_t g_events[AUDIO_EVENT_MAX] = {
@@ -136,6 +133,9 @@ const mm_sound_dbus_signal_info_t g_events[AUDIO_EVENT_MAX] = {
        },
        [AUDIO_EVENT_FOCUS_WATCH] = {
                .name = "FocusWatch",
+       },
+       [AUDIO_EVENT_EMERGENT_EXIT] = {
+               .name = "EmergentExit",
        }
 };
 
@@ -413,26 +413,29 @@ static void _dbus_signal_callback(GDBusConnection  *connection,
        debug_log("Signal(%s.%s) Received , Let's call Wrapper-Callback", interface_name, signal_name);
 
        if (!strcmp(signal_name, g_events[AUDIO_EVENT_VOLUME_CHANGED].name)) {
-           (cb_data->user_cb)(AUDIO_EVENT_VOLUME_CHANGED, params, cb_data->user_data);
+               (cb_data->user_cb)(AUDIO_EVENT_VOLUME_CHANGED, params, cb_data->user_data);
        } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_CONNECTED].name)) {
-             (cb_data->user_cb)(AUDIO_EVENT_DEVICE_CONNECTED, params, cb_data->user_data);
+               (cb_data->user_cb)(AUDIO_EVENT_DEVICE_CONNECTED, params, cb_data->user_data);
        } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_INFO_CHANGED].name)) {
-             (cb_data->user_cb)(AUDIO_EVENT_DEVICE_INFO_CHANGED, params, cb_data->user_data);
+               (cb_data->user_cb)(AUDIO_EVENT_DEVICE_INFO_CHANGED, params, cb_data->user_data);
        } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_CHANGED].name)) {
-             (cb_data->user_cb)(AUDIO_EVENT_FOCUS_CHANGED, params, cb_data->user_data);
+               (cb_data->user_cb)(AUDIO_EVENT_FOCUS_CHANGED, params, cb_data->user_data);
        } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_WATCH].name)) {
-             (cb_data->user_cb)(AUDIO_EVENT_FOCUS_WATCH, params, cb_data->user_data);
+               (cb_data->user_cb)(AUDIO_EVENT_FOCUS_WATCH, params, cb_data->user_data);
        } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_PLAY_FILE_END].name)) {
-             (cb_data->user_cb)(AUDIO_EVENT_PLAY_FILE_END, params, cb_data->user_data);
+               (cb_data->user_cb)(AUDIO_EVENT_PLAY_FILE_END, params, cb_data->user_data);
+       } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_EMERGENT_EXIT].name)) {
+               (cb_data->user_cb)(AUDIO_EVENT_EMERGENT_EXIT, params, cb_data->user_data);
        }
 }
 
 static void callback_data_free_func(gpointer data)
 {
-    struct callback_data *cb_data = (struct callback_data *) data;
+       struct callback_data *cb_data = (struct callback_data *) data;
 
-    cb_data->free_func(cb_data->user_data);
-    g_free(cb_data);
+       if (cb_data->free_func)
+               cb_data->free_func(cb_data->user_data);
+       g_free(cb_data);
 }
 
 EXPORT_API
@@ -519,7 +522,7 @@ int mm_sound_dbus_emit_signal(audio_provider_t provider, audio_event_t event, GV
        }
 
        dbus_ret = g_dbus_connection_emit_signal (conn,
-                                                 g_paths[provider].bus_name, g_paths[provider].object,
+                                                 NULL, g_paths[provider].object,
                                                  g_paths[provider].interface, g_events[event].name,
                                                  param, &err);
        if (!dbus_ret) {
index 74e3ffb..64aadcf 100644 (file)
@@ -63,6 +63,7 @@ typedef struct {
        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\n", node->pid); \
+               __clear_focus_pipe(node); \
                x = g_list_remove (x, node); \
                g_free (node); \
        } \
@@ -162,11 +163,6 @@ static char* __get_focus_pipe_path(int instance_id, int handle, const char* post
        return path;
 }
 
-static void _clear_focus_node_list_func (focus_node_t *node, gpointer user_data)
-{
-       CLEAR_DEAD_NODE_LIST(g_focus_node_list);
-}
-
 static void __clear_focus_pipe(focus_node_t *node)
 {
        char *filename = NULL;
@@ -195,6 +191,11 @@ static void __clear_focus_pipe(focus_node_t *node)
        debug_fleave();
 }
 
+static void _clear_focus_node_list_func (focus_node_t *node, gpointer user_data)
+{
+       CLEAR_DEAD_NODE_LIST(g_focus_node_list);
+}
+
 static int _mm_sound_mgr_focus_get_priority_from_stream_type(int *priority, const char *stream_type)
 {
        int ret = MM_ERROR_NONE;
index 536abf0..3521302 100644 (file)
@@ -122,7 +122,6 @@ static void handle_method_acquire_focus(GDBusMethodInvocation* invocation);
 static void handle_method_release_focus(GDBusMethodInvocation* invocation);
 static void handle_method_watch_focus(GDBusMethodInvocation* invocation);
 static void handle_method_unwatch_focus(GDBusMethodInvocation* invocation);
-static void handle_method_emergent_exit_focus (GDBusMethodInvocation* invocation);
 
 /* Currently , Just using method's name and handler */
 /* TODO : generate introspection xml automatically, with these value include argument and reply */
@@ -182,17 +181,12 @@ mm_sound_dbus_method_intf_t methods[AUDIO_METHOD_MAX] = {
                        .name = "UnwatchFocus",
                },
                .handler = handle_method_unwatch_focus
-       },
-       [AUDIO_METHOD_EMERGENT_EXIT_FOCUS] = {
-               .info = {
-                       .name = "EmergentExitFocus",
-               },
-               .handler = handle_method_emergent_exit_focus
-       },
+       }
 };
 
 static GDBusNodeInfo *introspection_data = NULL;
 guint focus_server_owner_id ;
+unsigned emergent_exit_subs_id;
 
 /*
         For pass error code with 'g_dbus_method_invocation_return_error'
@@ -567,34 +561,6 @@ send_reply:
        debug_fleave();
 }
 
-static void handle_method_emergent_exit_focus (GDBusMethodInvocation* invocation)
-{
-       int ret = MM_ERROR_NONE;
-       int pid = 0;
-       GVariant *params = NULL;
-
-       debug_fenter();
-
-       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
-               debug_error("Parameter for Method is NULL");
-               goto send_reply;
-       }
-
-       g_variant_get(params, "(i)", &pid);
-       ret = __mm_sound_mgr_focus_ipc_emergent_exit(_get_sender_pid(invocation));
-       if(ret)
-               debug_error("__mm_sound_mgr_focus_ipc_emergent_exit faild : 0x%x", ret);
-
-send_reply:
-       if (ret == MM_ERROR_NONE) {
-               _method_call_return_value(invocation, g_variant_new("()"));
-       } else {
-               _method_call_return_error(invocation, ret);
-       }
-
-       debug_fleave();
-}
-
 /**********************************************************************************/
 static void handle_method_call(GDBusConnection *connection,
                                                        const gchar *sender,
@@ -646,6 +612,25 @@ static gboolean handle_set_property(GDBusConnection *connection,
        return TRUE;
 }
 
+void emergent_exit_signal_handler(audio_event_t event, GVariant *param, void *userdata)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0;
+
+       if (event != AUDIO_EVENT_EMERGENT_EXIT)
+               return;
+
+       debug_fenter();
+
+       g_variant_get(param, "(i)", &pid);
+       debug_log("emergent exit : pid %d", pid);
+       ret = __mm_sound_mgr_focus_ipc_emergent_exit(pid);
+       if (ret)
+               debug_error("__mm_sound_mgr_focus_ipc_emergent_exit faild : 0x%x", ret);
+
+       debug_fleave();
+}
+
 static const GDBusInterfaceVTable interface_vtable =
 {
        handle_method_call,
@@ -778,7 +763,6 @@ int __mm_sound_mgr_focus_dbus_get_stream_list(stream_list_t* stream_list)
        return ret;
 }
 
-
 int MMSoundMgrFocusDbusInit(void)
 {
        debug_enter();
@@ -791,6 +775,10 @@ int MMSoundMgrFocusDbusInit(void)
                debug_error ("dbus own name for focus-server error\n");
                return MM_ERROR_SOUND_INTERNAL;
        }
+       if (mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_EMERGENT_EXIT, emergent_exit_signal_handler, NULL, NULL, &emergent_exit_subs_id) != MM_ERROR_NONE) {
+               debug_error ("dbus signal subscribe for emergent exit error\n");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
 
        debug_leave();
 
@@ -799,12 +787,14 @@ int MMSoundMgrFocusDbusInit(void)
 
 void MMSoundMgrFocusDbusFini(void)
 {
-       debug_enter("\n");
+       debug_enter();
 
+       if (emergent_exit_subs_id != 0)
+               mm_sound_dbus_signal_unsubscribe(emergent_exit_subs_id);
        _mm_sound_mgr_focus_dbus_unown_name(focus_server_owner_id);
        g_dbus_node_info_unref (introspection_data);
 
-       debug_leave("\n");
+       debug_leave();
 }
 
 
index 3fe4df6..30f6f3d 100644 (file)
@@ -66,7 +66,6 @@ typedef enum audio_method {
        AUDIO_METHOD_RELEASE_FOCUS,
        AUDIO_METHOD_WATCH_FOCUS,
        AUDIO_METHOD_UNWATCH_FOCUS,
-       AUDIO_METHOD_EMERGENT_EXIT_FOCUS,
 
        AUDIO_METHOD_MAX
 } audio_method_t;
@@ -79,6 +78,7 @@ typedef enum audio_event {
        AUDIO_EVENT_DEVICE_INFO_CHANGED,
        AUDIO_EVENT_FOCUS_CHANGED,
        AUDIO_EVENT_FOCUS_WATCH,
+       AUDIO_EVENT_EMERGENT_EXIT,
        AUDIO_EVENT_MAX
 } audio_event_t;
 
index 12c8a62..fdbbb27 100644 (file)
@@ -72,7 +72,7 @@ int mm_sound_proxy_acquire_focus(int instance, int id, mm_sound_focus_type_e typ
 int mm_sound_proxy_release_focus(int instance, int id, mm_sound_focus_type_e type, const char *option, bool is_for_session);
 int mm_sound_proxy_set_focus_watch_callback(int instance, int handle, mm_sound_focus_type_e type, mm_sound_focus_changed_watch_cb callback, bool is_for_session, void *user_data);
 int mm_sound_proxy_unset_focus_watch_callback(int focus_tid, int handle, bool is_for_session);
-int mm_sound_proxy_emergent_exit_focus(int exit_pid);
+int mm_sound_proxy_emergent_exit(int exit_pid);
 #endif
 
 int mm_sound_proxy_add_test_callback(mm_sound_test_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id);
index d0bd3c0..104c95a 100644 (file)
 
 #define VOLUME_TYPE_LEN 64
 
-struct sigaction FOCUS_int_old_action;
-struct sigaction FOCUS_abrt_old_action;
-struct sigaction FOCUS_segv_old_action;
-struct sigaction FOCUS_term_old_action;
-struct sigaction FOCUS_sys_old_action;
-struct sigaction FOCUS_xcpu_old_action;
+struct sigaction system_int_old_action;
+struct sigaction system_abrt_old_action;
+struct sigaction system_segv_old_action;
+struct sigaction system_term_old_action;
+struct sigaction system_sys_old_action;
+struct sigaction system_xcpu_old_action;
 
 struct callback_data {
        void *user_cb;
@@ -142,10 +142,9 @@ static pthread_mutex_t g_id_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 guint g_focus_signal_handle = 0;
 
-void _focus_signal_handler(int signo)
+void _system_signal_handler(int signo)
 {
        int ret = MM_ERROR_NONE;
-       int exit_pid = 0;
        int index = 0;
        sigset_t old_mask, all_mask;
 
@@ -156,20 +155,9 @@ void _focus_signal_handler(int signo)
        sigfillset(&all_mask);
        sigprocmask(SIG_BLOCK, &all_mask, &old_mask);
 
-       exit_pid = getpid();
-
-       /* need implementation */
-       //send exit pid to focus server and focus server will clear focus or watch if necessary.
-
-       for (index = 0; index < FOCUS_HANDLE_MAX; index++) {
-               if (g_focus_sound_handle[index].is_used == true && g_focus_sound_handle[index].focus_tid == exit_pid) {
-                       ret = mm_sound_proxy_emergent_exit_focus(exit_pid);
-                       break;
-               }
-       }
-
+       ret = mm_sound_proxy_emergent_exit(getpid());
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to emergnet_exit_focus\n");
+               debug_msg("[Client] Success to emergnet_exit\n");
        else
                debug_error("[Client] Error occurred : 0x%x \n",ret);
 
@@ -178,27 +166,27 @@ void _focus_signal_handler(int signo)
 
        switch (signo) {
        case SIGINT:
-               sigaction(SIGINT, &FOCUS_int_old_action, NULL);
+               sigaction(SIGINT, &system_int_old_action, NULL);
                raise( signo);
                break;
        case SIGABRT:
-               sigaction(SIGABRT, &FOCUS_abrt_old_action, NULL);
+               sigaction(SIGABRT, &system_abrt_old_action, NULL);
                raise( signo);
                break;
        case SIGSEGV:
-               sigaction(SIGSEGV, &FOCUS_segv_old_action, NULL);
+               sigaction(SIGSEGV, &system_segv_old_action, NULL);
                raise( signo);
                break;
        case SIGTERM:
-               sigaction(SIGTERM, &FOCUS_term_old_action, NULL);
+               sigaction(SIGTERM, &system_term_old_action, NULL);
                raise( signo);
                break;
        case SIGSYS:
-               sigaction(SIGSYS, &FOCUS_sys_old_action, NULL);
+               sigaction(SIGSYS, &system_sys_old_action, NULL);
                raise( signo);
                break;
        case SIGXCPU:
-               sigaction(SIGXCPU, &FOCUS_xcpu_old_action, NULL);
+               sigaction(SIGXCPU, &system_xcpu_old_action, NULL);
                raise( signo);
                break;
        default:
@@ -215,22 +203,19 @@ int mm_sound_client_initialize(void)
 
        mm_sound_proxy_initialize();
 
-#ifdef USE_FOCUS
-
-       struct sigaction FOCUS_action;
-       FOCUS_action.sa_handler = _focus_signal_handler;
-       FOCUS_action.sa_flags = SA_NOCLDSTOP;
 
-       sigemptyset(&FOCUS_action.sa_mask);
+       struct sigaction system_action;
+       system_action.sa_handler = _system_signal_handler;
+       system_action.sa_flags = SA_NOCLDSTOP;
 
-       sigaction(SIGINT, &FOCUS_action, &FOCUS_int_old_action);
-       sigaction(SIGABRT, &FOCUS_action, &FOCUS_abrt_old_action);
-       sigaction(SIGSEGV, &FOCUS_action, &FOCUS_segv_old_action);
-       sigaction(SIGTERM, &FOCUS_action, &FOCUS_term_old_action);
-       sigaction(SIGSYS, &FOCUS_action, &FOCUS_sys_old_action);
-       sigaction(SIGXCPU, &FOCUS_action, &FOCUS_xcpu_old_action);
+       sigemptyset(&system_action.sa_mask);
 
-#endif
+       sigaction(SIGINT, &system_action, &system_int_old_action);
+       sigaction(SIGABRT, &system_action, &system_abrt_old_action);
+       sigaction(SIGSEGV, &system_action, &system_segv_old_action);
+       sigaction(SIGTERM, &system_action, &system_term_old_action);
+       sigaction(SIGSYS, &system_action, &system_sys_old_action);
+       sigaction(SIGXCPU, &system_action, &system_xcpu_old_action);
 
        debug_fleave();
        return ret;
@@ -242,20 +227,25 @@ int mm_sound_client_finalize(void)
 
        debug_fenter();
 
+       ret = mm_sound_proxy_emergent_exit(getpid());
+       if (ret == MM_ERROR_NONE)
+               debug_msg("[Client] Success to emergnet_exit\n");
+       else
+               debug_error("[Client] Error occurred : 0x%x \n",ret);
+
+       sigaction(SIGINT, &system_int_old_action, NULL);
+       sigaction(SIGABRT, &system_abrt_old_action, NULL);
+       sigaction(SIGSEGV, &system_segv_old_action, NULL);
+       sigaction(SIGTERM, &system_term_old_action, NULL);
+       sigaction(SIGSYS, &system_sys_old_action, NULL);
+       sigaction(SIGXCPU, &system_xcpu_old_action, NULL);
+
        ret = mm_sound_proxy_finalize();
 
 
 #ifdef USE_FOCUS
 
        int index = 0;
-       int exit_pid = 0;
-
-       exit_pid = getpid();
-       for (index = 0; index < FOCUS_HANDLE_MAX; index++) {
-               if (g_focus_sound_handle[index].is_used == true && g_focus_sound_handle[index].focus_tid == exit_pid) {
-                       mm_sound_proxy_emergent_exit_focus(exit_pid);
-               }
-       }
 
        if (g_focus_thread) {
                g_main_loop_quit(g_focus_loop);
@@ -265,14 +255,6 @@ int mm_sound_client_finalize(void)
                g_focus_thread = NULL;
        }
 
-       /* is it necessary? */
-       sigaction(SIGINT, &FOCUS_int_old_action, NULL);
-       sigaction(SIGABRT, &FOCUS_abrt_old_action, NULL);
-       sigaction(SIGSEGV, &FOCUS_segv_old_action, NULL);
-       sigaction(SIGTERM, &FOCUS_term_old_action, NULL);
-       sigaction(SIGSYS, &FOCUS_sys_old_action, NULL);
-       sigaction(SIGXCPU, &FOCUS_xcpu_old_action, NULL);
-
 #endif
 
        debug_fleave();
index 3dd46b9..dd2ea1e 100644 (file)
@@ -576,6 +576,30 @@ int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id)
        return ret;
 }
 
+int mm_sound_proxy_emergent_exit(int exit_pid)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant* params = NULL;
+
+       debug_fenter();
+
+       params = g_variant_new("(i)", exit_pid);
+       if (params) {
+           if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_EMERGENT_EXIT, params)) != MM_ERROR_NONE) {
+                       debug_error("dbus emergent exit failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for emergent exit signal failed");
+               ret = MM_ERROR_SOUND_INTERNAL;
+       }
+
+cleanup:
+
+       debug_fleave();
+       return ret;
+}
+
 /*------------------------------------------ FOCUS --------------------------------------------------*/
 #ifdef USE_FOCUS
 
@@ -883,33 +907,6 @@ int mm_sound_proxy_unset_focus_watch_callback(int focus_tid, int handle, bool is
        return ret;
 }
 
-int mm_sound_proxy_emergent_exit_focus(int exit_pid)
-{
-       int ret = MM_ERROR_NONE;
-       GVariant* params = NULL, *result = NULL;
-
-       debug_fenter();
-
-       params = g_variant_new("(i)", exit_pid);
-       if (params) {
-               if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_EMERGENT_EXIT_FOCUS, params, &result)) != MM_ERROR_NONE) {
-                       debug_error("dbus emergent exit focus failed");
-                       goto cleanup;
-               }
-       } else {
-               debug_error("Construct Param for method call failed");
-       }
-
-cleanup:
-       if (ret != MM_ERROR_NONE)
-               g_variant_get(result, "(i)",  &ret);
-       if (result)
-               g_variant_unref(result);
-
-       debug_fleave();
-       return ret;
-}
-
 #endif /* USE_FOCUS */
 /*------------------------------------------ FOCUS --------------------------------------------------*/
 
index 37688e1..d03374e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.10.8
+Version:    0.10.9
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0