Update IPC 41/43441/2 tizen_3.0.m1_mobile tizen_3.0.m1_tv accepted/tizen/mobile/20150714.041217 accepted/tizen/tv/20150714.041235 accepted/tizen/wearable/20150714.041242 submit/tizen/20150714.015754 submit/tizen_common/20151023.083358 submit/tizen_common/20151026.085049 tizen_3.0.m1_mobile_release tizen_3.0.m1_tv_release
authorky85.kim <ky85.kim@samsung.com>
Thu, 9 Jul 2015 09:02:01 +0000 (18:02 +0900)
committerky85.kim <ky85.kim@samsung.com>
Thu, 9 Jul 2015 10:38:05 +0000 (19:38 +0900)
Apply Dbus activation for daemon start
Apply Dbus policy config

Change-Id: Ia0d520529bfc05ca4c94414ca2d2eeb4164fb580

22 files changed:
CMakeLists.txt
changelog
client/stt.c
client/stt_client.c
client/stt_dbus.c
client/stt_file.c
common/stt_config_mgr.c
common/stt_config_parser.c
common/stt_defs.h
common/stt_engine.c
org.tizen.voice.sttserver.service [new file with mode: 0644]
packaging/stt.spec
server/sttd_client_data.c
server/sttd_dbus.c
server/sttd_dbus.h
server/sttd_dbus_server.c
server/sttd_engine_agent.c
server/sttd_main.c
server/sttd_main.h
server/sttd_recorder.c
server/sttd_server.c
stt-server.conf [new file with mode: 0644]

index 6bfaa53..0e4799d 100644 (file)
@@ -23,7 +23,7 @@ PROJECT(stt)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(EXEC_PREFIX "${PREFIX}")
-SET(VERSION 0.2.53)
+SET(VERSION 0.2.54)
 
 ## Include common directory ##
 INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/common")
@@ -55,3 +55,5 @@ ADD_SUBDIRECTORY(test)
 ## config ##
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/stt-config.xml DESTINATION /usr/lib/voice/stt/1.0)
 
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/stt-server.conf DESTINATION /etc/dbus-1/system.d)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.voice.sttserver.service DESTINATION /usr/share/dbus-1/system-services)
index 97cbeb1..37a87f1 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,11 @@
+stt (0.2.54) -- Tue, 2 Jun 2015
+
+  * Update IPC for getting volume not to use file (Dongyeol Lee <dy3.lee@samsung.com>)
+  * Remove unused smack label (Kwangyoun Kim <ky85.kim@samsung.com>)
+  * Update daemon start by dbus activation (Dongyeol Lee <dy3.lee@samsung.com>)
+  * Update state changed callback for thread (Dongyeol Lee <dy3.lee@samsung.com>)
+  * Apply dbus policy config (Kwangyoun Kim <ky85.kim@samsung.com>)
+
 stt (0.2.53) -- Thu, 21 Aug 2014
 
   * Remove agreement api (Dongyeol Lee <dy3.lee@samsung.com>)
index ec0aeed..ea44190 100644 (file)
 #include "stt_main.h"
 
 
-static bool g_is_daemon_started = false;
-
 static Ecore_Timer* g_connect_timer = NULL;
 
-static Eina_Bool __stt_notify_state_changed(void *data);
+static void __stt_notify_state_changed(void *data);
 static Eina_Bool __stt_notify_error(void *data);
 
-static int g_stt_daemon_pid = -1;
 static int g_count_check_daemon = 0;
 
 const char* stt_tag()
@@ -229,8 +226,6 @@ int stt_destroy(stt_h stt)
                if (0 != ret) {
                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret));
                }
-
-               g_is_daemon_started = false;
        case STT_STATE_CREATED:
                if (NULL != g_connect_timer) {
                        SLOG(LOG_DEBUG, TAG_STTC, "Connect Timer is deleted");
@@ -251,6 +246,8 @@ int stt_destroy(stt_h stt)
                }
        }
 
+       stt = NULL;
+
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
        SLOG(LOG_DEBUG, TAG_STTC, " ");
 
@@ -435,115 +432,13 @@ int stt_set_engine(stt_h stt, const char* engine_id)
        }
 
        client->current_engine_id = strdup(engine_id);
-#if 0
-       if (client->current_state == STT_STATE_READY) {
-               int ret = 0;
-               bool silence_supported = false;
-
-               ret = stt_dbus_request_set_current_engine(client->uid, engine_id, &silence_supported);
-
-               if (0 != ret) {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret));
-                       return ret;
-               } else {
-                       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", engine_id);
 
-                       /* success to change engine */
-                       client->silence_supported = silence_supported;
-                       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s)", silence_supported ? "true" : "false");
-               }
-       }
-#endif
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
        SLOG(LOG_DEBUG, TAG_STTC, " ");
 
        return 0;
 }
 
-static int __read_proc(const char *path, char *buf, int size)
-{
-       int fd;
-       int ret;
-
-       if (NULL == buf || NULL == path) {
-               return -1;
-       }
-
-       fd = open(path, O_RDONLY);
-       if (fd < 0) {
-               return -1;
-       }
-
-       ret = read(fd, buf, size - 1);
-       if (0 >= ret) {
-               close(fd);
-               return -1;
-       } else {
-               buf[ret] = 0;
-       }
-       close(fd);
-       return ret;
-}
-
-static bool __stt_check_daemon_exist()
-{
-       char buf[128];
-       int ret;
-
-       FILE* fp;
-       fp = fopen(STT_PID_FILE_PATH, "r");
-       if (NULL == fp) {
-               return false;
-       }
-
-       g_stt_daemon_pid = -1;
-       int pid;
-       if (0 >= fscanf(fp, "%d", &pid)) {
-               SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Fail to read pid");
-               fclose(fp);
-               return false;
-       }
-
-       fclose(fp);
-       snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
-       ret = __read_proc(buf, buf, sizeof(buf));
-       if (0 >= ret) {
-               return false;
-       } else {
-               if (!strcmp(buf, "/usr/bin/stt-daemon")) {
-                       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Daemon existed - [%d]%s", pid, buf);
-                       g_stt_daemon_pid = pid;
-                       return true;
-               }
-       }
-       return false;
-}
-
-static void* __fork_stt_daemon(void* NotUsed)
-{
-       int pid, i;
-       pid = fork();
-
-       switch(pid) {
-       case -1:
-               SLOG(LOG_DEBUG, TAG_STTC, "[STT ERROR] fail to create STT-DAEMON");
-               break;
-
-       case 0:
-               setsid();
-               for (i = 0;i < _NSIG;i++)
-                       signal(i, SIG_DFL);
-
-               execl("/usr/bin/stt-daemon", "/usr/bin/stt-daemon", NULL);
-               break;
-
-       default:
-               break;
-       }
-
-       return (void*) 1;
-}
-
 static Eina_Bool __stt_connect_daemon(void *data)
 {
        stt_client_s* client = (stt_client_s*)data;
@@ -556,47 +451,11 @@ static Eina_Bool __stt_connect_daemon(void *data)
        /* Send hello */
        int ret = -1;
        ret = stt_dbus_request_hello();
-
-       if (STT_DAEMON_NORMAL != ret) {
+       if (0 != ret) {
                if (STT_ERROR_INVALID_STATE == ret) {
                        return EINA_FALSE;
                }
-
-               if (STT_DAEMON_ON_TERMINATING == ret) {
-                       /* Todo - Wait for terminating and do it again*/
-                       usleep(50);
-                       return EINA_TRUE;
-               } else {
-                       /* for new daemon */
-                       bool check = __stt_check_daemon_exist();
-                       if (true == check) {
-                               g_count_check_daemon++;
-                               if (3 < g_count_check_daemon) {
-                                       /* Todo - Kill daemon and restart */
-                                       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Need to Kill daemon");
-                               }
-                               usleep(50);
-                               return EINA_TRUE;
-                       } else {
-                               if (false == g_is_daemon_started) {
-                                       g_is_daemon_started = true;
-                                       
-                                       pthread_t thread;
-                                       int thread_id;
-                                       thread_id = pthread_create(&thread, NULL, __fork_stt_daemon, NULL);
-                                       if (thread_id < 0) {
-                                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to make thread");
-                                               g_connect_timer = NULL;
-                                               return EINA_FALSE;
-                                       }
-
-                                       pthread_detach(thread);
-                               }
-
-                               usleep(50);
-                               return EINA_TRUE;
-                       }
-               }
+               return EINA_TRUE;
        }
 
        g_connect_timer = NULL;
@@ -637,9 +496,9 @@ static Eina_Bool __stt_connect_daemon(void *data)
                                        return ret;
                                } else {
                                        SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                                       usleep(10);
+                                       usleep(10000);
                                        count++;
-                                       if (10 == count) {
+                                       if (STT_RETRY_COUNT == count) {
                                                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                                return ret;
                                        }
@@ -719,11 +578,14 @@ int stt_prepare(stt_h stt)
 
 int stt_unprepare(stt_h stt)
 {
-       bool supported = false;
-       if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &supported)) {
-               if (false == supported) {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
-                       return STT_ERROR_NOT_SUPPORTED;
+       bool stt_supported = false;
+       bool mic_supported = false;
+       if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) {
+               if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) {
+                       if (false == stt_supported || false == mic_supported) {
+                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
+                               return STT_ERROR_NOT_SUPPORTED;
+                       }
                }
        }
 
@@ -755,9 +617,9 @@ int stt_unprepare(stt_h stt)
                                break;
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10);
+                               usleep(10000);
                                count++;
-                               if (10 == count) {
+                               if (STT_RETRY_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                        break;
                                }
@@ -765,8 +627,6 @@ int stt_unprepare(stt_h stt)
                }
        }
 
-       g_is_daemon_started = false;
-
        client->internal_state = STT_INTERNAL_STATE_NONE;
 
        client->before_state = client->current_state;
@@ -851,6 +711,10 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac
                }
        } else {
                current_engine_id = strdup(client->current_engine_id);
+               if (NULL == current_engine_id) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+                       return STT_ERROR_OUT_OF_MEMORY;
+               }
        }
 
        client->supported_lang_cb = callback;
@@ -1001,9 +865,9 @@ int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support
                                return ret;
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10);
+                               usleep(10000);
                                count++;
