Add to set false as exit when dbus disconnects
[platform/core/uifw/stt.git] / server / sttd_dbus.c
index 99a29a2..cf69d02 100644 (file)
@@ -350,11 +350,6 @@ int sttdc_send_result(int uid, int event, const char** data, int data_count, con
 
 int sttdc_send_error_signal(int uid, int reason, const char *err_msg)
 {
-       if (NULL == err_msg) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Input parameter is NULL");
-               return STTD_ERROR_INVALID_PARAMETER;
-       }
-
        int pid = sttd_client_get_pid(uid);
        if (0 > pid) {
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
@@ -509,17 +504,14 @@ void __sttd_dbus_connection_free()
 {
        if (NULL != g_conn_listener) {
                dbus_connection_close(g_conn_listener);
-               dbus_connection_unref(g_conn_listener);
                g_conn_listener = NULL;
        }
        if (NULL != g_conn_sender) {
                dbus_connection_close(g_conn_sender);
-               dbus_connection_unref(g_conn_sender);
                g_conn_sender = NULL;
        }
        if (NULL != g_conn_custom) {
                dbus_connection_close(g_conn_custom);
-               dbus_connection_unref(g_conn_custom);
                g_conn_custom = NULL;
        }
 }
@@ -588,7 +580,7 @@ int __sttd_get_buxtonkey()
 
        __sttd_dbus_service_free();
 
-       if (NULL == engine_appid || NULL == engine_default || 0 == strncmp(engine_appid, engine_default, strlen(engine_appid))) {
+       if (NULL == engine_default || 0 == strncmp(engine_appid, engine_default, strlen(engine_appid))) {
                g_server_service_name = (char*)calloc(strlen(STT_SERVER_SERVICE_NAME) + 1, sizeof(char));
                if (g_server_service_name)
                        snprintf(g_server_service_name, strlen(STT_SERVER_SERVICE_NAME) + 1, "%s", STT_SERVER_SERVICE_NAME);
@@ -660,6 +652,13 @@ int __sttd_request_custom_dbus_name()
                return STTD_ERROR_OPERATION_FAILED;
        }
 
+       if (NULL == g_conn_custom) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to get dbus connection");
+               return STT_ERROR_OPERATION_FAILED;
+       }
+
+       dbus_connection_set_exit_on_disconnect(g_conn_custom, false);
+
        int ret = dbus_bus_request_name(g_conn_custom, STT_SERVER_CUSTOM_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
        if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to be primary owner");
@@ -683,7 +682,6 @@ int __sttd_request_custom_dbus_name()
        }
 
        dbus_connection_close(g_conn_custom);
-       dbus_connection_unref(g_conn_custom);
        g_conn_custom = NULL;
 
        SLOG(LOG_DEBUG, TAG_STTD, "==");
@@ -709,6 +707,8 @@ int sttd_dbus_open_connection()
                return STTD_ERROR_OPERATION_FAILED;
        }
 
+       dbus_connection_set_exit_on_disconnect(g_conn_sender, false);
+
        /* connect to the bus and check for errors */
        g_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
 
@@ -723,6 +723,8 @@ int sttd_dbus_open_connection()
                return STTD_ERROR_OPERATION_FAILED;
        }
 
+       dbus_connection_set_exit_on_disconnect(g_conn_listener, false);
+
        /* Get buxton key */
        ret = __sttd_get_buxtonkey();
        if (0 != ret) {