tizen beta release
authorKibum Kim <kb0929.kim@samsung.com>
Mon, 27 Feb 2012 12:16:43 +0000 (21:16 +0900)
committerKibum Kim <kb0929.kim@samsung.com>
Mon, 27 Feb 2012 12:16:43 +0000 (21:16 +0900)
48 files changed:
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0644]
COPYING [new file with mode: 0644]
client/CMakeLists.txt [new file with mode: 0644]
client/stt-setting.pc.in [new file with mode: 0644]
client/stt.c [new file with mode: 0644]
client/stt.h [new file with mode: 0644]
client/stt.pc.in [new file with mode: 0644]
client/stt_client.c [new file with mode: 0644]
client/stt_client.h [new file with mode: 0644]
client/stt_dbus.c [new file with mode: 0644]
client/stt_dbus.h [new file with mode: 0644]
client/stt_main.h [new file with mode: 0644]
client/stt_setting.c [new file with mode: 0644]
client/stt_setting.h [new file with mode: 0644]
client/stt_setting_dbus.c [new file with mode: 0644]
client/stt_setting_dbus.h [new file with mode: 0644]
common/stt_defs.h [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/copyright [new file with mode: 0644]
debian/dirs [new file with mode: 0644]
debian/docs [new file with mode: 0644]
debian/libstt-dev.install.in [new file with mode: 0644]
debian/libstt.install.in [new file with mode: 0644]
debian/rules [new file with mode: 0755]
packaging/stt.spec [new file with mode: 0644]
server/CMakeLists.txt [new file with mode: 0644]
server/sttd_client_data.c [new file with mode: 0644]
server/sttd_client_data.h [new file with mode: 0644]
server/sttd_config.c [new file with mode: 0644]
server/sttd_config.h [new file with mode: 0644]
server/sttd_dbus.c [new file with mode: 0644]
server/sttd_dbus.h [new file with mode: 0644]
server/sttd_dbus_server.c [new file with mode: 0644]
server/sttd_dbus_server.h [new file with mode: 0644]
server/sttd_engine_agent.c [new file with mode: 0644]
server/sttd_engine_agent.h [new file with mode: 0644]
server/sttd_main.c [new file with mode: 0644]
server/sttd_main.h [new file with mode: 0644]
server/sttd_network.c [new file with mode: 0644]
server/sttd_network.h [new file with mode: 0644]
server/sttd_recorder.c [new file with mode: 0644]
server/sttd_recorder.h [new file with mode: 0644]
server/sttd_server.c [new file with mode: 0644]
server/sttd_server.h [new file with mode: 0644]
server/sttp.h [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..cd12545
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Dongyeol Lee <dy3.lee@samsung.com> 
+Sehwan Park <sehwan@samsung.com>
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..daa263b
--- /dev/null
@@ -0,0 +1,18 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(libstt)
+
+## Include common directory ##
+INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/common")
+
+## Dependent packages ##
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED 
+       glib-2.0 dbus-1 
+       vconf dlog mm-player mm-common mm-camcorder openssl ecore
+)
+
+## Client library ##
+ADD_SUBDIRECTORY(client)
+
+## Server daemon ##
+ADD_SUBDIRECTORY(server)
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..1c166a2
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,10 @@
+Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+       http://www.apache.org/licenses/LICENSE-2.0
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f460be5
--- /dev/null
@@ -0,0 +1,68 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(stt C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "${PREFIX}")
+SET(LIBDIR "${PREFIX}/lib")
+SET(INCLUDEDIR "${PREFIX}/include")
+SET(VERSION 0.0.1)
+
+SET(SRCS 
+       stt.c
+       stt_client.c
+       stt_dbus.c
+)
+
+set(SETTING_SRCS
+       stt_setting.c
+       stt_setting_dbus.c      
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${INCLUDEDIR})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common)
+
+## Dependent packages ##
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED 
+       glib-2.0 dbus-1 dlog ecore
+)
+
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF ("${ARCH}" STREQUAL "arm")
+       ADD_DEFINITIONS("-DTARGET_ARM")
+       MESSAGE("[TARGET] Compile")
+ELSE  ("${ARCH}" STREQUAL "arm")
+       ADD_DEFINITIONS("-DTARGET_I386")
+       MESSAGE("[i386] Compile")
+ENDIF ("${ARCH}" STREQUAL "arm")
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+## Add definitions ##
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+#ADD_DEFINITIONS(-DSLP_DEBUG)
+
+## stt library ##
+ADD_LIBRARY("${PROJECT_NAME}_static" STATIC ${SRCS})
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS})
+
+## stt-setting library ##
+ADD_LIBRARY("${PROJECT_NAME}_setting" SHARED ${SETTING_SRCS})
+TARGET_LINK_LIBRARIES("${PROJECT_NAME}_setting" ${pkgs_LDFLAGS})
+
+## configure pkgconfig files ##
+CONFIGURE_FILE(stt.pc.in "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc" @ONLY)
+CONFIGURE_FILE(stt-setting.pc.in "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-setting.pc" @ONLY)
+
+## Install library files ##
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries)
+INSTALL(TARGETS "${PROJECT_NAME}_setting" DESTINATION lib COMPONENT RuntimeLibraries)
+INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc" "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-setting.pc" DESTINATION lib/pkgconfig)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/stt.h ${CMAKE_CURRENT_SOURCE_DIR}/stt_setting.h DESTINATION include)
diff --git a/client/stt-setting.pc.in b/client/stt-setting.pc.in
new file mode 100644 (file)
index 0000000..90658bc
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: lib@PROJECT_NAME@_setting
+Description: Speech To Text client Setting library
+Requires: glib-2.0 dbus-1 
+Version: @VERSION@
+Libs: -L${libdir} -l@PROJECT_NAME@_setting
+Cflags: -I${includedir}
diff --git a/client/stt.c b/client/stt.c
new file mode 100644 (file)
index 0000000..536c811
--- /dev/null
@@ -0,0 +1,928 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include <sys/wait.h>
+#include <sys/types.h> 
+#include <unistd.h>
+
+#include "stt.h"
+#include "stt_main.h"
+#include "stt_client.h"
+#include "stt_dbus.h"
+
+#define CONNECTION_RETRY_COUNT 3
+
+int __check_stt_daemon();
+
+int stt_create(stt_h* stt)
+{
+       int ret = 0; 
+
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Create STT");
+
+       if (NULL == stt) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is null");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       /* check stt-daemon. */
+       __check_stt_daemon();   
+
+       if (0 == stt_client_get_size()) {
+               if (0 != stt_dbus_open_connection()) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open connection\n ");
+                       return STT_ERROR_OPERATION_FAILED;
+               }
+       }
+
+       if (0 != stt_client_new(stt)) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client!!!!!");
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
+
+       /* request initialization */
+       int i = 0;
+       while (1) {
+               ret = stt_dbus_request_initialize((*stt)->handle);
+               
+               if (STT_ERROR_ENGINE_NOT_FOUND == ret) {
+                       stt_client_destroy(*stt);
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : STT Engine Not founded");
+                       return ret;
+               } else if(0 != ret) {
+                       sleep(1);
+                       if(CONNECTION_RETRY_COUNT == i) {
+                               stt_client_destroy(*stt);
+                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : TIMED OUT");
+                               return STT_ERROR_TIMED_OUT;                         
+                       }    
+                       i++;
+               } else {
+                       /* success to connect stt-daemon */
+                       break;
+               }
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "[Success] uid(%d)", (*stt)->handle);
+       
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return STT_ERROR_NONE;
+}
+
+int stt_destroy(stt_h stt)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT");
+
+       if (NULL == stt) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+       
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+       
+       int ret = stt_dbus_request_finalize(client->uid);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize");
+       }
+       
+       /* Free resources */
+       stt_client_destroy(stt);
+
+       SLOG(LOG_DEBUG, TAG_STTC, "Success: destroy");
+
+       if (0 == stt_client_get_size()) {
+               if (0 != stt_dbus_close_connection()) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to close connection\n ");
+               }
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return STT_ERROR_NONE;
+}
+
+int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported Language");
+
+       if (NULL == stt || NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = stt_dbus_request_get_support_langs(client->uid, client->stt, callback, user_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages");
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return STT_ERROR_NONE;
+}
+
+
+int stt_get_default_language(stt_h stt, char** language)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Get Default Language");
+
+       if (NULL == stt || NULL == language) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = stt_dbus_request_get_default_lang(client->uid, language);
+
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail : request get default language");
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current language = %s", *language);
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_get_state(stt_h stt, stt_state_e* state)
+{
+       if (NULL == stt || NULL == state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               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;
+       }
+
+       *state = client->current_state;
+
+       switch(*state) {
+               case STT_STATE_READY:           SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'");          break;
+               case STT_STATE_RECORDING:       SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'");      break;
+               case STT_STATE_PROCESSING:      SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'");     break;
+       }
+
+       return STT_ERROR_NONE;
+}
+
+int stt_is_partial_result_supported(stt_h stt, bool* partial_result)
+{
+       if (NULL == stt || NULL == partial_result) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       stt_client_s* client = stt_client_get(stt);
+
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not valid");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = stt_dbus_request_is_partial_result_supported(client->uid, partial_result);
+
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get partial result supported");
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Partial result supporting is %s", *partial_result ? "true " : "false");
+       }
+
+       return STT_ERROR_NONE;
+}
+
+int stt_set_profanity_filter(stt_h stt, stt_option_profanity_e type)
+{
+       if (NULL == stt) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               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;
+       }
+
+       if (type >= STT_OPTION_PROFANITY_FALSE && type <= STT_OPTION_PROFANITY_AUTO)
+               client->profanity = type;       
+       else {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Type is invalid");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       return STT_ERROR_NONE;
+}
+
+int stt_set_punctuation_override(stt_h stt, stt_option_punctuation_e type)
+{
+       if (NULL == stt) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               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;
+       }
+       
+       if (type >= STT_OPTION_PUNCTUATION_FALSE && type <= STT_OPTION_PUNCTUATION_AUTO)
+               client->punctuation = type;     
+       else {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Type is invalid");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       return STT_ERROR_NONE;
+}
+
+int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type)
+{
+       if (NULL == stt) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               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;
+       }
+
+       if (type >= STT_OPTION_SILENCE_DETECTION_FALSE && type <= STT_OPTION_SILENCE_DETECTION_AUTO)
+               client->silence = type; 
+       else {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Type is invalid");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       return STT_ERROR_NONE;
+}
+
+int stt_start(stt_h stt, const char* language, const char* type)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== STT START");
+
+       if (NULL == stt) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       /* check state */
+       if (client->current_state != STT_STATE_READY) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); 
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       char* temp;
+       if (NULL == language) {
+               temp = strdup("default");
+       } else {
+               temp = strdup(language);
+       }
+
+       int ret; 
+       /* do request */
+       ret = stt_dbus_request_start(client->uid, temp, type, client->profanity, client->punctuation, client->silence);
+
+       if (ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start");
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]");
+
+               if (NULL != client->state_changed_cb) {
+                       client->state_changed_cb(client->stt, client->current_state, STT_STATE_RECORDING, client->state_changed_user_data); 
+                       SLOG(LOG_DEBUG, TAG_STTC, "Called state changed : STT_STATE_RECORDING");
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register state changed callback");
+               }    
+
+               client->current_state = STT_STATE_RECORDING;
+       }
+
+       free(temp);
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_stop(stt_h stt)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== STT STOP");
+
+       if (NULL == stt) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] [ERROR] Input parameter is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }   
+       
+       /* check state */
+       if (client->current_state != STT_STATE_RECORDING) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state is NOT RECORDING"); 
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       int ret = 0; 
+       /* do request */
+       ret = stt_dbus_request_stop(client->uid);
+       if (0 != ret) {
+               SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Fail to stop");
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]");
+
+               if (NULL != client->state_changed_cb) {
+                       client->state_changed_cb(client->stt, client->current_state, STT_STATE_PROCESSING, client->state_changed_user_data); 
+                       SLOG(LOG_DEBUG, TAG_STTC, "Called state changed : STT_STATE_PROCESSING");
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register state changed callback");
+               }
+
+               client->current_state = STT_STATE_PROCESSING;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+
+int stt_cancel(stt_h stt)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL");
+
+       if (NULL == stt) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_PARAMETER;
+       }       
+
+       /* check state */
+       if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
+               SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : Current state is 'Ready'");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       int ret; 
+       /* do request */
+       ret = stt_dbus_request_cancel(client->uid);
+       if (0 != ret) {
+               SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Fail to cancel");
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]");
+               if (NULL != client->state_changed_cb) {
+                       client->state_changed_cb(client->stt, client->current_state, STT_STATE_READY, client->state_changed_user_data); 
+                       SLOG(LOG_DEBUG, TAG_STTC, "Called state changed : STT_STATE_READY");
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register state changed callback");
+               }
+
+               client->current_state = STT_STATE_READY;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_get_recording_volume(stt_h stt, float* volume)
+{
+       if (NULL == stt || NULL == volume) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       } 
+       
+       if (STT_STATE_RECORDING != client->current_state) {
+               SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state");
+               return STT_ERROR_INVALID_STATE;
+       }    
+       
+       int ret = 0; 
+       ret = stt_dbus_request_get_audio_volume(client->uid, volume);
+       if (ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get audio volume");
+               return ret;
+       }    
+
+       return STT_ERROR_NONE;
+}
+
+int __stt_cb_error(int uid, int reason)
+{
+       stt_client_s* client = stt_client_get_by_uid(uid);
+       if( NULL == client ) {
+               SLOG(LOG_ERROR, TAG_STTC, "Handle not found\n");
+               return -1;
+       }
+
+       client->current_state = STT_STATE_READY;
+
+       if (NULL != client->error_cb) {
+               stt_client_use_callback(client);
+               client->error_cb(client->stt, reason, client->error_user_data); 
+               stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "client error callback called");
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Error occur but user callback is null");
+       }    
+
+       return 0;
+}
+
+int __stt_cb_result(int uid, const char* type, const char** data, int data_count, const char* msg)
+{
+       stt_client_s* client = NULL;
+       
+       client = stt_client_get_by_uid(uid);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid");
+               return -1;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg);
+
+       int i=0;
+       for (i = 0;i < data_count;i++) {
+               if(NULL != data[i])
+                       SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
+       }       
+
+       if (NULL != client->result_cb) {
+               stt_client_use_callback(client);
+               client->result_cb(client->stt, type, data, data_count, msg, client->result_user_data);
+               stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "client result callback called");
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
+       }   
+
+       if (NULL != client->state_changed_cb) {
+               client->state_changed_cb(client->stt, client->current_state, STT_STATE_READY, client->state_changed_user_data); 
+               SLOG(LOG_DEBUG, TAG_STTC, "client state changed callback called");
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register result callback");
+       }
+
+       client->current_state = STT_STATE_READY;
+
+       return 0;
+}
+
+int __stt_cb_partial_result(int uid, const char* data)
+{
+       stt_client_s* client = NULL;
+
+       client = stt_client_get_by_uid(uid);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid");
+               return -1;
+       }
+
+       if (client->current_state == STT_STATE_READY) {
+               SLOG(LOG_ERROR, TAG_STTC, "Current state has already been 'Ready' state");      
+               return 0;
+       }
+
+       if (client->partial_result_cb) {
+               stt_client_use_callback(client);
+               client->partial_result_cb(client->stt, data, client->partial_result_user_data);
+               stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "client partial result callback called");
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Don't register partial result callback");
+       }   
+
+       return 0;
+}
+
+int __stt_cb_stop_by_daemon(int uid)
+{
+       stt_client_s* client = stt_client_get_by_uid(uid);
+       if( NULL == client ) {
+               SLOG(LOG_ERROR, TAG_STTC, "Handle not found\n");
+               return -1;
+       }
+
+       if (client->current_state != STT_STATE_RECORDING) {
+               SLOG(LOG_ERROR, TAG_STTC, "Current state is NOT 'Recording' state");    
+               return 0;
+       }
+
+       if (NULL != client->state_changed_cb) {
+               stt_client_use_callback(client);
+               client->state_changed_cb(client->stt, client->current_state, STT_STATE_PROCESSING, client->state_changed_user_data); 
+               stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "client state changed callback called");
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Error occur but user callback is null");
+       }
+
+       client->current_state = STT_STATE_PROCESSING;
+
+       return 0;
+}
+
+int stt_set_result_cb(stt_h stt, stt_result_cb callback, void* user_data)
+{
+       if (stt == NULL || callback == NULL)
+               return STT_ERROR_INVALID_PARAMETER;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (STT_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       client->result_cb = callback;
+       client->result_user_data = user_data;
+
+       return 0;
+}
+
+int stt_unset_result_cb(stt_h stt)
+{
+       if (NULL == stt)
+               return STT_ERROR_INVALID_PARAMETER;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (STT_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       client->result_cb = NULL;
+       client->result_user_data = NULL;
+
+       return 0;
+}
+
+int stt_set_partial_result_cb(stt_h stt, stt_partial_result_cb callback, void* user_data)
+{
+       if (NULL == stt || NULL == callback)
+               return STT_ERROR_INVALID_PARAMETER;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (STT_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       client->partial_result_cb = callback;
+       client->partial_result_user_data = user_data;
+
+       return 0;
+}
+
+int stt_unset_partial_result_cb(stt_h stt)
+{
+       if (NULL == stt)
+               return STT_ERROR_INVALID_PARAMETER;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (STT_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       client->partial_result_cb = NULL;
+       client->partial_result_user_data = NULL;
+
+       return 0;
+}
+
+int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data)
+{
+       if (NULL == stt || NULL == callback)
+               return STT_ERROR_INVALID_PARAMETER;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (STT_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       client->state_changed_cb = callback;
+       client->state_changed_user_data = user_data;
+
+       return 0;
+}
+
+int stt_unset_state_changed_cb(stt_h stt)
+{
+       if (NULL == stt)
+               return STT_ERROR_INVALID_PARAMETER;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (STT_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       client->state_changed_cb = NULL;
+       client->state_changed_user_data = NULL;
+
+       return 0;
+}
+
+
+int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
+{
+       if (NULL == stt || NULL == callback)
+               return STT_ERROR_INVALID_PARAMETER;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (STT_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       client->error_cb = callback;
+       client->error_user_data = user_data;
+
+       return 0;
+}
+
+int stt_unset_error_cb(stt_h stt)
+{
+       if (NULL == stt)
+               return STT_ERROR_INVALID_PARAMETER;
+
+       stt_client_s* client = stt_client_get(stt);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (STT_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); 
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       client->error_cb = NULL;
+       client->error_user_data = NULL;
+
+       return 0;
+}
+
+static bool __stt_is_alive()
+{
+       FILE *fp = NULL;
+       char buff[256];
+       char cmd[256];
+       int i=0;
+
+       memset(buff, '\0', 256);
+       memset(cmd, '\0', 256);
+
+       if ((fp = popen("ps -eo \"cmd\"", "r")) == NULL) {
+               SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] popen error \n");
+               return FALSE;
+       }
+
+       while(fgets(buff, 255, fp)) {
+               if (i == 0) {
+                       i++;
+                       continue;
+               }
+
+               sscanf(buff, "%s", cmd);
+
+               if( 0 == strncmp(cmd, "[stt-daemon]", strlen("[stt-daemon]")) ||
+                       0 == strncmp(cmd, "stt-daemon", strlen("stt-daemon")) ||
+                       0 == strncmp(cmd, "/usr/bin/stt-daemon", strlen("/usr/bin/stt-daemon"))
+                       ) {
+                       fclose(fp);
+                       return TRUE;
+               }
+               i++;
+       }
+       fclose(fp);
+
+       return FALSE;
+}
+
+static void __my_sig_child(int signo, siginfo_t *info, void *data)
+{
+       int status;
+       pid_t child_pid, child_pgid;
+
+       child_pgid = getpgid(info->si_pid);
+       SLOG(LOG_DEBUG, TAG_STTC, "Signal handler: dead pid = %d, pgid = %d\n", info->si_pid, child_pgid);
+
+       while((child_pid = waitpid(-1, &status, WNOHANG)) > 0) {
+               if(child_pid == child_pgid)
+                       killpg(child_pgid, SIGKILL);
+       }
+
+       return;
+}
+
+
+int __check_stt_daemon()
+{
+       if( TRUE == __stt_is_alive() )
+               return 0;
+       
+       /* fork-exec stt-daemon */
+       SLOG(LOG_DEBUG, TAG_STTC, "THERE IS NO stt-daemon \n");
+
+       int pid, i;
+       struct sigaction act, dummy;
+
+       act.sa_handler = NULL;
+       act.sa_sigaction = __my_sig_child;
+       sigemptyset(&act.sa_mask);
+       act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
+               
+       if(sigaction(SIGCHLD, &act, &dummy) < 0) {
+               SLOG(LOG_DEBUG, TAG_STTC, "%s\n", "Cannot make a signal handler\n");
+               return -1;
+       }
+
+       pid = fork();
+
+       switch(pid) {
+       case -1:
+               SLOG(LOG_DEBUG, TAG_STTC, "[STT ERROR] fail to create STT-DAEMON \n");
+               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:
+               sleep(1);
+               break;
+       }
+
+       return 0;
+}
+
+
+
+
diff --git a/client/stt.h b/client/stt.h
new file mode 100644 (file)
index 0000000..0fdf71c
--- /dev/null
@@ -0,0 +1,668 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STT_H__
+#define __STT_H__
+
+#include <errno.h>
+#include <stdbool.h>
+
+/**
+* @addtogroup CAPI_UIX_STT_MODULE
+* @{
+*/
+
+#ifdef __cplusplus
+extern "C" 
+{
+#endif
+
+/** 
+* @brief Enumerations of error codes.
+*/
+typedef enum {
+       STT_ERROR_NONE                  = 0,            /**< Successful */
+       STT_ERROR_OUT_OF_MEMORY         = -ENOMEM,      /**< Out of Memory */
+       STT_ERROR_IO_ERROR              = -EIO,         /**< I/O error */
+       STT_ERROR_INVALID_PARAMETER     = -EINVAL,      /**< Invalid parameter */
+       STT_ERROR_TIMED_OUT             = -ETIMEDOUT,   /**< No answer from the daemon */
+       STT_ERROR_RECORDER_BUSY         = -EBUSY,       /**< Busy recorder */
+       STT_ERROR_OUT_OF_NETWORK        = -ENETDOWN,    /**< Out of network */
+       STT_ERROR_INVALID_STATE         = -0x0100031,   /**< Invalid state */
+       STT_ERROR_INVALID_LANGUAGE      = -0x0100032,   /**< Invalid language */
+       STT_ERROR_ENGINE_NOT_FOUND      = -0x0100033,   /**< No available engine  */    
+       STT_ERROR_OPERATION_FAILED      = -0x0100034    /**< Operation failed  */
+}stt_error_e;
+
+/** 
+* @brief Recognition type : free form dictation or default type.
+*/
+#define STT_RECOGNITION_TYPE_FREE                      "stt.recognition.type.FREE"
+
+/** 
+* @brief Recognition type : web search. 
+*/
+#define STT_RECOGNITION_TYPE_WEB_SEARCH                        "stt.recognition.type.WEB_SEARCH"
+
+/** 
+* @brief Recognition type : all voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND                   "stt.recognition.type.COMMAND"
+
+/** 
+* @brief Recognition type : call of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_CALL              "stt.recognition.type.COMMAND.CALL"
+
+/** 
+* @brief Recognition type : music of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_MUSIC             "stt.recognition.type.COMMAND.MUSIC"
+
+/** 
+* @brief Recognition type : web search of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_WEB_SEARCH                "stt.recognition.type.COMMAND.WEB_SEARCH"
+
+/** 
+* @brief Recognition type : schedule of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_SCHEDULE          "stt.recognition.type.COMMAND.SCHEDULE"
+
+/** 
+* @brief Recognition type : search of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_SEARCH            "stt.recognition.type.COMMAND.SEARCH"
+
+/** 
+* @brief Recognition type : contact of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_CONTACT           "stt.recognition.type.COMMAND.CONTACT"
+
+/** 
+* @brief Recognition type : social of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_SOCIAL            "stt.recognition.type.COMMAND.SOCIAL"
+
+/** 
+* @brief Recognition type : message of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_MESSAGE           "stt.recognition.type.COMMAND.MESSAGE"
+
+/** 
+* @brief Recognition type : email of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_EMAIL             "stt.recognition.type.COMMAND.EMAIL"
+
+/** 
+* @brief Recognition type : memo of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_MEMO              "stt.recognition.type.COMMAND.MEMO"
+
+/** 
+* @brief Recognition type : alarm of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_ALARM             "stt.recognition.type.COMMAND.ALARM"
+
+/** 
+* @brief Recognition type : application of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_APPLICATION       "stt.recognition.type.COMMAND.APPLICATION"
+
+/** 
+* @brief Recognition type : driving mode of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_DRIVING_MODE      "stt.recognition.type.COMMAND.DRIVING_MODE"
+
+/** 
+* @brief Recognition type : navigation of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_NAVIGATION                "stt.recognition.type.COMMAND.NAVIGATION"
+
+/** 
+* @brief Recognition type : text-to-speech of voice commands 
+*/
+#define STT_RECOGNITION_TYPE_COMMAND_TTS               "stt.recognition.type.COMMAND.TTS"
+
+/** 
+* @brief Enumerations of state.
+*/
+typedef enum {
+       STT_STATE_READY = 0,                    /**< 'READY' state */
+       STT_STATE_RECORDING,                    /**< 'RECORDING' state */
+       STT_STATE_PROCESSING                    /**< 'PROCESSING' state*/
+}stt_state_e;
+
+/** 
+* @brief Enumerations of profanity type.
+*/
+typedef enum {
+       STT_OPTION_PROFANITY_FALSE = 0,         /**< Profanity type - False */
+       STT_OPTION_PROFANITY_TRUE = 1,          /**< Profanity type - True */
+       STT_OPTION_PROFANITY_AUTO = 2           /**< Profanity type - Auto */
+}stt_option_profanity_e;
+
+/** 
+* @brief Enumerations of punctuation type.
+*/
+typedef enum {
+       STT_OPTION_PUNCTUATION_FALSE = 0,       /**< Punctuation type - False */
+       STT_OPTION_PUNCTUATION_TRUE = 1,        /**< Punctuation type - True */
+       STT_OPTION_PUNCTUATION_AUTO = 2         /**< Punctuation type - Auto */
+}stt_option_punctuation_e;
+
+/** 
+* @brief Enumerations of silence detection type.
+*/
+typedef enum {
+       STT_OPTION_SILENCE_DETECTION_FALSE = 0, /**< Silence detection type - False */
+       STT_OPTION_SILENCE_DETECTION_TRUE = 1,  /**< Silence detection type - True */
+       STT_OPTION_SILENCE_DETECTION_AUTO = 2   /**< Silence detection type - Auto */   
+}stt_option_silence_detection_e;
+
+/** 
+* @brief A structure of handle for STT
+*/
+typedef struct stt_s *stt_h;
+
+/**
+* @brief Called when STT gets the recognition result from engine after the application call stt_stop().
+*
+* @remark If results of recognition is valid after stt_stop() is called or silence is detected from recording, 
+*      this function is called. 
+*
+* @param[in] stt The handle for STT
+* @param[in] type Recognition type
+* @param[in] data Result data
+* @param[in] data_count Result count
+* @param[in] msg Engine message
+* @param[in] user_data The user data passed from the callback registration function
+*
+* @pre stt_stop() will invoke this callback if you register it using stt_set_result_cb().
+* @post If this function is called, the STT state will be #STT_STATE_READY.
+*
+* @see stt_stop()
+* @see stt_set_result_cb()
+* @see stt_unset_result_cb()
+*/
+typedef void (*stt_result_cb)(stt_h stt, const char* type, const char** data, int data_count, const char* msg, void *user_data);
+
+/**
+* @brief Called when STT gets recognition the partial result from engine after the application calls stt_start().
+*
+* @remark If a current engine supports partial result of recognition, this function can be called.
+*
+* @param[in] stt The handle for STT
+* @param[in] data Result data
+* @param[in] user_data The user data passed from the callback registration function
+*
+* @pre stt_start() will invoke this callback if you register it using stt_set_partial_result_cb().
+*
+* @see stt_start()
+* @see stt_set_partial_result_cb()
+* @see stt_unset_partial_result_cb()
+* @see stt_is_partial_result_supported()
+*/
+typedef void (*stt_partial_result_cb)(stt_h stt, const char* data, void *user_data);
+
+/**
+* @brief Called when the state of STT is changed. 
+*
+* @param[in] stt The handle for STT
+* @param[in] previous A previous state
+* @param[in] current A current state
+* @param[in] user_data The user data passed from the callback registration function.
+*
+* @pre An application registers this callback using stt_set_state_changed_cb() to detect changing state.
+*
+* @see stt_start()
+* @see stt_stop()
+* @see stt_cancel()
+* @see stt_result_cb()
+* @see stt_set_state_changed_cb()
+* @see stt_unset_state_changed_cb()
+*/
+typedef void (*stt_state_changed_cb)(stt_h stt, stt_state_e previous, stt_state_e current, void* user_data);
+
+/**
+* @brief Called when error occurred. 
+*
+* @param[in] stt The handle for STT
+* @param[in] reason The error type (e.g. #STT_ERROR_OUT_OF_NETWORK, #STT_ERROR_IO_ERROR)
+* @param[in] user_data The user data passed from the callback registration function
+*
+* @pre An application registers this callback using stt_set_error_cb() to detect error.
+*
+* @see stt_set_error_cb()
+* @see stt_unset_error_cb()
+*/
+typedef void (*stt_error_cb)(stt_h stt, stt_error_e reason, void *user_data);
+
+/**
+* @brief Called to retrieve the supported languages. 
+*
+* @param[in] stt The handle for STT
+* @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
+*              followed by ISO 639-1 for the two-letter language code. \n
+*              For example, "ko_KR" for Korean, "en_US" for American English.
+* @param[in] user_data The user data passed from the foreach function
+*
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+* @pre stt_foreach_supported_languages() will invoke this callback. 
+*
+* @see stt_foreach_supported_languages()
+*/
+typedef bool(*stt_supported_language_cb)(stt_h stt, const char* language, void* user_data);
+
+
+/**
+* @brief Creates a handle for STT and connects daemon. 
+*
+* @param[out] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_TIMED_OUT The daemon is blocked or do not exist
+* @retval #STT_ERROR_ENGINE_NOT_FOUND No available engine \n Engine should be installed
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_OUT_OF_MEMORY Out of memory
+* @retval #STT_ERROR_OPERATION_FAILED Operation failure
+*
+* @see stt_destroy()
+*/
+int stt_create(stt_h* stt);
+
+/**
+* @brief Destroys the handle and disconnects the daemon.
+*
+* @param[in] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+*
+* @see stt_create()
+*/
+int stt_destroy(stt_h stt);
+
+/**
+* @brief Retrieves all supported languages of current engine using callback function.
+*
+* @param[in] stt The handle for STT
+* @param[in] callback The callback function to invoke
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_OPERATION_FAILED Operation failure
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+* @post        This function invokes stt_supported_language_cb() repeatedly for getting languages. 
+*
+* @see stt_supported_language_cb()
+* @see stt_get_default_language()
+*/
+int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data);
+
+/**
+* @brief Gets the default language set by user.
+*
+* @remark If the function succeeds, @a language must be released with free() by you when you no longer need it.
+*
+* @param[in] stt The handle for STT
+* @param[out] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
+*                      followed by ISO 639-1 for the two-letter language code. \n
+*                      For example, "ko_KR" for Korean, "en_US" for American English.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_OUT_OF_MEMORY Out of memory
+* @retval #STT_ERROR_OPERATION_FAILED Operation failure
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*
+* @see stt_foreach_supported_languages()
+*/
+int stt_get_default_language(stt_h stt, char** language);
+
+/**
+* @brief Gets the current state of STT.
+*
+* @param[in] stt The handle for STT
+* @param[out] state The current state of STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+*
+* @see stt_start()
+* @see stt_stop()
+* @see stt_cancel()
+* @see stt_state_changed_cb()
+*/
+int stt_get_state(stt_h stt, stt_state_e* state);
+
+/**
+* @brief Checks whether the partial results can be returned while a recognition is in process.
+*
+* @param[in] stt The handle for STT
+* @param[out] partial_result The partial result status : (@c true = supported, @c false = not supported)
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_OPERATION_FAILED Operation failure
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*
+* @see stt_partial_result_cb()
+*/
+int stt_is_partial_result_supported(stt_h stt, bool* partial_result);
+
+/**
+* @brief Sets profanity filter.
+*
+* @param[in] stt The handle for STT
+* @param[in] type The option type
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*/
+int stt_set_profanity_filter(stt_h stt, stt_option_profanity_e type);
+
+/**
+* @brief Sets punctuation override.
+*
+* @param[in] stt The handle for STT
+* @param[in] type The option type
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*/
+int stt_set_punctuation_override(stt_h stt, stt_option_punctuation_e type);
+
+/**
+* @brief Sets silence detection.
+*
+* @param[in] stt The handle for STT
+* @param[in] type The option type
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*/
+int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type);
+
+/**
+* @brief Starts recording and recognition.
+*
+* @remark This function starts recording in the daemon and sending recording data to engine.
+*      This work continues until stt_stop(), stt_cancel() or silence detected.
+*
+* @param[in] stt The handle for STT
+* @param[in] language The language selected from stt_foreach_supported_languages()
+* @param[in] type The type for recognition (e.g. #RECOGNITION_TYPE_FREE, #RECOGNITION_TYPE_WEB_SEARCH)
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+* @retval #STT_ERROR_OPERATION_FAILED Operation failure
+* @retval #STT_ERROR_RECORDER_BUSY Recorder busy
+* @retval #STT_ERROR_INVALID_LANGUAGE Invalid language
+*
+* @pre The state should be #STT_STATE_READY.
+* @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb().
+*      If this function succeeds, the STT state will be #STT_STATE_RECORDING.
+*
+* @see stt_stop()
+* @see stt_cancel()
+* @see stt_state_changed_cb()
+* @see stt_error_cb()
+*/
+int stt_start(stt_h stt, const char* language, const char* type);
+
+/**
+* @brief Finishes recording and starts recognition processing in engine.
+*
+* @param[in] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_OUT_OF_MEMORY Not enough memory
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+* @retval #STT_ERROR_OPERATION_FAILED Operation failure
+*
+* @pre The state should be #STT_STATE_RECORDING.
+* @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb().
+*      If this function succeeds, the STT state will be #STT_STATE_PROCESSING.
+*      After processing of engine, stt_result_cb() is called.
+*
+* @see stt_start()
+* @see stt_cancel()
+* @see stt_state_changed_cb()
+* @see stt_error_cb()
+*/
+int stt_stop(stt_h stt);
+
+/**
+* @brief Cancels processing recognition and recording.
+*
+* @remark This function cancels recording and engine cancels recognition processing.
+*      After successful cancel, stt_state_changed_cb() is called otherwise
+*      if error is occurred, stt_error_cb() is called. 
+*
+* @param[in] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_OUT_OF_MEMORY Not enough memory
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+* @retval #STT_ERROR_OPERATION_FAILED Operation failure
+*
+* @pre The state should be #STT_STATE_RECORDING or #STT_STATE_PROCESSING.
+* @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb().
+*      If this function succeeds, the STT state will be #STT_STATE_READY.
+*
+* @see stt_start()
+* @see stt_stop()
+* @see stt_state_changed_cb()
+* @see stt_error_cb()
+*/
+int stt_cancel(stt_h stt);
+
+/**
+* @brief Gets the microphone volume during recording.
+*      
+* @param[in] stt The handle for STT
+* @param[out] volume Recording volume
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+* @retval #STT_ERROR_OPERATION_FAILED Operation failure
+*
+* @pre The state should be #STT_STATE_RECORDING.
+* 
+* @see stt_start()
+*/
+int stt_get_recording_volume(stt_h stt, float* volume);
+
+/**
+* @brief Registers a callback function for getting recognition result.
+*
+* @param[in] stt The handle for STT
+* @param[in] callback The callback function to register
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*
+* @see stt_result_cb()
+* @see stt_unset_result_cb()
+*/
+int stt_set_result_cb(stt_h stt, stt_result_cb callback, void* user_data);
+
+/**
+* @brief Unregisters the callback function.
+*
+* @param[in] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*
+* @see stt_set_result_cb()
+*/
+int stt_unset_result_cb(stt_h stt);
+
+/**
+* @brief Registers a callback function for getting partial result of recognition.
+*
+* @param[in] stt The handle for STT
+* @param[in] callback The callback function to register
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @see stt_partial_result_cb()
+* @see stt_unset_partial_result_cb()
+*/
+int stt_set_partial_result_cb(stt_h stt, stt_partial_result_cb callback, void* user_data);
+
+/**
+* @brief Unregisters the callback function.
+*
+* @param[in] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*
+* @see stt_set_partial_result_cb()
+*/
+int stt_unset_partial_result_cb(stt_h stt);
+
+/**
+* @brief Registers a callback function to be called when STT state changes.
+*
+* @param[in] stt The handle for STT
+* @param[in] callback The callback function to register
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*
+* @see stt_state_changed_cb()
+* @see stt_unset_state_changed_cb()
+*/
+int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data);
+
+/**
+* @brief Unregisters the callback function.
+*
+* @param[in] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*
+* @see stt_set_state_changed_cb()
+*/
+int stt_unset_state_changed_cb(stt_h stt);
+
+/**
+* @brief Registers a callback function to be called when an error occurred.
+*
+* @param[in] stt The handle for STT
+* @param[in] callback The callback function to register
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*
+* @see stt_error_cb()
+* @see stt_unset_error_cb()
+*/
+int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data);
+
+/**
+* @brief Unregisters the callback function.
+*
+* @param[in] stt The handle for STT
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STT_ERROR_NONE Successful
+* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STT_ERROR_INVALID_STATE Invalid state
+*
+* @pre The state should be #STT_STATE_READY.
+*
+* @see stt_set_error_cb()
+*/
+int stt_unset_error_cb(stt_h stt);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}@}
+ */
+
+#endif /* __STT_H__ */
diff --git a/client/stt.pc.in b/client/stt.pc.in
new file mode 100644 (file)
index 0000000..6f95833
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: lib@PROJECT_NAME@
+Description: Speech To Text client library
+Requires: glib-2.0 dbus-1 
+Version: @VERSION@
+Libs: -L${libdir} -l@PROJECT_NAME@
+Cflags: -I${includedir}
diff --git a/client/stt_client.c b/client/stt_client.c
new file mode 100644 (file)
index 0000000..6bb5772
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include "stt_client.h"
+
+#define MUTEX_TIME 3
+
+/* Max number of handle */
+static const int g_max_handle = 999;
+/* allocated handle */
+static int g_allocated_handle = 0;
+/* client list */
+static GList *g_client_list = NULL;
+
+
+/* private functions */
+static int __client_generate_uid(int pid)
+{
+       g_allocated_handle++;
+
+       if (g_allocated_handle > g_max_handle) {
+               g_allocated_handle = 1;
+       }
+
+       /* generate uid, handle number should be smaller than 1000 */
+       return pid * 1000 + g_allocated_handle;
+}
+
+int stt_client_new(stt_h* stt)
+{
+       stt_client_s *client = NULL;
+
+       client = (stt_client_s*)g_malloc0 (sizeof(stt_client_s));
+
+       stt_h temp = (stt_h)g_malloc0(sizeof(stt_h));
+       temp->handle = __client_generate_uid(getpid()); 
+
+       /* initialize client data */
+       client->stt = temp;
+       client->pid = getpid(); 
+       client->uid = temp->handle;
+       
+       client->result_cb = NULL;
+       client->result_user_data = NULL;
+       client->partial_result_cb = NULL;
+       client->partial_result_user_data = NULL;
+       client->state_changed_cb = NULL;
+       client->state_changed_user_data = NULL;
+       client->error_cb = NULL;
+       client->error_user_data = NULL;
+
+       client->profanity = STT_OPTION_PROFANITY_AUTO;  
+       client->punctuation = STT_OPTION_PUNCTUATION_AUTO;
+       client->silence = STT_OPTION_SILENCE_DETECTION_AUTO;
+
+       client->current_state = STT_STATE_READY; 
+
+       client->cb_ref_count = 0;
+
+       g_client_list = g_list_append(g_client_list, client);
+
+       *stt = temp;
+
+       return 0;       
+}
+
+int stt_client_destroy(stt_h stt)
+{
+       if (stt == NULL) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return 0;
+       }       
+
+       GList *iter = NULL;
+       stt_client_s *data = NULL;
+
+       /* if list have item */
+       if (g_list_length(g_client_list) > 0) {
+               /* Get a first item */
+               iter = g_list_first(g_client_list);
+
+               while (NULL != iter) {
+                       data = iter->data;
+                       if (stt->handle == data->stt->handle) {
+                               g_client_list = g_list_remove_link(g_client_list, iter);
+
+                               while (0 != data->cb_ref_count)
+                               {
+                                       /* wait for release callback function */
+                               }
+                               free(data);
+                               free(stt);
+
+                               return 0;
+                       }
+
+                       /* Next item */
+                       iter = g_list_next(iter);
+               }
+       }
+
+       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] client Not founded");
+
+       return -1;
+}
+
+
+stt_client_s* stt_client_get(stt_h stt)
+{
+       if (stt == NULL) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               return NULL;
+       }
+
+       GList *iter = NULL;
+       stt_client_s *data = NULL;
+
+       if (g_list_length(g_client_list) > 0) {
+               /* Get a first item */
+               iter = g_list_first(g_client_list);
+
+               while (NULL != iter) {
+                       data = iter->data;
+
+                       if (stt->handle == data->stt->handle) 
+                               return data;
+
+                       /* Next item */
+                       iter = g_list_next(iter);
+               }
+       }
+
+       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get client by stt");
+
+       return NULL;
+}
+
+stt_client_s* stt_client_get_by_uid(const int uid)
+{
+       if (uid < 0) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] out of range : handle");
+               return NULL;
+       }
+
+       GList *iter = NULL;
+       stt_client_s *data = NULL;
+
+       if (g_list_length(g_client_list) > 0) {
+               /* Get a first item */
+               iter = g_list_first(g_client_list);
+
+               while (NULL != iter) {
+                       data = iter->data;
+                       if (uid == data->uid) {
+                               return data;
+                       }
+
+                       /* Next item */
+                       iter = g_list_next(iter);
+               }
+       }
+
+       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get client by uid");
+
+       return NULL;
+}
+
+int stt_client_get_size()
+{
+       return g_list_length(g_client_list);
+}
+
+int stt_client_use_callback(stt_client_s* client)
+{
+       client->cb_ref_count++;
+       return 0;
+}
+
+int stt_client_not_use_callback(stt_client_s* client)
+{
+       client->cb_ref_count--;
+       return 0;
+}
+
+
+
diff --git a/client/stt_client.h b/client/stt_client.h
new file mode 100644 (file)
index 0000000..3cfa7a1
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STT_CLIENT_H_
+#define __STT_CLIENT_H_
+
+#include <pthread.h>
+#include "stt.h"
+#include "stt_main.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct {
+       /* base info */
+       stt_h   stt;
+       int     pid; 
+       int     uid;    /*<< unique id = pid + handle */
+
+       stt_result_cb           result_cb;
+       void*                   result_user_data;
+       stt_partial_result_cb   partial_result_cb;
+       void*                   partial_result_user_data;
+       stt_state_changed_cb    state_changed_cb;
+       void*                   state_changed_user_data;
+       stt_error_cb            error_cb;
+       void*                   error_user_data;
+
+       /* option */
+       stt_option_profanity_e          profanity;      
+       stt_option_punctuation_e        punctuation;
+       stt_option_silence_detection_e  silence;
+
+       /* state */
+       stt_state_e     current_state;
+
+       /* mutex */
+       int             cb_ref_count;
+}stt_client_s;
+
+int stt_client_new(stt_h* stt);
+
+int stt_client_destroy(stt_h stt);
+
+stt_client_s* stt_client_get(stt_h stt);
+
+stt_client_s* stt_client_get_by_uid(const int uid);
+
+int stt_client_get_size();
+
+int stt_client_use_callback(stt_client_s* client);
+
+int stt_client_not_use_callback(stt_client_s* client);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STT_CLIENT_H_ */
diff --git a/client/stt_dbus.c b/client/stt_dbus.c
new file mode 100644 (file)
index 0000000..cbfb0cb
--- /dev/null
@@ -0,0 +1,866 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include "stt_main.h"
+#include "stt_dbus.h"
+#include "stt_defs.h"
+
+#include <Ecore.h>
+
+static Ecore_Fd_Handler* g_fd_handler = NULL;
+
+static DBusConnection* g_conn = NULL;
+
+
+extern int __stt_cb_error(int uid, int reason);
+
+extern int __stt_cb_result(int uid, const char* type, const char** data, int data_count, const char* msg);
+       
+extern int __stt_cb_partial_result(int uid, const char* data);
+
+extern int __stt_cb_stop_by_daemon(int uid);
+
+static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
+{
+       DBusConnection* conn = (DBusConnection*)data;
+       DBusMessage* msg = NULL;
+
+       if (NULL == conn)
+               return ECORE_CALLBACK_RENEW;
+
+       dbus_connection_read_write_dispatch(conn, 50);
+
+       msg = dbus_connection_pop_message(conn);
+
+       /* loop again if we haven't read a message */
+       if (NULL == msg) { 
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       DBusError err;
+       dbus_error_init(&err);
+       char if_name[64];
+       snprintf(if_name, 64, "%s%d", STT_CLIENT_SERVICE_INTERFACE, getpid());
+
+       if( dbus_message_is_signal(msg, if_name, STT_SIGNAL_RESULT)) {
+               SLOG(LOG_DEBUG, TAG_STTC, "===== Get Result");
+               int uid = 0;
+               DBusMessageIter args;
+                       
+               dbus_message_iter_init(msg, &args);
+               
+               /* Get result */
+               if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                       dbus_message_iter_get_basic(&args, &uid);
+                       dbus_message_iter_next(&args);
+               }
+               
+               if (uid > 0) {
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get result : uid(%d) \n", uid);
+                       char** temp_result;
+                       char* temp_msg = NULL;
+                       char* temp_char = NULL;
+                       char* temp_type = 0;
+                       int temp_count = 0;
+
+                       /* Get recognition type */
+                       if (DBUS_TYPE_STRING == dbus_message_iter_get_arg_type(&args)) {
+                               dbus_message_iter_get_basic(&args, &temp_type);
+                               dbus_message_iter_next(&args);
+                       }
+
+                       if (DBUS_TYPE_STRING == dbus_message_iter_get_arg_type(&args)) {
+                               dbus_message_iter_get_basic(&args, &(temp_msg) );
+                               dbus_message_iter_next(&args);
+                       }
+
+                       /* Get voice size */
+                       if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                               dbus_message_iter_get_basic(&args, &temp_count);
+                               dbus_message_iter_next(&args);
+                       }
+
+                       if (temp_count <= 0) {
+                               SLOG(LOG_ERROR, TAG_STTC, "Result count is 0");
+                               __stt_cb_result(uid, temp_type, NULL, 0, temp_msg);
+                       } else {
+                               temp_result = g_malloc0(temp_count * sizeof(char*));
+
+                               if (NULL == temp_result)        {
+                                       SLOG(LOG_ERROR, TAG_STTC, "Fail : memory allocation error \n");
+                               } else {
+                                       int i = 0;
+                                       for (i = 0;i < temp_count;i++) {
+                                               dbus_message_iter_get_basic(&args, &(temp_char) );
+                                               dbus_message_iter_next(&args);
+                                               
+                                               if (NULL != temp_char)
+                                                       temp_result[i] = strdup(temp_char);
+                                       }
+               
+                                       __stt_cb_result(uid, temp_type, (const char**)temp_result, temp_count, temp_msg);
+
+                                       for (i = 0;i < temp_count;i++) {
+                                               if (NULL != temp_result[i])
+                                                       free(temp_result[i]);
+                                       }
+
+                                       g_free(temp_result);
+                               }
+                       }       
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get result : invalid uid \n");
+               } 
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+       }/* STT_SIGNAL_RESULT */
+
+       else if( dbus_message_is_signal(msg, if_name, STT_SIGNAL_PARTIAL_RESULT)) {
+               SLOG(LOG_DEBUG, TAG_STTC, "===== Get Partial Result");
+               int uid = 0;
+               DBusMessageIter args;
+
+               dbus_message_iter_init(msg, &args);
+
+               /* Get result */
+               if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                       dbus_message_iter_get_basic(&args, &uid);
+                       dbus_message_iter_next(&args);
+               }
+
+               if (uid > 0) {
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get partial result : uid(%d) \n", uid);
+                       char* temp_char = NULL;
+
+                       if (DBUS_TYPE_STRING == dbus_message_iter_get_arg_type(&args)) {
+                               dbus_message_iter_get_basic(&args, &(temp_char) );
+                               dbus_message_iter_next(&args);
+                       }
+
+                       __stt_cb_partial_result(uid, temp_char);
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get partial result : invalid uid \n");
+               }
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+       }/* STT_SIGNAL_PARTIAL_RESULT */
+
+       else if( dbus_message_is_signal(msg, if_name, STT_SIGNAL_STOP)) {
+               SLOG(LOG_DEBUG, TAG_STTC, "===== Get Silence Detection");
+               int uid;
+               dbus_message_get_args(msg, &err,
+                       DBUS_TYPE_INT32, &uid,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< Get stop by daemon signal : Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+               } else {
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< Get stop by daemon signal : uid(%d)\n", uid);
+                       __stt_cb_stop_by_daemon(uid);
+               }
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+       }/* STT_SIGNAL_STOP */
+
+       else if( dbus_message_is_signal(msg, if_name, STT_SIGNAL_ERROR)) {
+               SLOG(LOG_DEBUG, TAG_STTC, "===== Get Error");
+               int uid;
+               int reason;
+               char* err_msg;
+
+               dbus_message_get_args(msg, &err,
+                       DBUS_TYPE_INT32, &uid,
+                       DBUS_TYPE_INT32, &reason,
+                       DBUS_TYPE_STRING, &err_msg,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< Get Error signal : Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+               } else {
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< Get Error signal : uid(%d), reason(%d), msg(%s)\n", uid, reason, err_msg);
+                       __stt_cb_error(uid, reason);
+               }
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+       }/* STT_SIGNAL_ERROR */
+
+       /* free the message */
+       dbus_message_unref(msg);
+
+       return ECORE_CALLBACK_PASS_ON;
+}
+
+int stt_dbus_open_connection()
+{
+       if (NULL != g_conn) {
+               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);
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTC, "Dbus Connection Error (%s)\n", err.message); 
+               dbus_error_free(&err); 
+       }
+
+       if (NULL == g_conn) {
+               SLOG(LOG_ERROR, TAG_STTC, "Fail to get dbus connection \n");
+               return STT_ERROR_OPERATION_FAILED; 
+       }
+
+       int pid = getpid();
+
+       char service_name[64];
+       memset(service_name, '\0', 64);
+       snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+
+       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);
+
+       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) {
+               printf("fail dbus_bus_request_name()\n");
+               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);
+
+       /* add a rule for which messages we want to see */
+       dbus_bus_add_match(g_conn, rule, &err); 
+       dbus_connection_flush(g_conn);
+
+       if (dbus_error_is_set(&err)) 
+       { 
+               SLOG(LOG_ERROR, TAG_STTC, "Match Error (%s)\n", err.message);
+               return STT_ERROR_OPERATION_FAILED; 
+       }
+
+       int fd = 0;
+       if (1 != dbus_connection_get_unix_fd(g_conn, &fd)) {
+               SLOG(LOG_ERROR, TAG_STTC, "fail to get fd from dbus \n");
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "Get fd from dbus : %d\n", fd);
+       }
+
+       g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn, NULL, NULL);
+
+       if (NULL == g_fd_handler) {
+               SLOG(LOG_ERROR, TAG_STTC, "fail to get fd handler from ecore \n");
+               return STT_ERROR_OPERATION_FAILED;
+       }
+
+       return 0;
+}
+
+int stt_dbus_close_connection()
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       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);
+
+       g_conn = NULL;
+
+       return 0;
+}
+
+int stt_dbus_request_initialize(int uid)
+{
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_METHOD_INITIALIZE);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt initialize : Fail to make message \n"); 
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt initialize : uid(%d)", uid);
+       }
+
+       int pid = getpid();
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &uid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL \n");
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt initialize : result = %d \n", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt initialize : result = %d \n", result);
+       }
+       
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_dbus_request_finalize(int uid)
+{
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_METHOD_FINALIZE);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt finalize : Fail to make message \n"); 
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt finalize : uid(%d)", uid);
+       }
+
+       dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, 
+                               DBUS_TYPE_INT32, &result,
+                               DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       printf("<<<< Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL \n");
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt finalize : result = %d \n", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt finalize : result = %d \n", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_language_cb callback, void* user_data)
+{
+       if (NULL == stt || NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_METHOD_GET_SUPPORT_LANGS);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get supported languages : Fail to make message \n"); 
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get supported languages : uid(%d)", uid);
+       }
+
+       dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       DBusMessageIter args;
+       int result = STT_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err );
+
+       if (NULL != result_msg) {
+               if (dbus_message_iter_init(result_msg, &args)) {
+                       /* Get result */
+                       if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                               dbus_message_iter_get_basic(&args, &result);
+                               dbus_message_iter_next(&args);
+                       }
+
+                       if (0 == result) {
+                               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get support languages : result = %d \n", result);
+
+                               /* Get voice size */
+                               int size ; 
+                               if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                                       dbus_message_iter_get_basic(&args, &size);
+                                       dbus_message_iter_next(&args);
+                               }
+
+                               if (0 >= size) {
+                                       SLOG(LOG_ERROR, TAG_STTC, "<<<< stt size of language error : size = %d \n", size);
+                               } else {
+                                       int i=0;
+                                       char* temp_lang;
+
+                                       for (i=0 ; i<size ; i++) {
+                                               dbus_message_iter_get_basic(&args, &(temp_lang));
+                                               dbus_message_iter_next(&args);
+
+                                               if (true != callback(stt, temp_lang, user_data)) {
+                                                       break;
+                                               }
+                                       }
+                               }
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get support languages : result = %d \n", result);
+                       }
+               } 
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get support languages : result message is NULL \n");
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_dbus_request_get_default_lang(int uid, char** language)
+{
+       if (NULL == language) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_METHOD_GET_CURRENT_LANG);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get default language : Fail to make message \n"); 
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get default language  : uid(%d)", uid);
+       }
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &uid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_ERROR_OPERATION_FAILED;
+       char* temp_lang = NULL;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err,
+                       DBUS_TYPE_INT32, &result,
+                       DBUS_TYPE_STRING, &temp_lang,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       printf("<<<< Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL \n");
+       }
+
+       if (0 == result) {
+               *language = strdup(temp_lang);
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get default language : result = %d, language = %s \n", result, *language);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get default language : result = %d \n", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_dbus_request_is_partial_result_supported(int uid, bool* partial_result)
+{
+       if (NULL == partial_result) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+                  STT_SERVER_SERVICE_NAME, 
+                  STT_SERVER_SERVICE_OBJECT_PATH, 
+                  STT_SERVER_SERVICE_INTERFACE, 
+                  STT_METHOD_IS_PARTIAL_SUPPORTED);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt is partial result supported : Fail to make message \n"); 
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt is partial result supported : uid(%d)", uid);
+       }
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &uid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_ERROR_OPERATION_FAILED;
+       int support = -1;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err,
+                       DBUS_TYPE_INT32, &result,
+                       DBUS_TYPE_INT32, &support,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       printf("<<<< Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL \n");
+       }
+
+       if (0 == result) {
+               *partial_result = (bool)support;
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt is partial result supported : result = %d, support = %s \n", result, *partial_result ? "true" : "false");
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt is partial result supported : result = %d \n", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_dbus_request_start(int uid, const char* lang, const char* type, int profanity, int punctuation, int silence)
+{
+       if (NULL == lang || NULL == type) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       /* create a signal & check for errors */
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME,
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE,   
+               STT_METHOD_START);              
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt start : Fail to make message \n"); 
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt start : uid(%d), language(%s), type(%s)", uid, lang, type);
+       }
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &uid, 
+               DBUS_TYPE_STRING, &lang,   
+               DBUS_TYPE_STRING, &type,
+               DBUS_TYPE_INT32, &profanity,
+               DBUS_TYPE_INT32, &punctuation,
+               DBUS_TYPE_INT32, &silence,
+               DBUS_TYPE_INVALID);
+       
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err,
+                       DBUS_TYPE_INT32, &result,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       printf("<<<< Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< Result Message is NULL");
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt start : result = %d ", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt start : result = %d ", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_dbus_request_stop(int uid)
+{
+       DBusMessage* msg;
+
+       /* create a signal & check for errors */
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME,
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE,   
+               STT_METHOD_STOP);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt stop : Fail to make message \n"); 
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt stop : uid(%d)", uid);
+       }
+
+       dbus_message_append_args(msg, 
+               DBUS_TYPE_INT32, &uid, 
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err,
+                       DBUS_TYPE_INT32, &result,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       printf("<<<< Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< Result Message is NULL");
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt stop : result = %d ", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt stop : result = %d ", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_dbus_request_cancel(int uid)
+{
+       DBusMessage* msg;
+
+       /* create a signal & check for errors */
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME,
+               STT_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
+               STT_SERVER_SERVICE_INTERFACE,   /* interface name of the signal */
+               STT_METHOD_CANCEL);     /* name of the signal */
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt cancel : Fail to make message \n"); 
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt cancel : uid(%d)", uid);
+       }
+
+       dbus_message_append_args(msg, 
+               DBUS_TYPE_INT32, &uid, 
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err,
+                       DBUS_TYPE_INT32, &result,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       printf("<<<< Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< Result Message is NULL");
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt cancel : result = %d ", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt cancel : result = %d ", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+
+int stt_dbus_request_get_audio_volume(int uid, float* volume)
+{
+       if (NULL == volume) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_METHOD_GET_AUDIO_VOLUME);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get volume : Fail to make message \n"); 
+               return STT_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get volume : uid(%d)", uid);
+       }
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &uid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_ERROR_OPERATION_FAILED;
+       double vol = 0;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err,
+                       DBUS_TYPE_INT32, &result,
+                       DBUS_TYPE_DOUBLE, &vol,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       printf("<<<<< Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< Result Message is NULL");
+       }
+
+       if (0 == result) {
+               *volume = (float)vol;
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get audio volume : result = %d, volume = %f \n", result, *volume);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get audio volume : result = %d\n", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+
diff --git a/client/stt_dbus.h b/client/stt_dbus.h
new file mode 100644 (file)
index 0000000..edc40d4
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+#ifndef __STT_DBUS_H_
+#define __STT_DBUS_H_
+
+#include "stt.h"
+#include "stt_main.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int stt_dbus_open_connection();
+
+int stt_dbus_close_connection();
+
+
+int stt_dbus_request_initialize(int uid);
+
+int stt_dbus_request_finalize(int uid);
+
+int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_language_cb callback, void* user_data);
+
+int stt_dbus_request_get_default_lang(int uid, char** language);
+
+int stt_dbus_request_get_audio_volume(int uid, float* volume); 
+
+int stt_dbus_request_is_partial_result_supported(int uid, bool* partial_result);
+
+int stt_dbus_request_start(int uid, const char* lang, const char* type, int profanity, int punctuation, int silence);
+
+int stt_dbus_request_stop(int uid);
+
+int stt_dbus_request_cancel(int uid);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STT_DBUS_H_ */
diff --git a/client/stt_main.h b/client/stt_main.h
new file mode 100644 (file)
index 0000000..bc1ec80
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+#ifndef __STT_MAIN_H_
+#define __STT_MAIN_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
+#include <dbus/dbus.h>
+#include <dlog.h>
+
+#include "stt_defs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TAG_STTC "sttc" 
+
+/** 
+* @brief A structure of handle for identification
+*/
+struct stt_s {
+       int handle;
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STT_CLIENT_H_ */
diff --git a/client/stt_setting.c b/client/stt_setting.c
new file mode 100644 (file)
index 0000000..cbe49c8
--- /dev/null
@@ -0,0 +1,642 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include <sys/wait.h>
+
+#include "stt_main.h"
+#include "stt_setting.h"
+#include "stt_setting_dbus.h"
+
+static bool g_is_setting_initialized = false;
+
+static int __check_stt_daemon();
+
+int stt_setting_initialize ()
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Initialize STT Setting");
+
+       int ret = 0;
+
+       /* Check daemon */
+       __check_stt_daemon();
+
+       if (true == g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT Setting has already been initialized. \n");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (0 != stt_setting_dbus_open_connection()) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open connection\n");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       }
+
+       /* do request */
+       int i = 0;
+       while(1) {
+               ret = stt_setting_dbus_request_initialize();
+
+               if (STT_SETTING_ERROR_ENGINE_NOT_FOUND == ret) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Engine not found");
+                       break;
+               } else if(ret) {
+                       sleep(1);
+                       if (i == 10) {
+                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection Time out");
+                               ret = STT_SETTING_ERROR_TIMED_OUT;                          
+                               break;
+                       }
+                       i++;
+               } else {
+                       /* success to connect stt-daemon */
+                       break;
+               }
+       }
+
+       if (0 == ret) {
+               g_is_setting_initialized = true;
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Initialize");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+
+int stt_setting_finalize ()
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Finalize STT Setting");
+       
+       int ret = 0;
+
+       if (false == g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       ret = stt_setting_dbus_request_finalilze();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "Fail : finialize(%d)", ret);
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return ret;
+       }
+    
+       if (0 != stt_setting_dbus_close_connection()) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to close connection");
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Finalize");
+       }
+
+       g_is_setting_initialized = false;
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return STT_SETTING_ERROR_NONE;
+}
+
+int stt_setting_foreach_supported_engines(stt_setting_supported_engine_cb callback, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach supported engines");
+
+       if (false == g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Callback is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = stt_setting_dbus_request_get_engine_list(callback, user_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Foreach supported engines");
+       }
+       
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_get_engine(char** engine_id)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Get current engine");
+
+       if (false == g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Engine id is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = stt_setting_dbus_request_get_engine(engine_id);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Get current engine");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_set_engine(const char* engine_id)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Set current engine");
+
+       if (false == g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Engine id is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = stt_setting_dbus_request_set_engine(engine_id);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set current engine");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+    
+       return ret;
+}
+
+int stt_setting_foreach_supported_languages(stt_setting_supported_language_cb callback, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach supported languages");
+
+       if (false == g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Param is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = stt_setting_dbus_request_get_language_list(callback, user_data);
+
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Foreach supported languages");
+       }
+       
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_get_default_language(char** language)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Get default language");
+
+       if (false == g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == language) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = stt_setting_dbus_request_get_default_language(language);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Foreach supported voices");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_set_default_language(const char* language)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Set default language");
+
+       if (false == g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == language) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = stt_setting_dbus_request_set_default_language(language);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set default voice");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_get_profanity_filter(bool* value)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Get profanity filter");
+
+       int ret = 0;
+
+       if (false == g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = stt_setting_dbus_request_get_profanity_filter(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result (%d)", ret);    
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Get profanity filter(%s)", *value ? "true":"false");
+       }
+       
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_set_profanity_filter(const bool value)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Set profanity filter");
+
+       int ret = 0;
+
+       if (!g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       ret = stt_setting_dbus_request_set_profanity_filter(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result (%d)", ret);    
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set profanity filter(%s)", value ? "true":"false");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_get_punctuation_override(bool* value)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Get punctuation override");
+
+       int ret = 0;
+
+       if (!g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] param is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = stt_setting_dbus_request_get_punctuation_override(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result (%d)", ret); 
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Get punctuation override(%s)", *value ? "true":"false");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_set_punctuation_override(bool value)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Set punctuation override");
+
+       int ret = 0;
+
+       if (!g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       ret = stt_setting_dbus_request_set_punctuation_override(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result (%d)", ret);    
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set punctuation override(%s)", value ? "true":"false");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_get_silence_detection(bool* value)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Get silence detection");
+
+       int ret = 0;
+
+       if (!g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] param is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = stt_setting_dbus_request_get_silence_detection(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result (%d)", ret);    
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Get silence detection(%s)", *value ? "true":"false");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_set_silence_detection(bool value)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Set silence detection");
+
+       int ret = 0;
+
+       if (!g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       ret = stt_setting_dbus_request_set_silence_detection(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result (%d)", ret);    
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set silence detection(%s)", value ? "true":"false");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_foreach_engine_settings(stt_setting_engine_setting_cb callback, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach engine setting");
+
+       int ret = 0;
+
+       if (!g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not initialized");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] parameter is NULL");
+               SLOG(LOG_DEBUG, TAG_STTC, "=====");
+               SLOG(LOG_DEBUG, TAG_STTC, " ");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = stt_setting_dbus_request_get_engine_setting(callback, user_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result (%d)", ret);    
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Foreach engine setting");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_setting_set_engine_setting(const char* key, const char* value)
+{
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Set engine setting");
+
+       int ret = 0;
+
+       if (!g_is_setting_initialized) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not initialized");
+               return STT_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == key || NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = stt_setting_dbus_request_set_engine_setting(key, value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR]  Result (%d)", ret);    
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set engine setting(%s)", *value ? "true":"false");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+static bool __stt_is_alive()
+{
+       FILE *fp = NULL;
+       char buff[256] = {'\0',};
+       char cmd[256] = {'\0',};
+       int i=0;
+
+       memset(buff, '\0', sizeof(char));
+       memset(cmd, '\0', sizeof(char));
+
+       if ((fp = popen("ps -eo \"cmd\"", "r")) == NULL) {
+               SLOG(LOG_DEBUG, TAG_STTC, "[STT ERROR] popen error \n");
+               return FALSE;
+       }
+
+       while (fgets(buff, 255, fp)) {
+               if (i == 0) {
+                       i++;
+                       continue;
+               }
+
+               sscanf(buff, "%s", cmd);
+
+               if( 0 == strncmp(cmd, "[stt-daemon]", strlen("[stt-daemon]")) ||
+                       0 == strncmp(cmd, "stt-daemon", strlen("stt-daemon")) ||
+                       0 == strncmp(cmd, "/usr/bin/stt-daemon", strlen("/usr/bin/stt-daemon"))
+                       ) {
+                       SLOG(LOG_DEBUG, TAG_STTC, "stt-daemon is ALIVE !! \n");
+                       fclose(fp);
+                       return TRUE;
+               }
+
+               i++;
+       }
+       fclose(fp);
+
+       SLOG(LOG_DEBUG, TAG_STTC, "THERE IS NO stt-daemon !! \n");
+
+       return FALSE;
+}
+
+static void __my_sig_child(int signo, siginfo_t *info, void *data)
+{
+       int status = 0;
+       pid_t child_pid, child_pgid;
+
+       child_pgid = getpgid(info->si_pid);
+       SLOG(LOG_DEBUG, TAG_STTC, "Signal handler: dead pid = %d, pgid = %d\n", info->si_pid, child_pgid);
+
+       while ((child_pid = waitpid(-1, &status, WNOHANG)) > 0) {
+               if(child_pid == child_pgid)
+                       killpg(child_pgid, SIGKILL);
+       }
+
+       return;
+}
+
+int __check_stt_daemon()
+{
+       if (TRUE == __stt_is_alive()) 
+               return 0;
+       
+       /* fork-exec stt-daemom */
+       SLOG(LOG_DEBUG, TAG_STTC, "THERE IS NO stt-daemon \n");
+
+       int pid = 0, i = 0;
+       struct sigaction act, dummy;
+       act.sa_handler = NULL;
+       act.sa_sigaction = __my_sig_child;
+       sigemptyset(&act.sa_mask);
+       act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
+       
+       if (sigaction(SIGCHLD, &act, &dummy) < 0) {
+               SLOG(LOG_ERROR, TAG_STTC, "%s\n", "Cannot make a signal handler\n");
+               return -1;
+       }
+
+       pid = fork();
+
+       switch(pid) {
+       case -1:
+               SLOG(LOG_DEBUG, TAG_STTC, "fail to create STT-DAEMON \n");
+               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:
+               sleep(1);
+               break;
+       }
+
+       return 0;
+}
+
diff --git a/client/stt_setting.h b/client/stt_setting.h
new file mode 100644 (file)
index 0000000..69731f9
--- /dev/null
@@ -0,0 +1,344 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STT_SETTING_H_
+#define __STT_SETTING_H_
+
+#include <errno.h>
+#include <stdbool.h>
+
+/**
+* @addtogroup STT_SETTING_MODULE
+* @{
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** 
+* @brief Enumerations of error codes.
+*/
+typedef enum {
+       STT_SETTING_ERROR_NONE                  = 0,            /**< Success, No error */
+       STT_SETTING_ERROR_OUT_OF_MEMORY         = -ENOMEM,      /**< Out of Memory */
+       STT_SETTING_ERROR_IO_ERROR              = -EIO,         /**< I/O error */
+       STT_SETTING_ERROR_INVALID_PARAMETER     = -EINVAL,      /**< Invalid parameter */
+       STT_SETTING_ERROR_INVALID_STATE         = -0x0100021,   /**< Invalid state */
+       STT_SETTING_ERROR_INVALID_LANGUAGE      = -0x0100022,   /**< Invalid language */
+       STT_SETTING_ERROR_ENGINE_NOT_FOUND      = -0x0100023,   /**< No available STT-engine  */
+       STT_SETTING_ERROR_TIMED_OUT             = -0x0100024,   /**< No answer from STT daemon */
+       STT_SETTING_ERROR_OPERATION_FAILED      = -0x0100025,   /**< STT daemon failed  */
+}stt_setting_error_e;
+
+/**
+* @brief Called to get a engine information.
+*
+* @param[in] engine_id Engine id.
+* @param[in] engine_name engine name.
+* @param[in] setting_path gadget path of engine specific setting.
+* @param[in] user_data User data passed from the stt_setting_foreach_supported_engines().
+*
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+* @pre stt_setting_foreach_supported_engines() will invoke this callback. 
+*
+* @see stt_setting_foreach_supported_engines()
+*/
+typedef bool(*stt_setting_supported_engine_cb)(const char* engine_id, const char* engine_name, const char* setting_path, void* user_data);
+
+/**
+* @brief Called to get a language.
+*
+* @param[in] engine_id Engine id.
+* @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code
+*              followed by ISO 639-1 for the two-letter language code. 
+*              For example, "ko_KR" for Korean, "en_US" for American English..
+* @param[in] user_data User data passed from the stt_setting_foreach_supported_languages().
+*
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+* @pre stt_setting_foreach_supported_languages() will invoke this callback. 
+*
+* @see stt_setting_foreach_supported_languages()
+*/
+typedef bool(*stt_setting_supported_language_cb)(const char* engine_id, const char* language, void* user_data);
+
+/**
+* @brief Called to get a engine setting.
+*
+* @param[in] engine_id Engine id.
+* @param[in] key Key.
+* @param[in] value Value.
+* @param[in] user_data User data passed from the stt_setting_foreach_engine_settings().
+*
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+* @pre stt_setting_foreach_engine_settings() will invoke this callback. 
+*
+* @see stt_setting_foreach_engine_settings()
+*/
+typedef bool(*stt_setting_engine_setting_cb)(const char* engine_id, const char* key, const char* value, void* user_data);
+
+
+/**
+* @brief Initialize STT setting and connect to stt-daemon.
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_TIMED_OUT stt daemon is blocked or stt daemon do not exist.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT setting has Already been initialized. 
+* @retval #STT_SETTING_ERROR_ENGINE_NOT_FOUND No available stt-engine. Engine should be installed.
+*
+* @see stt_setting_finalize()
+*/
+int stt_setting_initialize(void);
+
+/**
+* @brief finalize stt setting and disconnect to stt-daemon. 
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_initialize()
+*/
+int stt_setting_finalize(void);
+
+/**
+* @brief Retrieve supported engine informations using callback function.
+*
+* @param[in] callback callback function
+* @param[in] user_data User data to be passed to the callback function.
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @post        This function invokes stt_setting_supported_engine_cb() repeatedly for getting engine information. 
+*
+* @see stt_setting_supported_engine_cb()
+*/
+int stt_setting_foreach_supported_engines(stt_setting_supported_engine_cb callback, void* user_data);
+
+/**
+* @brief Get current engine id.
+*
+* @remark If the function is success, @a engine_id must be released with free() by you.
+*
+* @param[out] engine_id engine id.
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_OUT_OF_MEMORY Out of memory.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_set_engine()
+*/
+int stt_setting_get_engine(char** engine_id);
+
+/**
+* @brief Set current engine id.
+*
+* @param[in] engine_id engine id.
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_get_engine()
+*/
+int stt_setting_set_engine(const char* engine_id);
+
+/**
+* @brief Get supported languages of current engine.
+*
+* @param[in] callback callback function.
+* @param[in] user_data User data to be passed to the callback function.
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @post        This function invokes stt_setting_supported_language_cb() repeatedly for getting supported languages. 
+*
+* @see stt_setting_supported_language_cb()
+*/
+int stt_setting_foreach_supported_languages(stt_setting_supported_language_cb callback, void* user_data);
+
+/**
+* @brief Get a default language of current engine.
+*
+* @remark If the function is success, @a language must be released with free() by you.
+*
+* @param[out] language current language
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_OUT_OF_MEMORY Out of memory.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_set_default_language()
+*/
+int stt_setting_get_default_language(char** language);
+
+/**
+* @brief Set a default language of current engine.
+*
+* @param[in] language language
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_get_default_language()
+*/
+int stt_setting_set_default_language(const char* language);
+
+/**
+* @brief Get profanity filter 
+*
+* @param[out] value Value. 
+*
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_set_profanity_filter()
+*/
+int stt_setting_get_profanity_filter(bool* value);
+
+/**
+* @brief Set profanity filter.
+*
+* @param[in] value Value.
+*
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_get_profanity_filter()
+*/
+int stt_setting_set_profanity_filter(const bool value);
+
+/**
+* @brief Get punctuation override.
+*
+* @param[out] value Value. 
+*
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_set_punctuation_override()
+*/
+int stt_setting_get_punctuation_override(bool* value);
+
+/**
+* @brief Set punctuation override.
+*
+* @param[in] value Value.
+*
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_get_punctuation_override()
+*/
+int stt_setting_set_punctuation_override(const bool value);
+
+/**
+* @brief Get silence detection.
+*
+* @param[out] value Value. 
+*
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_set_silence_detection()
+*/
+int stt_setting_get_silence_detection(bool* value);
+
+/**
+* @brief Set silence detection.
+*
+* @param[in] value Value. 
+*
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_get_silence_detection()
+*/
+int stt_setting_set_silence_detection(const bool value);
+
+/**
+* @brief Get setting information of current engine.
+*
+* @param[in] callback callback function
+* @param[in] user_data User data to be passed to the callback function.
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @post        This function invokes stt_setting_engine_setting_cb() repeatedly for getting engine settings. 
+*
+* @see stt_setting_engine_setting_cb()
+*/
+int stt_setting_foreach_engine_settings(stt_setting_engine_setting_cb callback, void* user_data);
+
+/**
+* @brief Set setting information.
+*
+* @param[in] key Key.
+* @param[in] value Value.
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STT_SETTING_ERROR_NONE Success.
+* @retval #STT_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #STT_SETTING_ERROR_INVALID_STATE STT Not initialized. 
+* @retval #STT_SETTING_ERROR_OPERATION_FAILED Operation failure.
+*
+* @see stt_setting_foreach_engine_settings()
+*/
+int stt_setting_set_engine_setting(const char* key, const char* value);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+* @}@}
+*/
+
+#endif /* __STT_SETTING_H_ */
diff --git a/client/stt_setting_dbus.c b/client/stt_setting_dbus.c
new file mode 100644 (file)
index 0000000..1b35c61
--- /dev/null
@@ -0,0 +1,1133 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include "stt_main.h"
+#include "stt_setting_dbus.h"
+
+static DBusConnection* g_conn = NULL;
+
+int stt_setting_dbus_open_connection()
+{
+       if( NULL != g_conn ) {
+               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);
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTC, "Dbus Connection Error (%s)\n", err.message); 
+               dbus_error_free(&err); 
+       }
+
+       if (NULL == g_conn) {
+               SLOG(LOG_ERROR, TAG_STTC, "fail to get dbus connection \n");
+               return STT_SETTING_ERROR_OPERATION_FAILED; 
+       }
+
+       int pid = getpid();
+
+       char service_name[64];
+       memset(service_name, 0, 64);
+       snprintf(service_name, 64, "%s%d", STT_SETTING_SERVICE_NAME, pid);
+
+       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);
+
+       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, "fail dbus_bus_request_name()\n");
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       }
+
+       return 0;
+}
+
+int stt_setting_dbus_close_connection()
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid = getpid();
+
+       char service_name[64];
+       memset(service_name, 0, 64);
+       snprintf(service_name, 64, "%s%d", STT_SETTING_SERVICE_NAME, pid);
+
+       dbus_bus_release_name(g_conn, service_name, &err);
+
+       g_conn = NULL;
+
+       return 0;
+}
+
+int stt_setting_dbus_request_initialize()
+{
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_INITIALIZE);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting initialize : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting initialize");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting initialize : result = %d", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting initialize : result = %d", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_finalilze(void)
+{
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_FINALIZE);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting finalize : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting finalize");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting finallize : result = %d", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting finallize : result = %d", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_get_engine_list(stt_setting_supported_engine_cb callback, void* user_data)
+{
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return -1;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_GET_ENGINE_LIST);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting get engine list : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting get engine list");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               DBusMessageIter args;
+               if (dbus_message_iter_init(result_msg, &args)) {
+                       /* Get result */
+                       if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                               dbus_message_iter_get_basic(&args, &result);
+                               dbus_message_iter_next(&args);
+                       } 
+
+                       if (0 == result) {
+                               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting get engine list : result = %d \n", result);
+
+                               int size ; 
+                               char* temp_id;
+                               char* temp_name;
+                               char* temp_path;
+
+                               /* Get engine count */
+                               if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                                       dbus_message_iter_get_basic(&args, &size);
+                                       dbus_message_iter_next(&args);
+                               }
+
+                               int i=0;
+                               for (i=0 ; i<size ; i++) {
+                                       dbus_message_iter_get_basic(&args, &(temp_id));
+                                       dbus_message_iter_next(&args);
+
+                                       dbus_message_iter_get_basic(&args, &(temp_name));
+                                       dbus_message_iter_next(&args);
+
+                                       dbus_message_iter_get_basic(&args, &(temp_path));
+                                       dbus_message_iter_next(&args);
+
+                                       if (true != callback(temp_id, temp_name, temp_path, user_data)) {
+                                               break;
+                                       }
+                               }
+                       }  else {
+                               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get engine list : result = %d \n", result);
+                       }
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get engine list : invalid message \n");
+               }
+
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get engine list : result message is NULL!! \n");
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_get_engine(char** engine_id)
+{
+       if (NULL == engine_id)  {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_GET_ENGINE);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting get engine : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting get engine ");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+       char* temp;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       }
+
+       if (0 == result) {
+               *engine_id = strdup(temp);
+
+               if (NULL == *engine_id) {
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get engine : Out of memory \n");
+                       result = STT_SETTING_ERROR_OUT_OF_MEMORY;
+               } else {
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting get engine : result(%d), engine id(%s)\n", result, *engine_id);
+               }
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get engine : result(%d) \n", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_set_engine(const char* engine_id)
+{
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_SET_ENGINE);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting set engine : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting set engine : engine id(%s)", engine_id);
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_STRING, &engine_id,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting set engine : result(%d) \n", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting set engine : result(%d) \n", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_get_language_list(stt_setting_supported_language_cb callback, void* user_data)
+{
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_GET_LANG_LIST);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting get language list : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting get language list");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               DBusMessageIter args;
+
+               if (dbus_message_iter_init(result_msg, &args)) {
+                       /* Get result */
+                       if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                               dbus_message_iter_get_basic(&args, &result);
+                               dbus_message_iter_next(&args);
+                       } 
+
+                       if (0 == result) {
+                               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting get language list : result = %d \n", result);
+
+                               int size = 0; 
+                               char* temp_id = NULL;
+                               char* temp_lang = NULL;
+
+                               /* Get engine id */
+                               dbus_message_iter_get_basic(&args, &temp_id);
+                               dbus_message_iter_next(&args);
+
+                               if (NULL != temp_id) {
+                                       /* Get language count */
+                                       if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                                               dbus_message_iter_get_basic(&args, &size);
+                                               dbus_message_iter_next(&args);
+                                       }
+
+                                       int i=0;
+                                       for (i=0 ; i<size ; i++) {
+                                               dbus_message_iter_get_basic(&args, &(temp_lang) );
+                                               dbus_message_iter_next(&args);
+
+                                               if (true != callback(temp_id, temp_lang, user_data)) {
+                                                       break;
+                                               }
+                                       }
+                               } else {
+                                       SLOG(LOG_ERROR, TAG_STTC, "Engine ID is NULL \n");
+                                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+                               }
+
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get language list : result = %d \n", result);
+                       }
+               } 
+
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get language list : Result message is NULL!!");
+       }
+
+       dbus_message_unref(msg);
+       
+       return result;
+}
+
+int stt_setting_dbus_request_get_default_language(char** language)
+{
+       if (NULL == language) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input Parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_GET_DEFAULT_LANG);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting get default language : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting get default language");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+       char* temp_char;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, 
+                       DBUS_TYPE_INT32, &result, 
+                       DBUS_TYPE_STRING, &temp_char,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       }
+
+       if (0 == result) {
+               *language = strdup(temp_char);
+
+               if (NULL == *language) {
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get default language : Out of memory \n");
+                       result = STT_SETTING_ERROR_OUT_OF_MEMORY;
+               } else {
+                       SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting get default language : result(%d), lang(%s)\n", result, *language);
+               }
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get default language : result(%d) \n", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+
+int stt_setting_dbus_request_set_default_language(const char* language)
+{
+       if (NULL == language) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input Parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_SET_DEFAULT_LANG);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting set default language : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting set default language : lang(%s)\n", language);
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_STRING, &language,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, 
+                       DBUS_TYPE_INT32, &result, 
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting set default language : result(%d)", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting set default language : result(%d)", result);
+       }
+
+       dbus_message_unref(msg);
+       
+       return result;
+}
+
+int stt_setting_dbus_request_get_engine_setting(stt_setting_engine_setting_cb callback, void* user_data)
+{
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input Parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_GET_ENGINE_SETTING);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting get engine setting : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting get engine setting");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               DBusMessageIter args;
+
+               if (dbus_message_iter_init(result_msg, &args)) {
+                       /* Get result */
+                       if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                               dbus_message_iter_get_basic(&args, &result);
+                               dbus_message_iter_next(&args);
+                       } 
+
+                       if (0 == result) {
+                               SLOG(LOG_DEBUG, TAG_STTC, "<<<< get engine setting : result = %d \n", result);
+                               int size; 
+                               char* temp_id = NULL;
+                               char* temp_key;
+                               char* temp_value;
+
+                               /* Get engine id */
+                               dbus_message_iter_get_basic(&args, &temp_id);
+                               dbus_message_iter_next(&args);
+
+                               if (NULL != temp_id) {
+                                       /* Get setting count */
+                                       if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
+                                               dbus_message_iter_get_basic(&args, &size);
+                                               dbus_message_iter_next(&args);
+                                       }
+
+                                       int i=0;
+                                       for (i=0 ; i<size ; i++) {
+                                               dbus_message_iter_get_basic(&args, &(temp_key) );
+                                               dbus_message_iter_next(&args);
+
+                                               dbus_message_iter_get_basic(&args, &(temp_value) );
+                                               dbus_message_iter_next(&args);
+
+                                               if (true != callback(temp_id, temp_key, temp_value, user_data)) {
+                                                       break;
+                                               }
+                                       } 
+                               } else {
+                                       SLOG(LOG_ERROR, TAG_STTC, "<<<< get engine setting : result message is invalid \n");
+                                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+                               }
+                       } 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< get engine setting : result message is invalid \n");
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< get engine setting : Result message is NULL!! \n");
+       }       
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_set_engine_setting(const char* key, const char* value)
+{
+       if (NULL == key || NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input Parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_SET_ENGINE_SETTING);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting set engine setting : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting set engine setting : key(%s), value(%s)", key, value);
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_STRING, &key,
+               DBUS_TYPE_STRING, &value, 
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = -1;
+               }
+               dbus_message_unref(result_msg);
+       }
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting set engine setting : result(%d)", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting set engine setting : result(%d)", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_get_profanity_filter(bool* value)
+{
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input Parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_GET_PROFANITY);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting set profanity filter : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting set profanity filter");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INT32, value, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       } 
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting get profanity filter : result(%d), value(%s)", result, *value ? "true":"false");
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get profanity filter : result(%d)", result);
+       }
+       
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_set_profanity_filter(const bool value)
+{
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_SET_PROFANITY);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting set profanity filter : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting set profanity filter : value(%s)", value ? "true":"false");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &value, 
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       } 
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting set profanity filter : result(%d)", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting set profanity filter : result(%d)", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_get_punctuation_override(bool* value)
+{
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input Parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_GET_PUNCTUATION);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting get punctuation override : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting get punctuation override ");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INT32, value, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       } 
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting get punctuation override : result(%d), value(%s)", result, *value ? "true":"false");
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting get punctuation override : result(%d)", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_set_punctuation_override(const bool value )
+{
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_SET_PUNCTUATION);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting set punctuation override : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting set punctuation override : value(%s)", value ? "true":"false");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &value, 
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       } 
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting set punctuation override : result(%d)", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting set punctuation override : result(%d)", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_get_silence_detection(bool* value)
+{
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTC, "Input Parameter is NULL");
+               return STT_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_GET_SILENCE);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting get silence detection : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting get silence detection : value(%s)", value ? "true":"false");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &value, 
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL == result_msg) {
+               dbus_message_unref(msg);
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       }
+
+       dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INT32, value, DBUS_TYPE_INVALID);
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+               dbus_error_free(&err); 
+               result = STT_SETTING_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "Get Silence Detection : result(%d), value(%d) \n", result, *value);
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+int stt_setting_dbus_request_set_silence_detection(const bool value)
+{
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+               STT_SERVER_SERVICE_NAME, 
+               STT_SERVER_SERVICE_OBJECT_PATH, 
+               STT_SERVER_SERVICE_INTERFACE, 
+               STT_SETTING_METHOD_SET_SILENCE);
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting set silence detection : Fail to make message \n"); 
+               return STT_SETTING_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request setting set silence detection : value(%s)", value ? "true":"false");
+       }
+
+       int pid = getpid();
+
+       dbus_message_append_args( msg, 
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &value, 
+               DBUS_TYPE_INVALID);
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       DBusMessage* result_msg;
+       int result = STT_SETTING_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) { 
+                       SLOG(LOG_ERROR, TAG_STTC, "Get arguments error (%s)\n", err.message);
+                       dbus_error_free(&err); 
+                       result = STT_SETTING_ERROR_OPERATION_FAILED;
+               }
+
+               dbus_message_unref(result_msg);
+       } 
+
+       if (0 == result) {
+               SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting set set silence detection : result(%d)", result);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTC, "<<<< setting set set silence detection : result(%d)", result);
+       }
+
+       dbus_message_unref(msg);
+
+       return result;
+}
+
+
+
+
+
+
+
diff --git a/client/stt_setting_dbus.h b/client/stt_setting_dbus.h
new file mode 100644 (file)
index 0000000..4e5d19f
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+#ifndef __STT_SETTING_DBUS_H_
+#define __STT_SETTING_DBUS_H_
+
+#include "stt_setting.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int stt_setting_dbus_open_connection();
+
+int stt_setting_dbus_close_connection();
+
+
+int stt_setting_dbus_request_initialize();
+
+int stt_setting_dbus_request_finalilze();
+
+int stt_setting_dbus_request_get_engine_list(stt_setting_supported_engine_cb callback, void* user_data);
+
+int stt_setting_dbus_request_get_engine(char** engine_id);
+
+int stt_setting_dbus_request_set_engine(const char* engine_id );
+
+int stt_setting_dbus_request_get_language_list(stt_setting_supported_language_cb callback, void* user_data);
+
+int stt_setting_dbus_request_get_default_language(char** language);
+
+int stt_setting_dbus_request_set_default_language(const char* language);
+
+int stt_setting_dbus_request_get_profanity_filter(bool* value);
+
+int stt_setting_dbus_request_set_profanity_filter(const bool value);
+
+int stt_setting_dbus_request_get_punctuation_override(bool* value);
+
+int stt_setting_dbus_request_set_punctuation_override(const bool value);
+
+int stt_setting_dbus_request_get_silence_detection(bool* value);
+
+int stt_setting_dbus_request_set_silence_detection(const bool value);
+
+int stt_setting_dbus_request_get_engine_setting(stt_setting_engine_setting_cb callback, void* user_data);
+
+int stt_setting_dbus_request_set_engine_setting(const char* key, const char* value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STT_SETTING_DBUS_H_ */
diff --git a/common/stt_defs.h b/common/stt_defs.h
new file mode 100644 (file)
index 0000000..3efe94c
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STT_DEFS_H__
+#define __STT_DEFS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************************
+* Definition for Dbus
+*******************************************************************************************/
+
+#define STT_CLIENT_SERVICE_NAME         "com.samsung.voice.sttclient"
+#define STT_CLIENT_SERVICE_OBJECT_PATH  "/com/samsung/voice/sttclient"
+#define STT_CLIENT_SERVICE_INTERFACE    "com.samsung.voice.sttclient"
+
+#define STT_SETTING_SERVICE_NAME        "com.samsung.voice.sttsetting"
+#define STT_SETTING_SERVICE_OBJECT_PATH "/com/samsung/voice/sttsetting"
+#define STT_SETTING_SERVICE_INTERFACE   "com.samsung.voice.sttsetting"
+
+#define STT_SERVER_SERVICE_NAME         "service.connect.sttserver"
+#define STT_SERVER_SERVICE_OBJECT_PATH  "/com/samsung/voice/sttserver"
+#define STT_SERVER_SERVICE_INTERFACE    "com.samsung.voice.sttserver"
+
+
+/******************************************************************************************
+* Message Definition for APIs
+*******************************************************************************************/
+
+#define STT_METHOD_INITIALIZE          "stt_method_initialize"
+#define STT_METHOD_FINALIZE            "stt_method_finalilze"
+#define STT_METHOD_GET_SUPPORT_LANGS   "stt_method_get_support_langs"
+#define STT_METHOD_GET_CURRENT_LANG    "stt_method_get_current_lang"
+#define STT_METHOD_IS_PARTIAL_SUPPORTED        "stt_method_is_partial_result_supported"
+#define STT_METHOD_GET_AUDIO_VOLUME    "stt_method_audio_volume"
+
+#define STT_METHOD_START               "stt_method_start"
+#define STT_METHOD_STOP                        "stt_method_stop"
+#define STT_METHOD_CANCEL              "stt_method_cancel"
+
+#define STT_SIGNAL_RESULT              "stt_signal_result"
+#define STT_SIGNAL_PARTIAL_RESULT      "stt_signal_partial_result"
+#define STT_SIGNAL_STOP                        "stt_signal_stop"
+#define STT_SIGNAL_ERROR               "stt_signal_error"
+
+#define STT_SIGNAL_STOP_BY_DAEMON      "STT_SIGNAL_STOP_BY_DAEMON"
+
+
+/******************************************************************************************
+* Message Definition for Setting
+*******************************************************************************************/
+
+#define STT_SETTING_METHOD_INITIALIZE          "stt_setting_method_initialize"
+#define STT_SETTING_METHOD_FINALIZE            "stt_setting_method_finalilze"
+#define STT_SETTING_METHOD_GET_ENGINE_LIST     "stt_setting_method_get_engine_list"
+#define STT_SETTING_METHOD_GET_ENGINE          "stt_setting_method_get_engine"
+#define STT_SETTING_METHOD_SET_ENGINE          "stt_setting_method_set_engine"
+#define STT_SETTING_METHOD_GET_LANG_LIST       "stt_setting_method_get_lang_list"
+#define STT_SETTING_METHOD_GET_DEFAULT_LANG    "stt_setting_method_get_default_lang"
+#define STT_SETTING_METHOD_SET_DEFAULT_LANG    "stt_setting_method_set_default_lang"
+#define STT_SETTING_METHOD_GET_PROFANITY       "stt_setting_method_get_profanity"
+#define STT_SETTING_METHOD_SET_PROFANITY       "stt_setting_method_set_profanity"
+#define STT_SETTING_METHOD_GET_PUNCTUATION     "stt_setting_method_get_punctuation"
+#define STT_SETTING_METHOD_SET_PUNCTUATION     "stt_setting_method_set_punctuation"
+#define STT_SETTING_METHOD_GET_SILENCE         "stt_setting_method_get_silence_detection"
+#define STT_SETTING_METHOD_SET_SILENCE         "stt_setting_method_set_silence_detection"
+#define STT_SETTING_METHOD_GET_ENGINE_SETTING  "stt_setting_method_get_engine_setting"
+#define STT_SETTING_METHOD_SET_ENGINE_SETTING  "stt_setting_method_set_engine_setting"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STT_DEFS_H__ */
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..f484f8e
--- /dev/null
@@ -0,0 +1,7 @@
+stt (0.1.1) unstable; urgency=low
+
+  * Beta release
+  * Git: tizen2/pkgs/s/stt
+  * Tag: stt_0.1.1
+
+ -- Dongyeol Lee <dy3.lee@samsung.com>  Fri, 17 Feb 2012 13:49:31 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..0277c5e
--- /dev/null
@@ -0,0 +1,25 @@
+Source: stt
+Section: libs
+Priority: standard
+Maintainer: Dongyeol Lee <dy3.lee@samsung.com>, Sehwan Park <sehwan@samsung.com>
+Build-Depends: debhelper (>= 5), libglib2.0-dev, libdbus-1-dev, 
+ libmm-player-dev, libmm-common-dev, libmm-camcorder-dev, dlog-dev, libecore-dev
+Standards-Version: 3.7.2
+
+Package: libstt-dev
+Section: libdevel
+Architecture: any
+Depends: libstt (= ${Source-Version})
+Description: Speech To Text header files for STT development
+
+Package: libstt
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Speech To Text client library and daemon
+
+Package: libstt-dbg
+Section: debug
+Architecture: any
+Depends: libstt (= ${Source-Version})
+Description: Speech To Text library (unstripped)
diff --git a/debian/copyright b/debian/copyright
new file mode 100644 (file)
index 0000000..1c166a2
--- /dev/null
@@ -0,0 +1,10 @@
+Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+       http://www.apache.org/licenses/LICENSE-2.0
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/debian/dirs b/debian/dirs
new file mode 100644 (file)
index 0000000..ca882bb
--- /dev/null
@@ -0,0 +1,2 @@
+usr/bin
+usr/sbin
diff --git a/debian/docs b/debian/docs
new file mode 100644 (file)
index 0000000..93e3f6a
--- /dev/null
@@ -0,0 +1,3 @@
+CMakeCache.txt
+CMakeLists.txt
+
diff --git a/debian/libstt-dev.install.in b/debian/libstt-dev.install.in
new file mode 100644 (file)
index 0000000..823ea70
--- /dev/null
@@ -0,0 +1,5 @@
+@PREFIX@/lib/pkgconfig/stt.pc
+@PREFIX@/lib/pkgconfig/stt-setting.pc
+@PREFIX@/include/stt.h
+@PREFIX@/include/stt_setting.h
+@PREFIX@/include/sttp.h
diff --git a/debian/libstt.install.in b/debian/libstt.install.in
new file mode 100644 (file)
index 0000000..31b3d80
--- /dev/null
@@ -0,0 +1,3 @@
+@PREFIX@/lib/libstt.so*
+@PREFIX@/lib/libstt_setting.so*
+@PREFIX@/bin/stt-daemon
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..4e0ba03
--- /dev/null
@@ -0,0 +1,140 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+CFLAGS += -Wall -g
+CXXFLAGS += -Wall -g
+LDFLAGS += 
+PREFIX += /usr
+DATADIR += /opt
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+       CXXFLAGS += -O0
+else
+       CFLAGS += -O2
+       CXXFLAGS += -O2
+endif
+
+#CFLASGS += -fpie -shared
+#CFLAGS += -fPIC -shared
+#CXXFLAGS += -fpie
+#LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -pie
+#LDFLAGS += -Wl,--rpath=$(PREFIX)/lib  -pie
+
+CFLASGS += -fpie
+CXXFLAGS += -fpie
+#LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -pie
+LDFLAGS += -Wl,--rpath=$(PREFIX)/lib  -pie
+
+configure: configure-stamp
+configure-stamp:
+       dh_testdir
+       # Add here commands to configure the package.
+       CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake . -DCMAKE_INSTALL_PREFIX=${PREFIX}
+
+       touch configure-stamp
+
+
+build: build-stamp
+
+build-stamp: configure-stamp 
+       dh_testdir
+
+       # Add here commands to compile the package.
+       $(MAKE)
+       #docbook-to-man debian/client.sgml > client.1
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               cat $$f > $${f%.in}; \
+               sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
+               sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \
+       done    
+
+       touch $@
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp configure-stamp
+
+       # Add here commands to clean up after the build process.
+       -$(MAKE) clean
+       rm -rf CMakeCache.txt
+       rm -rf CMakeFiles
+       rm -rf cmake_install.cmake
+       rm -rf Makefile
+       rm -rf install_manifest.txt
+       rm -rf client/CMakeCache.txt
+       rm -rf client/CMakeFiles
+       rm -rf client/cmake_install.cmake
+       rm -rf client/Makefile
+       rm -rf client/install_manifest.txt
+       rm -rf client/*.pc
+       rm -rf server/CMakeCache.txt
+       rm -rf server/CMakeFiles
+       rm -rf server/cmake_install.cmake
+       rm -rf server/Makefile
+       rm -rf server/install_manifest.txt              
+       rm -rf server/*.pc
+       rm -rf *.pc
+       rm -rf *.so
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               rm -f $${f%.in}; \
+       done
+
+       dh_clean 
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k 
+       dh_installdirs
+
+       # Add here commands to install the package into debian/client.
+       $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       dh_installchangelogs 
+       dh_installdocs
+       dh_installexamples
+       dh_install --sourcedir=debian/tmp
+#      dh_installmenu
+#      dh_installdebconf       
+#      dh_installlogrotate
+#      dh_installemacsen
+#      dh_installpam
+#      dh_installmime
+#      dh_python
+#      dh_installinit
+#      dh_installcron
+#      dh_installinfo
+       dh_installman
+       dh_link
+       dh_strip --dbg-package=libstt-dbg
+       dh_compress
+       dh_fixperms
+#      dh_perl
+#      dh_makeshlibs
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/packaging/stt.spec b/packaging/stt.spec
new file mode 100644 (file)
index 0000000..c109a22
--- /dev/null
@@ -0,0 +1,73 @@
+Name:       stt
+Summary:    Speech To Text client library and daemon
+Version:    0.1.1
+Release:    1
+Group:      libs
+License:    Samsung
+Source0:    stt-0.1.1.tar.gz
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(dbus-1)
+BuildRequires:  pkgconfig(ecore)
+BuildRequires:  pkgconfig(openssl)
+BuildRequires:  pkgconfig(mm-player)
+BuildRequires:  pkgconfig(mm-common)
+BuildRequires:  pkgconfig(mm-sound)
+BuildRequires:  pkgconfig(mm-camcorder)
+BuildRequires:  pkgconfig(dnet)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(vconf)
+
+BuildRequires:  cmake
+
+%description
+Speech To Text client library and daemon.
+
+
+%package devel
+Summary:    Speech To Text header files for STT development
+Group:      libdevel
+Requires:   %{name} = %{version}-%{release}
+
+%description devel
+Speech To Text header files for STT development.
+
+
+%prep
+%setup -q -n %{name}-%{version}
+
+
+%build
+cmake . -DCMAKE_INSTALL_PREFIX=/usr
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+
+
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+
+
+
+%files
+%defattr(-,root,root,-)
+%{_libdir}/libstt.so
+%{_libdir}/libstt_setting.so
+%{_bindir}/stt-daemon
+
+
+%files devel
+%defattr(-,root,root,-)
+%{_libdir}/pkgconfig/stt.pc
+%{_libdir}/pkgconfig/stt-setting.pc
+%{_includedir}/stt.h
+%{_includedir}/stt_setting.h
+%{_includedir}/sttp.h
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
new file mode 100644 (file)
index 0000000..03cbdb5
--- /dev/null
@@ -0,0 +1,50 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(stt-daemon)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "${PREFIX}")
+SET(LIBDIR "${PREFIX}/lib")
+SET(INCLUDEDIR "${PREFIX}/include")
+SET(VERSION 0.0.1)
+
+SET(SRCS
+       sttd_config.c
+       sttd_client_data.c
+       sttd_engine_agent.c
+       sttd_server.c
+       sttd_recorder.c
+       sttd_network.c
+       sttd_dbus_server.c
+       sttd_dbus.c
+       sttd_main.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${INCLUDEDIR})
+INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/../common")
+
+## Dependent packages ##
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED 
+       glib-2.0 dbus-1 
+       vconf dlog mm-player mm-common mm-camcorder openssl
+)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_C_FLAGS_RELEASE "-O2")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wall,--as-needed")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+
+## Executable ##
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS})
+
+## Install
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/sttp.h DESTINATION include)
diff --git a/server/sttd_client_data.c b/server/sttd_client_data.c
new file mode 100644 (file)
index 0000000..d61931a
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include "sttd_main.h"
+#include "sttd_client_data.h"
+
+/* Client list */
+static GList *g_client_list = NULL;
+
+int client_show_list()
+{
+       GList *iter = NULL;
+       client_info_s *data = NULL;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "----- client list"); 
+
+       if (g_list_length(g_client_list) > 0) {
+               /* Get a first item */
+               iter = g_list_first(g_client_list);
+
+               int i = 1;      
+               while (NULL != iter) {
+                       /*Get handle data from list*/
+                       data = iter->data;
+
+                       SLOG(LOG_DEBUG, TAG_STTD, "[%dth] uid(%d), state(%d)", i, data->uid, data->state); 
+                       
+                       /*Get next item*/
+                       iter = g_list_next(iter);
+                       i++;
+               }
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "No Client"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "-----"); 
+
+       return 0;
+}
+
+GList* sttd_client_get_item(const int uid)
+{
+       GList *iter = NULL;
+       client_info_s *data = NULL;
+
+       if (0 < g_list_length(g_client_list)) {
+               iter = g_list_first(g_client_list);
+
+               while (NULL != iter) {
+                       /* Get handle data from list */
+                       data = iter->data;
+
+                       if (uid == data->uid) 
+                               return iter;
+                       
+                       iter = g_list_next(iter);
+               }
+       }
+
+       return NULL;
+}
+
+int sttd_client_add(const int pid, const int uid)
+{
+       /*Check uid is duplicated*/
+       GList *tmp = NULL;
+       tmp = sttd_client_get_item(uid);
+       
+       if (NULL != tmp) {
+               SLOG(LOG_WARN, TAG_STTD, "[Client Data] Client uid is already registered"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       client_info_s *info = (client_info_s*)g_malloc0(sizeof(client_info_s));
+
+       info->pid = pid;
+       info->uid = uid;
+       info->state = APP_STATE_READY;
+
+       /* Add item to global list */
+       g_client_list = g_list_append(g_client_list, info);
+       
+       if (NULL == g_client_list) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to add new client"); 
+               return -1;
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data SUCCESS] Add new client"); 
+       }
+
+#ifdef CLIENT_DATA_DEBUG
+       client_show_list();
+#endif 
+
+       return 0;
+}
+
+int sttd_client_delete(const int uid)
+{
+       GList *tmp = NULL;
+       client_info_s* hnd = NULL;
+
+       /*Get handle*/
+       tmp = sttd_client_get_item(uid);
+       if (NULL == tmp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /*Free client structure*/
+       hnd = tmp->data;
+       if (NULL != hnd) {
+               g_free(hnd);
+       }
+
+       /*Remove handle from list*/
+       g_client_list = g_list_remove_link(g_client_list, tmp);
+
+#ifdef CLIENT_DATA_DEBUG
+       client_show_list();
+#endif 
+
+       return 0;
+}
+
+int sttd_client_get_state(const int uid, app_state_e* state)
+{
+       GList *tmp = NULL;
+       client_info_s* hnd = NULL;
+
+       tmp = sttd_client_get_item(uid);
+       if (NULL == tmp) {
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       hnd = tmp->data;
+       *state = hnd->state;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Client Data] Get state : uid(%d), state(%d)", uid, *state);
+
+       return 0;
+}
+
+int sttd_client_set_state(const int uid, const app_state_e state)
+{
+       GList *tmp = NULL;
+       client_info_s* hnd = NULL;
+
+       tmp = sttd_client_get_item(uid);
+       if (NULL == tmp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       hnd = tmp->data;
+       hnd->state = state ;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Client Data SUCCESS] Set state : uid(%d), state(%d)", uid, state);
+
+       return 0;
+}
+
+int sttd_client_get_ref_count()
+{
+       return g_list_length(g_client_list);
+}
+
+int sttd_client_get_pid(const int uid)
+{
+       GList *tmp = NULL;
+       client_info_s* hnd = NULL;
+
+       tmp = sttd_client_get_item(uid);
+       if (NULL == tmp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] sttd_client_get_pid : uid(%d) is not found", uid); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       hnd = tmp->data;
+
+       return hnd->pid;
+}
+
+int sttd_client_get_current_recording()
+{
+       GList *iter = NULL;
+       client_info_s *data = NULL;
+
+       if (0 < g_list_length(g_client_list)) {
+               iter = g_list_first(g_client_list);
+
+               while (NULL != iter) {
+                       /* Get handle data from list */
+                       data = iter->data;
+
+                       if (APP_STATE_RECORDING == data->state) 
+                               return data->uid;
+
+                       iter = g_list_next(iter);
+               }
+       }
+
+       return -1;
+}
+
+int sttd_client_get_current_thinking()
+{
+       GList *iter = NULL;
+       client_info_s *data = NULL;
+
+       if (0 < g_list_length(g_client_list)) {
+               iter = g_list_first(g_client_list);
+
+               while (NULL != iter) {
+                       /* Get handle data from list */
+                       data = iter->data;
+
+                       if (APP_STATE_PROCESSING == data->state) 
+                               return data->uid;
+
+                       iter = g_list_next(iter);
+               }
+       }
+
+       return -1;
+}
diff --git a/server/sttd_client_data.h b/server/sttd_client_data.h
new file mode 100644 (file)
index 0000000..5a80c84
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STTD_CLIENT_DATA_H_
+#define __STTD_CLIENT_DATA_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+       APP_STATE_READY         = 0,
+       APP_STATE_RECORDING     = 1,
+       APP_STATE_PROCESSING    = 2
+}app_state_e;
+
+typedef struct {
+       int     pid;
+       int     uid;
+       app_state_e     state;
+} client_info_s;
+
+int sttd_client_add(const int pid, const int uid);
+
+int sttd_client_delete(const int uid);
+
+int sttd_client_get_state(const int uid, app_state_e* state);
+
+int sttd_client_set_state(const int uid, const app_state_e state);
+
+int sttd_client_get_ref_count();
+
+int sttd_client_get_pid(const int uid);
+
+int sttd_client_get_current_recording();
+
+int sttd_client_get_current_thinking();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STTD_CLIENT_DATA_H_ */
+
diff --git a/server/sttd_config.c b/server/sttd_config.c
new file mode 100644 (file)
index 0000000..de21d3c
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include <vconf.h>
+
+#include "sttd_main.h"
+#include "sttd_config.h"
+
+
+/*
+* stt-daemon config
+*/
+
+int sttd_config_get_char_type(const char* key, char** value)
+{
+       if (NULL == key || NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
+               return STTD_ERROR_INVALID_PARAMETER;
+       } 
+
+       *value = vconf_get_str(key);
+       if (NULL == *value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get char type from config : key(%s)", key);
+               return -1;
+       }
+
+       return 0;
+}
+
+int sttd_config_set_char_type(const char* key, const char* value)
+{
+       if (NULL == key || NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
+               return STTD_ERROR_INVALID_PARAMETER;
+       } 
+
+       if (0 != vconf_set_str(key, value)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to set char type"); 
+               return -1;
+       }
+
+       return 0;
+}
+
+int sttd_config_get_bool_type(const char* key, bool* value)
+{
+       if (NULL == key || NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
+               return STTD_ERROR_INVALID_PARAMETER;
+       } 
+
+       int result ;
+       if (0 != vconf_get_int(key, &result)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get bool type config : key(%s)", key);
+               return -1;
+       }
+
+       *value = (bool) result;
+
+       return 0;
+}
+
+int sttd_config_set_bool_type(const char* key, const bool value)
+{
+       if (NULL == key) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Input parameter is NULL");
+               return STTD_ERROR_INVALID_PARAMETER;
+       } 
+
+       int result = (int)value;
+       if (0 != vconf_set_int(key, result)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get bool type config : key(%s)", key);
+               return -1;
+       }
+
+       return 0;
+}
+
+/*
+* plug-in daemon interface
+*/
+
+int __make_key_for_engine(const char* engine_id, const char* key, char** out_key)
+{
+       int key_size = strlen(STTD_CONFIG_PREFIX) + strlen(engine_id) + strlen(key) + 2; /* 2 means both '/' and '\0'*/
+
+       *out_key = (char*) malloc( sizeof(char) * key_size);
+
+       snprintf(*out_key, key_size, "%s%s/%s", STTD_CONFIG_PREFIX, engine_id, key );
+
+       return 0;
+}
+
+int sttd_config_set_persistent_data(const char* engine_id, const char* key, const char* value)
+{
+       if (NULL == engine_id || NULL == key || NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] BAD Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       char* vconf_key = NULL;
+       if (0 != __make_key_for_engine(engine_id, key, &vconf_key)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail __make_key_for_engine()");
+               return -1;
+       }
+
+       if (NULL == vconf_key)          
+               return -1;
+
+       if (0 != vconf_set_str(vconf_key, value)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to set key, value");
+
+               if (vconf_key != NULL)  
+                       free(vconf_key);
+
+               return -1;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[STTD Config DEBUG] sttd_config_set_persistent_data : key(%s), value(%s)", vconf_key, value);
+
+       if (NULL != vconf_key)  
+               free(vconf_key);
+
+       return 0;
+}
+
+int sttd_config_get_persistent_data(const char* engine_id, const char* key, char** value)
+{
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] BAD Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       char* vconf_key = NULL;
+
+       if (0 != __make_key_for_engine(engine_id, key, &vconf_key)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail __make_key_for_engine()");
+               return -1;
+       }
+
+       if (NULL == vconf_key)
+               return -1;
+
+       char* temp;
+       temp = vconf_get_str(vconf_key);
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to get value");
+
+               if(vconf_key != NULL)   
+                       free(vconf_key);
+
+               return -1;
+       }
+
+       *value = g_strdup(temp);
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[STTD Config DEBUG] sttd_config_get_persistent_data : key(%s), value(%s)", vconf_key, *value);
+
+       if (vconf_key != NULL)  free(vconf_key);
+       if (temp != NULL)       free(temp);
+
+       return 0;
+}
+
+int sttd_config_remove_persistent_data(const char* engine_id, const char* key)
+{
+       if (NULL == engine_id || NULL == key) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] BAD Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       char* vconf_key = NULL;
+       if (0 != __make_key_for_engine(engine_id, key, &vconf_key)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail __make_key_for_engine()");
+               return -1;
+       }
+
+       if (NULL == vconf_key)          
+               return -1;
+
+       if (0 != vconf_unset(vconf_key)) {      
+               SLOG(LOG_ERROR, TAG_STTD, "[STTD Config ERROR] Fail to remove key");
+
+               if(vconf_key != NULL)   
+                       free(vconf_key);
+
+               return -1;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[STTD Config DEBUG] sttd_config_remove_persistent_data : key(%s)", vconf_key);
+
+       if( NULL != vconf_key )         
+               free(vconf_key);
+
+       return 0;
+}
+
+
diff --git a/server/sttd_config.h b/server/sttd_config.h
new file mode 100644 (file)
index 0000000..d87d290
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STTD_CONFIG_H_
+#define __STTD_CONFIG_H_
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define STTD_CONFIG_PREFIX "db/sttd/"
+
+#define CONFIG_KEY_DEFAULT_ENGINE_ID   STTD_CONFIG_PREFIX"engine"
+#define CONFIG_KEY_DEFAULT_LANGUAGE    STTD_CONFIG_PREFIX"language"
+#define CONFIG_KEY_PROFANITY_FILTER    STTD_CONFIG_PREFIX"profanity"
+#define CONFIG_KEY_PUNCTUATION_OVERRIDE        STTD_CONFIG_PREFIX"punctuation"
+#define CONFIG_KEY_SILENCE_DETECTION   STTD_CONFIG_PREFIX"silence"
+
+
+/*
+* stt-daemon config
+*/
+
+int sttd_config_get_char_type(const char* key, char** value);
+
+int sttd_config_set_char_type(const char* key, const char* value);
+
+int sttd_config_get_bool_type(const char* key, bool* value);
+
+int sttd_config_set_bool_type(const char* key, const bool value);
+
+
+/*
+* interface for engine plug-in
+*/
+
+int sttd_config_set_persistent_data(const char* engine_id, const char* key, const char* value);
+
+int sttd_config_get_persistent_data(const char* engine_id, const char* key, char** value);
+
+int sttd_config_remove_persistent_data(const char* engine_id, const char* key);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STTD_CONFIG_H_ */
diff --git a/server/sttd_dbus.c b/server/sttd_dbus.c
new file mode 100644 (file)
index 0000000..9c6db16
--- /dev/null
@@ -0,0 +1,482 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include <dbus/dbus.h>
+#include <Ecore.h>
+
+#include "sttd_main.h"
+#include "sttd_dbus.h"
+#include "sttd_client_data.h"
+#include "sttd_dbus_server.h"
+#include "stt_defs.h"
+
+static DBusConnection* g_conn;
+
+int sttdc_send_result(int uid, const char* type, 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;
+       }
+
+       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 result signal : uid(%d), type(%s), result count(%d)", uid, type, data_count);
+
+       msg = dbus_message_new_signal(
+               STT_CLIENT_SERVICE_OBJECT_PATH,  
+               target_if_name,                  
+               STT_SIGNAL_RESULT );              
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
+               return -1;
+       }
+
+       DBusMessageIter args;
+       dbus_message_iter_init_append(msg, &args);
+
+       /* Append uid & type */
+       dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &uid);
+
+       char* msg_temp;
+       if (NULL == type) {
+               msg_temp = strdup("None");
+               dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(msg_temp));
+               SLOG(LOG_WARN, TAG_STTD, "[Dbus] result type is NULL"); 
+               free(msg_temp);
+       } else {
+               dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(type));
+               SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result type(%s)", type ); 
+       }       
+
+       /* Append result msg */
+       if (NULL == result_msg) {
+               msg_temp = strdup("None");
+               dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &msg_temp);
+               SLOG(LOG_WARN, TAG_STTD, "[Dbus] result message is NULL"); 
+               free(msg_temp);
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result message(%s)", result_msg ); 
+               dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(result_msg));
+       }
+       
+       /* Append result size */
+       if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(data_count))) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus] response message : Fail to append result size"); 
+               return -1;
+       }
+
+       int i;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result size (%d)", data_count); 
+       for (i=0 ; i<data_count ; i++) {
+               if (NULL != data[i]) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result (%d, %s)", i, data[i] ); 
+
+                       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;
+                       }
+               } else {
+                       int reason = (int)STTD_ERROR_OPERATION_FAILED;
+
+                       if (0 != sttdc_send_error_signal(uid, reason, "Fail to get recognition result from engine")) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send error info. Remove client data"); 
+
+                               /* clean client data */
+                               sttd_client_delete(uid);
+                       }
+
+                       SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Result from engine is NULL(%d) %s", i); 
+
+                       return -1;
+               }
+       }
+       
+       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;
+}
+
+int sttdc_send_partial_result(int uid, const char* data)
+{
+       int pid = sttd_client_get_pid(uid);
+
+       if (0 > pid) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid" );
+               return -1;
+       }
+
+       if (NULL == data) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Input data is NULL" );
+               return -1;
+       }
+
+       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 result signal : uid(%d), result(%s)", uid, data);
+
+       msg = dbus_message_new_signal(
+               STT_CLIENT_SERVICE_OBJECT_PATH,  
+               target_if_name,                  
+               STT_SIGNAL_PARTIAL_RESULT );              
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message"); 
+               return -1;
+       }
+
+       DBusMessageIter args;
+       dbus_message_iter_init_append(msg, &args);
+
+       /* Append uid & type */
+       dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &uid);
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Partial result (%s)", data ); 
+
+       if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, data)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus] response message : Fail to append result data");
+               return -1;
+       }
+       
+       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;
+}
+
+int sttdc_send_error_signal(int uid, int reason, char *err_msg)
+{
+       if (NULL == err_msg) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int pid = sttd_client_get_pid(uid);
+
+       if (0 > pid) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid" );
+               return -1;
+       }
+
+       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);
+       msg = dbus_message_new_signal(
+               STT_CLIENT_SERVICE_OBJECT_PATH,  /* object name of the signal */
+               target_if_name,                  /* interface name of the signal */
+               STT_SIGNAL_ERROR );              /* name of the signal */
+
+       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, &reason, 
+               DBUS_TYPE_STRING, &err_msg,
+               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;
+}
+
+int sttd_send_stop(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;
+       }
+
+       char target_if_name[64];
+       snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] send %s signal : ifname(%s), uid(%d)", signal, target_if_name, uid);
+
+       DBusMessage* msg;
+
+       /* create a signal & check for errors */
+       msg = dbus_message_new_signal(
+               STT_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
+               target_if_name,                 /* interface name of the signal */
+               STT_SIGNAL_STOP );              /* name of the signal */
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create stop message"); 
+               return -1;
+       }
+
+       dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       /* send the message and flush the connection */
+       if (!dbus_connection_send(g_conn, msg, NULL)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Out Of Memory!"); 
+               return -1;
+       }
+
+       dbus_connection_flush(g_conn);
+       dbus_message_unref(msg);
+
+       return 0;
+}
+
+
+static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
+{
+       DBusConnection* conn = (DBusConnection*)data;
+       DBusMessage* msg = NULL;
+
+       if (NULL == conn)
+               return ECORE_CALLBACK_RENEW;
+
+       dbus_connection_read_write_dispatch(conn, 50);
+       
+       msg = dbus_connection_pop_message(conn);
+
+       /* loop again if we haven't read a message */
+       if (NULL == msg) { 
+               return ECORE_CALLBACK_RENEW;
+       }
+
+
+       /* daemon internal event */
+       if (dbus_message_is_signal(msg, STT_SERVER_SERVICE_INTERFACE, STT_SIGNAL_STOP_BY_DAEMON))
+               sttd_dbus_server_stop_by_daemon(msg);
+
+       /* client event */
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_INITIALIZE))
+               sttd_dbus_server_initialize(conn, msg);
+       
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_FINALIZE))
+               sttd_dbus_server_finalize(conn, 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);
+
+       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);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_IS_PARTIAL_SUPPORTED))
+               sttd_dbus_server_is_partial_result_supported(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_GET_AUDIO_VOLUME))
+               sttd_dbus_server_get_audio_volume(conn, 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_CANCEL)) 
+               sttd_dbus_server_cancel(conn, msg);
+
+
+       /* setting event */
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_INITIALIZE))
+               sttd_dbus_server_setting_initialize(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_FINALIZE))
+               sttd_dbus_server_setting_finalize(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_ENGINE_LIST))
+               sttd_dbus_server_setting_get_engine_list(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_ENGINE))
+               sttd_dbus_server_setting_get_engine(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_ENGINE))
+               sttd_dbus_server_setting_set_engine(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_LANG_LIST))
+               sttd_dbus_server_setting_get_language_list(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_DEFAULT_LANG))
+               sttd_dbus_server_setting_get_default_language(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_DEFAULT_LANG))
+               sttd_dbus_server_setting_set_default_language(conn, msg);
+
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_PROFANITY))
+               sttd_dbus_server_setting_get_profanity_filter(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_PROFANITY))
+               sttd_dbus_server_setting_set_profanity_filter(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_PUNCTUATION))
+               sttd_dbus_server_setting_get_punctuation_override(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_PUNCTUATION))
+               sttd_dbus_server_setting_set_punctuation_override(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_SILENCE))
+               sttd_dbus_server_setting_get_silence_detection(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_SILENCE))
+               sttd_dbus_server_setting_set_silence_detection(conn, msg);
+
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_ENGINE_SETTING))
+               sttd_dbus_server_setting_get_engine_setting(conn, msg);
+
+       else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_ENGINE_SETTING))
+               sttd_dbus_server_setting_set_engine_setting(conn, msg);
+
+       else 
+               return ECORE_CALLBACK_RENEW; 
+
+       return ECORE_CALLBACK_RENEW;
+}
+
+int sttd_dbus_open_connection()
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int ret;
+
+       /* connect to the bus and check for errors */
+       g_conn = 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) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get dbus connection" );
+               return -1;
+       }
+
+       /* 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);
+
+       if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
+               printf("Fail to be primary owner in dbus request.");
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to be primary owner");
+               return -1;
+       }
+
+       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;
+       }
+
+       /* add a rule for getting signal */
+       char rule[128];
+       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);
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_add_match() : %s", err.message);
+               return -1; 
+       }
+
+       int fd = 0;
+       dbus_connection_get_unix_fd(g_conn, &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) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get fd handler");
+               return -1;
+       }
+
+       return 0;
+}
+
+int sttd_dbus_close_connection()
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       dbus_bus_release_name (g_conn, 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;
+       }
+
+       return 0;
+}
+
+int sttd_send_stop_recognition_by_daemon(int uid)
+{
+       DBusMessage* msg;
+
+       msg = dbus_message_new_signal(
+               STT_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
+               STT_SERVER_SERVICE_INTERFACE,   /* interface name of the signal */
+               STT_SIGNAL_STOP_BY_DAEMON );    /* name of the signal */
+
+       if (NULL == msg) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] >>>> Fail to make message for 'stop by daemon'"); 
+               return -1;
+       } 
+
+       dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);        
+
+       if (!dbus_connection_send(g_conn, msg, NULL)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message for 'stop by daemon'"); 
+       }
+
+       dbus_connection_flush(g_conn);
+       dbus_message_unref(msg);
+
+       return 0;
+}
diff --git a/server/sttd_dbus.h b/server/sttd_dbus.h
new file mode 100644 (file)
index 0000000..37dbb13
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STTD_DBUS_h__
+#define __STTD_DBUS_h__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int sttd_dbus_open_connection();
+
+int sttd_dbus_close_connection();
+
+
+int sttdc_send_result(int uid, const char* type, const char** data, int data_count, const char* result_msg);
+
+int sttdc_send_partial_result(int uid, const char* data);
+
+int sttdc_send_error_signal(int uid, int reason, char *err_msg);
+
+int sttd_send_stop(int uid);
+
+int sttd_send_stop_recognition_by_daemon(int uid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STTD_DBUS_h__ */
diff --git a/server/sttd_dbus_server.c b/server/sttd_dbus_server.c
new file mode 100644 (file)
index 0000000..cf8b6cb
--- /dev/null
@@ -0,0 +1,1527 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include "sttd_main.h"
+#include "sttd_dbus.h"
+#include "sttd_dbus_server.h"
+#include "sttd_server.h"
+#include "sttd_client_data.h"
+#include "stt_defs.h"
+
+/*
+* Dbus Client-Daemon Server
+*/ 
+
+int sttd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       int uid;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &uid,
+               DBUS_TYPE_INVALID);
+       
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Initialize");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt initialize : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt initialize : pid(%d), uid(%d)", pid , uid); 
+               ret =  sttd_server_initialize(pid, uid);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+       dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Finalize");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt finalize : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt finalize : uid(%d)", uid); 
+               ret =  sttd_server_finalize(uid);
+       }
+
+       DBusMessage* reply;
+       
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_get_support_lang(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+       GList* lang_list = NULL;
+
+       dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Get supported langs");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt supported langs : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt supported langs : uid(%d)", uid); 
+               ret = sttd_server_get_supported_languages(uid, &lang_list);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               DBusMessageIter args;
+               dbus_message_iter_init_append(reply, &args);
+
+               /* Append result*/
+               dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(ret));
+
+               if (0 == ret) {
+                       /* Append language size */
+                       int size = g_list_length(lang_list);
+
+                       if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to append type"); 
+                               ret = STTD_ERROR_OPERATION_FAILED;
+                       } else {
+                               GList *iter = NULL;
+                               char* temp_lang;
+
+                               iter = g_list_first(lang_list);
+
+                               while (NULL != iter) {
+                                       temp_lang = iter->data;
+
+                                       dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(temp_lang) );
+                                       
+                                       if (NULL != temp_lang)
+                                               free(temp_lang);
+                                       
+                                       lang_list = g_list_remove_link(lang_list, iter);
+
+                                       iter = g_list_first(lang_list);
+                               } 
+                       }
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+               
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_get_default_lang(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+       char* lang;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Get default langs");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt get default lang : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt get default lang : uid(%d)", uid); 
+               ret = sttd_server_get_current_langauage(uid, &lang);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       /* Append result and language */
+                       dbus_message_append_args( reply, 
+                               DBUS_TYPE_INT32, &ret,
+                               DBUS_TYPE_STRING, &lang,
+                               DBUS_TYPE_INVALID);
+
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+
+                       if (NULL != lang) {
+                               g_free(lang);
+                       }
+               } else {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_is_partial_result_supported(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+       int support = -1;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT is partial result supported");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt is partial result supported : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt is partial result supported : uid(%d)", uid); 
+               ret = sttd_server_is_partial_result_supported(uid, &support);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               /* Append result and language */
+               dbus_message_append_args(reply, 
+                       DBUS_TYPE_INT32, &ret,
+                       DBUS_TYPE_INT32, &support,
+                       DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d), Support(%s)", ret, support ? "true" : "false"); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_get_audio_volume(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+       float current_volume = 0.0;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Get audio volume");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt get audio volume : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt get audio volume : uid(%d)", uid); 
+               ret =  sttd_server_get_audio_volume(uid, &current_volume);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               double temp = (double)current_volume;
+
+               dbus_message_append_args(reply, 
+                       DBUS_TYPE_INT32, &ret, 
+                       DBUS_TYPE_DOUBLE, &temp, 
+                       DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d), volume - double(%f), float(%f)", ret, temp, current_volume); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_start(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+       char* lang;
+       char* type;
+       int profanity;
+       int punctuation;
+       int silence;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err, 
+               DBUS_TYPE_INT32, &uid, 
+               DBUS_TYPE_STRING, &lang,   
+               DBUS_TYPE_STRING, &type,
+               DBUS_TYPE_INT32, &profanity,
+               DBUS_TYPE_INT32, &punctuation,
+               DBUS_TYPE_INT32, &silence,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Start");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt start : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt start : uid(%d), lang(%s), type(%s), profanity(%d), punctuation(%d), silence(%d)"
+                                       , uid, lang, type, profanity, punctuation, silence); 
+               ret = sttd_server_start(uid, lang, type, profanity, punctuation, silence);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+       dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Stop");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt stop : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt stop : uid(%d)", uid); 
+               ret = sttd_server_stop(uid);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_cancel(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+       dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Cancel");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt cancel : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt cancel : uid(%d)", uid); 
+               ret = sttd_server_cancel(uid);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+
+/*
+* Dbus Setting-Daemon Server
+*/ 
+
+int sttd_dbus_server_setting_initialize(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Initialize");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting initializie : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting initializie : uid(%d)", pid); 
+               ret =  sttd_server_setting_initialize(pid);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_finalize(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err, 
+               DBUS_TYPE_INT32, &pid, 
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Finalize");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting finalize : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting finalize : uid(%d)", pid); 
+               ret =  sttd_server_setting_finalize(pid);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_get_engine_list(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       GList* engine_list = NULL;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err, 
+               DBUS_TYPE_INT32, &pid, 
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Get Engine List");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting get engine list : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting get engine list : uid(%d)", pid); 
+               ret = sttd_server_setting_get_engine_list(pid, &engine_list);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               DBusMessageIter args;
+
+               dbus_message_iter_init_append(reply, &args);
+
+               /* Append result*/
+               dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(ret) );
+
+               if (0 == ret) {
+                       /* Append size */
+                       int size = g_list_length(engine_list);
+                       if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
+                               ret = STTD_ERROR_OPERATION_FAILED;
+                       } else {
+                               GList *iter = NULL;
+                               engine_s* engine;
+
+                               iter = g_list_first(engine_list);
+
+                               while (NULL != iter) {
+                                       engine = iter->data;
+                                       SLOG(LOG_DEBUG, TAG_STTD, "engine id : %s, engine name : %s, ug_name, : %s", 
+                                               engine->engine_id, engine->engine_name, engine->ug_name);
+
+                                       dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine->engine_id) );
+                                       dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine->engine_name) );
+                                       dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine->ug_name) );
+
+                                       if (NULL != engine->engine_id)
+                                               g_free(engine->engine_id);
+                                       if (NULL != engine->engine_name);
+                                               g_free(engine->engine_name);
+                                       if (NULL != engine->ug_name);
+                                               g_free(engine->ug_name);
+                                       if (NULL != engine);
+                                               g_free(engine);
+
+                                       engine_list = g_list_remove_link(engine_list, iter);
+
+                                       iter = g_list_first(engine_list);
+                               } 
+                       }
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_get_engine(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       char* engine_id;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Get Engine");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting get engine : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting get engine : uid(%d)", pid); 
+               ret = sttd_server_setting_get_engine(pid, &engine_id);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_STRING, &engine_id, DBUS_TYPE_INVALID);
+
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d), Engine id(%s)", ret, engine_id); 
+                       g_free(engine_id);              
+               } else {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_set_engine(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       char* engine_id;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_STRING, &engine_id,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Set Engine");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting set engine : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting set engine : uid(%d)", pid); 
+               ret = sttd_server_setting_set_engine(pid, engine_id);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d) ", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d) ", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_get_language_list(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       GList* lang_list = NULL;
+       char* engine_id;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Get Language List");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting get language list : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting get language list : uid(%d)", pid); 
+               ret = sttd_server_setting_get_lang_list(pid, &engine_id, &lang_list);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               DBusMessageIter args;
+               dbus_message_iter_init_append(reply, &args);
+
+               /* Append result*/
+               dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &ret);
+
+               if (0 == ret) {
+                       dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine_id));
+
+                       int size = g_list_length(lang_list);
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT DEBUG] Count(%d) ", size); 
+
+                       /* Append size */
+                       if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
+                               ret = STTD_ERROR_OPERATION_FAILED;
+                               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d) ", ret); 
+                       } else {
+                               GList *iter = NULL;
+                               char* temp_lang;
+
+                               iter = g_list_first(lang_list);
+
+                               while (NULL != iter) {
+                                       temp_lang = iter->data;
+
+                                       dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(temp_lang) );
+                                       
+                                       if (NULL != temp_lang)
+                                               free(temp_lang);
+                                       
+                                       lang_list = g_list_remove_link(lang_list, iter);
+
+                                       iter = g_list_first(lang_list);
+                               } 
+                               SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d) ", ret); 
+                       }
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d) ", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_get_default_language(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       char* language;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Get Default Language");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting get default language : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting get default language : uid(%d)", pid); 
+               ret = sttd_server_setting_get_default_language(pid, &language);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_STRING, &language, DBUS_TYPE_INVALID);
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d), Default Language(%s)", ret, language); 
+                       free(language);         
+               } else {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_set_default_language(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       char* language;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_STRING, &language,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Set Default Language");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting set default language : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting set default language : uid(%d), language(%s)", pid, language); 
+               ret = sttd_server_setting_set_default_language(pid, language);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_get_profanity_filter(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       bool value;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Get Profanity Filter");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting get profanity filter : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting get profanity filter : uid(%d)", pid); 
+               ret = sttd_server_setting_get_profanity_filter(pid, &value);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INT32, &value, DBUS_TYPE_INVALID);
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d) , value(%s)", ret, value ? "true":"false"); 
+               } else {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_set_profanity_filter(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       bool value;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &value,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Set Profanity Filter");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting set profanity filter : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting set profanity filter : uid(%d), value(%s)", pid, value ? "true":"false"); 
+               ret =  sttd_server_setting_set_profanity_filter(pid, (bool)value);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_get_punctuation_override(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       bool value;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Get Punctuation Override");
+       
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting get punctuation override : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting get punctuation override : uid(%d)", pid); 
+               ret =  sttd_server_setting_get_punctuation_override(pid, &value);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INT32, &value, DBUS_TYPE_INVALID);
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d) , value(%s)", ret, value ? "true":"false"); 
+               } else {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+                       return -1;
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_set_punctuation_override(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       bool value;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &value,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Set Profanity Filter");
+       
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting set punctuation override : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting set punctuation override : uid(%d), value(%s)", pid, value ? "true":"false"); 
+               ret =  sttd_server_setting_set_punctuation_override(pid, value);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+                       return -1;
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_get_silence_detection(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       bool value;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Get Silence Detection");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting get silence detection : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting get silence detection : uid(%d)", pid); 
+               ret =  sttd_server_setting_get_silence_detection(pid, &value);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INT32, &value, DBUS_TYPE_INVALID);
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d) , Value(%s)", ret, value ? "true":"false"); 
+               } else {
+                       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+                       return -1;
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_set_silence_detection(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       bool value;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &value,
+               DBUS_TYPE_INVALID);
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Set Silence Detection");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting set silence detection : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting set silence detection : uid(%d), value(%s)", pid, value ? "true":"false"); 
+               ret =  sttd_server_setting_set_silence_detection(pid, value);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+
+int sttd_dbus_server_setting_get_engine_setting(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       char* engine_id;
+       GList* engine_setting_list = NULL;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Get Engine Setting");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting get engine setting : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting get engine setting : uid(%d)", pid); 
+               ret = sttd_server_setting_get_engine_setting(pid, &engine_id, &engine_setting_list);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               DBusMessageIter args;
+               dbus_message_iter_init_append(reply, &args);
+
+               /* Append result*/
+               dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(ret) );
+
+               if (0 == ret) {
+                       if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine_id))) {
+                               ret = STTD_ERROR_OPERATION_FAILED;
+                               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to add engine id");
+                       } else {
+                               if (NULL != engine_id)  free(engine_id);
+
+                               /* Append size */
+                               int size = g_list_length(engine_setting_list);
+                               if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
+                                       ret = STTD_ERROR_OPERATION_FAILED;
+                                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] setting get engine setting : result(%d)", ret);
+                               } else {
+                                       GList *iter = NULL;
+                                       engine_setting_s* setting;
+
+                                       iter = g_list_first(engine_setting_list);
+
+                                       while (NULL != iter) {
+                                               setting = iter->data;
+
+                                               dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(setting->key) );
+                                               dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(setting->value) );
+
+                                               if (NULL != setting->key)
+                                                       g_free(setting->key);
+                                               if (NULL != setting->value)
+                                                       g_free(setting->value);
+                                               if (NULL != setting);
+                                                       g_free(setting);
+
+                                               engine_setting_list = g_list_remove_link(engine_setting_list, iter);
+
+                                               iter = g_list_first(engine_setting_list);
+                                       } 
+                                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] setting engine setting list : result(%d) \n", ret); 
+                               }
+                       }
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_setting_set_engine_setting(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int pid;
+       char* key;
+       char* value;
+       int ret = STTD_ERROR_OPERATION_FAILED;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_STRING, &key,
+               DBUS_TYPE_STRING, &value,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Setting Set Engine Setting");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] setting set engine setting : get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+               ret = STTD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] setting set engine setting : uid(%d), key(%s), value(%s)", pid, key, value); 
+               ret = sttd_server_setting_set_engine_setting(pid, key, value);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
+
+       if (NULL != reply) {
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
+
+int sttd_dbus_server_stop_by_daemon(DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &uid,
+               DBUS_TYPE_INVALID);
+
+       SLOG(LOG_DEBUG, TAG_STTD, ">>>>> Stop by daemon");
+
+       if (dbus_error_is_set(&err)) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] sttd stop by daemon : Get arguments error (%s)", err.message);
+               dbus_error_free(&err); 
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[IN] sttd stop by daemon : uid(%d)", uid);
+               sttd_server_stop(uid);
+
+               /* check silence detection option from config */
+               int ret = sttd_send_stop(uid); 
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); 
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); 
+               }
+       }
+       
+       SLOG(LOG_DEBUG, TAG_STTD, "<<<<<");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return 0;
+}
diff --git a/server/sttd_dbus_server.h b/server/sttd_dbus_server.h
new file mode 100644 (file)
index 0000000..23a55ab
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+
+#ifndef __STTD_DBUS_SERVER_h__
+#define __STTD_DBUS_SERVER_h__
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <dbus/dbus.h>
+
+/*
+* Dbus Server functions for APIs
+*/ 
+
+int sttd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_get_support_lang(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_get_default_lang(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_is_partial_result_supported(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_get_audio_volume(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_start(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_cancel(DBusConnection* conn, DBusMessage* msg);
+
+
+/*
+* Dbus Server functions for Setting
+*/ 
+
+int sttd_dbus_server_setting_initialize(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_finalize(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_get_engine_list(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_get_engine(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_set_engine(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_get_language_list(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_get_default_language(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_set_default_language(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_get_profanity_filter(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_set_profanity_filter(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_get_punctuation_override(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_set_punctuation_override(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_get_silence_detection(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_set_silence_detection(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_get_engine_setting(DBusConnection* conn, DBusMessage* msg);
+
+int sttd_dbus_server_setting_set_engine_setting(DBusConnection* conn, DBusMessage* msg);
+
+/*
+* Dbus Server functions for stt daemon internal
+*/ 
+
+int sttd_dbus_server_stop_by_daemon(DBusMessage* msg);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __STTD_DBUS_SERVER_h__ */
diff --git a/server/sttd_engine_agent.c b/server/sttd_engine_agent.c
new file mode 100644 (file)
index 0000000..c18e09e
--- /dev/null
@@ -0,0 +1,1798 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include <dlfcn.h>
+#include <dirent.h>
+
+#include "sttd_main.h"
+#include "sttd_client_data.h"
+#include "sttd_config.h"
+#include "sttd_engine_agent.h"
+
+
+/*
+* Internal data structure
+*/
+
+typedef struct {
+       /* engine info */
+       char*   engine_uuid;
+       char*   engine_name; 
+       char*   engine_path;
+
+       /* engine load info */
+       bool    is_set;
+       bool    is_loaded;      
+       bool    need_network;
+       bool    support_silence_detection;
+       void    *handle;
+
+       /* engine base setting */
+       char*   default_lang;
+       bool    profanity_filter;
+       bool    punctuation_override;
+       bool    silence_detection;
+
+       sttpe_funcs_s*  pefuncs;
+       sttpd_funcs_s*  pdfuncs;
+
+       int (*sttp_load_engine)(sttpd_funcs_s* pdfuncs, sttpe_funcs_s* pefuncs);
+       int (*sttp_unload_engine)();
+} sttengine_s;
+
+typedef struct _sttengine_info {
+       char*   engine_uuid;
+       char*   engine_path;
+       char*   engine_name;
+       char*   setting_ug_path;
+       bool    use_network;
+       bool    support_silence_detection;
+} sttengine_info_s;
+
+
+/*
+* static data
+*/
+
+/** stt engine agent init */
+static bool g_agent_init;
+
+/** stt engine list */
+static GList *g_engine_list;           
+
+/** current engine infomation */
+static sttengine_s g_cur_engine;
+
+/** default option value */
+static bool g_default_profanity_filter;
+static bool g_default_punctuation_override;
+static bool g_default_silence_detected;
+
+/** callback functions */
+static result_callback g_result_cb;
+static partial_result_callback g_partial_result_cb;
+static silence_dectection_callback g_silence_cb;
+
+
+/** callback functions */
+void __result_cb(sttp_result_event_e event, const char* type, 
+                       const char** data, int data_count, const char* msg, void *user_data);
+
+void __partial_result_cb(sttp_result_event_e event, const char* data, void *user_data);
+
+void __detect_silence_cb(void* user_data);
+
+bool __supported_language_cb(const char* language, void* user_data);
+
+void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name, 
+                     bool use_network, void* user_data);
+
+bool __engine_setting_cb(const char* key, const char* value, void* user_data);
+
+/** Free voice list */
+void __free_language_list(GList* lang_list);
+
+
+/*
+* Internal Interfaces 
+*/
+/** Set current engine */
+int __internal_set_current_engine(const char* engine_uuid);
+
+/** check engine id */
+int __internal_check_engine_id(const char* engine_uuid);
+
+/** update engine list */
+int __internal_update_engine_list();
+
+/** get engine info */
+int __internal_get_engine_info(const char* filepath, sttengine_info_s** info);
+
+int __log_enginelist();
+
+/*
+* STT Engine Agent Interfaces
+*/
+int sttd_engine_agent_init(result_callback result_cb, partial_result_callback partial_result_cb, silence_dectection_callback silence_cb)
+{
+       /* initialize static data */
+       if (NULL == result_cb || NULL == silence_cb) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine agent ERROR] sttd_engine_agent_init : invalid parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       g_result_cb = result_cb;
+       g_partial_result_cb = partial_result_cb;
+       g_silence_cb = silence_cb;
+
+       g_cur_engine.engine_uuid = NULL;
+       g_cur_engine.engine_name = NULL;
+       g_cur_engine.engine_path = NULL;
+
+       g_cur_engine.is_set = false;
+       g_cur_engine.handle = NULL;
+       g_cur_engine.pefuncs = (sttpe_funcs_s*)malloc( sizeof(sttpe_funcs_s) );
+       g_cur_engine.pdfuncs = (sttpd_funcs_s*)malloc( sizeof(sttpd_funcs_s) );
+
+       g_agent_init = true;
+
+       if (0 != sttd_config_get_char_type(CONFIG_KEY_DEFAULT_LANGUAGE, &(g_cur_engine.default_lang)) ) {
+               /* Default Voice is NULL */
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No default language in config"); 
+               g_cur_engine.default_lang = NULL;
+       }
+
+       bool temp;
+       if (0 != sttd_config_get_bool_type(CONFIG_KEY_PROFANITY_FILTER, &temp)) {
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No profanity filter value in config"); 
+               sttd_config_set_bool_type(CONFIG_KEY_PROFANITY_FILTER, false);
+               g_default_profanity_filter = false;
+       } else {
+               g_default_profanity_filter = temp;
+       }
+
+       if (0 != sttd_config_get_bool_type(CONFIG_KEY_PUNCTUATION_OVERRIDE, &temp)) {
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No punctuation override value in config"); 
+               sttd_config_set_bool_type(CONFIG_KEY_PUNCTUATION_OVERRIDE, false);
+               g_default_punctuation_override = false;
+       } else {
+               g_default_punctuation_override = temp;
+       }
+
+       if (0 != sttd_config_get_bool_type(CONFIG_KEY_SILENCE_DETECTION, &temp)) {
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no silence detection in config"); 
+               sttd_config_set_bool_type(CONFIG_KEY_SILENCE_DETECTION, true);
+               g_default_silence_detected = true;
+       } else {
+               g_default_silence_detected = temp;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Engine Agent Initialize"); 
+
+       return 0;
+}
+
+int sttd_engine_agent_release()
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       /* unload current engine */
+       sttd_engine_agent_unload_current_engine();
+
+       /* release engine list */
+       GList *iter = NULL;
+       sttengine_s *data = NULL;
+
+       if (g_list_length(g_engine_list) > 0) {
+               /* Get a first item */
+               iter = g_list_first(g_engine_list);
+
+               while (NULL != iter) {
+                       /* Get handle data from list */
+                       data = iter->data;
+                       dlclose(data->handle); 
+
+                       iter = g_list_remove(iter, data);
+               }
+       }
+
+       g_list_free(iter);
+       
+       /* release current engine data */
+       if( NULL != g_cur_engine.pefuncs )
+               free(g_cur_engine.pefuncs);
+
+       if( NULL != g_cur_engine.pdfuncs )
+               free(g_cur_engine.pdfuncs);
+
+       g_result_cb = NULL;
+       g_silence_cb = NULL;
+
+       g_agent_init = false;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Engine Agent release"); 
+
+       return 0;
+}
+
+int sttd_engine_agent_initialize_current_engine()
+{
+       /* check agent init */
+       if (false == g_agent_init ) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       /* update engine list */
+       if (0 != __internal_update_engine_list()) {
+               SLOG(LOG_ERROR, TAG_STTD, "[engine agent] sttd_engine_agent_init : __internal_update_engine_list : no engine error"); 
+               return STTD_ERROR_ENGINE_NOT_FOUND;
+       }
+
+       /* get current engine from config */
+       char* cur_engine_uuid = NULL;
+       bool is_get_engineid_from_config = false;
+
+       if (0 != sttd_config_get_char_type(CONFIG_KEY_DEFAULT_ENGINE_ID, &cur_engine_uuid)) {
+
+               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] There is not current engine from config"); 
+
+               /* not set current engine */
+               /* set system default engine */
+               GList *iter = NULL;
+               if (0 < g_list_length(g_engine_list)) {
+                       iter = g_list_first(g_engine_list);
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[engine agent ERROR] sttd_engine_agent_initialize_current_engine() : no engine error"); 
+                       return -1;      
+               }
+
+               sttengine_info_s *data = NULL;
+               data = iter->data;
+
+               cur_engine_uuid = g_strdup(data->engine_uuid);
+
+               is_get_engineid_from_config = false;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] current engine from config : %s", cur_engine_uuid); 
+
+               is_get_engineid_from_config = true;
+       }
+
+       /* check whether cur engine uuid is valid or not. */
+       if (0 != __internal_check_engine_id(cur_engine_uuid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] It is not valid engine id and find other engine id");
+
+               GList *iter = NULL;
+               if (0 < g_list_length(g_engine_list)) {
+                       iter = g_list_first(g_engine_list);
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_agent_initialize_current_engine() : no engine error"); 
+                       return -1;      
+               }
+
+               if (NULL != cur_engine_uuid)    
+                       free(cur_engine_uuid);
+               
+               sttengine_info_s *data = NULL;
+               data = iter->data;
+
+               cur_engine_uuid = g_strdup(data->engine_uuid);
+               
+               is_get_engineid_from_config = false;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Current Engine Id : %s", cur_engine_uuid);
+
+       /* set current engine */
+       if (0 != __internal_set_current_engine(cur_engine_uuid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[engine agent ERROR] __internal_set_current_engine : no engine error"); 
+
+               if( cur_engine_uuid != NULL)    
+                       free(cur_engine_uuid);
+
+               return STTD_ERROR_ENGINE_NOT_FOUND;
+       }
+
+       if (false == is_get_engineid_from_config) {
+               if (0 != sttd_config_set_char_type(CONFIG_KEY_DEFAULT_ENGINE_ID, cur_engine_uuid))
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default engine "); 
+       }
+
+       if( cur_engine_uuid != NULL )   
+               free(cur_engine_uuid);
+
+       return 0;
+}
+
+int __internal_check_engine_id(const char* engine_uuid)
+{
+       if (NULL == engine_uuid) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       GList *iter = NULL;
+       sttengine_s *data = NULL;
+
+       if (0 < g_list_length(g_engine_list)) {
+               /*Get a first item*/
+               iter = g_list_first(g_engine_list);
+
+               while (NULL != iter) {
+                       data = iter->data;
+                       
+                       if (0 == strncmp(engine_uuid, data->engine_uuid, strlen(data->engine_uuid))) {
+                               return 0;
+                       }
+
+                       iter = g_list_next(iter);
+               }
+       }
+
+       return -1;
+}
+
+void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name, 
+                     bool use_network, void* user_data)
+{
+       sttengine_info_s* temp = (sttengine_info_s*)user_data; 
+
+       temp->engine_uuid = g_strdup(engine_uuid);
+       temp->engine_name = g_strdup(engine_name);
+       temp->setting_ug_path = g_strdup(setting_ug_name);
+       temp->use_network = use_network;
+}
+
+
+int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
+{
+       if (NULL == filepath || NULL == info) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* load engine */
+       char *error;
+       void* handle;
+
+       handle = dlopen (filepath, RTLD_LAZY);
+
+       if (!handle) {
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine : %s", filepath); 
+               return -1;
+       }
+
+       /* link engine to daemon */
+       dlsym(handle, "sttp_load_engine");
+       if ((error = dlerror()) != NULL) {
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine. Fail to open sttp_load_engine : %s", filepath); 
+               dlclose(handle);
+               return -1;
+       }
+
+       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", filepath); 
+               dlclose(handle);
+               return -1;
+       }
+
+       int (*get_engine_info)(sttpe_engine_info_cb callback, void* user_data);
+
+       get_engine_info = (int (*)(sttpe_engine_info_cb, void*))dlsym(handle, "sttp_get_engine_info");
+       if ((error = dlerror()) != NULL) {
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Invalid engine. Fail to open sttp_get_engine_info : %s", filepath); 
+               dlclose(handle);
+               return -1;
+       }
+
+       sttengine_info_s* temp;
+       temp = (sttengine_info_s*)g_malloc0( sizeof(sttengine_info_s) );
+
+       /* 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);
+               g_free(temp);
+               return -1;
+       }
+
+       /* close engine */
+       dlclose(handle);
+
+       temp->engine_path = g_strdup(filepath);
+
+       SLOG(LOG_DEBUG, TAG_STTD, "----- Valid Engine");
+       SLOG(LOG_DEBUG, TAG_STTD, "Engine uuid : %s", temp->engine_uuid);
+       SLOG(LOG_DEBUG, TAG_STTD, "Engine name : %s", temp->engine_name);
+       SLOG(LOG_DEBUG, TAG_STTD, "Setting ug path : %s", temp->setting_ug_path);
+       SLOG(LOG_DEBUG, TAG_STTD, "Engine path : %s", temp->engine_path);
+       SLOG(LOG_DEBUG, TAG_STTD, "Use network : %s", temp->use_network ? "true":"false");
+       SLOG(LOG_DEBUG, TAG_STTD, "-----");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       *info = temp;
+
+       return 0;
+}
+
+int __internal_update_engine_list()
+{
+       /* relsease engine list */
+       GList *iter = NULL;
+       sttengine_info_s *data = NULL;
+
+       if (0 < g_list_length(g_engine_list)) {
+               /* Get a first item */
+               iter = g_list_first(g_engine_list);
+
+               while (NULL != iter) {
+                       /* Get handle data from list */
+                       data = iter->data;
+
+                       if (NULL != data) {
+                               if (NULL != data->engine_uuid)          free(data->engine_uuid);
+                               if (NULL != data->engine_path)          free(data->engine_path);
+                               if (NULL != data->engine_name)          free(data->engine_name);
+                               if (NULL != data->setting_ug_path)      free(data->setting_ug_path);
+                               
+                               free(data);
+                       }
+
+                       g_engine_list = g_list_remove_link(g_engine_list, iter);
+                       iter = g_list_first(g_engine_list);
+               }
+       }
+
+       /* get file name from engine directory and get engine infomation from each filename */
+       DIR *dp;
+       struct dirent *dirp;
+       dp  = opendir(ENGINE_DIRECTORY);
+       if (NULL == dp) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] __internal_update_engine_list : error opendir"); 
+               return -1;
+       }
+
+       while (NULL != (dirp = readdir(dp))) {
+               sttengine_info_s* info;
+               char* filepath;
+               int filesize;
+               
+               filesize = strlen(ENGINE_DIRECTORY) + strlen(dirp->d_name) + 5;
+               filepath = (char*) g_malloc0(sizeof(char) * filesize);
+               
+               if (NULL != filepath) {
+                       strncpy(filepath, ENGINE_DIRECTORY, strlen(ENGINE_DIRECTORY) );
+                       strncat(filepath, "/", strlen("/") );
+                       strncat(filepath, dirp->d_name, strlen(dirp->d_name) );
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Memory not enough!!" );
+                       continue;       
+               }
+               
+               /* get its info and update engine list */
+               if (0 == __internal_get_engine_info(filepath, &info)) {
+                       /* add engine info to g_engine_list */
+                       g_engine_list = g_list_append(g_engine_list, info);
+               }
+
+               if (NULL != filepath)
+                       g_free(filepath);
+       }
+
+       closedir(dp);
+
+       if (0 >= g_list_length(g_engine_list)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No Engine"); 
+               return STTD_ERROR_ENGINE_NOT_FOUND;     
+       }
+
+       __log_enginelist();
+       
+       return 0;
+}
+
+int __internal_set_current_engine(const char* engine_uuid)
+{
+       if (NULL == engine_uuid) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* check whether engine id is valid or not.*/
+       GList *iter = NULL;
+       sttengine_info_s *data = NULL;
+
+       bool flag = false;
+       if (g_list_length(g_engine_list) > 0) {
+               /*Get a first item*/
+               iter = g_list_first(g_engine_list);
+
+               while (NULL != iter) {
+                       /*Get handle data from list*/
+                       data = iter->data;
+
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] engine_uuid(%s) engine list->uuid(%s)", engine_uuid, data->engine_uuid);
+
+                       if (0 == strncmp(data->engine_uuid, engine_uuid, strlen(engine_uuid))) {
+                               flag = true;
+                               break;
+                       }
+
+                       /*Get next item*/
+                       iter = g_list_next(iter);
+               }
+       }
+
+       /* If current engine does not exist, return error */
+       if (false == flag) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] __internal_set_current_engine : Cannot find engine id"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       } else {
+               if (NULL != g_cur_engine.engine_uuid) {
+                       /*compare current engine uuid */
+                       if (0 == strncmp(g_cur_engine.engine_uuid, data->engine_uuid, strlen(engine_uuid))) {
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Check] stt engine has already been set");
+                               return 0;
+                       }
+               }
+       }
+
+       /* set data from g_engine_list */
+       if (g_cur_engine.engine_uuid != NULL)   free(g_cur_engine.engine_uuid);
+       if (g_cur_engine.engine_name != NULL)   free(g_cur_engine.engine_name);
+       if (g_cur_engine.engine_path != NULL)   free(g_cur_engine.engine_path);
+
+       g_cur_engine.engine_uuid = g_strdup(data->engine_uuid);
+       g_cur_engine.engine_name = g_strdup(data->engine_name);
+       g_cur_engine.engine_path = g_strdup(data->engine_path);
+
+       g_cur_engine.handle = NULL;
+       g_cur_engine.is_loaded = false;
+       g_cur_engine.is_set = true;
+       g_cur_engine.need_network = data->use_network;
+       g_cur_engine.support_silence_detection = data->support_silence_detection;
+
+       g_cur_engine.profanity_filter = g_default_profanity_filter;
+       g_cur_engine.punctuation_override = g_default_punctuation_override;
+       g_cur_engine.silence_detection = g_default_silence_detected;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "-----");
+       SLOG(LOG_DEBUG, TAG_STTD, " Current engine uuid : %s", g_cur_engine.engine_uuid);
+       SLOG(LOG_DEBUG, TAG_STTD, " Current engine name : %s", g_cur_engine.engine_name);
+       SLOG(LOG_DEBUG, TAG_STTD, " Current engine path : %s", g_cur_engine.engine_path);
+       SLOG(LOG_DEBUG, TAG_STTD, "-----");
+
+       return 0;
+}
+
+int sttd_engine_agent_load_current_engine()
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_set) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_agent_load_current_engine : No Current Engine "); 
+               return -1;
+       }
+
+       /* check whether current engine is loaded or not */
+       if (true == g_cur_engine.is_loaded) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] sttd_engine_agent_load_current_engine : Engine has already been loaded ");
+               return 0;
+       }
+       
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Current engine path : %s", g_cur_engine.engine_path);
+
+       /* open engine */
+       char *error;
+       g_cur_engine.handle = dlopen(g_cur_engine.engine_path, RTLD_LAZY);
+
+       if ((error = dlerror()) != NULL || !g_cur_engine.handle) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine handle"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+       
+       g_cur_engine.sttp_unload_engine = (int (*)())dlsym(g_cur_engine.handle, "sttp_unload_engine");
+       if ((error = dlerror()) != NULL) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to link daemon to sttp_unload_engine()"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       g_cur_engine.sttp_load_engine = (int (*)(sttpd_funcs_s*, sttpe_funcs_s*) )dlsym(g_cur_engine.handle, "sttp_load_engine");
+       if ((error = dlerror()) != NULL) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to link daemon to sttp_load_engine()"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* load engine */
+       g_cur_engine.pdfuncs->version = 1;
+       g_cur_engine.pdfuncs->size = sizeof(sttpd_funcs_s);
+
+       if (0 != g_cur_engine.sttp_load_engine(g_cur_engine.pdfuncs, g_cur_engine.pefuncs)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail sttp_load_engine()"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] engine info : version(%d), size(%d)",g_cur_engine.pefuncs->version, g_cur_engine.pefuncs->size); 
+
+       /* engine error check */
+       if (g_cur_engine.pefuncs->size != sizeof(sttpe_funcs_s)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_agent_load_current_engine : engine is not valid"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* initalize engine */
+       if (0 != g_cur_engine.pefuncs->initialize(__result_cb, __partial_result_cb, __detect_silence_cb)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to initialize stt-engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* set default setting */
+       int ret = 0;
+
+       if (NULL == g_cur_engine.pefuncs->set_profanity_filter) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_profanity_filter of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+       
+       ret = g_cur_engine.pefuncs->set_profanity_filter(g_cur_engine.profanity_filter);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to set profanity filter value to engine");
+       }
+       
+       if (NULL == g_cur_engine.pefuncs->set_punctuation) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_punctuation of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       ret = g_cur_engine.pefuncs->set_punctuation(g_cur_engine.punctuation_override);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to set punctuation override value to engine");
+       }
+       
+       if (true == g_cur_engine.support_silence_detection) {
+               if (NULL == g_cur_engine.pefuncs->set_silence_detection) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_silence_detection of engine is NULL!!");
+                       return STTD_ERROR_OPERATION_FAILED;
+               }
+
+               ret = g_cur_engine.pefuncs->set_silence_detection(g_cur_engine.silence_detection);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to set silence detection value(%s)", g_cur_engine.silence_detection ? "true":"false");
+               }
+       }
+       
+       /* select default language */
+       bool set_voice = false;
+       if (NULL != g_cur_engine.default_lang) {
+               if (NULL == g_cur_engine.pefuncs->is_valid_lang) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_default_lang of engine is NULL!!");
+                       return STTD_ERROR_OPERATION_FAILED;
+               }
+
+               if (true == g_cur_engine.pefuncs->is_valid_lang(g_cur_engine.default_lang)) {
+                       set_voice = true;
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Set origin default voice to current engine : lang(%s)", g_cur_engine.default_lang);
+               } else {
+                       SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail set origin default language : lang(%s)", g_cur_engine.default_lang);
+               }
+       }
+
+       if (false == set_voice) {
+               if (NULL == g_cur_engine.pefuncs->foreach_langs) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] foreach_langs of engine is NULL!!");
+                       return STTD_ERROR_OPERATION_FAILED;
+               }
+
+               /* get language list */
+               int ret;
+               GList* lang_list = NULL;
+
+               ret = g_cur_engine.pefuncs->foreach_langs(__supported_language_cb, &lang_list);
+
+               if (0 == ret && 0 < g_list_length(lang_list)) {
+                       GList *iter = NULL;
+                       iter = g_list_first(lang_list);
+
+                       if (NULL != iter) {
+                               char* temp_lang = iter->data;
+
+                               if (true != g_cur_engine.pefuncs->is_valid_lang(temp_lang)) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail voice is NOT valid");
+                                       return STTD_ERROR_OPERATION_FAILED;
+                               }
+
+                               sttd_config_set_char_type(CONFIG_KEY_DEFAULT_LANGUAGE, temp_lang);
+                               
+                               g_cur_engine.default_lang = g_strdup(temp_lang);
+                               
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Select default voice : lang(%s)", temp_lang);
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
+                               return STTD_ERROR_OPERATION_FAILED;
+                       }
+
+                       __free_language_list(lang_list);
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
+                       return STTD_ERROR_OPERATION_FAILED;
+               }
+
+       } 
+
+       g_cur_engine.is_loaded = true;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] The %s has been loaded !!!", g_cur_engine.engine_name); 
+
+       return 0;
+}
+
+int sttd_engine_agent_unload_current_engine()
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized "); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_set) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_agent_unload_current_engine : No Current Engine "); 
+               return -1;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Current engine has already been unloaded "); 
+               return 0;
+       }
+
+       /* shutdown engine */
+       if (NULL == g_cur_engine.pefuncs->deinitialize) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] shutdown of engine is NULL!!");
+       } else {
+               g_cur_engine.pefuncs->deinitialize();
+       }
+
+       /* unload engine */
+       if (0 != g_cur_engine.sttp_unload_engine()) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to unload engine"); 
+       }
+
+       dlclose(g_cur_engine.handle);
+
+       /* reset current engine data */
+       g_cur_engine.handle = NULL;
+       g_cur_engine.is_loaded = false;
+
+       return 0;
+}
+
+bool sttd_engine_agent_need_network()
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return g_cur_engine.need_network;
+}
+
+/*
+* STT Engine Interfaces for client
+*/
+
+int __set_option(int profanity, int punctuation, int silence)
+{
+       if (2 == profanity) {
+               /* Default selection */
+               if (g_default_profanity_filter != g_cur_engine.profanity_filter) {
+                       if (NULL != g_cur_engine.pefuncs->set_profanity_filter) {
+                               if (0 != g_cur_engine.pefuncs->set_profanity_filter(g_default_profanity_filter)) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set profanity filter");
+                                       return STTD_ERROR_OPERATION_FAILED;
+                               }
+                               g_cur_engine.profanity_filter = g_default_profanity_filter;
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set profanity filter : %s", g_cur_engine.profanity_filter ? "true" : "false");
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] profanity_filter() of engine is NULL!!");
+                               return STTD_ERROR_OPERATION_FAILED;
+                       }
+               }
+       } else {
+               /* Client selection */
+               if (g_cur_engine.profanity_filter != profanity) {
+                       if (NULL != g_cur_engine.pefuncs->set_profanity_filter) {
+                               if (0 != g_cur_engine.pefuncs->set_profanity_filter((bool)profanity)) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set profanity filter");
+                                       return STTD_ERROR_OPERATION_FAILED;
+                               }
+
+                               g_cur_engine.profanity_filter = (bool)profanity;
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set profanity filter : %s", g_cur_engine.profanity_filter ? "true" : "false");
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] profanity_filter() of engine is NULL!!");
+                               return STTD_ERROR_OPERATION_FAILED;
+                       }
+               }
+       }
+
+       if (2 == punctuation) {
+               /* Default selection */
+               if (g_default_punctuation_override != g_cur_engine.punctuation_override) {
+                       if (NULL != g_cur_engine.pefuncs->set_punctuation) {
+                               if (0 != g_cur_engine.pefuncs->set_punctuation(g_default_punctuation_override)) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set punctuation override");
+                                       return STTD_ERROR_OPERATION_FAILED;
+                               }
+                               g_cur_engine.punctuation_override = g_default_punctuation_override;
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set punctuation override : %s", g_cur_engine.punctuation_override ? "true" : "false");
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_punctuation() of engine is NULL!!");
+                               return STTD_ERROR_OPERATION_FAILED;
+                       }
+               }
+       } else {
+               /* Client selection */
+               if (g_cur_engine.punctuation_override != punctuation) {
+                       if (NULL != g_cur_engine.pefuncs->set_punctuation) {
+                               if (0 != g_cur_engine.pefuncs->set_punctuation((bool)punctuation)) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set punctuation override");
+                                       return STTD_ERROR_OPERATION_FAILED;
+                               }
+
+                               g_cur_engine.punctuation_override = (bool)punctuation;
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set punctuation override : %s", g_cur_engine.punctuation_override ? "true" : "false");
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_punctuation() of engine is NULL!!");
+                               return STTD_ERROR_OPERATION_FAILED;
+                       }
+               }
+       }
+
+       if (2 == silence) {
+               /* Default selection */
+               if (g_default_silence_detected != g_cur_engine.silence_detection) {
+                       if (NULL != g_cur_engine.pefuncs->set_silence_detection) {
+                               if (0 != g_cur_engine.pefuncs->set_silence_detection(g_default_silence_detected)) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection");
+                                       return STTD_ERROR_OPERATION_FAILED;
+                               }
+                               g_cur_engine.silence_detection = g_default_silence_detected;
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", g_cur_engine.silence_detection ? "true" : "false");
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_silence() of engine is NULL!!");
+                               return STTD_ERROR_OPERATION_FAILED;
+                       }
+               }
+       } else {
+               /* Client selection */
+               if (g_cur_engine.silence_detection != punctuation) {
+                       if (NULL != g_cur_engine.pefuncs->set_silence_detection) {
+                               if (0 != g_cur_engine.pefuncs->set_silence_detection((bool)silence)) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection");
+                                       return STTD_ERROR_OPERATION_FAILED;
+                               }
+
+                               g_cur_engine.silence_detection = (bool)silence;
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", g_cur_engine.silence_detection ? "true" : "false");
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_silence() of engine is NULL!!");
+                               return STTD_ERROR_OPERATION_FAILED;
+                       }
+               }
+       }
+       
+       return 0;
+}
+
+int sttd_engine_recognize_start(const char* lang, const char* recognition_type, 
+                               int profanity, int punctuation, int silence, void* user_param)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == lang || NULL == recognition_type) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (0 != __set_option(profanity, punctuation, silence)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set options"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->start) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] start() of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       char* temp;
+       if (0 == strncmp(lang, "default", strlen("default"))) {
+               temp = strdup(g_cur_engine.default_lang);
+       } else {
+               temp = strdup(lang);
+       }
+
+       int ret = g_cur_engine.pefuncs->start(temp, recognition_type, user_param);
+       free(temp);
+
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_recognize_start : recognition start error(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] sttd_engine_recognize_start");
+
+       return 0;
+}
+
+int sttd_engine_recognize_audio(const void* data, unsigned int length)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == data) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->set_recording) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       int ret = g_cur_engine.pefuncs->set_recording(data, length);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set recording error(%d)", ret); 
+               return ret;
+       }
+
+       return 0;
+}
+
+int sttd_engine_recognize_stop()
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->stop) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       int ret = g_cur_engine.pefuncs->stop();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] stop recognition error(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return 0;
+}
+
+int sttd_engine_recognize_cancel()
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+       
+       if (NULL == g_cur_engine.pefuncs->cancel) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       int ret = g_cur_engine.pefuncs->cancel();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return 0;
+}
+
+int sttd_engine_get_audio_format(sttp_audio_type_e* types, int* rate, int* channels)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->get_audio_format) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       int ret = g_cur_engine.pefuncs->get_audio_format(types, rate, channels);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get audio format error(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return 0;
+}
+
+
+/*
+* STT Engine Interfaces for client and setting
+*/
+bool __supported_language_cb(const char* language, void* user_data)
+{
+       GList** lang_list = (GList**)user_data;
+
+       if (NULL == language || NULL == lang_list) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Input parameter is NULL in callback!!!!");
+               return false;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "-- Language(%s)", language);
+
+       char* temp_lang = g_strdup(language);
+
+       *lang_list = g_list_append(*lang_list, temp_lang);
+
+       return true;
+}
+
+int sttd_engine_supported_langs(GList** lang_list)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->foreach_langs) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       int ret = g_cur_engine.pefuncs->foreach_langs(__supported_language_cb, (void*)lang_list);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get language list error(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return 0;
+}
+
+
+int sttd_engine_get_default_lang(char** lang)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == lang) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* get default language */
+       *lang = g_strdup(g_cur_engine.default_lang);
+
+       return 0;
+}
+
+int sttd_engine_is_partial_result_supported(bool* partial_result)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == partial_result) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->support_partial_result) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       *partial_result = g_cur_engine.pefuncs->support_partial_result();
+
+       return 0;
+}
+
+
+/*
+* STT Engine Interfaces for setting
+*/
+
+int sttd_engine_setting_get_engine_list(GList** engine_list)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* update engine list */
+       if (0 != __internal_update_engine_list()) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_setting_get_engine_list : __internal_update_engine_list()"); 
+               return -1;
+       }
+
+       GList *iter = NULL;
+       sttengine_info_s *data = NULL;
+
+       iter = g_list_first(g_engine_list);
+
+       SLOG(LOG_DEBUG, TAG_STTD, "----- [Engine Agent] engine list -----");
+
+       while (NULL != iter) {
+               engine_s* temp_engine;
+
+               temp_engine = (engine_s*)g_malloc0(sizeof(engine_s));
+
+               data = iter->data;
+
+               temp_engine->engine_id = strdup(data->engine_uuid);
+               temp_engine->engine_name = strdup(data->engine_name);
+               temp_engine->ug_name = strdup(data->setting_ug_path);
+
+               *engine_list = g_list_append(*engine_list, temp_engine);
+
+               iter = g_list_next(iter);
+
+               SLOG(LOG_DEBUG, TAG_STTD, " -- engine id(%s) engine name(%s) ug name(%s) \n", 
+                       temp_engine->engine_id, temp_engine->engine_name, temp_engine->ug_name);
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "--------------------------------------");
+
+       return 0;
+}
+
+int sttd_engine_setting_get_engine(char** engine_id)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+               return STTD_ERROR_ENGINE_NOT_FOUND;
+       }
+
+       *engine_id = strdup(g_cur_engine.engine_uuid);
+
+       return 0;
+}
+
+int sttd_engine_setting_set_engine(const char* engine_id)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* compare current engine and new engine. */
+       if (NULL != g_cur_engine.engine_uuid) {
+               if (0 == strncmp(g_cur_engine.engine_uuid, engine_id, strlen(g_cur_engine.engine_uuid))) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent] New engine is the same as current engine"); 
+                       return 0;
+               }
+       }
+
+       char* tmp_uuid = NULL;
+       tmp_uuid = g_strdup(g_cur_engine.engine_uuid);
+       if (NULL == tmp_uuid) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not enough memory!!"); 
+               return STTD_ERROR_OUT_OF_MEMORY;
+       }
+
+       /* unload engine */
+       if (0 != sttd_engine_agent_unload_current_engine()) 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to unload current engine"); 
+       else
+               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] unload current engine");
+
+       /* change current engine */
+       if (0 != __internal_set_current_engine(engine_id)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] __internal_set_current_engine : no engine error"); 
+               
+               /* roll back to old current engine. */
+               __internal_set_current_engine(tmp_uuid);
+
+               if (NULL != tmp_uuid)   
+                       free(tmp_uuid);
+
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (0 != sttd_engine_agent_load_current_engine()) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load new engine"); 
+
+               if (NULL != tmp_uuid)   
+                       free(tmp_uuid);
+
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] sttd_engine_setting_set_engine() : Load new engine");
+
+       if( tmp_uuid != NULL )  
+               free(tmp_uuid);
+
+       /* set engine id to config */
+       if (0 != sttd_config_set_char_type(CONFIG_KEY_DEFAULT_ENGINE_ID, engine_id)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set engine id"); 
+       }
+
+       return 0;
+}
+
+int sttd_engine_setting_get_lang_list(char** engine_id, GList** lang_list)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == lang_list || NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* get language list from engine */
+       int ret = sttd_engine_supported_langs(lang_list); 
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail get lang list (%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       *engine_id = strdup(g_cur_engine.engine_uuid);
+
+       return 0;
+}
+
+int sttd_engine_setting_get_default_lang(char** language)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == language) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL != g_cur_engine.default_lang) {
+               *language = strdup(g_cur_engine.default_lang);
+
+               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Get default lanaguae : language(%s)", *language);
+       } else {
+               if (NULL == g_cur_engine.pefuncs->foreach_langs) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] foreach_langs of engine is NULL!!");
+                       return STTD_ERROR_OPERATION_FAILED;
+               }
+
+               /* get language list */
+               int ret;
+               GList* lang_list = NULL;
+
+               ret = g_cur_engine.pefuncs->foreach_langs(__supported_language_cb, &lang_list);
+
+               if (0 == ret && 0 < g_list_length(lang_list)) {
+                       GList *iter = NULL;
+                       iter = g_list_first(lang_list);
+
+                       if (NULL != iter) {
+                               char* temp_lang = iter->data;
+
+                               if (true != g_cur_engine.pefuncs->is_valid_lang(temp_lang)) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail voice is NOT valid");
+                                       return STTD_ERROR_OPERATION_FAILED;
+                               }
+
+                               sttd_config_set_char_type(CONFIG_KEY_DEFAULT_LANGUAGE, temp_lang);
+
+                               g_cur_engine.default_lang = g_strdup(temp_lang);
+
+                               *language = strdup(g_cur_engine.default_lang);
+
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Select default voice : lang(%s)", temp_lang);
+                       } else {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
+                               return STTD_ERROR_OPERATION_FAILED;
+                       }
+
+                       __free_language_list(lang_list);
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
+                       return STTD_ERROR_OPERATION_FAILED;
+               }
+       }
+       
+       return 0;
+}
+
+int sttd_engine_setting_set_default_lang(const char* language)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->is_valid_lang) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get_voice_list() of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       int ret = -1;
+       if(false == g_cur_engine.pefuncs->is_valid_lang(language)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Language is NOT valid !!");
+               return STTD_ERROR_INVALID_LANGUAGE;
+       }
+
+       if (NULL != g_cur_engine.default_lang)
+               g_free(g_cur_engine.default_lang);
+
+       g_cur_engine.default_lang = strdup(language);
+
+       ret = sttd_config_set_char_type(CONFIG_KEY_DEFAULT_LANGUAGE, language);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default lang (%d)", ret); 
+       }
+
+       return 0;
+}
+
+int sttd_engine_setting_get_profanity_filter(bool* value)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       *value = g_default_profanity_filter;    
+
+       return 0;
+}
+
+int sttd_engine_setting_set_profanity_filter(bool value)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->set_profanity_filter) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       int ret = g_cur_engine.pefuncs->set_profanity_filter(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail set profanity filter : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       g_default_profanity_filter = value;
+
+       ret = sttd_config_set_bool_type(CONFIG_KEY_PROFANITY_FILTER, value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default lang (%d)", ret); 
+       }
+
+       return 0;
+}
+
+int sttd_engine_setting_get_punctuation_override(bool* value)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       *value = g_default_punctuation_override;
+
+       return 0;
+}
+
+int sttd_engine_setting_set_punctuation_override(bool value)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->set_punctuation) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       int ret = g_cur_engine.pefuncs->set_punctuation(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail set punctuation override : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+       g_default_punctuation_override = value;
+
+       ret = sttd_config_set_bool_type(CONFIG_KEY_PUNCTUATION_OVERRIDE, value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set punctuation override (%d)", ret); 
+       }
+
+       return 0;
+}
+
+int sttd_engine_setting_get_silence_detection(bool* value)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       *value = g_default_silence_detected;
+
+       return 0;
+}
+
+int sttd_engine_setting_set_silence_detection(bool value)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       int ret = g_cur_engine.pefuncs->set_silence_detection(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail set silence detection : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+       
+       g_default_silence_detected = value;
+
+       ret = sttd_config_set_bool_type(CONFIG_KEY_SILENCE_DETECTION, value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection (%d)", ret); 
+       }
+       
+       return 0;
+}
+
+bool __engine_setting_cb(const char* key, const char* value, void* user_data)
+{
+       GList** engine_setting_list = (GList**)user_data;
+
+       if (NULL == engine_setting_list || NULL == key || NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Input parameter is NULL in engine setting callback!!!!");
+               return false;
+       }
+
+       engine_setting_s* temp = g_malloc0(sizeof(engine_setting_s));
+       temp->key = g_strdup(key);
+       temp->value = g_strdup(value);
+
+       *engine_setting_list = g_list_append(*engine_setting_list, temp);
+
+       return true;
+}
+
+int sttd_engine_setting_get_engine_setting_info(char** engine_id, GList** setting_list)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == setting_list) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Input parameter is NULL");
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->foreach_engine_settings) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] foreach_engine_settings() of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* get setting info and move setting info to input parameter */
+       int result = 0;
+
+       result = g_cur_engine.pefuncs->foreach_engine_settings(__engine_setting_cb, setting_list);
+
+       if (0 == result && 0 < g_list_length(*setting_list)) {
+               *engine_id = strdup(g_cur_engine.engine_uuid);
+       } else {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] fail to get setting info : result(%d)\n", result);
+               result = STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return result;
+}
+
+int sttd_engine_setting_set_engine_setting(const char* key, const char* value)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == key || NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == g_cur_engine.pefuncs->set_engine_setting) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_engine_setting() of engine is NULL!!");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* get setting info and move setting info to input parameter */
+       int ret = g_cur_engine.pefuncs->set_engine_setting(key, value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail set setting info (%d) ", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return 0;
+}
+
+/*
+* STT Engine Callback Functions                                                                                        `                                 *
+*/
+
+void __result_cb(sttp_result_event_e event, const char* type, 
+                                       const char** data, int data_count, const char* msg, void *user_data)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Result Callback : Not Initialized"); 
+               return;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Result Callback : Not loaded engine"); 
+               return;
+       }
+
+       return g_result_cb(event, type, data, data_count, msg, user_data);
+}
+
+void __partial_result_cb(sttp_result_event_e event, const char* data, void *user_data)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Partial Result Callback : Not Initialized"); 
+               return;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Partial Result Callback : Not loaded engine"); 
+               return;
+       }
+
+       return g_partial_result_cb(event, data, user_data);
+}
+
+void __detect_silence_cb(void* user_data)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not Initialized"); 
+               return;
+       }
+
+       if (false == g_cur_engine.is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not loaded engine"); 
+               return;
+       }
+
+       if (true == g_cur_engine.silence_detection) {
+               g_silence_cb(user_data);
+       } else {
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Silence detection callback is blocked because option value is false.");
+       }
+}
+
+void __free_language_list(GList* lang_list)
+{
+       GList *iter = NULL;
+       char* data = NULL;
+
+       /* if list have item */
+       if (g_list_length(lang_list) > 0) {
+               /* Get a first item */
+               iter = g_list_first(lang_list);
+
+               while (NULL != iter) {
+                       data = iter->data;
+
+                       if (NULL != data)
+                               g_free(data);
+                       
+                       lang_list = g_list_remove_link(lang_list, iter);
+
+                       iter = g_list_first(lang_list);
+               }
+       }
+}
+
+/* A function forging */
+int __log_enginelist()
+{
+       GList *iter = NULL;
+       sttengine_info_s *data = NULL;
+
+       if (0 < g_list_length(g_engine_list)) {
+
+               /* Get a first item */
+               iter = g_list_first(g_engine_list);
+
+               SLOG(LOG_DEBUG, TAG_STTD, "--------------- engine list -------------------");
+
+               int i = 1;      
+               while (NULL != iter) {
+                       /* Get handle data from list */
+                       data = iter->data;
+
+                       SLOG(LOG_DEBUG, TAG_STTD, "[%dth]", i);
+                       SLOG(LOG_DEBUG, TAG_STTD, "  engine uuid : %s", data->engine_uuid);
+                       SLOG(LOG_DEBUG, TAG_STTD, "  engine name : %s", data->engine_name);
+                       SLOG(LOG_DEBUG, TAG_STTD, "  engine path : %s", data->engine_path);
+                       SLOG(LOG_DEBUG, TAG_STTD, "  setting ug path : %s", data->setting_ug_path);
+
+                       iter = g_list_next(iter);
+                       i++;
+               }
+               SLOG(LOG_DEBUG, TAG_STTD, "----------------------------------------------");
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "-------------- engine list -------------------");
+               SLOG(LOG_DEBUG, TAG_STTD, "  No Engine in engine directory");
+               SLOG(LOG_DEBUG, TAG_STTD, "----------------------------------------------");
+       }
+
+       return 0;
+}
+
+
+
diff --git a/server/sttd_engine_agent.h b/server/sttd_engine_agent.h
new file mode 100644 (file)
index 0000000..aa5a875
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+
+#ifndef __STTD_ENGINE_AGENT_H_
+#define __STTD_ENGINE_AGENT_H_
+
+#include "sttd_main.h"
+#include "sttp.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+* Constants & Structures       
+*/
+
+#define        ENGINE_PATH_SIZE 256
+
+typedef void (*result_callback)(sttp_result_event_e event, const char* type, 
+                               const char** data, int data_count, const char* msg, void *user_data);
+
+typedef void (*partial_result_callback)(sttp_result_event_e event, const char* data, void *user_data);
+
+typedef void (*silence_dectection_callback)(void *user_data);
+
+
+
+/*
+* STT Engine Agent Interfaces
+*/
+
+/** Init engine agent */
+int sttd_engine_agent_init(result_callback result_cb, partial_result_callback partial_result_cb, silence_dectection_callback silence_cb);
+
+/** Release engine agent */
+int sttd_engine_agent_release();
+
+/** Set current engine */
+int sttd_engine_agent_initialize_current_engine();
+
+/** load current engine */
+int sttd_engine_agent_load_current_engine();
+
+/** Unload current engine */
+int sttd_engine_agent_unload_current_engine();
+
+/** test for language list */
+int sttd_print_enginelist();
+
+/** Get state of current engine to need network */
+bool sttd_engine_agent_need_network();
+
+/*
+* STT Engine Interfaces for client
+*/
+
+int sttd_engine_supported_langs(GList** lang_list);
+
+int sttd_engine_get_default_lang(char** lang);
+
+int sttd_engine_recognize_start(const char* lang, const char* recognition_type, 
+                               int profanity, int punctuation, int silence, void* user_param);
+
+int sttd_engine_recognize_audio(const void* data, unsigned int length);
+
+int sttd_engine_is_partial_result_supported(bool* partial_result);
+
+int sttd_engine_recognize_stop();
+
+int sttd_engine_recognize_cancel();
+
+int sttd_engine_get_audio_format(sttp_audio_type_e* types, int* rate, int* channels);
+
+
+/*
+* STT Engine Interfaces for setting
+*/
+
+int sttd_engine_setting_get_engine_list(GList** engine_list);
+
+int sttd_engine_setting_get_engine(char** engine_id);
+
+int sttd_engine_setting_set_engine(const char* engine_id);
+
+int sttd_engine_setting_get_lang_list(char** engine_id, GList** lang_list);
+
+int sttd_engine_setting_get_default_lang(char** language);
+
+int sttd_engine_setting_set_default_lang(const char* language);
+
+int sttd_engine_setting_get_profanity_filter(bool* value);
+
+int sttd_engine_setting_set_profanity_filter(bool value);
+
+int sttd_engine_setting_get_punctuation_override(bool* value);
+
+int sttd_engine_setting_set_punctuation_override(bool value);
+
+int sttd_engine_setting_get_silence_detection(bool* value);
+
+int sttd_engine_setting_set_silence_detection(bool value);
+
+int sttd_engine_setting_get_engine_setting_info(char** engine_id, GList** setting_list); 
+
+int sttd_engine_setting_set_engine_setting(const char* key, const char* value);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STTD_ENGINE_AGENT_H_ */
diff --git a/server/sttd_main.c b/server/sttd_main.c
new file mode 100644 (file)
index 0000000..dc2b307
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include "sttd_main.h"
+#include "sttd_server.h"
+#include "sttd_network.h"
+#include "sttd_dbus.h"
+
+#include <Ecore.h>
+
+int main(int argc, char** argv)
+{
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+       SLOG(LOG_DEBUG, TAG_STTD, "===== STT Daemon Initialize");
+
+       if (0 != sttd_initialize()) {
+               SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to initialize stt-daemon"); 
+               return EXIT_FAILURE;
+       }
+
+       if (0 != sttd_dbus_open_connection()) {
+               SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to open connection");
+               return EXIT_FAILURE;
+       }
+
+       sttd_network_initialize();
+
+       printf("stt-daemon start...\n");
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Main] stt-daemon start..."); 
+
+       SLOG(LOG_DEBUG, TAG_STTD, "=====");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       ecore_main_loop_begin();
+
+       ecore_shutdown();
+
+       sttd_dbus_close_connection();
+
+       sttd_network_finalize();
+
+       return 0;
+}
+
+
+
diff --git a/server/sttd_main.h b/server/sttd_main.h
new file mode 100644 (file)
index 0000000..0e0f550
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STTD_MAIN_H_
+#define __STTD_MAIN_H_
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
+#include <dlog.h>
+#include <errno.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+* STT Daemon Define
+*/
+
+#define TAG_STTD "sttd"
+
+#define ENGINE_DIRECTORY "/usr/lib/voice/stt/1.0/engine"
+#define ENGINE_DIRECTORY_DOWNLOAD "/opt/apps/voice/stt/engine"
+
+/* for debug message */
+#define RECORDER_DEBUG
+
+typedef enum {
+       STTD_ERROR_NONE                 = 0,            /**< Successful */
+       STTD_ERROR_OUT_OF_MEMORY        = -ENOMEM,      /**< Out of Memory */
+       STTD_ERROR_IO_ERROR             = -EIO,         /**< I/O error */
+       STTD_ERROR_INVALID_PARAMETER    = -EINVAL,      /**< Invalid parameter */
+       STTD_ERROR_TIMED_OUT            = -ETIMEDOUT,   /**< No answer from the daemon */
+       STTD_ERROR_RECORDER_BUSY        = -EBUSY,       /**< Busy recorder */
+       STTD_ERROR_OUT_OF_NETWORK       = -ENETDOWN,    /**< Out of network */
+       STTD_ERROR_INVALID_STATE        = -0x0100031,   /**< Invalid state */
+       STTD_ERROR_INVALID_LANGUAGE     = -0x0100032,   /**< Invalid language */
+       STTD_ERROR_ENGINE_NOT_FOUND     = -0x0100033,   /**< No available engine  */    
+       STTD_ERROR_OPERATION_FAILED     = -0x0100034    /**< Operation failed  */
+}stt_error_e;
+
+typedef struct {
+       char* engine_id;
+       char* engine_name;
+       char* ug_name;
+}engine_s;
+
+typedef struct {
+       char* key;
+       char* value;
+}engine_setting_s;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STTD_MAIN_H_ */
diff --git a/server/sttd_network.c b/server/sttd_network.c
new file mode 100644 (file)
index 0000000..879cf69
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include "sttd_main.h"
+#include "sttd_network.h"
+
+#include <vconf.h>
+
+static bool g_is_connected;
+
+bool sttd_network_is_connected()
+{
+       return g_is_connected;
+}
+
+void __net_config_change_cb(keynode_t* node, void *data) 
+{
+       int network_configuration = 0;
+       vconf_get_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND , &network_configuration);
+
+       if (network_configuration == 0) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Network DEBUG] Change Network Connection is OFF ");
+               g_is_connected = false;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Network DEBUG] Change Network Connection is ON ");
+               g_is_connected = true;
+               
+               /* need to notify changing net to engine. */
+       }
+
+       return;
+}
+
+int sttd_network_initialize()
+{
+       int network_configuration = 0;
+       vconf_get_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND , &network_configuration);
+
+       if (network_configuration == 0) {
+               /*      "0" means the network configuration is not set. 
+               *       It could be network connection is not open
+               */
+
+               int network_status = 0;
+               vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status);
+
+               if(network_status == VCONFKEY_NETWORK_OFF){
+                       printf("Current network connection is OFF!! \n");
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Network DEBUG] Current network connection is OFF.");
+               }
+               else{
+                       /*
+                       *       This is the problem of network connection
+                       *       Just terminate the application, network f/w will fix the problem automatically.
+                       */
+                       printf("network status is wrong or IP is not set\n");
+                       printf("network has problem, try again\n");
+                       exit(0);
+               }
+
+               g_is_connected = false;
+       } else {
+               printf("Current network connection is ON. \n");
+               SLOG(LOG_DEBUG, TAG_STTD, "[Network DEBUG] Current network connection is ON.");
+                       
+               g_is_connected = true;
+       }
+
+       vconf_notify_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, __net_config_change_cb, NULL);
+       
+       return 0;
+}
+
+int sttd_network_finalize()
+{
+       vconf_ignore_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, __net_config_change_cb);
+
+       return 0;
+}
+
diff --git a/server/sttd_network.h b/server/sttd_network.h
new file mode 100644 (file)
index 0000000..8f76e74
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STTD_NETWORK_H_
+#define __STTD_NETWORK_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int sttd_network_initialize();
+
+int sttd_network_finalize();
+
+bool sttd_network_is_connected();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __STTD_NETWORK_H_ */
diff --git a/server/sttd_recorder.c b/server/sttd_recorder.c
new file mode 100644 (file)
index 0000000..da65b56
--- /dev/null
@@ -0,0 +1,707 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include <mm_error.h>
+#include <mm_player.h>
+#include <mm_types.h>
+#include <mm_sound.h>
+#include <mm_camcorder.h>
+#include <mm_session.h>
+
+/* private Header */
+#include "sttd_recorder.h"
+#include "sttd_main.h"
+
+/* Contant values  */
+#define DEF_TIMELIMIT 120
+#define DEF_SAMPLERATE 16000
+#define DEF_BITRATE_AMR 12200
+#define DEF_MAXSIZE 1024 * 1024 * 5
+#define DEF_SOURCECHANNEL 1
+#define DEF_BUFFER_SIZE 1024
+
+/* Sound buf save */
+//#define BUF_SAVE_MODE
+
+typedef struct {
+       unsigned int    size_limit;
+       unsigned int    time_limit;
+       unsigned int    now;
+       unsigned int    now_ms;
+       unsigned int    frame;
+       float           volume;
+
+       /* For MMF */
+       unsigned int    bitrate;
+       unsigned int    samplerate;    
+       sttd_recorder_channel   channel;
+       sttd_recorder_state     state;
+       sttd_recorder_audio_type        audio_type;
+
+       sttvr_audio_cb  streamcb;
+
+       MMHandleType    rec_handle;
+       MMHandleType    ply_handle;
+} sttd_recorder_s;
+
+
+static sttd_recorder_s *g_objRecorer = NULL;
+static bool g_init = false;
+
+static char g_temp_file_name[128] = {'\0',};
+
+/* Recorder obj */
+sttd_recorder_s *__recorder_getinstance();
+void __recorder_state_set(sttd_recorder_state state);
+
+/* MMFW caller */
+int __recorder_setup();
+int __recorder_run();
+int __recorder_pause();
+int __recorder_send_buf_from_file();
+
+int __recorder_cancel_to_stop();
+int __recorder_commit_to_stop();
+
+
+/* Event Callback Function */
+gboolean _mm_recorder_audio_stream_cb (MMCamcorderAudioStreamDataType *stream, void *user_param)
+{
+       sttd_recorder_s *pVr = __recorder_getinstance();
+
+       if (stream->length > 0 && stream->data) {
+               pVr->frame++;
+       
+               /* If stream callback is set */
+               if (STTD_RECORDER_PCM_S16 == pVr->audio_type || STTD_RECORDER_PCM_U8 == pVr->audio_type) {
+#ifdef BUF_SAVE_MODE
+                       /* write pcm buffer */
+                       fwrite(stream->data, 1, stream->length, g_pFile);
+#else
+                       if (pVr->streamcb) {
+                               pVr->streamcb(stream->data, stream->length);
+                       }
+#endif
+               } 
+       }
+
+       return TRUE;
+}
+
+
+int _camcorder_message_cb (int id, void *param, void *user_param)
+{
+       MMMessageParamType *m = (MMMessageParamType *)param;
+
+       sttd_recorder_s *pVr = __recorder_getinstance();
+
+       if (pVr) {
+               switch(id) {
+               case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM:
+                       break;
+               case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
+                       break;
+               case MM_MESSAGE_CAMCORDER_MAX_SIZE:
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] MM_MESSAGE_CAMCORDER_MAX_SIZE");
+                       sttd_recorder_stop();
+                       break;
+               case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE:
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] MM_MESSAGE_CAMCORDER_NO_FREE_SPACE");
+                       sttd_recorder_cancel();
+                       break;
+               case MM_MESSAGE_CAMCORDER_TIME_LIMIT:
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] MM_MESSAGE_CAMCORDER_TIME_LIMIT");
+                       sttd_recorder_stop();
+                       break;
+               case MM_MESSAGE_CAMCORDER_ERROR:
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] MM_MESSAGE_CAMCORDER_ERROR");
+                       sttd_recorder_cancel();
+                       break;
+               case MM_MESSAGE_CAMCORDER_RECORDING_STATUS:
+                       break;
+               case MM_MESSAGE_CAMCORDER_CURRENT_VOLUME:
+                       pVr->volume = m->rec_volume_dB;
+                       break;
+               default:
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Other Message=%d", id);
+                       break;
+               }
+       } else {
+               return -1;
+       }
+
+       return 0;
+}
+
+
+sttd_recorder_s *__recorder_getinstance()
+{
+       if (!g_objRecorer) {
+               g_objRecorer = NULL;
+               g_objRecorer = g_malloc0(sizeof(sttd_recorder_s));
+
+               /* set default value */
+               g_objRecorer->time_limit = DEF_TIMELIMIT;
+               g_objRecorer->size_limit = DEF_MAXSIZE;    
+               g_objRecorer->now        = 0;
+               g_objRecorer->now_ms     = 0;
+               g_objRecorer->frame      = 0;
+               g_objRecorer->volume     = 0.0f;
+               g_objRecorer->state      = STTD_RECORDER_STATE_READY;
+               g_objRecorer->channel    = STTD_RECORDER_CHANNEL_MONO;
+               g_objRecorer->audio_type = STTD_RECORDER_PCM_S16;
+               g_objRecorer->samplerate = DEF_SAMPLERATE;
+               g_objRecorer->streamcb   = NULL;
+       }
+
+       return g_objRecorer;
+}
+
+void __recorder_state_set(sttd_recorder_state state)
+{
+       sttd_recorder_s* pVr = __recorder_getinstance();
+       pVr->state = state;
+}
+
+void __recorder_remove_temp_file()
+{
+       /* NOTE: temp file can cause permission problem */
+       if (0 != access(g_temp_file_name, R_OK|W_OK)) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] *** You don't have access right to temp file");
+       } else {
+               if (0 != remove(g_temp_file_name)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to remove temp file");
+               }
+       }
+}
+
+
+/* MMFW Interface functions */
+int __recorder_setup()
+{
+       sttd_recorder_s *pVr = __recorder_getinstance();
+
+       /* mm-camcorder preset */
+       MMCamPreset cam_info;
+
+       int     mmf_ret = MM_ERROR_NONE;
+       int     err = 0;
+       char*   err_attr_name = NULL;
+
+       cam_info.videodev_type = MM_VIDEO_DEVICE_NONE;
+
+       /* Create camcorder */
+       mmf_ret = mm_camcorder_create( &pVr->rec_handle, &cam_info);
+       if (MM_ERROR_NONE != mmf_ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail mm_camcorder_create ret=(%X)", mmf_ret);
+               return mmf_ret;
+       }
+
+       switch (pVr->audio_type) {
+       case STTD_RECORDER_PCM_U8:
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] STTD_RECORDER_PCM_U8");
+               err = mm_camcorder_set_attributes(pVr->rec_handle, 
+                       &err_attr_name,
+                       MMCAM_MODE, MM_CAMCORDER_MODE_AUDIO,
+                       MMCAM_AUDIO_DEVICE, MM_AUDIO_DEVICE_MIC,
+
+                       MMCAM_AUDIO_ENCODER, MM_AUDIO_CODEC_AAC, 
+                       MMCAM_FILE_FORMAT, MM_FILE_FORMAT_3GP, 
+
+                       MMCAM_AUDIO_SAMPLERATE, pVr->samplerate,
+                       MMCAM_AUDIO_FORMAT, MM_CAMCORDER_AUDIO_FORMAT_PCM_U8,
+                       MMCAM_AUDIO_CHANNEL, pVr->channel,
+                       MMCAM_AUDIO_INPUT_ROUTE, MM_AUDIOROUTE_CAPTURE_NORMAL,
+                       NULL );
+
+               if (MM_ERROR_NONE != err) {
+                       /* Error */
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail mm_camcorder_set_attributes ret=(%X)", mmf_ret);
+                       return err;
+               }
+               
+               break;
+
+       case STTD_RECORDER_PCM_S16:        
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] STTD_RECORDER_PCM_S16");
+               err = mm_camcorder_set_attributes(pVr->rec_handle, 
+                       &err_attr_name,
+                       MMCAM_MODE, MM_CAMCORDER_MODE_AUDIO,
+                       MMCAM_AUDIO_DEVICE, MM_AUDIO_DEVICE_MIC,
+                       MMCAM_AUDIO_ENCODER, MM_AUDIO_CODEC_AAC,
+                       MMCAM_FILE_FORMAT, MM_FILE_FORMAT_3GP,
+                       MMCAM_AUDIO_SAMPLERATE, pVr->samplerate,
+                       MMCAM_AUDIO_FORMAT, MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE,
+                       MMCAM_AUDIO_CHANNEL, pVr->channel,
+                       MMCAM_AUDIO_INPUT_ROUTE, MM_AUDIOROUTE_CAPTURE_NORMAL,
+                       NULL );
+
+               if (MM_ERROR_NONE != err) {
+                       /* Error */
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail mm_camcorder_set_attributes ret=(%X)", mmf_ret);
+                       return err;
+               }
+               break;
+
+       case STTD_RECORDER_AMR:
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] STTD_RECORDER_AMR");
+               err = mm_camcorder_set_attributes(pVr->rec_handle, 
+                       &err_attr_name,
+                       MMCAM_MODE, MM_CAMCORDER_MODE_AUDIO,
+                       MMCAM_AUDIO_DEVICE, MM_AUDIO_DEVICE_MIC,
+
+                       MMCAM_AUDIO_ENCODER, MM_AUDIO_CODEC_AMR,
+                       MMCAM_FILE_FORMAT, MM_FILE_FORMAT_AMR,
+
+                       MMCAM_AUDIO_SAMPLERATE, pVr->samplerate,
+                       MMCAM_AUDIO_CHANNEL, pVr->channel,
+
+                       MMCAM_AUDIO_INPUT_ROUTE, MM_AUDIOROUTE_CAPTURE_NORMAL,
+                       MMCAM_TARGET_TIME_LIMIT, pVr->time_limit,
+                       MMCAM_TARGET_FILENAME, g_temp_file_name, strlen(g_temp_file_name)+1,
+                       NULL );
+
+               if (MM_ERROR_NONE != err) {
+                       /* Error */
+                       SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail mm_camcorder_set_attributes ret=(%X)", mmf_ret);
+                       return err;
+               }
+               break;
+
+       default:
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder ERROR]");
+               return -1;
+               break;
+       }
+
+       mmf_ret = mm_camcorder_set_audio_stream_callback(pVr->rec_handle, (mm_camcorder_audio_stream_callback)_mm_recorder_audio_stream_cb, NULL);
+       if (MM_ERROR_NONE != err) {
+               /* Error */
+               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail mm_camcorder_set_audio_stream_callback ret=(%X)", mmf_ret);
+               return err;
+       }
+       
+       mmf_ret = mm_camcorder_set_message_callback(pVr->rec_handle, (MMMessageCallback)_camcorder_message_cb, pVr);
+       if (MM_ERROR_NONE != err) {
+               /* Error */
+               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail mm_camcorder_set_message_callback ret=(%X)", mmf_ret);
+               return err;
+       }
+
+       mmf_ret = mm_camcorder_realize(pVr->rec_handle);
+       if (MM_ERROR_NONE != err) {
+               /* Error */
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail mm_camcorder_realize=(%X)", mmf_ret);
+               return err;
+       }
+
+       /* Camcorder start */
+       mmf_ret = mm_camcorder_start(pVr->rec_handle);
+       if (MM_ERROR_NONE != mmf_ret) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail mm_camcorder_start=(%X)", mmf_ret);
+               return mmf_ret;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, " - size_limit=%3d", pVr->size_limit);
+       SLOG(LOG_DEBUG, TAG_STTD, " - time_limit=%3d", pVr->time_limit);
+       SLOG(LOG_DEBUG, TAG_STTD, " - Audio Type=%d", pVr->audio_type);
+       SLOG(LOG_DEBUG, TAG_STTD, " - Sample rates=%d", pVr->samplerate);
+       SLOG(LOG_DEBUG, TAG_STTD, " - channel=%d", pVr->channel);       
+
+       return 0;
+}
+
+int __recorder_run()
+{
+       sttd_recorder_s *pVr = __recorder_getinstance();
+       int     mmf_ret = MM_ERROR_NONE;
+
+       /* If recorder already has recording state, cancel */
+       if (STTD_RECORDER_STATE_RECORDING == pVr->state) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Stop recording first");
+               __recorder_cancel_to_stop();        
+       }
+       
+       /* Reset frame number */
+       pVr->frame = 0;
+
+       /* Record start */
+       mmf_ret = mm_camcorder_record(pVr->rec_handle);
+       if(MM_ERROR_NONE != mmf_ret ) {
+               /* Error */
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail mm_camcorder_record=(%X)", mmf_ret);
+               return mmf_ret;        
+       }
+       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Success mm_camcorder_record");
+
+       return 0;
+}
+
+int __recorder_pause()
+{
+       sttd_recorder_s *pVr = __recorder_getinstance();
+       int mmf_ret = MM_ERROR_NONE;
+       MMCamcorderStateType state_now = MM_CAMCORDER_STATE_NONE;
+
+       /* Get state from MMFW */
+       mmf_ret = mm_camcorder_get_state(pVr->rec_handle, &state_now);
+       if(mmf_ret != MM_ERROR_NONE ) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to get state : mm_camcorder_get_state");
+               return mmf_ret;
+       }
+
+       /* Check recording state */
+       if(MM_CAMCORDER_STATE_RECORDING != state_now) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Not recording state");
+               return mmf_ret;
+       }
+
+       /* Pause recording */
+       mmf_ret = mm_camcorder_pause(pVr->rec_handle);
+       if(mmf_ret == MM_ERROR_NONE ) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] mm_camcorder_pause OK");
+               return mmf_ret;
+       }
+
+       return 0;
+}
+
+int __recorder_cancel_to_stop()
+{
+       sttd_recorder_s *pVr = __recorder_getinstance();
+       int     mmf_ret = MM_ERROR_NONE;
+       MMCamcorderStateType rec_status = MM_CAMCORDER_STATE_NONE;
+
+       /* Cancel camcorder */
+       mmf_ret = mm_camcorder_cancel(pVr->rec_handle);
+       if(mmf_ret != MM_ERROR_NONE ) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to mm_camcorder_cancel");
+               return -1;
+       }
+
+       /* Stop camcorder */
+       mmf_ret = mm_camcorder_stop(pVr->rec_handle);
+       if(mmf_ret != MM_ERROR_NONE ) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to mm_camcorder_stop");
+               return -1;    
+       }
+
+       /* Release resouces */
+       mm_camcorder_get_state(pVr->rec_handle, &rec_status);
+       if (MM_CAMCORDER_STATE_READY == rec_status) {
+               mmf_ret = mm_camcorder_unrealize(pVr->rec_handle);
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Call mm_camcorder_unrealize ret=(%X)", mmf_ret);
+       }
+
+       return 0;
+}
+
+
+int __recorder_commit_to_stop()
+{
+       sttd_recorder_s *pVr = __recorder_getinstance();
+       int     mmf_ret = MM_ERROR_NONE;
+       MMCamcorderStateType rec_status = MM_CAMCORDER_STATE_NONE;    
+
+       /* Commit camcorder */
+       mmf_ret = mm_camcorder_commit(pVr->rec_handle);
+       if(mmf_ret != MM_ERROR_NONE ) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail mm_camcorder_commit=%x", mmf_ret);
+       }
+
+       /* Stop camcorder */
+       mmf_ret = mm_camcorder_stop(pVr->rec_handle);
+       if(mmf_ret != MM_ERROR_NONE ) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail mm_camcorder_stop=%x", mmf_ret);
+       }
+
+       /* Release resouces */
+       mm_camcorder_get_state(pVr->rec_handle, &rec_status);
+       if (MM_CAMCORDER_STATE_READY == rec_status) {
+               mmf_ret = mm_camcorder_unrealize(pVr->rec_handle);
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Call mm_camcorder_unrealize ret=(%X)", mmf_ret);
+       }
+
+       return 0;
+}
+
+
+int __recorder_send_buf_from_file()
+{
+       sttd_recorder_s *pVr = __recorder_getinstance();
+
+       FILE * pFile;
+       if (!pVr->streamcb) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Return callback is not set");
+               return -1;
+       }
+
+       if (STTD_RECORDER_AMR != pVr->audio_type) {
+#ifndef BUF_SAVE_MODE
+               return 0;
+#else 
+               fclose(g_pFile);
+#endif         
+       } 
+
+       pFile = fopen(g_temp_file_name, "rb");
+       if (!pFile) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] File not found!");
+               return -1;
+       }
+
+       char buff[1024];
+       size_t read_size = 0;
+       int ret = 0;
+       
+       while (!feof(pFile)) {
+               read_size = fread(buff, 1, 1024, pFile);
+               if (read_size > 0) {
+                       ret = pVr->streamcb((void*)buff, read_size);
+
+                       if(ret != 0) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to set recording");
+                               break;
+                       }
+               }
+       }
+
+       fclose(pFile);
+
+       return 0;
+}
+
+int __vr_mmcam_destroy()
+{
+       int err = 0;
+       sttd_recorder_s *pVr = __recorder_getinstance();
+
+       MMCamcorderStateType rec_status = MM_CAMCORDER_STATE_NONE;
+
+       mm_camcorder_get_state(pVr->rec_handle, &rec_status);
+       if (rec_status == MM_CAMCORDER_STATE_NULL) {
+               err = mm_camcorder_destroy(pVr->rec_handle);
+
+               if (MM_ERROR_NONE == err) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] mm_camcorder_destroy OK");
+                       pVr->rec_handle = 0;
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Error mm_camcorder_destroy %x", err);            
+               }
+
+       }
+
+       return 0;
+}
+
+
+/* External functions */
+int sttd_recorder_init()
+{
+       /* Create recorder instance     */
+       sttd_recorder_s *pVr = __recorder_getinstance();
+       if (!pVr) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to initialize voice recorder!");
+               return -1;    
+       }
+       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Voice Recorder Initialized p=%p", pVr);
+
+       /* Set temp file name */
+       snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/stt_temp_%d", getpid());
+       SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Temp file name=[%s]", g_temp_file_name);
+
+       g_init = true;
+
+       return 0;
+}
+
+int sttd_recorder_set(sttd_recorder_audio_type type, sttd_recorder_channel ch, unsigned int sample_rate, 
+                     unsigned int max_time, sttvr_audio_cb cbfunc)
+{
+       sttd_recorder_s *pVr = __recorder_getinstance();
+       int ret = 0;
+
+       if (STTD_RECORDER_STATE_RECORDING == pVr->state) 
+               __recorder_cancel_to_stop();
+
+       if (STTD_RECORDER_STATE_READY != pVr->state) 
+               __vr_mmcam_destroy();
+
+       /* Set attributes */
+       pVr->audio_type = type;
+       pVr->channel    = ch;
+       pVr->samplerate = sample_rate;
+       pVr->time_limit = max_time;
+
+       /* Stream data Callback function */
+       if (cbfunc)
+               pVr->streamcb = cbfunc;
+
+       return ret;
+}
+
+int sttd_recorder_start()
+{
+       int ret = 0;
+
+       __recorder_remove_temp_file();
+
+#ifdef BUF_SAVE_MODE
+       sttd_recorder_s *pVr = __recorder_getinstance();
+       if (!pVr) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to initialize voice recorder!");
+               return -1;    
+       }
+
+       if (STTD_RECORDER_AMR != pVr->audio_type) {
+               /* open test file */
+               g_pFile = fopen(g_temp_file_name, "wb+");
+               if (!g_pFile) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] File not found!");
+                       return -1;
+               }       
+       }
+#endif 
+
+       /* Check if initialized */
+       ret = __recorder_setup();
+       if (ret) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to call __recorder_setup");
+       }
+
+       /* Start camcorder */
+       ret = __recorder_run();
+       if (ret) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to call __recorder_run");                
+       }
+
+       __recorder_state_set(STTD_RECORDER_STATE_RECORDING);
+
+       return 0;
+}
+
+
+int sttrecorder_pause()
+{
+       int ret = 0;
+
+       ret = __recorder_pause();
+       if (ret) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to call __recorder_pause");
+               return -1;
+       }
+
+       /* Set state */
+       __recorder_state_set(STTD_RECORDER_STATE_PAUSED);    
+
+       return 0;
+}
+
+int sttd_recorder_cancel()
+{
+       int ret = 0;    
+       ret = __recorder_cancel_to_stop();
+       if (ret) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to call __recorder_cancel_to_stop");
+               return -1;
+       }
+
+       ret = __vr_mmcam_destroy();
+       if (ret) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to call __vr_mmcam_destroy");
+               return -1;
+       }      
+
+       /* Set state */
+       __recorder_state_set(STTD_RECORDER_STATE_READY);    
+
+       return 0;
+}
+
+
+int sttd_recorder_stop()
+{
+       int ret = 0;
+
+       ret = __recorder_commit_to_stop();
+       if (ret) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to call __recorder_commit_to_stop");
+               return -1;
+       }
+
+       ret = __recorder_send_buf_from_file();
+       if (ret) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to call __recorder_send_buf_from_file");
+               return -1;
+       }    
+
+       ret = __vr_mmcam_destroy();
+       if (ret) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to call __vr_mmcam_destroy");
+               return -1;
+       }
+
+       __recorder_state_set(STTD_RECORDER_STATE_READY);
+
+       return 0;
+}
+
+
+int sttd_recorder_destroy()
+{
+       /* Destroy recorder object */
+       if (g_objRecorer)
+               g_free(g_objRecorer);
+
+       g_objRecorer = NULL;
+       
+       __recorder_state_set(STTD_RECORDER_STATE_READY);
+
+       return 0;
+}
+
+
+int sttd_recorder_state_get(sttd_recorder_state* state)
+{
+       sttd_recorder_s *pVr = __recorder_getinstance();
+       if (!pVr) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to get instance"); 
+               return -1;
+       }
+
+       *state = pVr->state;
+
+       return 0;
+}
+
+
+int sttd_recorder_get_volume(float *vol)
+{
+       sttd_recorder_state state;
+
+       sttd_recorder_s *pVr = __recorder_getinstance();
+       if (!pVr) {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Fail to get instance"); 
+               return -1;
+       }
+
+       sttd_recorder_state_get(&state);
+       if (STTD_RECORDER_STATE_RECORDING != state) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Not in Recording state");
+               return -1;
+       }
+       *vol = pVr->volume;
+
+       return 0;
+}
diff --git a/server/sttd_recorder.h b/server/sttd_recorder.h
new file mode 100644 (file)
index 0000000..6bc4928
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STTD_RECORDER_H__
+#define __STTD_RECORDER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+       STTD_RECORDER_STATE_READY,      /**< Recorder is ready to start */
+       STTD_RECORDER_STATE_RECORDING,  /**< In the middle of recording */
+       STTD_RECORDER_STATE_PAUSED
+} sttd_recorder_state;
+
+typedef enum {
+       STTD_RECORDER_PCM_S16,          /**< PCM, signed 16-bit */
+       STTD_RECORDER_PCM_U8,           /**< PCM, unsigned 8-bit */
+       STTD_RECORDER_AMR               /**< AMR (Callback will be invoked after recording) */
+} sttd_recorder_audio_type;
+
+typedef enum {
+       STTD_RECORDER_CHANNEL_MONO      = 1,    /**< Mono channel : Default value */
+       STTD_RECORDER_CHANNEL_STEREO    = 2     /**< Stereo */
+} sttd_recorder_channel;
+
+
+typedef int (*sttvr_audio_cb)(const void* data, const unsigned int length);
+typedef int (*sttvr_volume_data_cb)(const float data);
+
+int sttd_recorder_set(sttd_recorder_audio_type type, sttd_recorder_channel ch, unsigned int sample_rate, unsigned int max_time, sttvr_audio_cb cbfunc);
+
+int sttd_recorder_init();
+
+int sttd_recorder_start();
+
+int sttd_recorder_cancel();
+
+int sttd_recorder_stop();
+
+int sttrecorder_pause();
+
+int sttd_recorder_state_get(sttd_recorder_state* state);
+
+int sttd_recorder_get_volume(float *vol);
+
+int sttd_recorder_destroy();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STTD_RECORDER_H__ */
+
diff --git a/server/sttd_server.c b/server/sttd_server.c
new file mode 100644 (file)
index 0000000..2ca7130
--- /dev/null
@@ -0,0 +1,972 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#include "sttd_main.h"
+#include "sttd_server.h"
+
+#include "sttd_client_data.h"
+#include "sttd_engine_agent.h"
+#include "sttd_config.h"
+#include "sttd_recorder.h"
+#include "sttd_network.h"
+#include "sttd_dbus.h"
+
+/*
+* STT Server static variable
+*/
+static bool g_is_engine;
+
+/*
+* STT Server Callback Functions                                                                                        `                                 *
+*/
+
+int audio_recorder_callback(const void* data, const unsigned int length)
+{
+       if (0 != sttd_engine_recognize_audio(data, length)) {
+               
+               /* send message for stop */
+               SLOG(LOG_DEBUG, TAG_STTD, "===== Fail to set recording data ");
+                       
+               int uid = sttd_client_get_current_recording();
+
+               app_state_e state;
+               if (0 != sttd_client_get_state(uid, &state)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is not valid "); 
+                       return -1;
+               }
+
+               if (APP_STATE_RECORDING != state) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording"); 
+                       return -1;
+               }
+
+               if (0 != sttd_send_stop_recognition_by_daemon(uid)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail "); 
+               } else {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] <<<< stop message : uid(%d)", uid); 
+               }
+
+               SLOG(LOG_DEBUG, TAG_STTD, "=====");
+               SLOG(LOG_DEBUG, TAG_STTD, "  ");
+               
+               return -1;
+       }
+       
+       
+
+       return 0;
+}
+
+void sttd_server_recognition_result_callback(sttp_result_event_e event, const char* type, 
+                                       const char** data, int data_count, const char* msg, void *user_data)
+{
+       SLOG(LOG_DEBUG, TAG_STTD, "===== Recognition Result Callback");
+
+       /* check uid */
+       int *uid = (int*)user_data;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid (%d), event(%d)", uid, event); 
+
+       app_state_e state;
+       if (0 != sttd_client_get_state(*uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               SLOG(LOG_DEBUG, TAG_STTD, "=====");
+               SLOG(LOG_DEBUG, TAG_STTD, "  ");
+               return;
+       }
+
+       /* send result to client */
+       if (STTP_RESULT_EVENT_SUCCESS == event && 0 < data_count && NULL != data) {
+
+               if (APP_STATE_PROCESSING == state ) {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Server] the size of result from engine is '%d' %s", data_count); 
+
+                       if (0 != sttdc_send_result(*uid, type, data, data_count, msg)) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result");        
+                               int reason = (int)STTD_ERROR_OPERATION_FAILED;
+
+                               if (0 != sttdc_send_error_signal(*uid, reason, "Fail to send recognition result")) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info . Remove client data"); 
+
+                                       /* clean client data */
+                                       sttd_client_delete(*uid);
+                               }
+                       }
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is NOT thinking"); 
+
+                       int reason = (int)STTD_ERROR_INVALID_STATE;             
+                       if (0 != sttdc_send_error_signal(*uid, reason, "Client state is NOT thinking. Client don't receive recognition result in current state.")) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info. Remove client data "); 
+
+                               /* clean client data */
+                               sttd_client_delete(*uid);               
+                       }
+               }
+       } else if (STTP_RESULT_EVENT_NO_RESULT == event) {
+
+               if (APP_STATE_PROCESSING == state ) {
+                       if (0 != sttdc_send_result(*uid, NULL, NULL, 0, NULL)) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result "); 
+
+                               /* send error msg */
+                               int reason = (int)STTD_ERROR_INVALID_STATE;     
+                               if (0 != sttdc_send_error_signal(*uid, reason, "[ERROR] Fail to send recognition result")) {
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info "); 
+                                       sttd_client_delete(*uid);
+                               }
+                       }
+               } else {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is NOT thinking "); 
+
+                       int reason = (int)STTD_ERROR_INVALID_STATE;             
+
+                       if (0 != sttdc_send_error_signal(*uid, reason, "Client state is NOT thinking. Client don't receive recognition result in current state.")) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info. Remove client data"); 
+
+                               /* clean client data */
+                               sttd_client_delete(*uid);               
+                       }
+               }
+       } else if (STTP_RESULT_EVENT_ERROR == event) {
+               int reason = (int)STTD_ERROR_OPERATION_FAILED;
+
+               if (0 != sttdc_send_error_signal(*uid, reason, "STT Engine ERROR : Recognition fail")) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info"); 
+                       sttd_client_delete(*uid);
+               }       
+       } else {
+               /* nothing */
+       }
+
+       /* change state of uid */
+       sttd_client_set_state(*uid, APP_STATE_READY);
+
+       if (NULL != user_data)  
+               free(user_data);
+
+       SLOG(LOG_DEBUG, TAG_STTD, "=====");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return;
+}
+
+void sttd_server_partial_result_callback(sttp_result_event_e event, const char* data, void *user_data)
+{
+       SLOG(LOG_DEBUG, TAG_STTD, "===== Partial Result Callback");
+
+       /* check uid */
+       int *uid = (int*)user_data;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid (%d), event(%d)", uid, event); 
+
+       app_state_e state;
+       if (0 != sttd_client_get_state(*uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               SLOG(LOG_DEBUG, TAG_STTD, "=====");
+               SLOG(LOG_DEBUG, TAG_STTD, "  ");
+               return;
+       }
+
+       /* send result to client */
+       if (STTP_RESULT_EVENT_SUCCESS == event && NULL != data) {
+               if (0 != sttdc_send_partial_result(*uid, data)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send partial result");        
+               }
+       } 
+
+       SLOG(LOG_DEBUG, TAG_STTD, "=====");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+}
+
+void sttd_server_silence_dectection_callback(void *user_param)
+{
+       SLOG(LOG_DEBUG, TAG_STTD, "===== Silence Detection Callback");
+
+       int uid = sttd_client_get_current_recording();
+
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is not valid "); 
+               return;
+       }
+
+       if (APP_STATE_RECORDING != state) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording"); 
+               return;
+       }
+
+       if (0 != sttd_send_stop_recognition_by_daemon(uid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail "); 
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] <<<< stop message : uid(%d)", uid); 
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "=====");
+       SLOG(LOG_DEBUG, TAG_STTD, "  ");
+
+       return;
+}
+
+/*
+* Daemon initialize
+*/
+
+int sttd_initialize()
+{
+       int ret = 0;
+
+       /* recoder init */
+       ret = sttd_recorder_init();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to initialize recorder : result(%d)", ret); 
+               return ret;
+       }
+
+       /* Engine Agent initialize */
+       ret = sttd_engine_agent_init(sttd_server_recognition_result_callback, sttd_server_partial_result_callback, 
+                               sttd_server_silence_dectection_callback);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
+               return ret;
+       }
+       
+       if (0 != sttd_engine_agent_initialize_current_engine()) {
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No STT-Engine !!!!!"); 
+               g_is_engine = false;
+       } else {
+               g_is_engine = true;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] initialize"); 
+
+       return 0;
+}
+
+/*
+* STT Server Functions for Client
+*/
+
+int sttd_server_initialize(int pid, int uid)
+{
+       if (false == g_is_engine) {
+               if (0 != sttd_engine_agent_initialize_current_engine()) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] No Engine"); 
+                       g_is_engine = false;
+                       return STTD_ERROR_ENGINE_NOT_FOUND;
+               } else {
+                       g_is_engine = true;
+               }
+       }
+
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 == sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid has already been registered"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+       
+       /* load if engine is unloaded */
+       if (0 == sttd_client_get_ref_count()) {
+               if (0 != sttd_engine_agent_load_current_engine()) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to load current engine"); 
+                       return STTD_ERROR_OPERATION_FAILED;
+               }
+       }
+
+       /* initialize recorder using audio format from engine */
+       sttp_audio_type_e atype;
+       int rate;
+       int channels;
+
+       if (0 != sttd_engine_get_audio_format(&atype, &rate, &channels)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get audio format of engine."); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       sttd_recorder_channel   sttchannel;
+       sttd_recorder_audio_type        sttatype;
+
+       switch (atype) {
+       case STTP_AUDIO_TYPE_PCM_S16_LE:        sttatype = STTD_RECORDER_PCM_S16;       break;
+       case STTP_AUDIO_TYPE_PCM_U8:            sttatype = STTD_RECORDER_PCM_U8;        break;
+       case STTP_AUDIO_TYPE_AMR:               sttatype = STTD_RECORDER_AMR;           break;
+       default:        
+               /* engine error */
+               sttd_engine_agent_unload_current_engine();
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Invalid Audio Type"); 
+               return STTD_ERROR_OPERATION_FAILED;
+               break;
+       }
+
+       switch (sttchannel) {
+       case 1:         sttchannel = STTD_RECORDER_CHANNEL_MONO;        break;
+       case 2:         sttchannel = STTD_RECORDER_CHANNEL_STEREO;      break;
+       default:        sttchannel = STTD_RECORDER_CHANNEL_MONO;        break;
+       }
+
+       if (0 != sttd_recorder_set(sttatype, sttchannel, rate, 60, audio_recorder_callback)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set recorder"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+       
+       /* Add client information to client manager */
+       if (0 != sttd_client_add(pid, uid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add client info"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] audio type(%d), channel(%d)", (int)atype, (int)sttchannel); 
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_finalize(const int uid)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* release recorder */
+       app_state_e appstate;
+       sttd_client_get_state(uid, &appstate);
+
+       if (APP_STATE_RECORDING == appstate || APP_STATE_PROCESSING == appstate) {
+               sttd_recorder_cancel();
+               sttd_engine_recognize_cancel();
+       }
+       
+       /* Remove client information */
+       if (0 != sttd_client_delete(uid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to delete client"); 
+       }
+
+       /* unload engine, if ref count of client is 0 */
+       if (0 == sttd_client_get_ref_count()) {
+               if (0 != sttd_engine_agent_unload_current_engine()) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unload current engine"); 
+               } else {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] unload current engine"); 
+               }
+       }
+       
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_get_supported_languages(const int uid, GList** lang_list)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* get language list from engine */
+       int ret = sttd_engine_supported_langs(lang_list);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get supported languages"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] sttd_server_get_supported_languages"); 
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_get_current_langauage(const int uid, char** current_lang)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == current_lang) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /*get current language from engine */
+       int ret = sttd_engine_get_default_lang(current_lang);
+       if (0 != ret) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get default language :result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] sttd_engine_get_default_lang"); 
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_is_partial_result_supported(int uid, int* partial_result)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == partial_result) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       bool temp;
+       int ret = sttd_engine_is_partial_result_supported(&temp);
+       if (0 != ret) { 
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get partial result supported : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Partial result supporting is %s", temp ? "true" : "false"); 
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_get_audio_volume( const int uid, float* current_volume)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* check uid state */
+       if (APP_STATE_RECORDING != state) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == current_volume) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* get audio volume from recorder */
+       int ret = sttd_recorder_get_volume(current_volume);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get volume : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_start(const int uid, const char* lang, const char* recognition_type, 
+                     int profanity, int punctuation, int silence)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* check uid state */
+       if (APP_STATE_READY != state) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] sttd_server_start : current state is not ready"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       if (0 < sttd_client_get_current_recording()) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT Engine is busy because of recording");
+               return STTD_ERROR_RECORDER_BUSY;
+       }
+
+       if (0 < sttd_client_get_current_thinking()) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT Engine is busy because of thinking");
+               return STTD_ERROR_RECORDER_BUSY;
+       }
+
+       /* check if engine use network */
+       if (true == sttd_engine_agent_need_network()) {
+               if (false == sttd_network_is_connected()) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Disconnect network. Current engine needs to network connection.");
+                       return STTD_ERROR_OUT_OF_NETWORK;
+               }
+       }
+
+       /* engine start recognition */
+       int* user_data;
+       user_data = (int*)malloc( sizeof(int) * 1);
+       
+       /* free on result callback */
+       *user_data = uid;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server] start : uid(%d), lang(%s), recog_type(%s)", *user_data, lang, recognition_type ); 
+
+       int ret = sttd_engine_recognize_start((char*)lang, recognition_type, profanity, punctuation, silence, (void*)user_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recognition : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* recorder start */
+       ret = sttd_recorder_start();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recorder : result(%d)", ret); 
+               sttd_engine_recognize_cancel();
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Server] start recording"); 
+
+       /* change uid state */
+       sttd_client_set_state(uid, APP_STATE_RECORDING);
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_stop(const int uid)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* check uid state */
+       if (APP_STATE_RECORDING != state) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       /* stop recorder */
+       sttd_recorder_stop();
+
+       /* stop engine recognition */
+       int ret = sttd_engine_recognize_stop();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop : result(%d)", ret); 
+               sttd_client_set_state(uid, APP_STATE_READY);            
+       
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* change uid state */
+       sttd_client_set_state(uid, APP_STATE_PROCESSING);
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_cancel(const int uid)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* check uid state */ 
+       if (APP_STATE_READY == state) {
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current state is ready"); 
+               return STTD_ERROR_INVALID_STATE;
+       }
+
+       /* stop recorder */
+       if (APP_STATE_RECORDING == state) 
+               sttd_recorder_cancel();
+
+       /* cancel engine recognition */
+       int ret = sttd_engine_recognize_cancel();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* change uid state */
+       sttd_client_set_state(uid, APP_STATE_READY);
+
+       return STTD_ERROR_NONE;
+}
+
+
+/******************************************************************************************
+* STT Server Functions for setting
+*******************************************************************************************/
+
+int sttd_server_setting_initialize(int uid)
+{
+       if (false == g_is_engine) {
+               if (0 != sttd_engine_agent_initialize_current_engine()) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] No Engine"); 
+                       g_is_engine = false;
+                       return STTD_ERROR_ENGINE_NOT_FOUND;
+               } else {
+                       g_is_engine = true;
+               }
+       }
+
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 == sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid has already been registered"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* load if engine is unloaded */
+       if (0 == sttd_client_get_ref_count()) {
+               if (0 != sttd_engine_agent_load_current_engine()) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to load current engine"); 
+                       return STTD_ERROR_OPERATION_FAILED;
+               }
+       }
+
+       /* Add client information to client manager (For internal use) */
+       if (0 != sttd_client_add(uid, uid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add client info"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_finalize(int uid)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* Remove client information */
+       if (0 != sttd_client_delete(uid)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to delete setting client"); 
+       }
+
+       /* unload engine, if ref count of client is 0 */
+       if (0 == sttd_client_get_ref_count()) {
+               if (0 != sttd_engine_agent_unload_current_engine()) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unload current engine"); 
+               } else {
+                       SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] unload current engine"); 
+               }
+       }
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_get_engine_list(int uid, GList** engine_list)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == engine_list) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = sttd_engine_setting_get_engine_list(engine_list); 
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine list : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_get_engine(int uid, char** engine_id)
+{
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* get engine */
+       int ret = sttd_engine_setting_get_engine(engine_id); 
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_set_engine(const int uid, const char* engine_id)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       /* set engine */
+       int ret = sttd_engine_setting_set_engine(engine_id); 
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set engine : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_get_lang_list(int uid, char** engine_id, GList** lang_list)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+       
+       if (NULL == lang_list) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] language is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+       
+       int ret = sttd_engine_setting_get_lang_list(engine_id, lang_list); 
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get language list : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_get_default_language(int uid, char** language)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == language) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] language is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = sttd_engine_setting_get_default_lang(language); 
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get default language : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }       
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_set_default_language(int uid, const char* language)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == language) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] language is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = sttd_engine_setting_set_default_lang((char*)language); 
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set default lang : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }       
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_get_profanity_filter(int uid, bool* value)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = sttd_engine_setting_get_profanity_filter(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get profanity filter : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }       
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_set_profanity_filter(int uid, bool value)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = sttd_engine_setting_set_profanity_filter(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set profanity filter: result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }       
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_get_punctuation_override(int uid, bool* value)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = sttd_engine_setting_get_punctuation_override(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get punctuation override : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }       
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_set_punctuation_override(int uid, bool value)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = sttd_engine_setting_set_punctuation_override(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set punctuation override : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }       
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_get_silence_detection(int uid, bool* value)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == value) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = sttd_engine_setting_get_silence_detection(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get silence detection : result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }       
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_set_silence_detection(int uid, bool value)
+{
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = sttd_engine_setting_set_silence_detection(value);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to Result(%d)", ret); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }       
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_get_engine_setting(int uid, char** engine_id, GList** lang_list)
+{      
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (0 != sttd_engine_setting_get_engine_setting_info(engine_id, lang_list)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine setting info"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return STTD_ERROR_NONE;
+}
+
+int sttd_server_setting_set_engine_setting(int uid, const char* key, const char* value)
+{      
+       /* check if uid is valid */
+       app_state_e state;
+       if (0 != sttd_client_get_state(uid, &state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); 
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (0 != sttd_engine_setting_set_engine_setting(key, value)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set engine setting info"); 
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       return STTD_ERROR_NONE;
+}
+
+
diff --git a/server/sttd_server.h b/server/sttd_server.h
new file mode 100644 (file)
index 0000000..878998f
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+
+#ifndef __STTD_SERVER_H_
+#define __STTD_SERVER_H_
+
+#include "sttd_main.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/** Daemon initialize */
+int sttd_initialize();
+
+/*
+* API for client
+*/
+
+int sttd_server_initialize(int pid, int uid);
+
+int sttd_server_finalize(const int uid);
+
+int sttd_server_get_supported_languages(const int uid, GList** lang_list);
+
+int sttd_server_get_current_langauage(const int uid, char** current_lang);
+
+int sttd_server_set_engine_data(int uid, const char* key, const char* value);
+
+int sttd_server_is_partial_result_supported(int uid, int* partial_result);
+
+int sttd_server_get_audio_volume(const int uid, float* current_volume);
+
+int sttd_server_start(const int uid, const char* lang, const char* recognition_type, 
+                       int profanity, int punctuation, int silence);
+
+int sttd_server_stop(const int uid);
+
+int sttd_server_cancel(const int uid);
+
+/*
+* API for setting
+*/
+
+int sttd_server_setting_initialize(int uid);
+
+int sttd_server_setting_finalize(int uid);
+
+int sttd_server_setting_get_engine_list(int uid, GList** engine_list);
+
+int sttd_server_setting_get_engine(int uid, char** engine_id);
+
+int sttd_server_setting_set_engine(const int uid, const char* engine_id);
+
+int sttd_server_setting_get_lang_list(int uid, char** engine_id, GList** lang_list);
+
+int sttd_server_setting_get_default_language(int uid, char** language);
+
+int sttd_server_setting_set_default_language(int uid, const char* language);
+
+int sttd_server_setting_get_profanity_filter(int uid, bool* value);
+
+int sttd_server_setting_set_profanity_filter(int uid, bool value);
+
+int sttd_server_setting_get_punctuation_override(int uid, bool* value);
+
+int sttd_server_setting_set_punctuation_override(int uid, bool value);
+
+int sttd_server_setting_get_silence_detection(int uid, bool* value);
+
+int sttd_server_setting_set_silence_detection(int uid, bool value);
+
+int sttd_server_setting_get_engine_setting(int uid, char** engine_id, GList** lang_list);
+
+int sttd_server_setting_set_engine_setting(int uid, const char* key, const char* value);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STTD_SERVER_H_ */
diff --git a/server/sttp.h b/server/sttp.h
new file mode 100644 (file)
index 0000000..da393f8
--- /dev/null
@@ -0,0 +1,577 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*  http://www.apache.org/licenses/LICENSE-2.0
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+#ifndef __STTP_H__
+#define __STTP_H__
+
+#include <errno.h>
+#include <stdbool.h>
+
+/**
+* @addtogroup STT_ENGINE_MODULE
+* @{
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** 
+* @brief Enumerations of error codes.
+*/
+typedef enum {
+       STTP_ERROR_NONE                 =  0,           /**< Successful */
+       STTP_ERROR_OUT_OF_MEMORY        = -ENOMEM,      /**< Out of Memory */
+       STTP_ERROR_IO_ERROR             = -EIO,         /**< I/O error */
+       STTP_ERROR_INVALID_PARAMETER    = -EINVAL,      /**< Invalid parameter */
+       STTP_ERROR_OUT_OF_NETWORK       = -ENETDOWN,    /**< Out of network */
+       STTP_ERROR_INVALID_STATE        = -0x0100031,   /**< Invalid state */
+       STTP_ERROR_INVALID_LANGUAGE     = -0x0100032,   /**< Invalid language */
+       STTP_ERROR_OPERATION_FAILED     = -0x0100034,   /**< Operation failed */
+       STTP_ERROR_NOT_SUPPORTED        = -0x0100035    /**< Not supported function */
+}sttp_error_e;
+
+/**
+* @brief Enumerations of audio type. 
+*/
+typedef enum {
+       STTP_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */
+       STTP_AUDIO_TYPE_PCM_U8,         /**< Unsigned 8bit audio type */
+       STTP_AUDIO_TYPE_AMR             /**< AMR audio type */
+}sttp_audio_type_e;
+
+/**
+* @brief Enumerations of callback event.
+*/
+typedef enum {
+       STTP_RESULT_EVENT_SUCCESS = 0,  /**< Event when the recognition full result is ready  */
+       STTP_RESULT_EVENT_NO_RESULT,    /**< Event when the recognition result is not */
+       STTP_RESULT_EVENT_ERROR         /**< Event when the recognition has failed */
+}sttp_result_event_e;
+
+/** 
+* @brief Recognition type : free form dictation or default type.
+*/
+#define STTP_RECOGNITION_TYPE_FREE                     "stt.recognition.type.FREE"
+
+/** 
+* @brief Recognition type : web search. 
+*/
+#define STTP_RECOGNITION_TYPE_WEB_SEARCH               "stt.recognition.type.WEB_SEARCH"
+
+/** 
+* @brief Recognition type : all voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND                  "stt.recognition.type.COMMAND"
+
+/** 
+* @brief Recognition type : call of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_CALL             "stt.recognition.type.COMMAND.CALL"
+
+/** 
+* @brief Recognition type : music of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_MUSIC            "stt.recognition.type.COMMAND.MUSIC"
+
+/** 
+* @brief Recognition type : web search of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_WEB_SEARCH       "stt.recognition.type.COMMAND.WEB_SEARCH"
+
+/** 
+* @brief Recognition type : schedule of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_SCHEDULE         "stt.recognition.type.COMMAND.SCHEDULE"
+
+/** 
+* @brief Recognition type : search of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_SEARCH           "stt.recognition.type.COMMAND.SEARCH"
+
+/** 
+* @brief Recognition type : contact of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_CONTACT          "stt.recognition.type.COMMAND.CONTACT"
+
+/** 
+* @brief Recognition type : social of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_SOCIAL           "stt.recognition.type.COMMAND.SOCIAL"
+
+/** 
+* @brief Recognition type : message of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_MESSAGE          "stt.recognition.type.COMMAND.MESSAGE"
+
+/** 
+* @brief Recognition type : email of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_EMAIL            "stt.recognition.type.COMMAND.EMAIL"
+
+/** 
+* @brief Recognition type : memo of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_MEMO             "stt.recognition.type.COMMAND.MEMO"
+
+/** 
+* @brief Recognition type : alarm of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_ALARM            "stt.recognition.type.COMMAND.ALARM"
+
+/** 
+* @brief Recognition type : application of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_APPLICATION      "stt.recognition.type.COMMAND.APPLICATION"
+
+/** 
+* @brief Recognition type : driving mode of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_DRIVING_MODE     "stt.recognition.type.COMMAND.DRIVING_MODE"
+
+/** 
+* @brief Recognition type : navigation of voice commands. 
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_NAVIGATION       "stt.recognition.type.COMMAND.NAVIGATION"
+
+/** 
+* @brief Recognition type : text-to-speech of voice commands.
+*/
+#define STTP_RECOGNITION_TYPE_COMMAND_TTS              "stt.recognition.type.COMMAND.TTS"
+
+
+/** 
+* @brief Called to get recognition result.
+* 
+* @param[in] event A result event
+* @param[in] type A recognition type
+* @param[in] data Result texts
+* @param[in] data_count Result text count
+* @param[in] msg engine A Message
+* @param[in] user_data The user data passed from the start function
+*
+* @pre sttpe_stop() will invoke this callback.
+*
+* @see sttpe_start()
+* @see sttpe_stop()
+*/
+typedef void (*sttpe_result_cb)(sttp_result_event_e event, const char* type, 
+                               const char** data, int data_count, const char* msg, void *user_data);
+
+/** 
+* @brief Called to get partial recognition result.
+* 
+* @param[in] event A result event
+* @param[in] data A result text
+* @param[in] user_data The user data passed from the start function.
+*
+* @pre sttpe_set_recording_data() will invoke this callback
+*
+* @see sttpe_set_recording_data()
+*/
+typedef void (*sttpe_partial_result_cb)(sttp_result_event_e event, const char* data, void *user_data);
+
+/** 
+* @brief Called to detect silence from recording data.
+* 
+* @param[in] user_data The user data passed from the start function.
+*
+* @pre sttpe_set_recording_data() will invoke this callback.
+*
+* @see sttpe_set_recording_data()
+*/
+typedef void (*sttpe_silence_detected_cb)(void *user_data);
+
+/**
+* @brief Called to retrieve the supported languages. 
+*
+* @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code
+*              followed by ISO 639-1 for the two-letter language code \n
+*              For example, "ko_KR" for Korean, "en_US" for American English
+* @param[in] user_data The user data passed from the foreach function
+*
+* @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
+*
+* @pre sttpe_foreach_supported_languages() will invoke this callback. 
+*
+* @see sttpe_foreach_supported_languages()
+*/
+typedef bool (*sttpe_supported_language_cb)(const char* language, void* user_data);
+
+/**
+* @brief Called to retrieve the supported engine settings.
+*
+* @param[in] key A key
+* @param[in] value A value
+* @param[in] user_data The user data passed from the foreach function
+*
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+* @pre sttpe_foreach_engine_settings() will invoke this callback. 
+*
+* @see sttpe_foreach_engine_settings()
+*/
+typedef bool (*sttpe_engine_setting_cb)(const char* key, const char* value, void* user_data);
+
+/**
+* @brief Initializes the engine.
+*
+* @param[in] result_cb A callback function for recognition result
+* @param[in] partial_result_cb A callback function for partial recognition result
+* @param[in] silence_cb A callback function for silence detection
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTP_ERROR_INVALID_STATE Already initialized
+* @retval #STTP_ERROR_OPERATION_FAILED Operation failed
+* 
+* @see sttpe_deinitialize()
+*/
+typedef int (* sttpe_initialize)(sttpe_result_cb result_cb, sttpe_partial_result_cb partial_result_cb, 
+                                sttpe_silence_detected_cb silence_cb);
+
+/**
+* @brief Deinitializes the engine
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+* 
+* @see sttpe_initialize()
+*/
+typedef int (* sttpe_deinitialize)(void);
+
+/**
+* @brief Retrieves all supported languages of the engine.
+*
+* @param[in] callback a callback function
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+*
+* @post        This function invokes sttpe_supported_language_cb() repeatedly for getting supported languages. 
+*
+* @see sttpe_supported_language_cb()
+*/
+typedef int (* sttpe_foreach_supported_languages)(sttpe_supported_language_cb callback, void* user_data);
+
+/**
+* @brief Checks whether a language is valid or not.
+*
+* @param[in] language A language
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+*
+* @see sttpe_foreach_supported_languages()
+*/
+typedef bool (* sttpe_is_valid_language)(const char* language);
+
+/**
+* @brief Gets whether the engine supports silence detection. 
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+*/
+typedef bool (* sttpe_support_silence_detection)(void);
+
+/**
+* @brief Gets supporting partial result. 
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+*/
+typedef bool (* sttpe_support_partial_result)(void);
+
+/**
+* @brief Gets recording format of the engine. 
+*
+* @param[out] types The format used by the recorder.
+* @param[out] rate The sample rate used by the recorder.
+* @param[out] channels The number of channels used by the recorder.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+*/
+typedef int (* sttpe_get_recording_format)(sttp_audio_type_e* types, int* rate, int* channels);
+
+/**
+* @brief Sets profanity filter option.
+* 
+* @param[in] value A value
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+* @retval #STTP_ERROR_NOT_SUPPORTED Not supported
+*/
+typedef int (* sttpe_set_profanity_filter)(bool value);
+
+/**
+* @brief Sets punctuation option.
+* 
+* @param[in] value A value
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+* @retval #STTP_ERROR_NOT_SUPPORTED Not supported
+*/
+typedef int (* sttpe_set_punctuation_override)(bool value);
+
+/**
+* @brief Sets silence detection option.
+* 
+* @param[in] value A value
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+* @retval #STTP_ERROR_NOT_SUPPORTED Not supported
+*/
+typedef int (* sttpe_set_silence_detection)(bool value);
+
+/**
+* @brief Start recognition.
+*
+* @param[in] language A language. 
+* @param[in] type A recognition type.
+* @param[in] user_data The user data to be passed to the callback function. 
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTP_ERROR_INVALID_STATE Invalid state
+* @retval #STTP_ERROR_INVALID_LANGUAGE Invalid language
+* @retval #STTP_ERROR_OPERATION_FAILED Operation failed
+* @retval #STTP_ERROR_OUT_OF_NETWORK Out of network
+*
+* @pre The engine is not in recognition processing.
+*
+* @see sttpe_set_recording_data()
+* @see sttpe_stop()
+* @see sttpe_cancel()
+*/
+typedef int (* sttpe_start)(const char* language, const char* type, void *user_data);
+
+/**
+* @brief Sets recording data for speech recognition from recorder. 
+*
+* @remark This function should be returned immediately after recording data copy. 
+* 
+* @param[in] data A recording data
+* @param[in] length A length of recording data
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTP_ERROR_INVALID_STATE Invalid state
+*
+* @pre sttpe_start() should succeed.
+* @post If the engine supports partial result, it will invoke sttpe_partial_result_cb().
+*
+* @see sttpe_start()
+* @see sttpe_cancel()
+* @see sttpe_stop()
+* @see sttpe_partial_result_cb()
+*/
+typedef int (* sttpe_set_recording_data)(const void* data, unsigned int length);
+
+/**
+* @brief Stops to set recording data.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_STATE Invalid state
+* @retval #STTP_ERROR_OPERATION_FAILED Operation failed
+* @retval #STTP_ERROR_OUT_OF_NETWORK Out of network
+*
+* @pre sttpe_start() should succeed.
+* @post After processing of the engine, sttpe_result_cb() is called.
+*
+* @see sttpe_start()
+* @see sttpe_set_recording_data()
+* @see sttpe_result_cb()
+* @see sttpe_cancel()
+*/
+typedef int (* sttpe_stop)(void);
+
+/**
+* @brief Cancels the recognition process.
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STTP_ERROR_NONE Successful.
+* @retval #STTP_ERROR_INVALID_STATE Invalid state.
+* @pre STT engine is in recognition processing.
+*
+* @see sttpe_start()
+* @see sttpe_stop()
+*/
+typedef int (* sttpe_cancel)(void);
+
+/**
+* @brief Gets setting information of the engine.
+*
+* @param[in] callback A callback function.
+* @param[in] user_data The user data to be passed to the callback function.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+* @retval #STTP_ERROR_OPERATION_FAILED Operation failed
+*
+* @post        This function invokes sttpe_engine_setting_cb() repeatedly for getting engine settings. 
+*
+* @see sttpe_engine_setting_cb()
+*/
+typedef int (* sttpe_foreach_engine_settings)(sttpe_engine_setting_cb callback, void* user_data);
+
+/**
+* @brief Set engine specific information. 
+*
+* @param[in] key A key
+* @param[in] value A value
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTP_ERROR_INVALID_STATE Not initialized
+* @retval #STTP_ERROR_OPERATION_FAILED Operation failed
+*
+* @see sttpe_foreach_engine_settings()
+*/
+typedef int (* sttpe_set_engine_setting)(const char* key, const char* value);
+
+
+/**
+* @brief A structure of the engine functions.
+*/
+typedef struct {
+       int size;                                               /**< Size of structure */    
+       int version;                                            /**< Version */
+       
+       sttpe_initialize                initialize;             /**< Initialize engine */
+       sttpe_deinitialize              deinitialize;           /**< Shutdown engine */
+
+       /* Get engine information */
+       sttpe_foreach_supported_languages foreach_langs;        /**< Foreach language list */
+       sttpe_is_valid_language         is_valid_lang;          /**< Check language */
+       sttpe_support_silence_detection support_silence;        /**< Get silence detection support */
+       sttpe_support_partial_result    support_partial_result; /**< Get partial result support */
+       sttpe_get_recording_format      get_audio_format;       /**< Get audio format */
+       
+       /* Set engine information */
+       sttpe_set_profanity_filter      set_profanity_filter;   /**< Set profanity filter */
+       sttpe_set_punctuation_override  set_punctuation;        /**< Set punctuation override */
+       sttpe_set_silence_detection     set_silence_detection;  /**< Set silence detection */
+
+       /* Control recognition */
+       sttpe_start                     start;                  /**< Start recognition */
+       sttpe_set_recording_data        set_recording;          /**< Set recording data */
+       sttpe_stop                      stop;                   /**< Shutdown function */
+       sttpe_cancel                    cancel;                 /**< Cancel recognition or cancel thinking */
+               
+       /* Engine setting */
+       sttpe_foreach_engine_settings   foreach_engine_settings;/**< Foreach engine specific info */
+       sttpe_set_engine_setting        set_engine_setting;     /**< Set engine specific info */
+} sttpe_funcs_s;
+
+/**
+* @brief A structure of the daemon functions.
+*/
+typedef struct {
+       int size;                                               /**< size */
+       int version;                                            /**< version */
+
+} sttpd_funcs_s;
+
+/**
+* @brief Loads the engine. 
+*
+* @param[in] pdfuncs The daemon functions
+* @param[out] pefuncs The engine functions
+*
+* @return This function returns zero on success, or negative with error code on failure
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTP_ERROR_OPERATION_FAILED Operation failed
+*
+* @pre The sttp_get_engine_info() should be successful.
+* @post The daemon calls engine functions of sttpe_funcs_s.
+*
+* @see sttp_get_engine_info()
+* @see sttp_unload_engine()
+*/
+int sttp_load_engine(sttpd_funcs_s* pdfuncs, sttpe_funcs_s* pefuncs);
+
+/**
+* @brief Unloads this engine by the daemon. 
+*
+* @pre The sttp_load_engine() should be successful.
+*
+* @see sttp_load_engine()
+*/
+void sttp_unload_engine(void);
+
+/**
+* @brief Called to get the engine base information.
+*
+* @param[in] engine_uuid The engine id
+* @param[in] engine_name The engine name
+* @param[in] setting_ug_name The setting ug name
+* @param[in] use_network @c true to need network @c false not to need network.
+* @param[in] user_data The User data passed from sttp_get_engine_info()
+*
+* @pre sttp_get_engine_info() will invoke this callback. 
+*
+* @see sttp_get_engine_info()
+*/
+typedef void (*sttpe_engine_info_cb)(const char* engine_uuid, const char* engine_name, const char* setting_ug_name, 
+                                    bool use_network, void* user_data);
+
+/**
+* @brief Gets the engine base information before the engine is loaded by the daemon. 
+*
+* @param[in] callback Callback function
+* @param[in] user_data User data to be passed to the callback function
+*
+* @return This function returns zero on success, or negative with error code on failure
+* @retval #STTP_ERROR_NONE Successful
+* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTP_ERROR_OPERATION_FAILED Operation failed
+*
+* @post        This function invokes sttpe_engine_info_cb() for getting engine information.
+*
+* @see sttpe_engine_info_cb()
+* @see sttp_load_engine()
+*/
+int sttp_get_engine_info(sttpe_engine_info_cb callback, void* user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}@}
+ */
+#endif /* __STTP_H__ */