-                               if (10 == count) {
+                               if (STT_RETRY_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                        return ret;
                                }
@@ -1082,8 +946,12 @@ int stt_set_start_sound(stt_h stt, const char* filename)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
+       if (0 != access(filename, F_OK)) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
 
+       stt_client_s* client = stt_client_get(stt);
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid");
                return STT_ERROR_INVALID_PARAMETER;
@@ -1105,9 +973,9 @@ int stt_set_start_sound(stt_h stt, const char* filename)
                                return ret;
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10);
+                               usleep(10000);
                                count++;
-                               if (10 == count) {
+                               if (STT_RETRY_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                        return ret;
                                }
@@ -1164,9 +1032,9 @@ int stt_unset_start_sound(stt_h stt)
                                return ret;
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10);
+                               usleep(10000);
                                count++;
-                               if (10 == count) {
+                               if (STT_RETRY_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                        return ret;
                                }
@@ -1200,6 +1068,11 @@ int stt_set_stop_sound(stt_h stt, const char* filename)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
+       if (0 != access(filename, F_OK)) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
        stt_client_s* client = stt_client_get(stt);
 
        if (NULL == client) {
@@ -1223,9 +1096,9 @@ int stt_set_stop_sound(stt_h stt, const char* filename)
                                return ret;
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10);
+                               usleep(10000);
                                count++;
-                               if (10 == count) {
+                               if (STT_RETRY_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                        return ret;
                                }
@@ -1282,9 +1155,9 @@ int stt_unset_stop_sound(stt_h stt)
                                return ret;
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10);
+                               usleep(10000);
                                count++;
-                               if (10 == count) {
+                               if (STT_RETRY_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                        return ret;
                                }
@@ -1345,10 +1218,11 @@ int stt_start(stt_h stt, const char* language, const char* type)
                return STT_ERROR_INVALID_STATE;
        }
 
+       int ret = -1;
        char appid[128] = {0, };
-       aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
-       
-       if (0 == strlen(appid)) {
+       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+
+       if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
        } else {
                SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid);
@@ -1361,7 +1235,7 @@ int stt_start(stt_h stt, const char* language, const char* type)
                temp = strdup(language);
        }
 
-       int ret = -1;
+       ret = -1;
        /* do request */
        int count = 0;
        while (0 != ret) {
@@ -1374,9 +1248,9 @@ int stt_start(stt_h stt, const char* language, const char* type)
                                return ret;
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry to start");
-                               usleep(10);
+                               usleep(10000);
                                count++;
-                               if (10 == count) {
+                               if (STT_RETRY_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                        if (NULL != temp)       free(temp);
                                        return ret;
@@ -1392,11 +1266,7 @@ int stt_start(stt_h stt, const char* language, const char* type)
                                client->current_state = STT_STATE_RECORDING;
 
                                if (NULL != client->state_changed_cb) {
-                                       stt_client_use_callback(client);
-                                       client->state_changed_cb(client->stt, client->before_state, 
-                                               client->current_state, client->state_changed_user_data);
-                                       stt_client_not_use_callback(client);
-                                       SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
+                                       ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
                                } else {
                                        SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
                                }
@@ -1477,9 +1347,9 @@ int stt_stop(stt_h stt)
                                return ret;
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry stop");
-                               usleep(10);
+                               usleep(10000);
                                count++;
-                               if (10 == count) {
+                               if (STT_RETRY_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                        return ret;
                                }
@@ -1491,10 +1361,7 @@ int stt_stop(stt_h stt)
                                client->current_state = STT_STATE_PROCESSING;
 
                                if (NULL != client->state_changed_cb) {
-                                       stt_client_use_callback(client);
-                                       client->state_changed_cb(client->stt, client->before_state, 
-                                               client->current_state, client->state_changed_user_data); 
-                                       stt_client_not_use_callback(client);
+                                       ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
                                        SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
                                } else {
                                        SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
@@ -1576,9 +1443,9 @@ int stt_cancel(stt_h stt)
                                return ret;
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10);
+                               usleep(10000);
                                count++;
-                               if (10 == count) {
+                               if (STT_RETRY_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
                                        return ret;
                                }
@@ -1590,10 +1457,7 @@ int stt_cancel(stt_h stt)
                        client->current_state = STT_STATE_READY;
 
                        if (NULL != client->state_changed_cb) {
-                               stt_client_use_callback(client);
-                               client->state_changed_cb(client->stt, client->before_state, 
-                                       client->current_state, client->state_changed_user_data); 
-                               stt_client_not_use_callback(client);
+                               ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
                                SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
                        } else {
                                SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
@@ -1781,18 +1645,19 @@ int __stt_cb_error(int uid, int reason)
        return 0;
 }
 
-static Eina_Bool __stt_notify_state_changed(void *data)
+static void __stt_notify_state_changed(void *data)
 {
        stt_client_s* client = (stt_client_s*)data;
 
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
-               return EINA_FALSE;
+               return;
        }
 
-       if (NULL == stt_client_get_by_uid(client->uid))
-               return EINA_FALSE;
+       if (NULL == stt_client_get_by_uid(client->uid)) {
+               return;
+       }
 
        if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) {
                client->internal_state = STT_INTERNAL_STATE_NONE;
@@ -1807,11 +1672,12 @@ static Eina_Bool __stt_notify_state_changed(void *data)
                client->state_changed_cb(client->stt, client->before_state, 
                        client->current_state, client->state_changed_user_data); 
                stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
        } else {
                SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
        }
 
-       return EINA_FALSE;
+       return;
 }
 
 static Eina_Bool __stt_notify_result(void *data)
@@ -1869,7 +1735,7 @@ static Eina_Bool __stt_notify_result(void *data)
                client->current_state = STT_STATE_READY;
 
                if (NULL != client->state_changed_cb) {
-                       ecore_timer_add(0, __stt_notify_state_changed, client);
+                       ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
                } else {
                        SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
                }
@@ -1885,7 +1751,7 @@ int __stt_cb_result(int uid, int event, char** data, int data_count, const char*
        client = stt_client_get_by_uid(uid);
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid");
-               return -1;
+               return STT_ERROR_INVALID_PARAMETER;
        }
 
        if (NULL != msg)        SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg);
@@ -1906,6 +1772,10 @@ int __stt_cb_result(int uid, int event, char** data, int data_count, const char*
                if (data_count > 0) {
                        char **temp = NULL;
                        temp = (char**)calloc(data_count, sizeof(char*));
+                       if (NULL == temp) {
+                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+                               return STT_ERROR_OUT_OF_MEMORY;
+                       }
 
                        for (i = 0;i < data_count;i++) {
                                if(NULL != data[i])
@@ -1916,13 +1786,13 @@ int __stt_cb_result(int uid, int event, char** data, int data_count, const char*
 
                        client->data_list = temp;
                }
-
-               ecore_timer_add(0, __stt_notify_result, client);
        } else {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
        }
 
-       return 0;
+       ecore_timer_add(0, __stt_notify_result, client);
+
+       return STT_ERROR_NONE;
 }
 
 int __stt_cb_set_state(int uid, int state)
@@ -1943,7 +1813,7 @@ int __stt_cb_set_state(int uid, int state)
        client->before_state = client->current_state;
        client->current_state = state_from_daemon;
 
-       ecore_timer_add(0, __stt_notify_state_changed, client);
+       ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
        return 0;
 }
 
index f9e28e2..b31915f 100644 (file)
@@ -41,10 +41,19 @@ int stt_client_new(stt_h* stt)
 {
        stt_client_s *client = NULL;
 
-       client = (stt_client_s*)g_malloc0 (sizeof(stt_client_s));
+       client = (stt_client_s*)calloc(1, sizeof(stt_client_s));
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
 
-       stt_h temp = (stt_h)g_malloc0(sizeof(struct stt_s));
-       temp->handle = __client_generate_uid(getpid()); 
+       stt_h temp = (stt_h)calloc(1, sizeof(struct stt_s));
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+               free(client);
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
+       temp->handle = __client_generate_uid(getpid());
 
        /* initialize client data */
        client->stt = temp;
index f453a45..6e26ddb 100644 (file)
@@ -23,7 +23,8 @@ static int g_waiting_short_time = 500;
 
 static Ecore_Fd_Handler* g_fd_handler = NULL;
 
-static DBusConnection* g_conn = NULL;
+static DBusConnection* g_conn_sender = NULL;
+static DBusConnection* g_conn_listener = NULL;
 
 
 extern int __stt_cb_error(int uid, int reason);
@@ -34,19 +35,15 @@ extern int __stt_cb_set_state(int uid, int state);
 
 static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
 {
-       DBusConnection* conn = (DBusConnection*)data;
-       DBusMessage* msg = NULL;
-       DBusMessage *reply = NULL;
-
-       if (NULL == conn)
-               return ECORE_CALLBACK_RENEW;
+       if (NULL == g_conn_listener)    return ECORE_CALLBACK_RENEW;
 
-       dbus_connection_read_write_dispatch(conn, 50);
+       dbus_connection_read_write_dispatch(g_conn_listener, 50);
 
-       msg = dbus_connection_pop_message(conn);
+       DBusMessage* msg = NULL;
+       msg = dbus_connection_pop_message(g_conn_listener);
 
-       if (true != dbus_connection_get_is_connected(conn)) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Conn is disconnected");
+       if (true != dbus_connection_get_is_connected(g_conn_listener)) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is disconnected");
                return ECORE_CALLBACK_RENEW;
        }
 
@@ -58,8 +55,10 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
        DBusError err;
        dbus_error_init(&err);
 
+       DBusMessage *reply = NULL;
+
        char if_name[64];
-       snprintf(if_name, 64, "%s%d", STT_CLIENT_SERVICE_INTERFACE, getpid());
+       snprintf(if_name, 64, "%s", STT_CLIENT_SERVICE_INTERFACE);
 
        if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_HELLO)) {
                SLOG(LOG_DEBUG, TAG_STTC, "===== Get Hello");
@@ -90,12 +89,12 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                if (NULL != reply) {
                        dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
 
-                       if (!dbus_connection_send(conn, reply, NULL))
+                       if (!dbus_connection_send(g_conn_listener, reply, NULL))
                                SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get hello : fail to send reply");
                        else 
                                SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get hello : result(%d)", response);
 
-                       dbus_connection_flush(conn);
+                       dbus_connection_flush(g_conn_listener);
                        dbus_message_unref(reply); 
                } else {
                        SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get hello : fail to create reply message");
@@ -108,7 +107,6 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
        else if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_SET_STATE)) {
                SLOG(LOG_DEBUG, TAG_STTC, "===== Set State");
                int uid = 0;
-               int response = -1;
                int state = -1;
 
                dbus_message_get_args(msg, &err, 
@@ -122,32 +120,15 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                }
 
                if (uid > 0 && state >= 0) {
-                       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set state : uid(%d), state(%d)", uid, state);
-
-                       response = __stt_cb_set_state(uid, state);
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set state : uid(%d), state(%d)", uid, state);
+                       __stt_cb_set_state(uid, state);
                } else {
                        SLOG(LOG_ERROR, TAG_STTC, "<<<< stt set state : invalid uid or state");
                }
 
-               reply = dbus_message_new_method_return(msg);
-
-               if (NULL != reply) {
-                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
-
-                       if (!dbus_connection_send(conn, reply, NULL)) {
-                               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt set state : fail to send reply");
-                       }
-
-                       dbus_connection_flush(conn);
-                       dbus_message_unref(reply); 
-               } else {
-                       SLOG(LOG_ERROR, TAG_STTC, ">>>> stt set state : fail to create reply message");
-               }
-
                SLOG(LOG_DEBUG, TAG_STTC, "=====");
                SLOG(LOG_DEBUG, TAG_STTC, " ");
        } /* STTD_METHOD_SET_STATE */
-
        else if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_GET_STATE)) {
                SLOG(LOG_DEBUG, TAG_STTC, "===== Get state");
                int uid = 0;
@@ -179,12 +160,12 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                if (NULL != reply) {
                        dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
 
-                       if (!dbus_connection_send(conn, reply, NULL))
+                       if (!dbus_connection_send(g_conn_listener, reply, NULL))
                                SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get state : fail to send reply");
                        else 
                                SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get state : result(%d)", response);
 
-                       dbus_connection_flush(conn);
+                       dbus_connection_flush(g_conn_listener);
                        dbus_message_unref(reply); 
                } else {
                        SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get hello : fail to create reply message");
@@ -284,27 +265,13 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                        DBUS_TYPE_INVALID);
 
                if (dbus_error_is_set(&err)) { 
-                       SLOG(LOG_ERROR, TAG_STTC, "<<<< stt Get Error message : Get arguments error (%s)\n", err.message);
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< stt Get Error message : Get arguments error (%s)", err.message);
                        dbus_error_free(&err); 
                } else {
-                       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt Get Error message : uid(%d), reason(%d), msg(%s)\n", uid, reason, err_msg);
+                       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt Get Error message : uid(%d), reason(%d), msg(%s)", uid, reason, err_msg);
                        __stt_cb_error(uid, reason);
                }
 
-               reply = dbus_message_new_method_return(msg);
-
-               if (NULL != reply) {
-                       if (!dbus_connection_send(conn, reply, NULL))
-                               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt Error message : fail to send reply");
-                       else 
-                               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt Error message");
-
-                       dbus_connection_flush(conn);
-                       dbus_message_unref(reply); 
-               } else {
-                       SLOG(LOG_ERROR, TAG_STTC, ">>>> stt Error message : fail to create reply message");
-               }
-
                SLOG(LOG_DEBUG, TAG_STTC, "=====");
                SLOG(LOG_DEBUG, TAG_STTC, " ");
        }/* STTD_METHOD_ERROR */
@@ -317,26 +284,39 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
 
 int stt_dbus_open_connection()
 {
-       if (NULL != g_conn) {
+       if (NULL != g_conn_sender && NULL != g_conn_listener) {
                SLOG(LOG_WARN, TAG_STTC, "already existed connection ");
                return 0;
        }
 
        DBusError err;
-       int ret;
 
        /* initialise the error value */
        dbus_error_init(&err);
 
        /* connect to the DBUS system bus, and check for errors */
-       g_conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
+       g_conn_sender = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
+       if (dbus_error_is_set(&err)) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Dbus Connection Error (%s)", err.message);
+               dbus_error_free(&err);
+       }
+
+       if (NULL == g_conn_sender) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to get dbus connection");
+               return STT_ERROR_OPERATION_FAILED;
+       }
+
+       dbus_connection_set_exit_on_disconnect(g_conn_sender, false);
+
+       /* connect to the DBUS system bus, and check for errors */
+       g_conn_listener = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
 
        if (dbus_error_is_set(&err)) { 
-               SLOG(LOG_ERROR, TAG_STTC, "Dbus Connection Error (%s)\n", err.message); 
+               SLOG(LOG_ERROR, TAG_STTC, "Dbus Connection Error (%s)", err.message); 
                dbus_error_free(&err);
        }
 
-       if (NULL == g_conn) {
+       if (NULL == g_conn_listener) {
                SLOG(LOG_ERROR, TAG_STTC, "Fail to get dbus connection");
                return STT_ERROR_OPERATION_FAILED; 
        }
@@ -345,34 +325,24 @@ int stt_dbus_open_connection()
 
        char service_name[64];
        memset(service_name, '\0', 64);
-       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+       snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
 
        SECURE_SLOG(LOG_DEBUG, TAG_STTC, "service name is %s\n", service_name);
 
        /* register our name on the bus, and check for errors */
-       ret = dbus_bus_request_name(g_conn, service_name, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
+       dbus_bus_request_name(g_conn_listener, service_name, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
 
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "Name Error (%s)\n", err.message); 
                dbus_error_free(&err); 
        }
 
-       if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
-               SLOG(LOG_ERROR, TAG_STTC, "[Dbus ERROR] Fail to be primary owner");
-               return -2;
-       }
-
-       if( NULL != g_fd_handler ) {
-               SLOG(LOG_WARN, TAG_STTC, "The handler already exists.");
-               return 0;
-       }
-
        char rule[128];
-       snprintf(rule, 128, "type='signal',interface='%s%d'", STT_CLIENT_SERVICE_INTERFACE, pid);
+       snprintf(rule, 128, "type='signal',interface='%s'", STT_CLIENT_SERVICE_INTERFACE);
 
        /* add a rule for which messages we want to see */
-       dbus_bus_add_match(g_conn, rule, &err); 
-       dbus_connection_flush(g_conn);
+       dbus_bus_add_match(g_conn_listener, rule, &err); 
+       dbus_connection_flush(g_conn_listener);
 
        if (dbus_error_is_set(&err)) { 
                SLOG(LOG_ERROR, TAG_STTC, "Match Error (%s)\n", err.message);
@@ -381,15 +351,14 @@ int stt_dbus_open_connection()
        }
 
        int fd = 0;
-       if (1 != dbus_connection_get_unix_fd(g_conn, &fd)) {
-               SLOG(LOG_ERROR, TAG_STTC, "fail to get fd from dbus");
+       if (true != dbus_connection_get_unix_fd(g_conn_listener, &fd)) {
+               SLOG(LOG_ERROR, TAG_STTC, "Fail to get fd from dbus");
                return STT_ERROR_OPERATION_FAILED;
        } else {
-               SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Get fd from dbus : %d\n", fd);
+               SLOG(LOG_DEBUG, TAG_STTC, "Get fd from dbus : %d", fd);
        }
 
-       g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn, NULL, NULL);
-
+       g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
        if (NULL == g_fd_handler) {
                SLOG(LOG_ERROR, TAG_STTC, "fail to get fd handler from ecore");
                return STT_ERROR_OPERATION_FAILED;
@@ -403,33 +372,37 @@ int stt_dbus_close_connection()
        DBusError err;
        dbus_error_init(&err);
 
+       if (NULL != g_fd_handler) {
+               ecore_main_fd_handler_del(g_fd_handler);
+               g_fd_handler = NULL;
+       }
+
        int pid = getpid();
 
        char service_name[64];
        memset(service_name, '\0', 64);
-       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
-
-       dbus_bus_release_name (g_conn, service_name, &err);
+       snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
 
+       dbus_bus_release_name (g_conn_listener, service_name, &err);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Release name Error (%s)", err.message);
                dbus_error_free(&err);
        }
 
-       dbus_connection_close(g_conn);
-
-       g_fd_handler = NULL;
-       g_conn = NULL;
+       g_conn_sender = NULL;
+       g_conn_listener = NULL;
 
        return 0;
 }
 
 int stt_dbus_reconnect()
 {
-       bool connected = dbus_connection_get_is_connected(g_conn);
-       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] %s", connected ? "Connected" : "Not connected");
+       bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
+       bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
+       SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] Sender(%s) Listener(%s)",
+               sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
 
-       if (false == connected) {
+       if (false == sender_connected || false == listener_connected) {
                stt_dbus_close_connection();
 
                if(0 != stt_dbus_open_connection()) {
@@ -458,30 +431,19 @@ int stt_dbus_request_hello()
                return STT_ERROR_OPERATION_FAILED;
        } 
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        DBusError err;
        dbus_error_init(&err);
 
        DBusMessage* result_msg = NULL;
-       int result = STT_DAEMON_NORMAL;
+       int result = 0;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_short_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_short_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                dbus_error_free(&err);
        }
 
-       int status = 0;
        if (NULL != result_msg) {
-               dbus_message_get_args(result_msg, &err,
-                               DBUS_TYPE_INT32, &status,
-                               DBUS_TYPE_INVALID);
-
                dbus_message_unref(result_msg);
 
                if (dbus_error_is_set(&err)) {
@@ -489,8 +451,7 @@ int stt_dbus_request_hello()
                        dbus_error_free(&err);
                }
 
-               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt hello - %d", status);
-               result = status;
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt hello");
        } else {
                result = STT_ERROR_TIMED_OUT;
        }
@@ -516,12 +477,6 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt initialize : uid(%d)", uid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        int pid = getpid();
        dbus_message_append_args( msg, 
                DBUS_TYPE_INT32, &pid,
@@ -534,7 +489,7 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported)
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -587,12 +542,6 @@ int stt_dbus_request_finalize(int uid)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt finalize : uid(%d)", uid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
 
        DBusError err;
@@ -601,7 +550,7 @@ int stt_dbus_request_finalize(int uid)
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_short_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_short_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -652,12 +601,6 @@ int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* si
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt set engine : uid(%d)", uid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args( msg, 
                DBUS_TYPE_INT32, &uid,
                DBUS_TYPE_STRING, &engine_id,
@@ -669,7 +612,7 @@ int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* si
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -727,12 +670,6 @@ int stt_dbus_request_check_app_agreed(int uid, const char* appid, bool* value)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt check app agreed : uid(%d) appid(%s)", uid, appid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args(msg,
                DBUS_TYPE_INT32, &uid,
                DBUS_TYPE_STRING, &appid,
@@ -745,7 +682,7 @@ int stt_dbus_request_check_app_agreed(int uid, const char* appid, bool* value)
        int result = STT_ERROR_OPERATION_FAILED;
        int available = -1;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -802,12 +739,6 @@ int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_languag
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get supported languages : uid(%d)", uid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
 
        DBusError err;
@@ -817,7 +748,7 @@ int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_languag
        DBusMessageIter args;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err );
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -893,12 +824,6 @@ int stt_dbus_request_get_default_lang(int uid, char** language)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get default language  : uid(%d)", uid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args( msg, 
                DBUS_TYPE_INT32, &uid,
                DBUS_TYPE_INVALID);
@@ -910,7 +835,7 @@ int stt_dbus_request_get_default_lang(int uid, char** language)
        int result = STT_ERROR_OPERATION_FAILED;
        char* temp_lang = NULL;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -967,12 +892,6 @@ int stt_dbus_request_is_recognition_type_supported(int uid, const char* type, bo
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt is recognition type supported : uid(%d) type(%s)", uid, type);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args( msg, 
                DBUS_TYPE_INT32, &uid,
                DBUS_TYPE_STRING, &type,
@@ -985,7 +904,7 @@ int stt_dbus_request_is_recognition_type_supported(int uid, const char* type, bo
        int result = STT_ERROR_OPERATION_FAILED;
        int result_support = -1;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1042,12 +961,6 @@ int stt_dbus_request_set_start_sound(int uid, const char* file)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt set start sound : uid(%d) file(%s)", uid, file);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args( msg, 
                DBUS_TYPE_INT32, &uid,
                DBUS_TYPE_STRING, &file,
@@ -1059,7 +972,7 @@ int stt_dbus_request_set_start_sound(int uid, const char* file)
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1109,12 +1022,6 @@ int stt_dbus_request_unset_start_sound(int uid)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt unset start sound : uid(%d)", uid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args( msg, 
                DBUS_TYPE_INT32, &uid,
                DBUS_TYPE_INVALID);
@@ -1125,7 +1032,7 @@ int stt_dbus_request_unset_start_sound(int uid)
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1180,12 +1087,6 @@ int stt_dbus_request_set_stop_sound(int uid, const char* file)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt set stop sound : uid(%d) file(%s)", uid, file);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args( msg, 
                DBUS_TYPE_INT32, &uid,
                DBUS_TYPE_STRING, &file,
@@ -1197,7 +1098,7 @@ int stt_dbus_request_set_stop_sound(int uid, const char* file)
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1247,12 +1148,6 @@ int stt_dbus_request_unset_stop_sound(int uid)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt unset stop sound : uid(%d)", uid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args( msg, 
                DBUS_TYPE_INT32, &uid,
                DBUS_TYPE_INVALID);
@@ -1263,7 +1158,7 @@ int stt_dbus_request_unset_stop_sound(int uid)
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1319,12 +1214,6 @@ int stt_dbus_request_start(int uid, const char* lang, const char* type, int sile
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt start : uid(%d), language(%s), type(%s)", uid, lang, type);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args( msg, 
                DBUS_TYPE_INT32, &uid, 
                DBUS_TYPE_STRING, &lang,   
@@ -1339,7 +1228,7 @@ int stt_dbus_request_start(int uid, const char* lang, const char* type, int sile
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1390,12 +1279,6 @@ int stt_dbus_request_stop(int uid)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt stop : uid(%d)", uid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args(msg, 
                DBUS_TYPE_INT32, &uid, 
                DBUS_TYPE_INVALID);
@@ -1406,7 +1289,7 @@ int stt_dbus_request_stop(int uid)
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1457,12 +1340,6 @@ int stt_dbus_request_cancel(int uid)
                SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt cancel : uid(%d)", uid);
        }
 
-       if (NULL == g_conn) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid");
-               dbus_message_unref(msg);
-               return STT_ERROR_INVALID_STATE;
-       }
-
        dbus_message_append_args(msg, 
                DBUS_TYPE_INT32, &uid, 
                DBUS_TYPE_INVALID);
@@ -1473,7 +1350,7 @@ int stt_dbus_request_cancel(int uid)
        DBusMessage* result_msg;
        int result = STT_ERROR_OPERATION_FAILED;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
index 00fccd2..1a9d6b3 100644 (file)
@@ -100,8 +100,8 @@ static int __stt_file_get_engine_info(const char* filepath, sttengine_info_s** i
        handle = dlopen (filepath, RTLD_LAZY);
 
        if (!handle) {
-               SECURE_SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Invalid engine : %s", filepath); 
-               return -1;
+               SECURE_SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Invalid engine : %s", filepath);
+               return STT_FILE_ERROR_ENGINE_NOT_FOUND;
        }
 
        /* link engine to daemon */
@@ -109,14 +109,14 @@ static int __stt_file_get_engine_info(const char* filepath, sttengine_info_s** i
        if ((error = dlerror()) != NULL) {
                SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Invalid engine. Fail to open sttp_load_engine : %s", error); 
                dlclose(handle);
-               return -1;
+               return STT_FILE_ERROR_ENGINE_NOT_FOUND;
        }
 
        dlsym(handle, "sttp_unload_engine");
        if ((error = dlerror()) != NULL) {
                SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Invalid engine. Fail to open sttp_unload_engine : %s", error); 
                dlclose(handle);
-               return -1;
+               return STT_FILE_ERROR_ENGINE_NOT_FOUND;
        }
 
        int (*get_engine_info)(sttpe_engine_info_cb callback, void* user_data);
@@ -130,13 +130,18 @@ static int __stt_file_get_engine_info(const char* filepath, sttengine_info_s** i
 
        sttengine_info_s* temp;
        temp = (sttengine_info_s*)calloc(1, sizeof(sttengine_info_s));
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Fail to allocate memory");
+               dlclose(handle);
+               return STT_FILE_ERROR_OUT_OF_MEMORY;
+       }
 
        /* get engine info */
        if (0 != get_engine_info(__stt_file_engine_info_cb, (void*)temp)) {
                SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Fail to get engine info from engine"); 
                dlclose(handle);
                free(temp);
-               return -1;
+               return STT_FILE_ERROR_ENGINE_NOT_FOUND;
        }
 
        /* close engine */
@@ -160,7 +165,7 @@ static int __stt_file_get_engine_info(const char* filepath, sttengine_info_s** i
 
        *info = temp;
 
-       return 0;
+       return STT_FILE_ERROR_NONE;
 }
 
 static bool __stt_file_is_engine(const char* filepath)
index 8d44b98..8110957 100644 (file)
@@ -24,7 +24,6 @@
 #include "stt_defs.h"
 #include "stt_config_parser.h"
 
-#define VCONFKEY_VOICE_INPUT_LANGUAGE     "db/voice_input/language"
 
 typedef struct {
        int     uid;
@@ -343,39 +342,23 @@ int __stt_config_mgr_unregister_config_event()
 int __stt_config_set_auto_language()
 {
        char* value = NULL;
-       value = vconf_get_str(VCONFKEY_VOICE_INPUT_LANGUAGE);
+       char candidate_lang[6] = {'\0', };
+
+       value = vconf_get_str(VCONFKEY_LANGSET);
        if (NULL == value) {
-               SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Fail to get voice input language");
+               SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Fail to get display language");
                return -1;
        }
 
-       char candidate_lang[6] = {'\0', };
-
-       /* Check auto is on or not */
-       if (0 == strncmp(value, "auto", 4)) {
-               free(value);
-       
-               value = vconf_get_str(VCONFKEY_LANGSET);
-               if (NULL == value) {
-                       SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Fail to get display language");
-                       return -1;
-               }
-
-               strncpy(candidate_lang, value, 5);
-               free(value);
+       strncpy(candidate_lang, value, 5);
+       free(value);
 
-               /* Check current language */
-               if (0 == strncmp(g_config_info->language, candidate_lang, 5)) {
-                       SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Config] Language is auto. STT language(%s) is same with display lang", g_config_info->language);
-                       return 0;
-               } else {
-                       SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Config] Display language : %s", candidate_lang);
-               }
+       /* Check current language */
+       if (0 == strncmp(g_config_info->language, candidate_lang, 5)) {
+               SLOG(LOG_DEBUG, stt_tag(), "[Config] Language is auto. STT language(%s) is same with display lang", g_config_info->language);
+               return 0;
        } else {
-               strncpy(candidate_lang, value, 5);
-               SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Config] Voice input language is NOT auto. Voice input language : %s", candidate_lang);
-
-               free(value);
+               SLOG(LOG_DEBUG, stt_tag(), "[Config] Display language : %s", candidate_lang);
        }
 
        if (true == __stt_config_mgr_check_lang_is_valid(g_config_info->engine_id, candidate_lang)) {
@@ -479,6 +462,182 @@ void __stt_config_language_changed_cb(keynode_t *key, void *data)
        return;
 }
 
+void __stt_config_release_client(int uid)
+{
+       GSList *iter = NULL;
+       stt_config_client_s* temp_client = NULL;
+
+       if (0 < g_slist_length(g_config_client_list)) {
+               /* Check uid */
+               iter = g_slist_nth(g_config_client_list, 0);
+
+               while (NULL != iter) {
+                       temp_client = iter->data;
+
+                       if (NULL != temp_client) {
+                               if (uid == temp_client->uid) {
+                                       g_config_client_list = g_slist_remove(g_config_client_list, temp_client);
+                                       free(temp_client);
+                                       temp_client = NULL;
+                                       break;
+                               }
+                       }
+
+                       iter = g_slist_next(iter);
+               }
+       }
+
+       if (0 < g_slist_length(g_config_client_list)) {
+               SLOG(LOG_DEBUG, stt_tag(), "Client count (%d)", g_slist_length(g_config_client_list));
+       }
+}
+
+void __stt_config_release_engine()
+{
+       GSList *iter = NULL;
+       stt_engine_info_s *engine_info = NULL;
+
+       if (0 < g_slist_length(g_engine_list)) {
+
+               /* Get a first item */
+               iter = g_slist_nth(g_engine_list, 0);
+
+               while (NULL != iter) {
+                       engine_info = iter->data;
+
+                       if (NULL != engine_info) {
+                               g_engine_list = g_slist_remove(g_engine_list, engine_info);
+
+                               stt_parser_free_engine_info(engine_info);
+                       }
+
+                       iter = g_slist_nth(g_engine_list, 0);
+               }
+       }
+}
+
+int __stt_config_mgr_check_engine_is_valid(const char* engine_id)
+{
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, stt_tag(), "Input parameter is NULL");
+               return STT_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       GSList *iter = NULL;
+       stt_engine_info_s *engine_info = NULL;
+
+       if (0 >= g_slist_length(g_engine_list)) {
+               SLOG(LOG_ERROR, stt_tag(), "There is no engine!!");
+               return STT_CONFIG_ERROR_ENGINE_NOT_FOUND;
+       }
+
+       /* Get a first item */
+       iter = g_slist_nth(g_engine_list, 0);
+
+       while (NULL != iter) {
+               engine_info = iter->data;
+
+               if (NULL == engine_info) {
+                       SLOG(LOG_ERROR, stt_tag(), "engine info is NULL");
+                       return STT_CONFIG_ERROR_ENGINE_NOT_FOUND;
+               }
+
+               if (0 == strcmp(engine_id, engine_info->uuid)) {
+                       SLOG(LOG_DEBUG, stt_tag(), "Default engine is valid : %s", engine_id);
+                       return STT_CONFIG_ERROR_NONE;
+               }
+
+               iter = g_slist_next(iter);
+       }
+
+       /* Change default engine */
+       iter = g_slist_nth(g_engine_list, 0);
+       engine_info = iter->data;
+       if (NULL == engine_info) {
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Engine info is NULL");
+               return STT_CONFIG_ERROR_ENGINE_NOT_FOUND;
+       }
+
+       if (NULL != g_config_info->engine_id) {
+               free(g_config_info->engine_id);
+               g_config_info->engine_id = NULL;
+       }
+       if (NULL != g_config_info->setting) {
+               free(g_config_info->setting);
+               g_config_info->setting = NULL;
+       }
+
+       if (NULL != engine_info->uuid) {
+               g_config_info->engine_id = strdup(engine_info->uuid);
+       }
+
+       if (NULL != engine_info->setting) {
+               g_config_info->setting = strdup(engine_info->setting);
+       }
+
+       /* Engine is valid*/
+       GSList *iter_lang = NULL;
+       char* lang;
+       bool is_valid_lang = false;
+
+       if (0 >= g_slist_length(engine_info->languages)) {
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty supported language");
+               return STT_CONFIG_ERROR_ENGINE_NOT_FOUND;
+       }
+
+       /* Get a first item */
+       iter_lang = g_slist_nth(engine_info->languages, 0);
+
+       while (NULL != iter_lang) {
+               /*Get handle data from list*/
+               lang = iter_lang->data;
+
+               SLOG(LOG_DEBUG, stt_tag(), " %s", lang);
+               if (NULL != lang) {
+                       if (0 == strcmp(lang, g_config_info->language)) {
+                               /* language is valid */
+                               is_valid_lang = true;
+                               break;
+                       }
+               }
+
+               /*Get next item*/
+               iter_lang = g_slist_next(iter_lang);
+       }
+
+       if (false == is_valid_lang) {
+               iter_lang = g_slist_nth(engine_info->languages, 0);
+               if (NULL != iter_lang) {
+                       lang = iter_lang->data;
+                       if (NULL != lang) {
+                               if (NULL != g_config_info->language)
+                                       free(g_config_info->language);
+                               g_config_info->language = strdup(lang);
+                       }
+               }
+       }
+
+       /* Check options */
+       if (false == engine_info->support_silence_detection) {
+               if (true == g_config_info->silence_detection)
+                       g_config_info->silence_detection = false;
+       }
+
+       SLOG(LOG_DEBUG, stt_tag(), "[Config] Engine changed");
+       SLOG(LOG_DEBUG, stt_tag(), "  Engine : %s", g_config_info->engine_id);
+       SLOG(LOG_DEBUG, stt_tag(), "  Setting : %s", g_config_info->setting);
+       SLOG(LOG_DEBUG, stt_tag(), "  language : %s", g_config_info->language);
+       SLOG(LOG_DEBUG, stt_tag(), "  Silence detection : %s", g_config_info->silence_detection ? "on" : "off");
+
+       if ( 0 != stt_parser_set_engine(g_config_info->engine_id, g_config_info->setting, g_config_info->language,
+               g_config_info->silence_detection)) {
+                       SLOG(LOG_ERROR, stt_tag(), " Fail to save config");
+                       return STT_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       return STT_CONFIG_ERROR_NONE;
+}
+
 int stt_config_mgr_initialize(int uid)
 {
        GSList *iter = NULL;
@@ -501,6 +660,10 @@ int stt_config_mgr_initialize(int uid)
                }
 
                temp_client = (stt_config_client_s*)calloc(1, sizeof(stt_config_client_s));
+               if (NULL == temp_client) {
+                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+                       return STT_CONFIG_ERROR_OUT_OF_MEMORY;
+               }
                temp_client->uid = uid;
                temp_client->bool_cb = NULL;
                temp_client->engine_cb = NULL;
@@ -567,7 +730,18 @@ int stt_config_mgr_initialize(int uid)
 
        if (0 != stt_parser_load_config(&g_config_info)) {
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse configure information");
-               return -1; 
+               __stt_config_release_client(uid);
+               __stt_config_release_engine();
+               return STT_CONFIG_ERROR_OPERATION_FAILED; 
+       }
+
+       /* Check whether engine id is valid */
+       if (0 != __stt_config_mgr_check_engine_is_valid(g_config_info->engine_id)) {
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to get default engine");
+               __stt_config_release_client(uid);
+               __stt_config_release_engine();
+               stt_parser_unload_config(g_config_info);
+               return STT_CONFIG_ERROR_ENGINE_NOT_FOUND;
        }
 
        if (true == g_config_info->auto_lang) {
@@ -579,7 +753,10 @@ int stt_config_mgr_initialize(int uid)
                        char* tmp_language;
                        if (0 != __stt_config_mgr_select_lang(g_config_info->engine_id, &tmp_language)) {
                                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to select language");
-                               return -1;
+                               __stt_config_release_client(uid);
+                               __stt_config_release_engine();
+                               stt_parser_unload_config(g_config_info);
+                               return STT_CONFIG_ERROR_OPERATION_FAILED;
                        }
 
                        if (NULL != tmp_language) {
@@ -604,14 +781,20 @@ int stt_config_mgr_initialize(int uid)
 
        if (0 != __stt_config_mgr_register_config_event()) {
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to register config event");
+               __stt_config_release_client(uid);
+               __stt_config_release_engine();
+               stt_parser_unload_config(g_config_info);
                return STT_CONFIG_ERROR_OPERATION_FAILED;
        }
 
        /* Register to detect display language change */
        vconf_notify_key_changed(VCONFKEY_LANGSET, __stt_config_language_changed_cb, NULL);
-       vconf_notify_key_changed(VCONFKEY_VOICE_INPUT_LANGUAGE, __stt_config_language_changed_cb, NULL);
 
        temp_client = (stt_config_client_s*)calloc(1, sizeof(stt_config_client_s));
+       if (NULL == temp_client) {
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+               return STT_CONFIG_ERROR_OUT_OF_MEMORY;
+       }
        temp_client->uid = uid;
        temp_client->bool_cb = NULL;
        temp_client->engine_cb = NULL;
@@ -675,7 +858,6 @@ int stt_config_mgr_finalize(int uid)
        }
 
        vconf_ignore_key_changed(VCONFKEY_LANGSET, __stt_config_language_changed_cb);
-       vconf_ignore_key_changed(VCONFKEY_VOICE_INPUT_LANGUAGE, __stt_config_language_changed_cb);
 
        __stt_config_mgr_unregister_config_event();
 
@@ -950,8 +1132,16 @@ int stt_config_mgr_get_engine_agreement(const char* engine, char** agreement)
 
        if (NULL == engine) {
                current_engine = strdup(g_config_info->engine_id);
+               if (NULL == current_engine) {
+                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+                       return STT_CONFIG_ERROR_OUT_OF_MEMORY;;
+               }
        } else {
                current_engine = strdup(engine);
+               if (NULL == current_engine) {
+                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+                       return STT_CONFIG_ERROR_OUT_OF_MEMORY;;
+               }
        }
 
        /* Get a first item */
@@ -1350,7 +1540,10 @@ int stt_config_mgr_add_time_info(int index, int event, const char* text, long st
        }
 
        stt_result_time_info_s *info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s));
-
+       if (NULL == info) {
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+               return STT_CONFIG_ERROR_OUT_OF_MEMORY;
+       }
        info->index = index;
        info->event = event;
        if (NULL != text) {
index 564705d..5446999 100644 (file)
@@ -86,6 +86,11 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
        /* alloc engine info */
        stt_engine_info_s* temp;
        temp = (stt_engine_info_s*)calloc(1, sizeof(stt_engine_info_s));
+       if (NULL == temp) {
+               xmlFreeDoc(doc);
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+               return -1;
+       }
 
        temp->name = NULL;
        temp->uuid = NULL;
@@ -306,6 +311,11 @@ int stt_parser_load_config(stt_config_s** config_info)
        /* alloc engine info */
        stt_config_s* temp;
        temp = (stt_config_s*)calloc(1, sizeof(stt_config_s));
+       if (NULL == temp) {
+               xmlFreeDoc(doc);
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+               return -1;
+       }
 
        temp->engine_id = NULL;
        temp->setting = NULL;
index 4f6fb23..7baa96a 100644 (file)
@@ -23,11 +23,11 @@ extern "C" {
 * Definition for Dbus
 *******************************************************************************************/
 
-#define STT_CLIENT_SERVICE_NAME         "org.tizen.voice.sttclient"
-#define STT_CLIENT_SERVICE_OBJECT_PATH  "/org/tizen/voice/sttclient"
-#define STT_CLIENT_SERVICE_INTERFACE    "org.tizen.voice.sttclient"
+#define STT_CLIENT_SERVICE_NAME         "org.tizen.stt.client"
+#define STT_CLIENT_SERVICE_OBJECT_PATH  "/org/tizen/stt/client"
+#define STT_CLIENT_SERVICE_INTERFACE    "org.tizen.stt.client"
 
-#define STT_SERVER_SERVICE_NAME         "service.connect.sttserver"
+#define STT_SERVER_SERVICE_NAME         "org.tizen.voice.sttserver"
 #define STT_SERVER_SERVICE_OBJECT_PATH  "/org/tizen/voice/sttserver"
 #define STT_SERVER_SERVICE_INTERFACE    "org.tizen.voice.sttserver"
 
@@ -67,8 +67,6 @@ extern "C" {
 
 #define STT_AUDIO_VOLUME_PATH          "/tmp/stt_vol"
 
-#define STT_PID_FILE_PATH              "/opt/home/app/.voice/sttd_info"
-
 #define STT_TIME_INFO_PATH             "/opt/home/app/.voice/stt-time.xml"
 
 #define STT_USR_BASE                   "/usr/lib/voice"
@@ -88,6 +86,8 @@ extern "C" {
 
 #define STT_BASE_LANGUAGE              "en_US"
 
+#define STT_RETRY_COUNT                        5
+
 #define STT_FEATURE_PATH               "tizen.org/feature/speech.recognition"
 #define STT_MIC_FEATURE_PATH           "tizen.org/feature/microphone"
 
index 3ddc644..5605bb5 100644 (file)
@@ -103,6 +103,10 @@ int stt_engine_load(int engine_id, const char* filepath)
 
        /* allocation memory */
        engine = (sttengine_s*)calloc(1, sizeof(sttengine_s));
+       if (NULL == engine) {
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+               return STTP_ERROR_OUT_OF_MEMORY;
+       }
 
        /* load engine */
        char *error;
@@ -115,7 +119,20 @@ int stt_engine_load(int engine_id, const char* filepath)
        }
 
        engine->pefuncs = (sttpe_funcs_s*)calloc(1, sizeof(sttpe_funcs_s));
+       if (NULL == engine->pefuncs) {
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+               dlclose(engine->handle);
+               free(engine);
+               return STTP_ERROR_OUT_OF_MEMORY;
+       }
        engine->pdfuncs = (sttpd_funcs_s*)calloc(1, sizeof(sttpd_funcs_s));
+       if (NULL == engine->pdfuncs) {
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+               dlclose(engine->handle);
+               free(engine->pefuncs);
+               free(engine);
+               return STTP_ERROR_OUT_OF_MEMORY;
+       }
 
        engine->sttp_unload_engine = NULL;
        engine->sttp_load_engine = NULL;
diff --git a/org.tizen.voice.sttserver.service b/org.tizen.voice.sttserver.service
new file mode 100644 (file)
index 0000000..12b72be
--- /dev/null
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=org.tizen.voice.sttserver
+Exec=/usr/bin/stt-daemon
+User=root
+Group=root
index 0ed62c7..153b304 100644 (file)
@@ -1,8 +1,8 @@
 Name:       stt
 Summary:    Speech To Text client library and daemon
-Version:    0.2.53
+Version:    0.2.54
 Release:    1
-Group:      Graphics & UI Framework/Libraries
+Group:      Graphics & UI Framework/Voice Framework
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1001: %{name}.manifest
@@ -104,8 +104,6 @@ chown 5000:5000 /opt/usr/data/voice/stt/1.0
 
 %postun -p /sbin/ldconfig
 
-/usr/bin/vconftool set -t string db/voice_input/language "auto" -g 5000 -f -s system::vconf_inhouse
-
 %files
 %manifest %{name}.manifest
 %license LICENSE.APLv2
@@ -115,6 +113,8 @@ chown 5000:5000 /opt/usr/data/voice/stt/1.0
 %{_libdir}/libstt_setting.so
 /usr/lib/voice/stt/1.0/stt-config.xml
 %{_bindir}/stt-daemon
+/etc/dbus-1/system.d/stt-server.conf
+/usr/share/dbus-1/system-services/org.tizen.voice.sttserver.service
 /opt/usr/devel/bin/stt-test
 /usr/share/license/%{name}
 
index d02c68a..4b3daa0 100644 (file)
@@ -85,6 +85,10 @@ int sttd_client_add(int pid, int uid)
        }
 
        client_info_s *info = (client_info_s*)calloc(1, sizeof(client_info_s));
+       if (NULL == info) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to allocate memory");
+               return STTD_ERROR_OUT_OF_MEMORY;
+       }
 
        info->pid = pid;
        info->uid = uid;
@@ -388,7 +392,11 @@ int sttd_client_get_list(int** uids, int* uid_count)
 
        int *tmp;
        tmp = (int*)calloc(count, sizeof(int));
-       
+       if (NULL == tmp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to allocate memory");
+               return STTD_ERROR_OUT_OF_MEMORY;
+       }
+
        GSList *iter = NULL;
        client_info_s *data = NULL;
        int i = 0;
index e23a0d8..d16d79e 100644 (file)
 #include "sttd_dbus_server.h"
 #include "stt_defs.h"
 
-static DBusConnection* g_conn;
+static DBusConnection* g_conn_sender = NULL;
+static DBusConnection* g_conn_listener = NULL;
+
+static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
+
 static int g_waiting_time = 3000;
 
+
 int sttdc_send_hello(int uid)
 {
        int pid = sttd_client_get_pid(uid);
-
        if (0 > pid) {
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
-               return -1;
+               return STTD_ERROR_INVALID_PARAMETER;
        }
 
        char service_name[64];
        memset(service_name, 0, 64);
-       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+       snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
 
        char target_if_name[128];
-       snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+       snprintf(target_if_name, sizeof(target_if_name), "%s", STT_CLIENT_SERVICE_INTERFACE);
 
-       DBusMessage* msg;
+       DBusMessage* msg = NULL;
 
        SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send hello message : uid(%d)", uid);
 
@@ -50,20 +54,19 @@ int sttdc_send_hello(int uid)
                target_if_name, 
                STTD_METHOD_HELLO);
 
-       if (NULL == msg) { 
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
-               return -1;
+       if (NULL == msg) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+               return STTD_ERROR_OUT_OF_MEMORY;
        }
 
        dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
 
        DBusError err;
        dbus_error_init(&err);
-
-       DBusMessage* result_msg;
        int result = -1;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       DBusMessage* result_msg = NULL;
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Send error (%s)", err.message);
@@ -82,12 +85,62 @@ int sttdc_send_hello(int uid)
                dbus_message_unref(result_msg);
        } else {
                SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Result message is NULL. Client is not available");
-               result = 0;
        }
 
        return result;
 }
 
+int sttdc_send_set_state(int uid, int state)
+{
+       int pid = sttd_client_get_pid(uid);
+
+       if (0 > pid) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
+               return -1;
+       }
+
+       char service_name[64];
+       memset(service_name, 0, 64);
+       snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
+
+       char target_if_name[128];
+       snprintf(target_if_name, sizeof(target_if_name), "%s", STT_CLIENT_SERVICE_INTERFACE);
+
+       DBusMessage* msg;
+
+       SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send change state message : uid(%d), state(%d)", uid, state);
+
+       msg = dbus_message_new_method_call(
+               service_name,
+               STT_CLIENT_SERVICE_OBJECT_PATH,
+               target_if_name,
+               STTD_METHOD_SET_STATE);
+
+       if (NULL == msg) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+               return -1;
+       }
+
+       dbus_message_append_args(msg,
+               DBUS_TYPE_INT32, &uid,
+               DBUS_TYPE_INT32, &state,
+               DBUS_TYPE_INVALID);
+
+       dbus_message_set_no_reply(msg, TRUE);
+
+       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !");
+       }
+       else {
+               SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send error message : uid(%d), state(%d)", uid, state);
+               dbus_connection_flush(g_conn_sender);
+       }
+
+       dbus_connection_flush(g_conn_sender);
+       dbus_message_unref(msg);
+
+       return 0;
+}
 int sttdc_send_get_state(int uid, int* state)
 {
        int pid = sttd_client_get_pid(uid);
@@ -99,10 +152,10 @@ int sttdc_send_get_state(int uid, int* state)
 
        char service_name[64];
        memset(service_name, 0, 64);
-       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+       snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
 
        char target_if_name[128];
-       snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+       snprintf(target_if_name, sizeof(target_if_name), "%s", STT_CLIENT_SERVICE_INTERFACE);
 
        DBusMessage* msg;
 
@@ -128,7 +181,7 @@ int sttdc_send_get_state(int uid, int* state)
        int tmp = -1;
        int result = 0;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Send error (%s)", err.message);
@@ -159,22 +212,21 @@ int sttdc_send_get_state(int uid, int* state)
 int sttdc_send_result(int uid, int event, const char** data, int data_count, const char* result_msg)
 {
        int pid = sttd_client_get_pid(uid);
-
        if (0 > pid) {
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid" );
-               return -1;
+               return STTD_ERROR_INVALID_PARAMETER;
        }
 
        char service_name[64];
        memset(service_name, 0, 64);
-       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+       snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
 
        char target_if_name[128];
-       snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+       memset(target_if_name, 0, 128);
+       snprintf(target_if_name, sizeof(target_if_name), "%s", STT_CLIENT_SERVICE_INTERFACE);
 
-       DBusMessage* msg;
-
-       SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] send result signal : uid(%d), event(%d), result count(%d)", uid, event, data_count);
+       DBusMessage* msg = NULL;
+       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] send result signal : uid(%d), event(%d), result count(%d)", uid, event, data_count);
 
        msg = dbus_message_new_method_call(
                service_name, 
@@ -182,9 +234,9 @@ int sttdc_send_result(int uid, int event, const char** data, int data_count, con
                target_if_name, 
                STTD_METHOD_RESULT);
 
-       if (NULL == msg) { 
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
-               return -1;
+       if (NULL == msg) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+               return STTD_ERROR_OUT_OF_MEMORY;
        }
 
        DBusMessageIter args;
@@ -221,7 +273,8 @@ int sttdc_send_result(int uid, int event, const char** data, int data_count, con
 
                        if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &data[i])) {
                                SLOG(LOG_ERROR, TAG_STTD, "[Dbus] response message : Fail to append result data");
-                               return -1;
+                               dbus_message_unref(msg);
+                               return STTD_ERROR_OPERATION_FAILED;
                        }
                } else {
                        int reason = (int)STTD_ERROR_OPERATION_FAILED;
@@ -233,17 +286,19 @@ int sttdc_send_result(int uid, int event, const char** data, int data_count, con
                                sttd_client_delete(uid);
                        }
 
-                       SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Result from engine is NULL(%d)", i); 
-                       return -1;
+                       dbus_message_unref(msg);
+                       SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Result from engine is NULL(%d)", i);
+                       return STTD_ERROR_OPERATION_FAILED;
                }
        }
-       
-       if (!dbus_connection_send(g_conn, msg, NULL)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !"); 
-               return -1;
+
+       dbus_message_set_no_reply(msg, TRUE);
+
+       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !");
        }
 
-       dbus_connection_flush(g_conn);
+       dbus_connection_flush(g_conn_sender);
        dbus_message_unref(msg);
 
        return 0;
@@ -257,31 +312,28 @@ int sttdc_send_error_signal(int uid, int reason, const char *err_msg)
        }
 
        int pid = sttd_client_get_pid(uid);
-
        if (0 > pid) {
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid" );
-               return -1;
+               return STTD_ERROR_INVALID_PARAMETER;
        }
 
        char service_name[64];
        memset(service_name, 0, 64);
-       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+       snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
 
        char target_if_name[128];
-       snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
-
-       DBusMessage* msg;
-       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] send error signal : reason(%d), Error Msg(%s)", reason, err_msg);
+       snprintf(target_if_name, sizeof(target_if_name), "%s", STT_CLIENT_SERVICE_INTERFACE);
 
+       DBusMessage* msg = NULL;
        msg = dbus_message_new_method_call(
                service_name, 
                STT_CLIENT_SERVICE_OBJECT_PATH, 
                target_if_name, 
                STTD_METHOD_ERROR);
 
-       if (NULL == msg) { 
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
-               return -1;
+       if (NULL == msg) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+               return STTD_ERROR_OUT_OF_MEMORY;
        }
 
        dbus_message_append_args(msg, 
@@ -289,70 +341,14 @@ int sttdc_send_error_signal(int uid, int reason, const char *err_msg)
                DBUS_TYPE_INT32, &reason, 
                DBUS_TYPE_STRING, &err_msg,
                DBUS_TYPE_INVALID);
-       
-       DBusError err;
-       dbus_error_init(&err);
-
-       DBusMessage* result_msg;
-
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
-       dbus_message_unref(msg);
-       if (dbus_error_is_set(&err)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Send error (%s)", err.message);
-               dbus_error_free(&err);
-       }
 
-       if (NULL != result_msg) {
-               dbus_message_unref(result_msg);
+       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] <<<< error message : Out Of Memory !");
        } else {
-               SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Result message is NULL.");
-       }
-
-       return 0;
-}
-
-int sttdc_send_set_state(int uid, int state)
-{
-       int pid = sttd_client_get_pid(uid);
-
-       if (0 > pid) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
-               return -1;
-       }
-
-       char service_name[64];
-       memset(service_name, 0, 64);
-       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
-
-       char target_if_name[128];
-       snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
-
-       DBusMessage* msg;
-
-       SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send change state message : uid(%d), state(%d)", uid, state);
-
-       msg = dbus_message_new_method_call(
-               service_name, 
-               STT_CLIENT_SERVICE_OBJECT_PATH, 
-               target_if_name, 
-               STTD_METHOD_SET_STATE);
-
-       if (NULL == msg) { 
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
-               return -1;
+               SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send error message : uid(%d), reason(%d), err_msg(%s)", uid, reason, err_msg);
+               dbus_connection_flush(g_conn_sender);
        }
 
-       dbus_message_append_args(msg, 
-               DBUS_TYPE_INT32, &uid, 
-               DBUS_TYPE_INT32, &state, 
-               DBUS_TYPE_INVALID);
-
-       if (!dbus_connection_send(g_conn, msg, NULL)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !"); 
-               return -1;
-       }
-
-       dbus_connection_flush(g_conn);
        dbus_message_unref(msg);
 
        return 0;
@@ -360,18 +356,15 @@ int sttdc_send_set_state(int uid, int state)
 
 static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
 {
-       DBusConnection* conn = (DBusConnection*)data;
-       DBusMessage* msg = NULL;
+       if (NULL == g_conn_listener)    return ECORE_CALLBACK_RENEW;
 
-       if (NULL == conn)
-               return ECORE_CALLBACK_RENEW;
+       dbus_connection_read_write_dispatch(g_conn_listener, 50);
 
-       dbus_connection_read_write_dispatch(conn, 50);
-       
-       msg = dbus_connection_pop_message(conn);
+       DBusMessage* msg = NULL;
+       msg = dbus_connection_pop_message(g_conn_listener);
 
-       if (true != dbus_connection_get_is_connected(conn)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Conn is disconnected");
+       if (true != dbus_connection_get_is_connected(g_conn_listener)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Connection is disconnected");
                return ECORE_CALLBACK_RENEW;
        }
 
@@ -382,51 +375,51 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
 
        /* client event */
        if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_HELLO))
-               sttd_dbus_server_hello(conn, msg);
+               sttd_dbus_server_hello(g_conn_listener, msg);
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_INITIALIZE))
-               sttd_dbus_server_initialize(conn, msg);
-       
+               sttd_dbus_server_initialize(g_conn_listener, msg);
+
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_FINALIZE))
-               sttd_dbus_server_finalize(conn, msg);
+               sttd_dbus_server_finalize(g_conn_listener, msg);
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_SET_CURRENT_ENGINE))
-               sttd_dbus_server_set_current_engine(conn, msg);
+               sttd_dbus_server_set_current_engine(g_conn_listener, msg);
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_CHECK_APP_AGREED))
-               sttd_dbus_server_check_app_agreed(conn, msg);
+               sttd_dbus_server_check_app_agreed(g_conn_listener, msg);
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_GET_SUPPORT_LANGS))
-               sttd_dbus_server_get_support_lang(conn, msg);
+               sttd_dbus_server_get_support_lang(g_conn_listener, msg);
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_GET_CURRENT_LANG))
-               sttd_dbus_server_get_default_lang(conn, msg);
+               sttd_dbus_server_get_default_lang(g_conn_listener, msg);
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_IS_TYPE_SUPPORTED))
-               sttd_dbus_server_is_recognition_type_supported(conn, msg);
+               sttd_dbus_server_is_recognition_type_supported(g_conn_listener, msg);
 
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_SET_START_SOUND))
-               sttd_dbus_server_set_start_sound(conn, msg);
+               sttd_dbus_server_set_start_sound(g_conn_listener, msg);
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_UNSET_START_SOUND))
-               sttd_dbus_server_unset_start_sound(conn, msg);
+               sttd_dbus_server_unset_start_sound(g_conn_listener, msg);
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_SET_STOP_SOUND))
-               sttd_dbus_server_set_stop_sound(conn, msg);
+               sttd_dbus_server_set_stop_sound(g_conn_listener, msg);
 
        else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_UNSET_STOP_SOUND))
-               sttd_dbus_server_unset_stop_sound(conn, msg);
+               sttd_dbus_server_unset_stop_sound(g_conn_listener, msg);
 
 
-       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_START)) 
-               sttd_dbus_server_start(conn, msg);
-       
-       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_STOP)) 
-               sttd_dbus_server_stop(conn, msg);
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_START))
+               sttd_dbus_server_start(g_conn_listener, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_STOP))
+               sttd_dbus_server_stop(g_conn_listener, msg);
 
-       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_CANCEL)) 
-               sttd_dbus_server_cancel(conn, msg);
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_CANCEL))
+               sttd_dbus_server_cancel(g_conn_listener, msg);
 
 
        /* free the message */
@@ -442,31 +435,43 @@ int sttd_dbus_open_connection()
 
        int ret;
 
+       /* Create connection for sender */
+       g_conn_sender = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+       if (dbus_error_is_set(&err)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
+               dbus_error_free(&err);
+       }
+
+       if (NULL == g_conn_sender) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get dbus connection sender");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
        /* connect to the bus and check for errors */
-       g_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+       g_conn_listener = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
 
        if (dbus_error_is_set(&err)) { 
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
                dbus_error_free(&err); 
        }
 
-       if (NULL == g_conn) { 
+       if (NULL == g_conn_listener) { 
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get dbus connection" );
-               return -1;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        /* request our name on the bus and check for errors */
-       ret = dbus_bus_request_name(g_conn, STT_SERVER_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
+       ret = dbus_bus_request_name(g_conn_listener, STT_SERVER_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");
-               return -1;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (dbus_error_is_set(&err)) { 
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_request_name() : %s", err.message);
-               dbus_error_free(&err); 
-               return -1;
+               dbus_error_free(&err);
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        /* add a rule for getting signal */
@@ -474,28 +479,21 @@ int sttd_dbus_open_connection()
        snprintf(rule, 128, "type='signal',interface='%s'", STT_SERVER_SERVICE_INTERFACE);
 
        /* add a rule for which messages we want to see */
-       dbus_bus_add_match(g_conn, rule, &err); /* see signals from the given interface */
-       dbus_connection_flush(g_conn);
+       dbus_bus_add_match(g_conn_listener, rule, &err); /* see signals from the given interface */
+       dbus_connection_flush(g_conn_listener);
 
        if (dbus_error_is_set(&err)) { 
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_add_match() : %s", err.message);
-               return -1; 
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        int fd = 0;
-       dbus_connection_get_unix_fd(g_conn, &fd);
+       dbus_connection_get_unix_fd(g_conn_listener, &fd);
 
-       if (!ecore_init()) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] ecore_init()");
-               return -1;
-       }
-
-       Ecore_Fd_Handler* fd_handler;
-       fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ , (Ecore_Fd_Cb)listener_event_callback, g_conn, NULL, NULL);
-
-       if (NULL == fd_handler) {
+       g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
+       if (NULL == g_dbus_fd_handler) {
                SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get fd handler");
-               return -1;
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        return 0;
@@ -506,13 +504,20 @@ int sttd_dbus_close_connection()
        DBusError err;
        dbus_error_init(&err);
 
-       dbus_bus_release_name (g_conn, STT_SERVER_SERVICE_NAME, &err);
+       if (NULL != g_dbus_fd_handler) {
+               ecore_main_fd_handler_del(g_dbus_fd_handler);
+               g_dbus_fd_handler = NULL;
+       }
+
+       dbus_bus_release_name(g_conn_listener, STT_SERVER_SERVICE_NAME, &err);
 
        if (dbus_error_is_set(&err)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_release_name() : %s", err.message); 
-               dbus_error_free(&err); 
-               return -1;
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_release_name() : %s", err.message);
+               dbus_error_free(&err);
        }
 
+       g_conn_listener = NULL;
+       g_conn_sender = NULL;
+
        return 0;
 }
index 6e1d11f..bb6b3fa 100644 (file)
@@ -28,12 +28,12 @@ int sttdc_send_hello(int uid);
 
 int sttdc_send_get_state(int uid, int* state);
 
+int sttdc_send_set_state(int uid, int state);
+
 int sttdc_send_result(int uid, int event, const char** data, int data_count, const char* result_msg);
 
 int sttdc_send_error_signal(int uid, int reason, const char *err_msg);
 
-int sttdc_send_set_state(int uid, int state);
-
 
 #ifdef __cplusplus
 }
index bcd6c82..1d3164d 100644 (file)
@@ -29,17 +29,7 @@ int sttd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg)
 
        DBusMessage* reply;
        reply = dbus_message_new_method_return(msg);
-
-       int status = -1;
-       if (EINA_TRUE == sttd_get_daemon_exist()) {
-               status = STTD_DAEMON_NORMAL;
-       } else {
-               status = STTD_DAEMON_ON_TERMINATING;
-       }
-
        if (NULL != reply) {
-               dbus_message_append_args(reply, DBUS_TYPE_INT32, &status, DBUS_TYPE_INVALID);
-
                if (!dbus_connection_send(conn, reply, NULL)) {
                        SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
                }
index ad96c5e..c4ac20b 100644 (file)
@@ -245,8 +245,8 @@ int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
        handle = dlopen (filepath, RTLD_LAZY);
 
        if (!handle) {
-               SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine : %s", filepath); 
-               return -1;
+               SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine : %s", filepath);
+               return STTD_ERROR_ENGINE_NOT_FOUND;
        }
 
        /* link engine to daemon */
@@ -254,14 +254,14 @@ int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
        if ((error = dlerror()) != NULL) {
                SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine. Fail to open sttp_load_engine : %s", error); 
                dlclose(handle);
-               return -1;
+               return STTD_ERROR_ENGINE_NOT_FOUND;
        }
 
        dlsym(handle, "sttp_unload_engine");
        if ((error = dlerror()) != NULL) {
                SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine. Fail to open sttp_unload_engine : %s", error); 
                dlclose(handle);
-               return -1;
+               return STTD_ERROR_ENGINE_NOT_FOUND;
        }
 
        int (*get_engine_info)(sttpe_engine_info_cb callback, void* user_data);
@@ -270,18 +270,23 @@ int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
        if ((error = dlerror()) != NULL || NULL == get_engine_info) {
                SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Invalid engine. Fail to open sttp_get_engine_info : %s", error); 
                dlclose(handle);
-               return -1;
+               return STTD_ERROR_ENGINE_NOT_FOUND;
        }
 
        sttengine_info_s* temp;
        temp = (sttengine_info_s*)calloc(1, sizeof(sttengine_info_s));
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to allocate memory");
+               dlclose(handle);
+               return STTD_ERROR_OUT_OF_MEMORY;
+       }
 
        /* get engine info */
        if (0 != get_engine_info(__engine_info_cb, (void*)temp)) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine info from engine"); 
                dlclose(handle);
                free(temp);
-               return -1;
+               return STTD_ERROR_ENGINE_NOT_FOUND;
        }
 
        /* close engine */
@@ -305,7 +310,7 @@ int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
 
        *info = temp;
 
-       return 0;
+       return STTD_ERROR_NONE;
 }
 
 bool __is_engine(const char* filepath)
@@ -635,7 +640,11 @@ int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
        
        if (NULL == client) {
                client = (sttengine_client_s*)calloc(1, sizeof(sttengine_client_s));
-               
+               if (NULL == client) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to allocate memory");
+                       return STTD_ERROR_OUT_OF_MEMORY;
+               }
+
                /* initialize */
                client->uid = uid;
                client->engine_id = -1;
@@ -807,6 +816,10 @@ int sttd_engine_agent_get_engine_list(GSList** engine_list)
                engine_s* temp_engine;
 
                temp_engine = (engine_s*)calloc(1, sizeof(engine_s));
+               if (NULL == temp_engine) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to allocate memory");
+                       return STTD_ERROR_OUT_OF_MEMORY;
+               }
 
                data = iter->data;
 
index 0a5baf1..a1ac2f0 100644 (file)
 
 static Ecore_Timer* g_check_client_timer = NULL;
 
-static int __save_stt_daemon_info()
-{
-       FILE* fp;
-       int pid = getpid();
-       fp = fopen(STT_PID_FILE_PATH, "w");
-       if (NULL == fp) {
-               SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to make pid file");
-               return -1;
-       }
-       fprintf(fp, "%d", pid);
-       fclose(fp);
-       return 0;
-}
-
-static int __delete_stt_daemon_info()
-{
-       if (0 == access(STT_PID_FILE_PATH, R_OK)) {
-               if (0 != remove(STT_PID_FILE_PATH)) {
-                       SLOG(LOG_WARN, TAG_STTD, "[WARN] Fail to remove pid file");
-                       return -1;
-               }
-       }
-       return 0;
-}
-
 int main(int argc, char** argv)
 {
        SLOG(LOG_DEBUG, TAG_STTD, "  ");
@@ -70,8 +45,6 @@ int main(int argc, char** argv)
                return EXIT_FAILURE;
        }
 
-       __save_stt_daemon_info();
-
        stt_network_initialize();
 
        g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, sttd_cleanup_client, NULL);
@@ -93,10 +66,6 @@ int main(int argc, char** argv)
                ecore_timer_del(g_check_client_timer);
        }
 
-       sttd_dbus_close_connection();
-
-       __delete_stt_daemon_info();
-
        stt_network_finalize();
 
        sttd_finalize();
index 5747b48..96704c6 100644 (file)
@@ -66,12 +66,6 @@ typedef struct {
        char* ug_name;
 }engine_s;
 
-typedef enum {
-       STTD_DAEMON_NORMAL              = 0,
-       STTD_DAEMON_ON_TERMINATING      = -1
-} sttd_daemon_status_e;
-
-
 #ifdef __cplusplus
 }
 #endif
index 6db1ed0..b300c3a 100644 (file)
@@ -226,6 +226,11 @@ int sttd_recorder_create(int engine_id, sttp_audio_type_e type, int channel, uns
 
        stt_recorder_s* recorder;
        recorder = (stt_recorder_s*)calloc(1, sizeof(stt_recorder_s));
+       if (NULL == recorder) {
+               audio_in_destroy(temp_in_h);
+               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to allocate memory");
+               return STTD_ERROR_OUT_OF_MEMORY;
+       }
 
        recorder->engine_id = engine_id;
        recorder->audio_h = temp_in_h;
@@ -272,8 +277,8 @@ int sttd_recorder_destroy(int engine_id)
 
 static float get_volume_decibel(char* data, int size, sttp_audio_type_e type)
 {
-       #define MAX_AMPLITUDE_MEAN_16 23170.115738161934
-       #define MAX_AMPLITUDE_MEAN_08    89.803909382810
+       #define MAX_AMPLITUDE_MEAN_16   32768
+       #define MAX_AMPLITUDE_MEAN_08   128
 
        int i, depthByte;
        int count = 0;
index 5416556..54eee3f 100644 (file)
@@ -34,19 +34,12 @@ static double g_recording_timeout = 60;
 Ecore_Timer*   g_recording_timer = NULL;
 Ecore_Timer*   g_processing_timer = NULL;
 
-static Eina_Bool g_stt_daemon_exist = EINA_TRUE;
-
 static int g_recording_log_count = 0;
 
 /*
 * STT Server Callback Functions
 */
 
-Eina_Bool sttd_get_daemon_exist()
-{
-       return g_stt_daemon_exist;
-}
-
 Eina_Bool __stop_by_silence(void *data)
 {
        SLOG(LOG_DEBUG, TAG_STTD, "===== Stop by silence detection");
@@ -590,7 +583,7 @@ int sttd_server_finalize(int uid)
 
        /* unload engine, if ref count of client is 0 */
        if (0 == sttd_client_get_ref_count()) {
-               g_stt_daemon_exist = EINA_FALSE;
+               sttd_dbus_close_connection();
                ecore_timer_add(0, __quit_ecore_loop, NULL);
        }
        
diff --git a/stt-server.conf b/stt-server.conf
new file mode 100644 (file)
index 0000000..8bb0c3f
--- /dev/null
@@ -0,0 +1,58 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+
+<!-- root can own the service -->
+  <policy user="default">
+    <allow own_prefix="org.tizen.stt.client"/>
+    <allow send_destination="org.tizen.stt.client"/>
+    <allow receive_sender="org.tizen.stt.client"/>
+  </policy>
+
+  <policy user="root">
+    <allow own_prefix="org.tizen.stt.client"/>
+    <allow send_destination="org.tizen.stt.client"/>
+    <allow receive_sender="org.tizen.stt.client"/>
+  </policy>
+
+  <policy context="default">
+    <allow own_prefix="org.tizen.stt.client"/>
+    <allow send_destination="org.tizen.stt.client"/>
+    <allow receive_sender="org.tizen.stt.client"/>
+  </policy>
+
+  <policy user="default">
+    <allow own="org.tizen.voice.sttserver"/>
+    <allow send_destination="org.tizen.voice.sttserver"/>
+    <allow receive_sender="org.tizen.voice.sttserver"/>
+  </policy>
+
+  <policy user="root">
+    <allow own="org.tizen.voice.sttserver"/>
+    <allow send_destination="org.tizen.voice.sttserver"/>
+    <allow receive_sender="org.tizen.voice.sttserver"/>
+  </policy>
+  
+  <policy user="system">
+    <allow own="org.tizen.voice.sttserver"/>
+    <allow send_destination="org.tizen.voice.sttserver"/>
+    <allow receive_sender="org.tizen.voice.sttserver"/>
+  </policy>
+  
+  
+  <!--
+  <policy context="default">
+    <check send_destination="org.tizen.voice.sttserver"
+    send_interface="org.tizen.voice.sttserver"
+    privilege="(n/a)" />
+  </policy>
+  -->
+  
+  <!--
+  <policy context="default">
+    <check send_destination="org.tizen.voice.sttserver"
+    send_interface="org.tizen.voice.sttserver"
+    privilege="http://tizen.org/privilege/recorder" />
+  </policy>
+  -->
+</busconfig>