From: ky85.kim Date: Thu, 12 Feb 2015 04:07:43 +0000 (+0900) Subject: Merge with Tizen 2.3 X-Git-Tag: accepted/tizen/common/20150601.145816^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=23e300999f1c74be9a304e681ce2c0c776558071;p=platform%2Fcore%2Fuifw%2Fstt.git Merge with Tizen 2.3 Update configure to XML based Update audion session Change api for partial result Support result time stamp Remove api for hide offensive word Support start and stop sound - Details in changelog - Change-Id: I556b3f71482a82c5b8064c53a27a7ff6c7268e8c --- diff --git a/AUTHORS b/AUTHORS index 3e21f67..d4434b8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,3 @@ Dongyeol Lee -Kwangyoun Kim +Kwangyoun Kim Sehwan Park \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index 35c7f5d..6bfaa53 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,57 @@ +# Copyright (c) 2011-2014 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. +# +# +# @file CMakeLists.txt +# @author Dongyeol Lee (dy3.lee@samsung.com) +# @version 0.1 +# @brief + CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(libstt) +PROJECT(stt) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${PREFIX}") +SET(VERSION 0.2.53) ## Include common directory ## INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/common") +INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include") ## Dependent packages ## INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED - glib-2.0 dbus-1 vconf dlog ecore ecore-file capi-media-audio-io capi-media-sound-manager libtzplatform-config + aul capi-media-audio-io capi-media-wav-player capi-system-info dbus-1 dlog ecore glib-2.0 + libtzplatform-config libxml-2.0 vconf vconf-internal-keys +) + +pkg_check_modules(pkgs_test REQUIRED + dlog ecore ) +## API ## +ADD_SUBDIRECTORY(include) + ## Client library ## ADD_SUBDIRECTORY(client) ## Server daemon ## ADD_SUBDIRECTORY(server) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/sysinfo-stt.xml DESTINATION /etc/config) +## Test ## +ADD_SUBDIRECTORY(test) + +## config ## +INSTALL(FILES ${CMAKE_SOURCE_DIR}/stt-config.xml DESTINATION /usr/lib/voice/stt/1.0) + diff --git a/NOTICE b/NOTICE index 1066e15..d08cb4d 100644 --- a/NOTICE +++ b/NOTICE @@ -1,3 +1,3 @@ -Copyright (c)2012 Samsung Electronics Co., Ltd. All rights reserved. +Copyright (c) 2011-2014 Samsung Electronics Co., Ltd. All rights reserved. Except as noted, this software is licensed under Apache License, Version 2. Please, see the LICENSE.APLv2 file for Apache License terms and conditions. diff --git a/changelog b/changelog index 9f7bb23..97cbeb1 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,603 @@ +stt (0.2.53) -- Thu, 21 Aug 2014 + + * Remove agreement api (Dongyeol Lee ) + * Add privilege http://tizen.org/privilege/recorder (Dongyeol Lee ) + * Update engine error print (Dongyeol Lee ) + * Update network check (Dongyeol Lee ) + * Check dbus connection valid (Dongyeol Lee ) + +stt (0.2.52) -- Mon, 14 Jul 2014 + + * Apply sound session manager api change (Kwangyoun Kim ) + * include header files (Kwangyoun Kim ) + * Fix dbus timeout and retry (Dongyeol Lee ) + * Update header (Kwangyoun Kim ) + * Fix memory issue (Kwangyoun Kim ) + +stt (0.2.51) -- Fri, 16 Jun 2014 + + * Add file recognition library (Dongyeol Lee ) + +stt (0.2.50) -- Fri, 23 May 2014 + + * Fix memory initialize bug (Dongyeol Lee ) + * Update License info (Kwangyoun Kim ) + * Fix bug on notify state changed (Kwangyoun Kim ) + +stt (0.2.49) -- Mon, 31 Mar 2014 + + * Remove build dependency of vconf key (Dongyeol Lee ) + +stt (0.2.48) -- Mon, 24 Mar 2014 + + * Release version (Kwangyoun Kim ) + +stt (0.2.47-1) -- Fri, 21 Mar 2014 + + * Error Handling for record fail (Kwangyoun Kim ) + +stt (0.2.47) -- Thu, 13 Feb 2014 + + * Release version (Kwangyoun Kim ) + +stt (0.2.46-1) -- Wed, 12 Feb 2014 + + * Add dbus error free (Kwangyoun Kim ) + * Update smack rule (Kwangyoun Kim ) + +stt (0.2.46) -- Wed, 22 Jan 2014 + + * Release version (Dongyeol Lee ) + +stt (0.2.45-1) -- Wed, 22 Jan 2014 + + * Update smack rule to access vconf key (Dongyeol Lee ) + +stt (0.2.45) -- Thu, 16 Jan 2014 + + * Release version (Dongyeol Lee ) + +stt (0.2.44-1) -- Thu, 16 Jan 2014 + + * Update smack rule to access vconf key (Dongyeol Lee ) + +stt (0.2.44) -- Fri, 27 Dec 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.43-1) -- Fri, 27 Dec 2013 + + * Update dbus retry (Dongyeol Lee ) + +stt (0.2.43) -- Wed, 18 Dec 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.42-2) -- Wed, 18 Dec 2013 + + * Add map type (Dongyeol Lee ) + +stt (0.2.42-1) -- Wed, 18 Dec 2013 + + * Fix session blocking (Dongyeol Lee ) + +stt (0.2.42) -- Mon, 16 Dec 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.41-1) -- Mon, 16 Dec 2013 + + * Fix minor bug (Dongyeol Lee ) + +stt (0.2.41) -- Fri, 13 Dec 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.40-1) -- Fri, 13 Dec 2013 + + * Fix bug not to notify state (Dongyeol Lee ) + +stt (0.2.40) -- Fri, 13 Dec 2013 + + * Release version (Dongyeol Lee ) + +stt (0.2.39-2) -- Thu, 12 Dec 2013 + + * Support engine disclaimer (Dongyeol Lee ) + +stt (0.2.39-1) -- Thu, 12 Dec 2013 + + * Fix bug on initialize timeout (Kwangyoun Kim ) + +stt (0.2.39) -- Wed, 11 Dec 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.38-1) -- Wed, 11 Dec 2013 + + * Fix bug to notify state not to use sound (Dongyeol Lee ) + +stt (0.2.38) -- Wed, 11 Dec 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.37-3) -- Wed, 11 Dec 2013 + + * Fix session bug (Dongyeol Lee ) + +stt (0.2.37-2) -- Wed, 11 Dec 2013 + + * Fix bug to play sound (Dongyeol Lee ) + +stt (0.2.37-1) -- Tue, 10 Dec 2013 + + * Support start sound and stop sound in daemon (Dongyeol Lee ) + +stt (0.2.37) -- Tue, 03 Dec 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.36-1) -- Mon, 02 Dec 2013 + + * Fix log crash bug (Dongyeol Lee ) + +stt (0.2.36) -- Fri, 29 Nov 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.35-2) -- Fri, 29 Nov 2013 + + * Fix spec file (Kwangyoun Kim ) + * Change sequence at start (Kwangyoun KIm ) + +stt (0.2.35-1) -- Fri, 29 Nov 2013 + + * Update recognition start (Dongyeol Lee ) + +stt (0.2.35) -- Thu, 28 Nov 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.34-1) -- Thu, 28 Nov 2013 + + * Update recorder to improve loading time (Dongyeol Lee ) + +stt (0.2.34) -- Thu, 28 Nov 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.33-1) -- Wed, 27 Nov 2013 + + * Add silence detection type for no speech (Kwangyoun Kim ) + +stt (0.2.33) -- Wed, 27 Nov 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.32-3) -- Wed, 27 Nov 2013 + + * Add ignored case for interrupt callback (Kwangyoun Kim ) + +stt (0.2.32-2) -- Wed, 27 Nov 2013 + + * Update interrupt callback of sound manager (Dongyeol Lee ) + +stt (0.2.32-1) -- Mon, 25 Nov 2013 + + * Remove not used engine api (Dongyeol Lee ) + +stt (0.2.32) -- Wed, 20 Nov 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.31-2) -- Wed, 20 Nov 2013 + + * Update dbus time out (Dongyeol Lee ) + +stt (0.2.31-1) -- Wed, 20 Nov 2013 + + * Add new api to notify default language change (Dongyeol Lee ) + +stt (0.2.31) -- Tue, 19 Nov 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.30-1) -- Tue, 19 Nov 2013 + + * Update audio session (Dongyeol Lee ) + +stt (0.2.30) -- Sat, 16 Nov 2013 + + * Release version (Dongyeol Lee ) + +stt (0.2.29-1) -- Fri, 15 Nov 2013 + + * Fix daemon language change bug (Dongyeol Lee ) + +stt (0.2.29) -- Wed, 13 Nov 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.28-2) -- Wed, 13 Nov 2013 + + * Update session manager and recorder type (Dongyeol Lee ) + +stt (0.2.28-1) -- Thu, 7 Nov 2013 + + * Update error log and clean up code (Dongyeol Lee ) + +stt (0.2.28) -- Wed, 6 Nov 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.27-2) -- Tue, 5 Nov 2013 + + * Fix time info file management (Dongyeol Lee ) + * Remove setting api of hide offensive word (Dongyeol Lee ) + +stt (0.2.27-1) -- Tue, 5 Nov 2013 + + * Add return value check (Kwangyoun Kim ) + +stt (0.2.27) -- Tue, 5 Nov 2013 + + * Release version (Dongyeol Lee ) + +stt (0.2.26-2) -- Mon, 4 Nov 2013 + + * Remove pause state and clean up code (Dongyeol Lee ) + +stt (0.2.26-1) -- Mon, 4 Nov 2013 + + * Update time stamp using XML file (Dongyeol Lee ) + +stt (0.2.26) -- Fri, 1 Nov 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.25-2) -- Thu, 31 Oct 2013 + + * Fix timing bug when daemon intialize and finalize (Kwangyoun Kim ) + +stt (0.2.25-1) -- Thu, 31 Oct 2013 + + * Fix time stamp size (Dongyeol Lee ) + +stt (0.2.25) -- Thu, 31 Oct 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.24-5) -- Wed, 30 Oct 2013 + + * Update TC (Kwangyoun Kim ) + +stt (0.2.24-4) -- Wed, 30 Oct 2013 + + * Fix bug on recognition result callback (Kwangyoun Kim ) + +stt (0.2.24-3) -- Wed, 30 Oct 2013 + + * Change dbus waiting time (Kwangyoun Kim ) + +stt (0.2.24-2) -- Tue, 29 Oct 2013 + + * Update time stamp api and engine api(Dongyeol Lee ) + +stt (0.2.24-1) -- Mon, 28 Oct 2013 + + * Remove hide offensive word api (Dongyeol Lee ) + +stt (0.2.24) -- Mon, 28 Oct 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.23-2) -- Thu, 24 Oct 2013 + + * Update TC for added API (Kwangyoun Kim ) + +stt (0.2.23-1) -- Wed, 23 Oct 2013 + + * Divide devel package (Dongyeol Lee ) + +stt (0.2.23) -- Tue, 22 Oct 2013 + + * Release version (Dongyeol Lee ) + +stt (0.2.22-3) -- Tue, 22 Oct 2013 + + * Add pluseaudio rule (Dongyeol Lee ) + * Update recorder create in daemon engine init (Dongyeol Lee ) + * Update daemon fork to use thread (Dongyeol Lee ) + +stt (0.2.22-2) -- Tue, 22 Oct 2013 + + * Remove not used setting api (Dongyeol Lee ) + * Fix error handling of recorder (Dongyeol Lee ) + +stt (0.2.22-1) -- Thu, 17 Oct 2013 + + * Add to unload engine in finalize (Dongyeol Lee ) + +stt (0.2.22) -- Wed, 16 Oct 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.21-3) -- Tue, 15 Oct 2013 + + * Fix crash issue from result callback (Dongyeol Lee ) + +stt (0.2.21-2) -- Mon, 14 Oct 2013 + + * Support time stamp (Dongyeol Lee ) + +stt (0.2.21-1) -- Tue, 08 Oct 2013 + + * Remove old api (Dongyeol Lee ) + +stt (0.2.21) -- Tue, 08 Oct 2013 + + * Release version (Dongyeol Lee ) + +stt (0.2.20-2) -- Tue, 08 Oct 2013 + + * Fix bug about recording and processing timer (Dongyeol Lee ) + +stt (0.2.20-1) -- Fri, 04 Oct 2013 + + * Update engine api for time stamp (Dongyeol Lee ) + * Fix small bug (Dongyeol Lee ) + +stt (0.2.20) -- Mon, 30 Sep 2013 + + * Release version (Dongyeol Lee ) + +stt (0.2.19-2) -- Fri, 27 Aug 2013 + + * Clean up code and fix bug (Dongyeol Lee ) + +stt (0.2.19-1) -- Thu, 26 Aug 2013 + + * Change api for partial result (Dongyeol Lee ) + +stt (0.2.19) -- Thu, 26 Sep 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.18-1) -- Wed, 25 Sep 2013 + + * Change engine api for partial result (Dongyeol Lee ) + +stt (0.2.18) -- Tue, 24 Sep 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.17-1) -- Tue, 24 Sep 2013 + + * Add TC (Kwangyoun Kim ) + +stt (0.2.17) -- Mon, 23 Sep 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.16-1) -- Mon, 16 Sep 2013 + + * Fix engine id (Kwangyoun Kim ) + +stt (0.2.16) -- Tue, 10 Sep 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.15-4) -- Mon, 9 Sep 2013 + + * Fix bug on dbus connection block (Kwangyoun Kim ) + +stt (0.2.15-3) -- Fri, 30 Aug 2013 + + * Fix CMakeList (Dongyeol Lee ) + +stt (0.2.15-2) -- Thu, 29 Aug 2013 + + * Update docs and change api folder (Dongyeol Lee ) + +stt (0.2.15-1) -- Tue, 27 Aug 2013 + + * Fix bug of memory check (Dongyeol Lee ) + +stt (0.2.15) -- Thu, 22 Aug 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.14-1) -- Thu, 22 Aug 2013 + + * Update engine plugin interface (Dongyeol Lee ) + * Fix the bug about memory clean up (Dongyeol Lee ) + +stt (0.2.14) -- Tue, 20 Aug 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.13-2) -- Fri, 16 Aug 2013 + + * Clean up log (Dongyeol Lee ) + +stt (0.2.13-1) -- Fri, 16 Aug 2013 + + * Remove punctuation override option (Dongyeol Lee ) + * Add error handling of recording fail (Dongyeol Lee ) + +stt (0.2.13) -- Thu, 08 Aug 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.12-1) -- Thu, 08 Aug 2013 + + * Remove ignore session of recording (Kwangyoun Kim ) + +stt (0.2.12) -- Wed, 31 Aug 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.11-1) -- Wed, 31 Jul 2013 + + * Remove test module (Kwangyoun Kim ) + +stt (0.2.11) -- Wed, 31 Jul 2013 + + * Fix bug on NULL callback (Kwangyoun Kim ) + * Release version (Kwangyoun Kim ) + +stt (0.2.11) -- Wed, 31 Jul 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.10-3) -- Wed, 31 Jul 2013 + + * Add build config for dlog (Kwangyoun Kim ) + +stt (0.2.10-2) -- Wed, 31 Jul 2013 + + * Add ignore session of recording (Dongyeol Lee ) + +stt (0.2.10-1) -- Tue, 30 Jul 2013 + + * Add test module (Kwangyoun Kim ) + +stt (0.2.10) -- Thu, 18 Jul 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.9-1) -- Thu, 18 Jul 2013 + + * Fix client create bug (Dongyeol Lee ) + * Clean up directory path (Dongyeol Lee ) + +stt (0.2.9) -- Thu, 13 Jul 2013 + + * Release version (Dongyeol Lee ) + +stt (0.2.8-1) -- Thu, 13 Jul 2013 + + * Fix memory init error of config (Dongyeol Lee ) + +stt (0.2.8) -- Thu, 11 Jul 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.7-1) -- Thu, 11 Jul 2013 + + * Fix prevent issue (Dongyeol Lee ) + +stt (0.2.7) -- Wed, 10 Jul 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.6-5) -- Tue, 09 Jul 2013 + + * Update to get info from config (Dongyeol Lee ) + * Fix code to manage config callback (Dongyeol Lee ) + +stt (0.2.6-4) -- Fri, 05 Jul 2013 + + * Fix bug to set engine id (Dongyeol Lee ) + +stt (0.2.6-3) -- Thu, 04 Jul 2013 + + * Set default language en_GB (Dongyeol Lee ) + +stt (0.2.6-2) -- Wed, 03 Jul 2013 + + * Update auto language (Dongyeol Lee ) + * Clean up config code (Dongyeol Lee ) + +stt (0.2.6-1) -- Sat, 29 Jun 2013 + + * Update smack label of voice directory (Dongyeol Lee ) + +stt (0.2.6) -- Wed, 12 Jun 2013 + + * Release version (Kwangyoun Kim ) + +stt (0.2.5-2) -- Wed, 12 Jun 2013 + + * Add code for secure log (Kwangyoun Kim ) + +stt (0.2.5-1) -- Wed, 12 Jun 2013 + + * Fix bug to get wrong default language (Dongyeol Lee ) + +stt (0.2.5) -- Fri, 07 May 2013 + + * Release version 0.2.5 (Dongyeol Lee ) + +stt (0.2.4-2) -- Fri, 07 May 2013 + + * Fix timer issue (Dongyeol Lee ) + +stt (0.2.4-1) -- Fri, 07 May 2013 + + * Fix timer double free (Dongyeol Lee ) + * Fix prevent issue (Dongyeol Lee ) + +stt (0.2.4) -- Mon, 17 May 2013 + + * Release version 0.2.4 (Dongyeol Lee ) + +stt (0.2.3-2) -- Mon, 27 May 2013 + + * Delete unused log (Kwangyoun Kim ) + +stt (0.2.3-1) -- Sat, 25 May 2013 + + * Update configure to XML based (Dongyeol Lee ) + +stt (0.2.3) -- Tue, 14 May 2013 + + * Release version 0.2.3 (Kwangyoun Kim ) + +stt (0.2.2-1) -- Tue, 14 May 2013 + + * Fix bug about client check in callback (Kwangyoun Kim ) + +stt (0.2.2) -- Wed, 08 May 2013 + + * Release version 0.2.2 (Dongyeol Lee ) + +stt (0.2.1-2) -- Wed, 08 May 2013 + + * Update to set default language from display language (Dongyeol Lee ) + +stt (0.2.1-1) -- Tue, 07 May 2013 + + * Delete code about print (Kwangyoun Kim ) + +stt (0.2.1) -- Mon, 06 May 2013 + + * Release version 0.2.1 (Dongyeol Lee ) + +stt (0.2.0-4) -- Mon, 06 May 2013 + + * Fix BS issue (Dongyeol Lee ) + +stt (0.2.0-3) -- Fri, 03 May 2013 + + * Update to retry daemon fork (Dongyeol Lee ) + +stt (0.2.0-2) -- Fri, 03 May 2013 + + * Add recording timeout (Dongyeol Lee ) + +stt (0.2.0-1) -- Tue, 23 Apr 2013 + + * Fix prevent issues (Dongyeol Lee ) + +stt (0.2.0) -- Fri, 19 Apr 2013 + + * Release version 0.2.0 (Dongyeol Lee ) + +stt (0.1.41-1) -- Thu, 18 Apr 2013 + + * Support multi-engine of application (Dongyeol Lee ) + stt (0.1.41) -- Tue, 16 Apr 2013 * Release version 0.1.41 (Kwangyoun Kim ) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 659fa72..1c2662c 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,43 +1,29 @@ -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 + ../common/stt_config_mgr.c + ../common/stt_config_parser.c +) + +SET(FILE_SRCS + stt_file.c + stt_file_client.c + ../common/stt_config_mgr.c + ../common/stt_config_parser.c + ../common/stt_engine.c + ../common/stt_network.c ) set(SETTING_SRCS stt_setting.c - stt_setting_dbus.c + ../common/stt_config_mgr.c + ../common/stt_config_parser.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") +INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/server) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -46,23 +32,20 @@ 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 file library ## +ADD_LIBRARY("${PROJECT_NAME}_file" SHARED ${FILE_SRCS}) +TARGET_LINK_LIBRARIES("${PROJECT_NAME}_file" ${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_INSTALL_DIR} COMPONENT RuntimeLibraries) -INSTALL(TARGETS "${PROJECT_NAME}_setting" DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) -INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc" "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-setting.pc" DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/stt.h ${CMAKE_CURRENT_SOURCE_DIR}/stt_setting.h DESTINATION include) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS "${PROJECT_NAME}_file" DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS "${PROJECT_NAME}_setting" DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries) diff --git a/client/stt.c b/client/stt.c index 76aa110..ec0aeed 100644 --- a/client/stt.c +++ b/client/stt.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2014 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 @@ -11,31 +11,125 @@ * limitations under the License. */ - -#include -#include -#include +#include +#include #include +#include +#include #include -#include +#include +#include +#include +#include #include "stt.h" -#include "stt_main.h" #include "stt_client.h" #include "stt_dbus.h" +#include "stt_config_mgr.h" +#include "stt_main.h" -#define CONNECTION_RETRY_COUNT 3 static bool g_is_daemon_started = false; static Ecore_Timer* g_connect_timer = NULL; -static int __check_stt_daemon(); static Eina_Bool __stt_notify_state_changed(void *data); static Eina_Bool __stt_notify_error(void *data); +static int g_stt_daemon_pid = -1; +static int g_count_check_daemon = 0; + +const char* stt_tag() +{ + return "sttc"; +} + +static const char* __stt_get_error_code(stt_error_e err) +{ + switch(err) { + case STT_ERROR_NONE: return "STT_ERROR_NONE"; + case STT_ERROR_OUT_OF_MEMORY: return "STT_ERROR_OUT_OF_MEMORY"; + case STT_ERROR_IO_ERROR: return "STT_ERROR_IO_ERROR"; + case STT_ERROR_INVALID_PARAMETER: return "STT_ERROR_INVALID_PARAMETER"; + case STT_ERROR_TIMED_OUT: return "STT_ERROR_TIMED_OUT"; + case STT_ERROR_RECORDER_BUSY: return "STT_ERROR_RECORDER_BUSY"; + case STT_ERROR_OUT_OF_NETWORK: return "STT_ERROR_OUT_OF_NETWORK"; + case STT_ERROR_PERMISSION_DENIED: return "STT_ERROR_PERMISSION_DENIED"; + case STT_ERROR_NOT_SUPPORTED: return "STT_ERROR_NOT_SUPPORTED"; + case STT_ERROR_INVALID_STATE: return "STT_ERROR_INVALID_STATE"; + case STT_ERROR_INVALID_LANGUAGE: return "STT_ERROR_INVALID_LANGUAGE"; + case STT_ERROR_ENGINE_NOT_FOUND: return "STT_ERROR_ENGINE_NOT_FOUND"; + case STT_ERROR_OPERATION_FAILED: return "STT_ERROR_OPERATION_FAILED"; + case STT_ERROR_NOT_SUPPORTED_FEATURE: return "STT_ERROR_NOT_SUPPORTED_FEATURE"; + default: + return "Invalid error code"; + } +} + +static int __stt_convert_config_error_code(stt_config_error_e code) +{ + if (code == STT_CONFIG_ERROR_NONE) return STT_ERROR_NONE; + if (code == STT_CONFIG_ERROR_OUT_OF_MEMORY) return STT_ERROR_OUT_OF_MEMORY; + if (code == STT_CONFIG_ERROR_IO_ERROR) return STT_ERROR_IO_ERROR; + if (code == STT_CONFIG_ERROR_INVALID_PARAMETER) return STT_ERROR_INVALID_PARAMETER; + if (code == STT_CONFIG_ERROR_PERMISSION_DENIED) return STT_ERROR_PERMISSION_DENIED; + if (code == STT_CONFIG_ERROR_NOT_SUPPORTED) return STT_ERROR_NOT_SUPPORTED; + if (code == STT_CONFIG_ERROR_INVALID_STATE) return STT_ERROR_INVALID_STATE; + if (code == STT_CONFIG_ERROR_INVALID_LANGUAGE) return STT_ERROR_INVALID_LANGUAGE; + if (code == STT_CONFIG_ERROR_ENGINE_NOT_FOUND) return STT_ERROR_ENGINE_NOT_FOUND; + if (code == STT_CONFIG_ERROR_OPERATION_FAILED) return STT_ERROR_OPERATION_FAILED; + + return code; +} + +void __stt_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data) +{ + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Language changed : Before lang(%s) Current lang(%s)", + before_language, current_language); + + if (0 == strcmp(before_language, current_language)) { + return; + } + + GList* client_list = NULL; + client_list = stt_client_get_client_list(); + + GList *iter = NULL; + stt_client_s *data = NULL; + + if (g_list_length(client_list) > 0) { + /* Get a first item */ + iter = g_list_first(client_list); + + while (NULL != iter) { + data = iter->data; + if (NULL != data->default_lang_changed_cb) { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Call default language changed callback : uid(%d)", data->uid); + data->default_lang_changed_cb(data->stt, before_language, current_language, + data->default_lang_changed_user_data); + } + + /* Next item */ + iter = g_list_next(iter); + } + } + + return; +} + int stt_create(stt_h* stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + SLOG(LOG_DEBUG, TAG_STTC, "===== Create STT"); if (NULL == stt) { @@ -55,7 +149,30 @@ int stt_create(stt_h* stt) return STT_ERROR_OUT_OF_MEMORY; } - SLOG(LOG_DEBUG, TAG_STTC, "[Success] uid(%d)", (*stt)->handle); + stt_client_s* client = stt_client_get(*stt); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client"); + stt_client_destroy(*stt); + return STT_ERROR_OPERATION_FAILED; + } + + int ret = stt_config_mgr_initialize(client->uid); + ret = __stt_convert_config_error_code(ret); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to init config manager : %s", __stt_get_error_code(ret)); + stt_client_destroy(*stt); + return ret; + } + + ret = stt_config_mgr_set_callback(client->uid, NULL, __stt_config_lang_changed_cb, NULL, NULL); + ret = __stt_convert_config_error_code(ret); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set config changed : %s", __stt_get_error_code(ret)); + stt_client_destroy(*stt); + return ret; + } + + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[Success] uid(%d)", (*stt)->handle); SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -65,6 +182,17 @@ int stt_create(stt_h* stt) int stt_destroy(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT"); if (NULL == stt) { @@ -88,6 +216,8 @@ int stt_destroy(stt_h stt) return STT_ERROR_OPERATION_FAILED; } + stt_config_mgr_finalize(client->uid); + int ret = -1; /* check state */ @@ -97,21 +227,24 @@ int stt_destroy(stt_h stt) case STT_STATE_READY: ret = stt_dbus_request_finalize(client->uid); if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret)); } + g_is_daemon_started = false; case STT_STATE_CREATED: if (NULL != g_connect_timer) { SLOG(LOG_DEBUG, TAG_STTC, "Connect Timer is deleted"); ecore_timer_del(g_connect_timer); + g_connect_timer = NULL; } + /* Free resources */ stt_client_destroy(stt); break; + default: + break; } - 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"); @@ -124,76 +257,417 @@ int stt_destroy(stt_h stt) return STT_ERROR_NONE; } -static Eina_Bool __stt_connect_daemon(void *data) +bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_name, + const char* setting, bool support_silence, void* user_data) { - stt_h stt = (stt_h)data; + stt_h stt = (stt_h)user_data; stt_client_s* client = stt_client_get(stt); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid"); + return false; + } + /* call callback function */ + if (NULL != client->supported_engine_cb) { + return client->supported_engine_cb(stt, engine_id, engine_name, client->supported_engine_user_data); + } else { + SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported engine"); + } + + return false; +} + +int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data) +{ + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + + SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported engine"); + + 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; } - /* Send hello */ - if (0 != stt_dbus_request_hello()) { - if (false == g_is_daemon_started) { - g_is_daemon_started = true; - __check_stt_daemon(); + if (client->current_state != STT_STATE_CREATED) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not CREATE"); + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + return STT_ERROR_INVALID_STATE; + } + + client->supported_engine_cb = callback; + client->supported_engine_user_data = user_data; + + int ret = 0; + ret = stt_config_mgr_get_engine_list(__stt_config_supported_engine_cb, client->stt); + ret = __stt_convert_config_error_code(ret); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get engines : %s", __stt_get_error_code(ret)); + } + + client->supported_engine_cb = NULL; + client->supported_engine_user_data = NULL; + + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + + return ret; +} + +int stt_get_engine(stt_h stt, char** engine_id) +{ + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } } - return EINA_TRUE; } - SLOG(LOG_DEBUG, TAG_STTC, "===== Connect daemon"); + SLOG(LOG_DEBUG, TAG_STTC, "===== Get current engine"); - /* request initialization */ - int ret = -1; - int i = 1; - bool silence_supported = false; - bool profanity_supported = false; - bool punctuation_supported = false; + if (NULL == stt || NULL == engine_id) { + 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; + } - while (1) { - ret = stt_dbus_request_initialize(client->uid, &silence_supported, &profanity_supported, &punctuation_supported); + if (client->current_state != STT_STATE_CREATED) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not CREATE"); + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + return STT_ERROR_INVALID_STATE; + } + + int ret = 0; + ret = stt_config_mgr_get_engine(engine_id); + ret = __stt_convert_config_error_code(ret); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request get current engine : %s", __stt_get_error_code(ret)); + } else { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id); + } - if (STT_ERROR_ENGINE_NOT_FOUND == ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : STT Engine Not found"); - - client->reason = STT_ERROR_ENGINE_NOT_FOUND; + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); - ecore_timer_add(0, __stt_notify_error, (void*)stt); + return ret; +} - return EINA_FALSE; +int stt_set_engine(stt_h stt, const char* engine_id) +{ + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } - } else if(0 != ret) { - usleep(1); - if(CONNECTION_RETRY_COUNT == i) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : TIMED OUT"); + SLOG(LOG_DEBUG, TAG_STTC, "===== Set current engine"); - client->reason = STT_ERROR_TIMED_OUT; + if (NULL == stt || NULL == engine_id) { + 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; + } - ecore_timer_add(0, __stt_notify_error, (void*)stt); + stt_client_s* client = stt_client_get(stt); - return EINA_FALSE; - } - i++; + /* 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_CREATED) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not CREATE"); + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + return STT_ERROR_INVALID_STATE; + } + + if (NULL != client->current_engine_id) { + free(client->current_engine_id); + } + + client->current_engine_id = strdup(engine_id); +#if 0 + if (client->current_state == STT_STATE_READY) { + int ret = 0; + bool silence_supported = false; + + ret = stt_dbus_request_set_current_engine(client->uid, engine_id, &silence_supported); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret)); + return ret; } else { - /* success to connect stt-daemon */ - stt_client_set_option_supported(client->stt, silence_supported, profanity_supported, punctuation_supported); - SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), profanity(%s), punctuation(%s)", - silence_supported ? "true" : "false", profanity_supported ? "true" : "false", punctuation_supported ? "true" : "false"); - break; + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", engine_id); + + /* success to change engine */ + client->silence_supported = silence_supported; + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s)", silence_supported ? "true" : "false"); } } +#endif + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); - client->before_state = client->current_state; - client->current_state = STT_STATE_READY; + return 0; +} - ecore_timer_add(0, __stt_notify_state_changed, (void*)stt); +static int __read_proc(const char *path, char *buf, int size) +{ + int fd; + int ret; + + if (NULL == buf || NULL == path) { + return -1; + } + + fd = open(path, O_RDONLY); + if (fd < 0) { + return -1; + } + + ret = read(fd, buf, size - 1); + if (0 >= ret) { + close(fd); + return -1; + } else { + buf[ret] = 0; + } + close(fd); + return ret; +} + +static bool __stt_check_daemon_exist() +{ + char buf[128]; + int ret; + + FILE* fp; + fp = fopen(STT_PID_FILE_PATH, "r"); + if (NULL == fp) { + return false; + } + + g_stt_daemon_pid = -1; + int pid; + if (0 >= fscanf(fp, "%d", &pid)) { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Fail to read pid"); + fclose(fp); + return false; + } + + fclose(fp); + snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); + ret = __read_proc(buf, buf, sizeof(buf)); + if (0 >= ret) { + return false; + } else { + if (!strcmp(buf, "/usr/bin/stt-daemon")) { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Daemon existed - [%d]%s", pid, buf); + g_stt_daemon_pid = pid; + return true; + } + } + return false; +} + +static void* __fork_stt_daemon(void* NotUsed) +{ + int pid, i; + pid = fork(); + + switch(pid) { + case -1: + SLOG(LOG_DEBUG, TAG_STTC, "[STT ERROR] fail to create STT-DAEMON"); + break; + + case 0: + setsid(); + for (i = 0;i < _NSIG;i++) + signal(i, SIG_DFL); + + execl("/usr/bin/stt-daemon", "/usr/bin/stt-daemon", NULL); + break; + + default: + break; + } + + return (void*) 1; +} + +static Eina_Bool __stt_connect_daemon(void *data) +{ + stt_client_s* client = (stt_client_s*)data; + + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + return EINA_FALSE; + } + + /* Send hello */ + int ret = -1; + ret = stt_dbus_request_hello(); + + if (STT_DAEMON_NORMAL != ret) { + if (STT_ERROR_INVALID_STATE == ret) { + return EINA_FALSE; + } + + if (STT_DAEMON_ON_TERMINATING == ret) { + /* Todo - Wait for terminating and do it again*/ + usleep(50); + return EINA_TRUE; + } else { + /* for new daemon */ + bool check = __stt_check_daemon_exist(); + if (true == check) { + g_count_check_daemon++; + if (3 < g_count_check_daemon) { + /* Todo - Kill daemon and restart */ + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Need to Kill daemon"); + } + usleep(50); + return EINA_TRUE; + } else { + if (false == g_is_daemon_started) { + g_is_daemon_started = true; + + pthread_t thread; + int thread_id; + thread_id = pthread_create(&thread, NULL, __fork_stt_daemon, NULL); + if (thread_id < 0) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to make thread"); + g_connect_timer = NULL; + return EINA_FALSE; + } + + pthread_detach(thread); + } + + usleep(50); + return EINA_TRUE; + } + } + } g_connect_timer = NULL; + SLOG(LOG_DEBUG, TAG_STTC, "===== Connect daemon"); + + /* request initialization */ + + bool silence_supported = false; + + ret = stt_dbus_request_initialize(client->uid, &silence_supported); + + if (STT_ERROR_ENGINE_NOT_FOUND == ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : %s", __stt_get_error_code(ret)); + + client->reason = STT_ERROR_ENGINE_NOT_FOUND; + ecore_timer_add(0, __stt_notify_error, (void*)client); + + return EINA_FALSE; + + } else if (STT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect"); + return EINA_TRUE; + } else { + /* success to connect stt-daemon */ + client->silence_supported = silence_supported; + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s)", silence_supported ? "true" : "false"); + } + + if (NULL != client->current_engine_id) { + ret = -1; + int count = 0; + silence_supported = false; + while (0 != ret) { + ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported); + if (0 != ret) { + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", client->current_engine_id); + + /* success to change engine */ + client->silence_supported = silence_supported; + SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s)", silence_supported ? "true" : "false"); + } + } + } + + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] uid(%d)", client->uid); - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] uid(%d)", client->uid); + client->before_state = client->current_state; + client->current_state = STT_STATE_READY; + + if (NULL != client->state_changed_cb) { + stt_client_use_callback(client); + client->state_changed_cb(client->stt, client->before_state, + client->current_state, client->state_changed_user_data); + stt_client_not_use_callback(client); + SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); + } SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -201,9 +675,19 @@ static Eina_Bool __stt_connect_daemon(void *data) return EINA_FALSE; } - int stt_prepare(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + SLOG(LOG_DEBUG, TAG_STTC, "===== Prepare STT"); stt_client_s* client = stt_client_get(stt); @@ -218,13 +702,14 @@ int stt_prepare(stt_h stt) /* check state */ if (client->current_state != STT_STATE_CREATED) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not 'CREATED'"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not 'CREATED'"); SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); return STT_ERROR_INVALID_STATE; } - g_connect_timer = ecore_timer_add(0, __stt_connect_daemon, (void*)stt); + g_count_check_daemon = 0; + g_connect_timer = ecore_timer_add(0, __stt_connect_daemon, (void*)client); SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -234,6 +719,14 @@ int stt_prepare(stt_h stt) int stt_unprepare(stt_h stt) { + bool supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &supported)) { + if (false == supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + SLOG(LOG_DEBUG, TAG_STTC, "===== Unprepare STT"); stt_client_s* client = stt_client_get(stt); @@ -246,22 +739,47 @@ int stt_unprepare(stt_h stt) /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not '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; } - int ret = stt_dbus_request_finalize(client->uid); - if (0 != ret) { - SLOG(LOG_WARN, TAG_STTC, "[ERROR] Fail to request finalize"); + int ret = -1; + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_finalize(client->uid); + if (0 != ret) { + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret)); + break; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + break; + } + } + } } + g_is_daemon_started = false; + client->internal_state = STT_INTERNAL_STATE_NONE; + client->before_state = client->current_state; client->current_state = STT_STATE_CREATED; - ecore_timer_add(0, __stt_notify_state_changed, (void*)stt); + if (NULL != client->state_changed_cb) { + stt_client_use_callback(client); + client->state_changed_cb(client->stt, client->before_state, + client->current_state, client->state_changed_user_data); + stt_client_not_use_callback(client); + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); + } SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -269,8 +787,39 @@ int stt_unprepare(stt_h stt) return STT_ERROR_NONE; } +bool __stt_config_supported_language_cb(const char* engine_id, const char* language, void* user_data) +{ + stt_h stt = (stt_h)user_data; + + stt_client_s* client = stt_client_get(stt); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid"); + return false; + } + + /* call callback function */ + if (NULL != client->supported_lang_cb) { + return client->supported_lang_cb(stt, language, client->supported_lang_user_data); + } else { + SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages"); + } + + return false; +} + int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported Language"); if (NULL == stt || NULL == callback) { @@ -290,29 +839,55 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac 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"); - return STT_ERROR_INVALID_STATE; + int ret; + char* current_engine_id = NULL; + + if (NULL == client->current_engine_id) { + ret = stt_config_mgr_get_engine(¤t_engine_id); + ret = __stt_convert_config_error_code(ret); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default engine id : %s", __stt_get_error_code(ret)); + return ret; + } + } else { + current_engine_id = strdup(client->current_engine_id); } - int ret = 0; - ret = stt_dbus_request_get_support_langs(client->uid, client->stt, callback, user_data); + client->supported_lang_cb = callback; + client->supported_lang_user_data = user_data; + + ret = stt_config_mgr_get_language_list(current_engine_id, __stt_config_supported_language_cb, client->stt); + ret = __stt_convert_config_error_code(ret); if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages"); - } else { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages : %s", __stt_get_error_code(ret)); + } + + if (NULL != current_engine_id) { + free(current_engine_id); } + client->supported_lang_cb = NULL; + client->supported_lang_user_data = NULL; + SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); - return STT_ERROR_NONE; + return ret; } - int stt_get_default_language(stt_h stt, char** language) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + SLOG(LOG_DEBUG, TAG_STTC, "===== Get Default Language"); if (NULL == stt || NULL == language) { @@ -332,17 +907,11 @@ int stt_get_default_language(stt_h stt, char** language) 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"); - return STT_ERROR_INVALID_STATE; - } - int ret = 0; - ret = stt_dbus_request_get_default_lang(client->uid, language); - + ret = stt_config_mgr_get_default_language(language); + ret = __stt_convert_config_error_code(ret); if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail : request get default language"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default language : %s", __stt_get_error_code(ret)); } else { SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current language = %s", *language); } @@ -355,6 +924,17 @@ int stt_get_default_language(stt_h stt, char** language) int stt_get_state(stt_h stt, stt_state_e* state) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt || NULL == state) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; @@ -374,14 +954,26 @@ int stt_get_state(stt_h stt, stt_state_e* 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; + default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break; } return STT_ERROR_NONE; } -int stt_is_partial_result_supported(stt_h stt, bool* partial_result) +int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support) { - if (NULL == stt || NULL == partial_result) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + + if (NULL == stt || NULL == type || NULL == support) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } @@ -395,24 +987,49 @@ int stt_is_partial_result_supported(stt_h stt, bool* partial_result) /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); return STT_ERROR_INVALID_STATE; } - 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"); + int ret = -1; + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_is_recognition_type_supported(client->uid, type, support); + if (0 != ret) { + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get recognition type supported : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } else { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] recognition type is %s", *support ? "true " : "false"); + break; + } } return STT_ERROR_NONE; } -int stt_set_profanity_filter(stt_h stt, stt_option_profanity_e type) +int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; @@ -427,14 +1044,14 @@ int stt_set_profanity_filter(stt_h stt, stt_option_profanity_e type) /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); return STT_ERROR_INVALID_STATE; } - if (true == client->profanity_supported) { - if (type >= STT_OPTION_PROFANITY_FALSE && type <= STT_OPTION_PROFANITY_AUTO) - client->profanity = type; - else { + if (true == client->silence_supported) { + 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; } @@ -445,8 +1062,80 @@ int stt_set_profanity_filter(stt_h stt, stt_option_profanity_e type) return STT_ERROR_NONE; } -int stt_set_punctuation_override(stt_h stt, stt_option_punctuation_e type) +int stt_set_start_sound(stt_h stt, const char* filename) +{ + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + + SLOG(LOG_DEBUG, TAG_STTC, "===== STT SET START SOUND"); + + if (NULL == stt || NULL == filename) { + 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; + } + + /* check state */ + if (client->current_state != STT_STATE_READY) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + return STT_ERROR_INVALID_STATE; + } + + int ret = -1; + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_set_start_sound(client->uid, filename); + if (0 != ret) { + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set start sound : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } else { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set start sound : %s", filename); + break; + } + } + + return STT_ERROR_NONE; +} + +int stt_unset_start_sound(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + + SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET START SOUND"); + if (NULL == stt) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; @@ -458,29 +1147,113 @@ int stt_set_punctuation_override(stt_h stt, stt_option_punctuation_e type) SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid"); 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_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); return STT_ERROR_INVALID_STATE; } - if (true == client->punctuation_supported) { - 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; + int ret = -1; + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_unset_start_sound(client->uid); + if (0 != ret) { + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset start sound : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } else { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset start sound"); + break; } - } else { - return STT_ERROR_NOT_SUPPORTED_FEATURE; } return STT_ERROR_NONE; } -int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type) +int stt_set_stop_sound(stt_h stt, const char* filename) +{ + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + + SLOG(LOG_DEBUG, TAG_STTC, "===== STT SET STOP SOUND"); + + if (NULL == stt || NULL == filename) { + 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; + } + + /* check state */ + if (client->current_state != STT_STATE_READY) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + return STT_ERROR_INVALID_STATE; + } + + int ret = -1; + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_set_stop_sound(client->uid, filename); + if (0 != ret) { + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set stop sound : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } else { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set stop sound : %s", filename); + break; + } + } + + return STT_ERROR_NONE; +} + +int stt_unset_stop_sound(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + + SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET STOP SOUND"); + if (NULL == stt) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; @@ -495,19 +1268,31 @@ int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type) /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); return STT_ERROR_INVALID_STATE; } - if (true == client->silence_supported) { - 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; + int ret = -1; + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_unset_stop_sound(client->uid); + if (0 != ret) { + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset stop sound : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } else { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset stop sound"); + break; } - } else { - return STT_ERROR_NOT_SUPPORTED_FEATURE; } return STT_ERROR_NONE; @@ -515,6 +1300,17 @@ int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type) int stt_start(stt_h stt, const char* language, const char* type) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + SLOG(LOG_DEBUG, TAG_STTC, "===== STT START"); if (NULL == stt) { @@ -536,36 +1332,86 @@ int stt_start(stt_h stt, const char* language, const char* type) /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not 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; + } + + if (STT_INTERNAL_STATE_NONE != client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); return STT_ERROR_INVALID_STATE; } - char* temp; + char appid[128] = {0, }; + aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)); + + if (0 == strlen(appid)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID"); + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid); + } + + char* temp = NULL; if (NULL == language) { temp = strdup("default"); } else { temp = strdup(language); } - int ret; + int ret = -1; /* 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]"); - - client->before_state = client->current_state; - client->current_state = STT_STATE_RECORDING; + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_start(client->uid, temp, type, client->silence, appid); + if (0 > ret) { + /* Failure */ + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start : %s", __stt_get_error_code(ret)); + if (NULL != temp) free(temp); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry to start"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + if (NULL != temp) free(temp); + return ret; + } + } + } else { + /* Success */ + if (NULL != temp) free(temp); + + if (STT_RESULT_STATE_DONE == ret) { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is done : %d", ret); + client->before_state = client->current_state; + client->current_state = STT_STATE_RECORDING; + + if (NULL != client->state_changed_cb) { + stt_client_use_callback(client); + client->state_changed_cb(client->stt, client->before_state, + client->current_state, client->state_changed_user_data); + stt_client_not_use_callback(client); + SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); + } + } else if (STT_RESULT_STATE_NOT_DONE == ret) { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is not done : %d", ret); + client->internal_state = STT_INTERNAL_STATE_STARTING; + } else { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid result : %d", ret); + } - ecore_timer_add(0, __stt_notify_state_changed, (void*)stt); + ret = STT_ERROR_NONE; + break; + } } - free(temp); - SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -574,10 +1420,21 @@ int stt_start(stt_h stt, const char* language, const char* type) int stt_stop(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + SLOG(LOG_DEBUG, TAG_STTC, "===== STT STOP"); if (NULL == stt) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] [ERROR] Input parameter is NULL"); + 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; @@ -595,24 +1452,62 @@ int stt_stop(stt_h stt) /* check state */ if (client->current_state != STT_STATE_RECORDING) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state is NOT 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]"); - - client->before_state = client->current_state; - client->current_state = STT_STATE_PROCESSING; + if (STT_INTERNAL_STATE_NONE != client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + return STT_ERROR_INVALID_STATE; + } - ecore_timer_add(0, __stt_notify_state_changed, (void*)stt); + int ret = -1; + /* do request */ + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_stop(client->uid); + if (0 > ret) { + /* Failure */ + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry stop"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } else { + if (STT_RESULT_STATE_DONE == ret) { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Stop is done : %d", ret); + client->before_state = client->current_state; + client->current_state = STT_STATE_PROCESSING; + + if (NULL != client->state_changed_cb) { + stt_client_use_callback(client); + client->state_changed_cb(client->stt, client->before_state, + client->current_state, client->state_changed_user_data); + stt_client_not_use_callback(client); + SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); + } + } else if (STT_RESULT_STATE_NOT_DONE == ret) { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Stop is not done : %d", ret); + client->internal_state = STT_INTERNAL_STATE_STOPING; + } else { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid result : %d", ret); + } + ret = STT_ERROR_NONE; + break; + } } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -624,6 +1519,17 @@ int stt_stop(stt_h stt) int stt_cancel(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL"); if (NULL == stt) { @@ -645,24 +1551,56 @@ int stt_cancel(stt_h stt) /* 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_ERROR, 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]"); - - client->before_state = client->current_state; - client->current_state = STT_STATE_READY; + if (STT_INTERNAL_STATE_NONE != client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + return STT_ERROR_INVALID_STATE; + } - ecore_timer_add(0, __stt_notify_state_changed, (void*)stt); + int ret = -1; + /* do request */ + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_cancel(client->uid); + if (0 != ret) { + /* Failure */ + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Fail to cancel : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry"); + usleep(10); + count++; + if (10 == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]"); + + client->before_state = client->current_state; + client->current_state = STT_STATE_READY; + + if (NULL != client->state_changed_cb) { + stt_client_use_callback(client); + client->state_changed_cb(client->stt, client->before_state, + client->current_state, client->state_changed_user_data); + stt_client_not_use_callback(client); + SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); + } + ret = STT_ERROR_NONE; + break; + } } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -690,6 +1628,17 @@ static int __stt_get_audio_volume(float* volume) int stt_get_recording_volume(stt_h stt, float* volume) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt || NULL == volume) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; @@ -711,16 +1660,52 @@ int stt_get_recording_volume(stt_h stt, float* volume) int ret = 0; ret = __stt_get_audio_volume(volume); if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get audio volume"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get audio volume : %s", __stt_get_error_code(ret)); return STT_ERROR_OPERATION_FAILED; } - return STT_ERROR_NONE; + return STT_ERROR_NONE; +} + +bool __stt_result_time_cb(int index, int event, const char* text, long start_time, long end_time, void* user_data) +{ + stt_client_s* client = (stt_client_s*)user_data; + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); + return EINA_FALSE; + } + + if (NULL != client->result_time_cb) { + SLOG(LOG_DEBUG, TAG_STTC, "(%d) event(%d) text(%s) start(%ld) end(%ld)", + index, event, text, start_time, end_time); + client->result_time_cb(client->stt, index, (stt_result_time_event_e)event, + text, start_time, end_time, client->result_time_user_data); + } else { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Callback is NULL"); + return false; + } + + return true; } -int stt_start_file_recognition(stt_h stt, const char* filepath, const char* language, const char* type) +int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data) { - if (NULL == stt || NULL == type || NULL == filepath) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + + SLOG(LOG_DEBUG, TAG_STTC, "===== STT FOREACH DETAILED RESULT"); + + if (NULL == callback) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } @@ -729,46 +1714,32 @@ int stt_start_file_recognition(stt_h stt, const char* filepath, const char* lang /* check handle */ if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail : A handle is not valid"); return STT_ERROR_INVALID_PARAMETER; - } - - if (STT_STATE_READY != client->current_state) { - SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Ready' state"); - return STT_ERROR_INVALID_STATE; - } - - char* temp; - if (NULL == language) { - temp = strdup("default"); - } else { - temp = strdup(language); } - int ret; - ret = stt_dbus_request_start_file_recognition(client->uid, filepath, temp, type, client->profanity, client->punctuation); - - if (ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start"); - } else { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]"); - - client->before_state = client->current_state; - client->current_state = STT_STATE_PROCESSING; + client->result_time_cb = callback; + client->result_time_user_data = user_data; - ecore_timer_add(0, __stt_notify_state_changed, (void*)stt); + int ret = -1; + ret = stt_config_mgr_foreach_time_info(__stt_result_time_cb, client); + ret = __stt_convert_config_error_code(ret); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to foreach time info : %s", __stt_get_error_code(ret)); } - free(temp); + client->result_time_cb = NULL; + client->result_time_user_data = NULL; - return STT_ERROR_NONE; + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + + return ret; } static Eina_Bool __stt_notify_error(void *data) { - stt_h stt = (stt_h)data; - - stt_client_s* client = stt_client_get(stt); + stt_client_s* client = (stt_client_s*)data; /* check handle */ if (NULL == client) { @@ -776,6 +1747,9 @@ static Eina_Bool __stt_notify_error(void *data) return EINA_FALSE; } + if (NULL == stt_client_get_by_uid(client->uid)) + return EINA_FALSE; + if (NULL != client->error_cb) { stt_client_use_callback(client); client->error_cb(client->stt, client->reason, client->error_user_data); @@ -799,7 +1773,7 @@ int __stt_cb_error(int uid, int reason) client->reason = reason; if (NULL != client->error_cb) { - ecore_timer_add(0, __stt_notify_error, client->stt); + ecore_timer_add(0, __stt_notify_error, client); } else { SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null"); } @@ -807,11 +1781,42 @@ int __stt_cb_error(int uid, int reason) return 0; } -static Eina_Bool __stt_notify_result(void *data) +static Eina_Bool __stt_notify_state_changed(void *data) { - stt_h stt = (stt_h)data; + stt_client_s* client = (stt_client_s*)data; - stt_client_s* client = stt_client_get(stt); + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); + return EINA_FALSE; + } + + if (NULL == stt_client_get_by_uid(client->uid)) + return EINA_FALSE; + + if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) { + client->internal_state = STT_INTERNAL_STATE_NONE; + SLOG(LOG_DEBUG, TAG_STTC, "Internal state change NULL"); + } else if (STT_INTERNAL_STATE_STOPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) { + client->internal_state = STT_INTERNAL_STATE_NONE; + SLOG(LOG_DEBUG, TAG_STTC, "Internal state change NULL"); + } + + if (NULL != client->state_changed_cb) { + stt_client_use_callback(client); + client->state_changed_cb(client->stt, client->before_state, + client->current_state, client->state_changed_user_data); + stt_client_not_use_callback(client); + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); + } + + return EINA_FALSE; +} + +static Eina_Bool __stt_notify_result(void *data) +{ + stt_client_s* client = (stt_client_s*)data; /* check handle */ if (NULL == client) { @@ -819,18 +1824,24 @@ static Eina_Bool __stt_notify_result(void *data) return EINA_FALSE; } - if (NULL != client->result_cb) { + if (NULL == stt_client_get_by_uid(client->uid)) { + return EINA_FALSE; + } + + if (NULL != client->recognition_result_cb) { stt_client_use_callback(client); - client->result_cb(client->stt, client->type, (const char**)client->data_list, client->data_count, client->msg, client->result_user_data); + client->recognition_result_cb(client->stt, client->event, (const char**)client->data_list, client->data_count, + client->msg, client->recognition_result_user_data); stt_client_not_use_callback(client); - SLOG(LOG_DEBUG, TAG_STTC, "client result callback called"); + SLOG(LOG_DEBUG, TAG_STTC, "client recognition result callback called"); } else { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null"); - } + SLOG(LOG_WARN, TAG_STTC, "[WARNING] User recognition result callback is NULL"); + } - /* Free result */ - if (NULL != client->type) - free(client->type); + if (NULL != client->msg) { + free(client->msg); + client->msg = NULL; + } if (NULL != client->data_list) { char **temp = NULL; @@ -838,47 +1849,36 @@ static Eina_Bool __stt_notify_result(void *data) int i = 0; for (i = 0;i < client->data_count;i++) { - if(NULL != temp[i]) + if (NULL != temp[i]) { free(temp[i]); - else + temp[i] = NULL; + } else { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); + } } free(client->data_list); + client->data_list = NULL; } - - if (NULL != client->msg) - free(client->msg); client->data_count = 0; - return EINA_FALSE; -} - -static Eina_Bool __stt_notify_state_changed(void *data) -{ - stt_h stt = (stt_h)data; - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); - return EINA_FALSE; - } + stt_config_mgr_remove_time_info_file(); + + if (STT_RESULT_EVENT_FINAL_RESULT == client->event || STT_RESULT_EVENT_ERROR == client->event) { + client->before_state = client->current_state; + client->current_state = STT_STATE_READY; - if (NULL != client->state_changed_cb) { - stt_client_use_callback(client); - client->state_changed_cb(client->stt, client->before_state, client->current_state, client->state_changed_user_data); - stt_client_not_use_callback(client); - SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called"); - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); + if (NULL != client->state_changed_cb) { + ecore_timer_add(0, __stt_notify_state_changed, client); + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); + } } return EINA_FALSE; } -int __stt_cb_result(int uid, const char* type, const char** data, int data_count, const char* msg) +int __stt_cb_result(int uid, int event, char** data, int data_count, const char* msg) { stt_client_s* client = NULL; @@ -888,22 +1888,24 @@ int __stt_cb_result(int uid, const char* type, const char** data, int data_count return -1; } - SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg); + if (NULL != msg) 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 != data[i]) SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]); } - if (NULL != client->result_cb) { - client->type = strdup(type); - client->msg = strdup(msg); + if (NULL != client->recognition_result_cb) { + client->event = event; + if (NULL != msg) { + client->msg = strdup(msg); + } + client->data_count = data_count; if (data_count > 0) { char **temp = NULL; - temp = malloc( sizeof(char*) * data_count); + temp = (char**)calloc(data_count, sizeof(char*)); for (i = 0;i < data_count;i++) { if(NULL != data[i]) @@ -915,72 +1917,11 @@ int __stt_cb_result(int uid, const char* type, const char** data, int data_count client->data_list = temp; } - ecore_timer_add(0, __stt_notify_result, client->stt); + ecore_timer_add(0, __stt_notify_result, client); } else { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null"); - } - - client->before_state = client->current_state; - client->current_state = STT_STATE_READY; - - if (NULL != client->state_changed_cb) { - ecore_timer_add(0, __stt_notify_state_changed, client->stt); - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); - } - - return 0; -} - -static Eina_Bool __stt_notify_partial_result(void *data) -{ - stt_h stt = (stt_h)data; - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); - return EINA_FALSE; - } - - if (client->partial_result_cb) { - stt_client_use_callback(client); - client->partial_result_cb(client->stt, client->partial_result, client->partial_result_user_data); - stt_client_not_use_callback(client); - SLOG(LOG_DEBUG, TAG_STTC, "Partial result callback is called"); - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] Partial result callback is null"); - } - - if (NULL != client->partial_result) - free(client->partial_result); - - return EINA_FALSE; -} - -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) { - client->partial_result = strdup(data); - ecore_timer_add(0, __stt_notify_partial_result, client->stt); - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] Partial result callback is null"); - } - return 0; } @@ -1002,12 +1943,23 @@ int __stt_cb_set_state(int uid, int state) client->before_state = client->current_state; client->current_state = state_from_daemon; - ecore_timer_add(0, __stt_notify_state_changed, client->stt); + ecore_timer_add(0, __stt_notify_state_changed, client); return 0; } -int stt_set_result_cb(stt_h stt, stt_result_cb callback, void* user_data) +int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (stt == NULL || callback == NULL) return STT_ERROR_INVALID_PARAMETER; @@ -1020,18 +1972,29 @@ int stt_set_result_cb(stt_h stt, stt_result_cb callback, void* user_data) } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); + 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; + client->recognition_result_cb = callback; + client->recognition_result_user_data = user_data; return 0; } -int stt_unset_result_cb(stt_h stt) +int stt_unset_recognition_result_cb(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt) return STT_ERROR_INVALID_PARAMETER; @@ -1044,18 +2007,29 @@ int stt_unset_result_cb(stt_h stt) } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); + 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; + client->recognition_result_cb = NULL; + client->recognition_result_user_data = NULL; return 0; } -int stt_set_partial_result_cb(stt_h stt, stt_partial_result_cb callback, void* user_data) +int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt || NULL == callback) return STT_ERROR_INVALID_PARAMETER; @@ -1068,18 +2042,29 @@ int stt_set_partial_result_cb(stt_h stt, stt_partial_result_cb callback, void* u } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); + 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; + client->state_changed_cb = callback; + client->state_changed_user_data = user_data; return 0; } -int stt_unset_partial_result_cb(stt_h stt) +int stt_unset_state_changed_cb(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt) return STT_ERROR_INVALID_PARAMETER; @@ -1092,18 +2077,29 @@ int stt_unset_partial_result_cb(stt_h stt) } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); + 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; + client->state_changed_cb = NULL; + client->state_changed_user_data = NULL; return 0; } -int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data) +int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt || NULL == callback) return STT_ERROR_INVALID_PARAMETER; @@ -1116,18 +2112,29 @@ int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* use } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); + 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; + client->error_cb = callback; + client->error_user_data = user_data; return 0; } -int stt_unset_state_changed_cb(stt_h stt) +int stt_unset_error_cb(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt) return STT_ERROR_INVALID_PARAMETER; @@ -1140,19 +2147,29 @@ int stt_unset_state_changed_cb(stt_h stt) } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); + 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; + client->error_cb = NULL; + client->error_user_data = NULL; return 0; } - -int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data) +int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt || NULL == callback) return STT_ERROR_INVALID_PARAMETER; @@ -1165,18 +2182,29 @@ int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data) } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); + 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; + client->default_lang_changed_cb = callback; + client->default_lang_changed_user_data = user_data; return 0; } -int stt_unset_error_cb(stt_h stt) +int stt_unset_default_language_changed_cb(stt_h stt) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } + } + } + if (NULL == stt) return STT_ERROR_INVALID_PARAMETER; @@ -1189,112 +2217,12 @@ int stt_unset_error_cb(stt_h stt) } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'."); + 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; -} - -int __get_cmd_line(char *file, char *buf) -{ - FILE *fp = NULL; - - fp = fopen(file, "r"); - if (fp == NULL) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get command line"); - return -1; - } - - memset(buf, 0, 256); - if (NULL == fgets(buf, 256, fp)) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to fget command line"); - fclose(fp); - return -1; - } - fclose(fp); - - return 0; -} - -static bool __stt_is_alive() -{ - DIR *dir; - struct dirent *entry; - struct stat filestat; - - int pid; - char cmdLine[256]; - char tempPath[256]; - - dir = opendir("/proc"); - if (NULL == dir) { - SLOG(LOG_ERROR, TAG_STTC, "process checking is FAILED"); - return FALSE; - } - - while ((entry = readdir(dir)) != NULL) { - if (0 != lstat(entry->d_name, &filestat)) - continue; - - if (!S_ISDIR(filestat.st_mode)) - continue; - - pid = atoi(entry->d_name); - if (pid <= 0) continue; - - sprintf(tempPath, "/proc/%d/cmdline", pid); - if (0 != __get_cmd_line(tempPath, cmdLine)) { - continue; - } - if ( 0 == strncmp(cmdLine, "[stt-daemon]", strlen("[stt-daemon]")) || - 0 == strncmp(cmdLine, "stt-daemon", strlen("stt-daemon")) || - 0 == strncmp(cmdLine, "/usr/bin/stt-daemon", strlen("/usr/bin/stt-daemon"))) { - SLOG(LOG_DEBUG, TAG_STTC, "stt-daemon is ALIVE !! \n"); - closedir(dir); - return TRUE; - } - } - SLOG(LOG_DEBUG, TAG_STTC, "THERE IS NO stt-daemon !! \n"); - - closedir(dir); - return FALSE; - -} - -static int __check_stt_daemon() -{ - if( TRUE == __stt_is_alive() ) - return 0; - - /* fork-exec stt-daemon */ - int pid, i; - - 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: - break; - } + client->default_lang_changed_cb = NULL; + client->default_lang_changed_user_data = NULL; return 0; } - - - - diff --git a/client/stt.h b/client/stt.h deleted file mode 100644 index 98313db..0000000 --- a/client/stt.h +++ /dev/null @@ -1,691 +0,0 @@ -/* - * Copyright (c) 2012, 2013 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 -#include - -/** -* @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 = -0x0100000 | 0x31, /**< Invalid state */ - STT_ERROR_INVALID_LANGUAGE = -0x0100000 | 0x32, /**< Invalid language */ - STT_ERROR_ENGINE_NOT_FOUND = -0x0100000 | 0x33, /**< No available engine */ - STT_ERROR_OPERATION_FAILED = -0x0100000 | 0x34, /**< Operation failed */ - STT_ERROR_NOT_SUPPORTED_FEATURE = -0x0100000 | 0x35 /**< Not supported feature of current engine */ -}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 Result message : None message -*/ -#define STT_RESULT_MESSAGE_NONE "stt.result.message.none" - -/** -* @brief Result warning message : The speech has started too soon -*/ -#define STT_RESULT_MESSAGE_WARNING_TOO_SOON "stt.result.message.warning.too.soon" - -/** -* @brief Result warning message : The speech is too short -*/ -#define STT_RESULT_MESSAGE_WARNING_TOO_SHORT "stt.result.message.warning.too.short" - -/** -* @brief Result warning message : The speech is too long -*/ -#define STT_RESULT_MESSAGE_WARNING_TOO_LONG "stt.result.message.warning.too.long" - -/** -* @brief Result warning message : The speech is too quiet to listen -*/ -#define STT_RESULT_MESSAGE_WARNING_TOO_QUIET "stt.result.message.warning.too.quiet" - -/** -* @brief Result warning message : The speech is too loud to listen -*/ -#define STT_RESULT_MESSAGE_WARNING_TOO_LOUD "stt.result.message.warning.too.loud" - -/** -* @brief Result warning message : The speech is too fast to listen -*/ -#define STT_RESULT_MESSAGE_WARNING_TOO_FAST "stt.result.message.warning.too.fast" - -/** -* @brief Result error message : Recognition was failed because the speech started too soon -*/ -#define STT_RESULT_MESSAGE_ERROR_TOO_SOON "stt.result.message.error.too.soon" - -/** -* @brief Result error message : Recognition was failed because the speech started too short -*/ -#define STT_RESULT_MESSAGE_ERROR_TOO_SHORT "stt.result.message.error.too.short" - -/** -* @brief Result error message : Recognition was failed because the speech started too long -*/ -#define STT_RESULT_MESSAGE_ERROR_TOO_LONG "stt.result.message.error.too.long" - -/** -* @brief Result error message : Recognition was failed because the speech started too quiet to listen -*/ -#define STT_RESULT_MESSAGE_ERROR_TOO_QUIET "stt.result.message.error.too.quiet" - -/** -* @brief Result error message : Recognition was failed because the speech started too loud to listen -*/ -#define STT_RESULT_MESSAGE_ERROR_TOO_LOUD "stt.result.message.error.too.loud" - -/** -* @brief Result error message : Recognition was failed because the speech started too fast to listen -*/ -#define STT_RESULT_MESSAGE_ERROR_TOO_FAST "stt.result.message.error.too.fast" - - -/** -* @brief Enumerations of state. -*/ -typedef enum { - STT_STATE_CREATED = 0, /**< 'CREATED' state */ - STT_STATE_READY, /**< '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 (e.g. #STT_RECOGNITION_TYPE_FREE, #STT_RECOGNITION_TYPE_WEB_SEARCH) -* @param[in] data Result texts -* @param[in] data_count Result text count -* @param[in] msg Engine message (e.g. #STT_RESULT_MESSAGE_WARNING_TOO_SOON, #STT_RESULT_MESSAGE_ERROR_TOO_SHORT) -* @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_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. -* -* @param[out] 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_OPERATION_FAILED Operation failure -* -* @post If this function is called, the STT state will be #STT_STATE_CREATED. -* -* @see stt_destroy() -*/ -int stt_create(stt_h* stt); - -/** -* @brief Destroys the handle. -* -* @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 Connects 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 -* @retval #STT_ERROR_INVALID_STATE Invalid state -* -* @pre The state should be #STT_STATE_CREATED. -* @post If this function is called, the STT state will be #STT_STATE_READY. -* -* @see stt_unprepare() -*/ -int stt_prepare(stt_h stt); - -/** -* @brief 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 -* @retval #STT_ERROR_INVALID_STATE Invalid state -* -* @pre The state should be #STT_STATE_READY. -* @post If this function is called, the STT state will be #STT_STATE_CREATED. -* -* @see stt_prepare() -*/ -int stt_unprepare(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 -* @retval #STT_ERROR_NOT_SUPPORTED_FEATURE Not supported feature of current engine -* -* @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 -* @retval #STT_ERROR_NOT_SUPPORTED_FEATURE Not supported feature of current engine -* -* @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 -* @retval #STT_ERROR_NOT_SUPPORTED_FEATURE Not supported feature of current engine -* -* @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. \n -* 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. #STT_RECOGNITION_TYPE_FREE, #STT_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(). \n -* 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(). \n -* If this function succeeds, the STT state will be #STT_STATE_PROCESSING. \n -* 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. \n -* 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(). \n -* 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_CREATED. -* -* @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_CREATED. -* -* @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 -* -* @pre The state should be #STT_STATE_CREATED. -* -* @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_CREATED. -* -* @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_CREATED. -* -* @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_CREATED. -* -* @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_CREATED. -* -* @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_CREATED. -* -* @see stt_set_error_cb() -*/ -int stt_unset_error_cb(stt_h stt); - - -#ifdef __cplusplus -} -#endif - -/** - * @}@} - */ - -#endif /* __STT_H__ */ diff --git a/client/stt_client.c b/client/stt_client.c index 0c00a06..f9e28e2 100644 --- a/client/stt_client.c +++ b/client/stt_client.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2014 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 @@ -51,30 +51,29 @@ int stt_client_new(stt_h* stt) 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->recognition_result_cb = NULL; + client->recognition_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->default_lang_changed_cb = NULL; + client->default_lang_changed_user_data = NULL; - client->silence_supported = false; - client->profanity_supported = false; - client->punctuation_supported = false; + client->current_engine_id = NULL; - client->profanity = STT_OPTION_PROFANITY_AUTO; - client->punctuation = STT_OPTION_PUNCTUATION_AUTO; + client->silence_supported = false; client->silence = STT_OPTION_SILENCE_DETECTION_AUTO; - client->type = NULL; + client->event = 0; client->data_list = NULL; client->data_count = 0; client->msg = NULL; client->before_state = STT_STATE_CREATED; - client->current_state = STT_STATE_CREATED; + client->current_state = STT_STATE_CREATED; + + client->internal_state = STT_INTERNAL_STATE_NONE; client->cb_ref_count = 0; @@ -90,7 +89,7 @@ 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; @@ -109,6 +108,11 @@ int stt_client_destroy(stt_h stt) { /* wait for release callback function */ } + + if (NULL != data->current_engine_id) { + free(data->current_engine_id); + } + free(data); free(stt); @@ -128,7 +132,7 @@ int stt_client_destroy(stt_h stt) stt_client_s* stt_client_get(stt_h stt) { - if (stt == NULL) { + if (NULL == stt) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return NULL; } @@ -142,10 +146,10 @@ stt_client_s* stt_client_get(stt_h stt) while (NULL != iter) { data = iter->data; - - if (stt->handle == data->stt->handle) - return data; - + if (NULL != data) { + if (stt->handle == data->stt->handle) + return data; + } /* Next item */ iter = g_list_next(iter); } @@ -208,19 +212,7 @@ int stt_client_get_use_callback(stt_client_s* client) return client->cb_ref_count; } -int stt_client_set_option_supported(stt_h stt, bool silence, bool profanity, bool punctuation) +GList* stt_client_get_client_list() { - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) - return STT_ERROR_INVALID_PARAMETER; - - client->silence_supported = silence; - client->profanity_supported = profanity; - client->punctuation_supported = punctuation; - - return 0; -} - - + return g_client_list; +} \ No newline at end of file diff --git a/client/stt_client.h b/client/stt_client.h index 7d0525c..6bbdbe1 100644 --- a/client/stt_client.h +++ b/client/stt_client.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2014 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 @@ -23,6 +23,11 @@ extern "C" { #endif +typedef enum { + STT_INTERNAL_STATE_NONE = 0, + STT_INTERNAL_STATE_STARTING = 1, + STT_INTERNAL_STATE_STOPING = 2 +}stt_internal_state_e; typedef struct { /* base info */ @@ -30,42 +35,51 @@ typedef struct { 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; + stt_recognition_result_cb recognition_result_cb; + void* recognition_result_user_data; + stt_result_time_cb result_time_cb; + void* result_time_user_data; - /* option */ - bool silence_supported; - bool profanity_supported; - bool punctuation_supported; + stt_state_changed_cb state_changed_cb; + void* state_changed_user_data; + stt_error_cb error_cb; + void* error_user_data; + stt_default_language_changed_cb default_lang_changed_cb; + void* default_lang_changed_user_data; + + stt_supported_engine_cb supported_engine_cb; + void* supported_engine_user_data; + stt_supported_language_cb supported_lang_cb; + void* supported_lang_user_data; - stt_option_profanity_e profanity; - stt_option_punctuation_e punctuation; + char* current_engine_id; + + /* option */ + bool silence_supported; stt_option_silence_detection_e silence; /* state */ stt_state_e before_state; stt_state_e current_state; + stt_internal_state_e internal_state; + /* mutex */ int cb_ref_count; /* result data */ - char* partial_result; - char* type; + int event; char** data_list; int data_count; char* msg; - + /* error data */ int reason; }stt_client_s; + +typedef bool (*stt_time_cb)(int index, int event, const char* text, long start_time, long end_time, void *user_data); + int stt_client_new(stt_h* stt); int stt_client_destroy(stt_h stt); @@ -82,7 +96,7 @@ int stt_client_not_use_callback(stt_client_s* client); int stt_client_get_use_callback(stt_client_s* client); -int stt_client_set_option_supported(stt_h stt, bool silence, bool profanity, bool punctuation); +GList* stt_client_get_client_list(); #ifdef __cplusplus } diff --git a/client/stt_dbus.c b/client/stt_dbus.c index 4925037..f453a45 100644 --- a/client/stt_dbus.c +++ b/client/stt_dbus.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2014 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 @@ -16,11 +16,10 @@ #include "stt_dbus.h" #include "stt_defs.h" -#include #include "stt_client.h" -static int g_waiting_time = 1500; -static int g_waiting_start_time = 2000; +static int g_waiting_time = 3000; +static int g_waiting_short_time = 500; static Ecore_Fd_Handler* g_fd_handler = NULL; @@ -29,9 +28,7 @@ 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_result(int uid, int event, char** data, int data_count, const char* msg); extern int __stt_cb_set_state(int uid, int state); @@ -48,6 +45,11 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle msg = dbus_connection_pop_message(conn); + if (true != dbus_connection_get_is_connected(conn)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Conn is disconnected"); + return ECORE_CALLBACK_RENEW; + } + /* loop again if we haven't read a message */ if (NULL == msg) { return ECORE_CALLBACK_RENEW; @@ -65,9 +67,13 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle int response = -1; dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get arguments error (%s)", err.message); + dbus_error_free(&err); + } if (uid > 0) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get hello : uid(%d) \n", uid); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get hello : uid(%d)", uid); /* check uid */ stt_client_s* client = stt_client_get_by_uid(uid); @@ -76,7 +82,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else response = 0; } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get hello : invalid uid \n"); + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get hello : invalid uid"); } reply = dbus_message_new_method_return(msg); @@ -110,8 +116,13 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get arguments error (%s)", err.message); + dbus_error_free(&err); + } + if (uid > 0 && state >= 0) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set state : uid(%d), state(%d)", uid, state); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set state : uid(%d), state(%d)", uid, state); response = __stt_cb_set_state(uid, state); } else { @@ -123,10 +134,9 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle if (NULL != reply) { dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID); - if (!dbus_connection_send(conn, reply, NULL)) + if (!dbus_connection_send(conn, reply, NULL)) { SLOG(LOG_ERROR, TAG_STTC, ">>>> stt set state : fail to send reply"); - else - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt set state : result(%d)", response); + } dbus_connection_flush(conn); dbus_message_unref(reply); @@ -145,18 +155,23 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get arguments error (%s)", err.message); + dbus_error_free(&err); + } + if (uid > 0) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get state : uid(%d) \n", uid); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get state : uid(%d)", uid); /* check state */ stt_client_s* client = stt_client_get_by_uid(uid); if( NULL != client ) response = client->current_state; else - SLOG(LOG_ERROR, TAG_STTC, "invalid uid \n"); + SLOG(LOG_ERROR, TAG_STTC, "invalid uid"); } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get state : invalid uid \n"); + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get state : invalid uid"); } reply = dbus_message_new_method_return(msg); @@ -193,16 +208,15 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle } if (uid > 0) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get result : uid(%d) \n", uid); - char** temp_result; + char** temp_result = NULL; char* temp_msg = NULL; char* temp_char = NULL; - char* temp_type = 0; + int temp_event = 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); + if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) { + dbus_message_iter_get_basic(&args, &temp_event); dbus_message_iter_next(&args); } @@ -217,72 +231,45 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle dbus_message_iter_next(&args); } + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get result : uid(%d) event(%d) message(%s) count(%d)", + uid, temp_event, temp_msg, temp_count); + if (temp_count <= 0) { - SLOG(LOG_WARN, TAG_STTC, "Result count is 0"); - __stt_cb_result(uid, temp_type, NULL, 0, temp_msg); + __stt_cb_result(uid, temp_event, NULL, 0, temp_msg); } else { - temp_result = g_malloc0(temp_count * sizeof(char*)); + temp_result = (char**)calloc(temp_count, sizeof(char*)); if (NULL == temp_result) { - SLOG(LOG_ERROR, TAG_STTC, "Fail : memory allocation error \n"); + SLOG(LOG_ERROR, TAG_STTC, "Fail : memory allocation error"); } 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) + + if (NULL != temp_char) { temp_result[i] = strdup(temp_char); + SLOG(LOG_DEBUG, TAG_STTC, "result[%d] : %s", i, temp_result[i]); + } } - - __stt_cb_result(uid, temp_type, (const char**)temp_result, temp_count, temp_msg); + + __stt_cb_result(uid, temp_event, 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); + 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, " "); - }/* STTD_METHOD_RESULT */ - - else if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_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_ERROR, TAG_STTC, "<<<< stt get result : invalid uid"); } SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); - }/* STTD_METHOD_PARTIAL_RESULT */ + }/* STTD_METHOD_RESULT */ else if (dbus_message_is_method_call(msg, if_name, STTD_METHOD_ERROR)) { SLOG(LOG_DEBUG, TAG_STTC, "===== Get Error"); @@ -300,7 +287,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle SLOG(LOG_ERROR, TAG_STTC, "<<<< stt Get Error message : Get arguments error (%s)\n", err.message); dbus_error_free(&err); } else { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt Get Error message : uid(%d), reason(%d), msg(%s)\n", uid, reason, err_msg); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt Get Error message : uid(%d), reason(%d), msg(%s)\n", uid, reason, err_msg); __stt_cb_error(uid, reason); } @@ -346,11 +333,11 @@ int stt_dbus_open_connection() if (dbus_error_is_set(&err)) { SLOG(LOG_ERROR, TAG_STTC, "Dbus Connection Error (%s)\n", err.message); - dbus_error_free(&err); + dbus_error_free(&err); } if (NULL == g_conn) { - SLOG(LOG_ERROR, TAG_STTC, "Fail to get dbus connection \n"); + SLOG(LOG_ERROR, TAG_STTC, "Fail to get dbus connection"); return STT_ERROR_OPERATION_FAILED; } @@ -360,7 +347,7 @@ int stt_dbus_open_connection() 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); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "service name is %s\n", service_name); /* register our name on the bus, and check for errors */ ret = dbus_bus_request_name(g_conn, service_name, DBUS_NAME_FLAG_REPLACE_EXISTING , &err); @@ -371,7 +358,7 @@ int stt_dbus_open_connection() } if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { - printf("fail dbus_bus_request_name()\n"); + SLOG(LOG_ERROR, TAG_STTC, "[Dbus ERROR] Fail to be primary owner"); return -2; } @@ -387,24 +374,24 @@ int stt_dbus_open_connection() dbus_bus_add_match(g_conn, rule, &err); dbus_connection_flush(g_conn); - if (dbus_error_is_set(&err)) - { + if (dbus_error_is_set(&err)) { SLOG(LOG_ERROR, TAG_STTC, "Match Error (%s)\n", err.message); + dbus_error_free(&err); 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"); + SLOG(LOG_ERROR, TAG_STTC, "fail to get fd from dbus"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, "Get fd from dbus : %d\n", fd); + SECURE_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"); + SLOG(LOG_ERROR, TAG_STTC, "fail to get fd handler from ecore"); return STT_ERROR_OPERATION_FAILED; } @@ -424,6 +411,11 @@ int stt_dbus_close_connection() dbus_bus_release_name (g_conn, service_name, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Release name Error (%s)", err.message); + dbus_error_free(&err); + } + dbus_connection_close(g_conn); g_fd_handler = NULL; @@ -432,6 +424,25 @@ int stt_dbus_close_connection() return 0; } +int stt_dbus_reconnect() +{ + bool connected = dbus_connection_get_is_connected(g_conn); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] %s", connected ? "Connected" : "Not connected"); + + if (false == connected) { + stt_dbus_close_connection(); + + if(0 != stt_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to reconnect"); + return -1; + } + + SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] Reconnect"); + } + + return 0; +} + int stt_dbus_request_hello() { DBusMessage* msg; @@ -443,34 +454,52 @@ int stt_dbus_request_hello() STT_METHOD_HELLO); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> Request stt hello : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> Request stt hello : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; + } + DBusError err; dbus_error_init(&err); DBusMessage* result_msg = NULL; - int result = 0; - - result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 500, &err); + int result = STT_DAEMON_NORMAL; + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_short_time, &err); dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + dbus_error_free(&err); + } + int status = 0; if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &status, + DBUS_TYPE_INVALID); + dbus_message_unref(result_msg); - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt hello"); - result = 0; + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get arguments error (%s)", err.message); + dbus_error_free(&err); + } + + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt hello - %d", status); + result = status; } else { - result = STT_ERROR_OPERATION_FAILED; + result = STT_ERROR_TIMED_OUT; } return result; } -int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* profanity_supported, bool* punctuation_supported) +int stt_dbus_request_initialize(int uid, bool* silence_supported) { DBusMessage* msg; @@ -481,10 +510,16 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* profanit STT_METHOD_INITIALIZE); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> stt initialize : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt initialize : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt initialize : uid(%d)", uid); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt initialize : uid(%d)", uid); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; } int pid = getpid(); @@ -500,13 +535,16 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* profanit int result = STT_ERROR_OPERATION_FAILED; result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INT32, silence_supported, - DBUS_TYPE_INT32, profanity_supported, - DBUS_TYPE_INT32, punctuation_supported, DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { @@ -515,19 +553,19 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* profanit result = STT_ERROR_OPERATION_FAILED; } - dbus_message_unref(result_msg); - } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL \n"); - } + if (0 == result) { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt initialize : result = %d, silence(%d)", + result, *silence_supported); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt initialize : result = %d", result); + } - if (0 == result) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt initialize : result = %d , silence(%d), profanity(%d), punctuation(%d)", - result, *silence_supported, *profanity_supported, *punctuation_supported); + dbus_message_unref(result_msg); } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt initialize : result = %d \n", result); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; } - - dbus_message_unref(msg); return result; } @@ -543,10 +581,16 @@ int stt_dbus_request_finalize(int uid) STT_METHOD_FINALIZE); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> stt finalize : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt finalize : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt finalize : uid(%d)", uid); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt finalize : uid(%d)", uid); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; } dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); @@ -557,7 +601,12 @@ int stt_dbus_request_finalize(int uid) DBusMessage* result_msg; int result = STT_ERROR_OPERATION_FAILED; - result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_short_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -565,23 +614,168 @@ int stt_dbus_request_finalize(int uid) DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { - printf("<<<< Get arguments error (%s)\n", err.message); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = STT_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt finalize : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt finalize : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; + } + + return result; +} + +int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* silence_supported) +{ + DBusMessage* msg; + + msg = dbus_message_new_method_call( + STT_SERVER_SERVICE_NAME, + STT_SERVER_SERVICE_OBJECT_PATH, + STT_SERVER_SERVICE_INTERFACE, + STT_METHOD_SET_CURRENT_ENGINE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt set engine : Fail to make message"); + return STT_ERROR_OPERATION_FAILED; + } else { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt set engine : uid(%d)", uid); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; + } + + dbus_message_append_args( msg, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &engine_id, + 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, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INT32, silence_supported, + 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); + + if (0 == result) { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set engine : result = %d , silence(%d)", + result, *silence_supported); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt set engine : result = %d", result); + } } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL \n"); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; } - if (0 == result) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt finalize : result = %d \n", result); + return result; +} + +int stt_dbus_request_check_app_agreed(int uid, const char* appid, bool* value) +{ + if (NULL == appid || NULL == value) { + 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_CHECK_APP_AGREED); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt check app agreed : Fail to make message"); + return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt finalize : result = %d \n", result); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt check app agreed : uid(%d) appid(%s)", uid, appid); } + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &appid, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = STT_ERROR_OPERATION_FAILED; + int available = -1; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INT32, &available, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = STT_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + *value = (bool)available; + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt check app agreed : result = %d, available = %d", result, *value); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt check app agreed : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; + } return result; } @@ -602,10 +796,16 @@ int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_languag STT_METHOD_GET_SUPPORT_LANGS); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get supported languages : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get supported languages : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get supported languages : uid(%d)", uid); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get supported languages : uid(%d)", uid); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; } dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); @@ -618,6 +818,11 @@ int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_languag int result = STT_ERROR_OPERATION_FAILED; result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err ); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } if (NULL != result_msg) { if (dbus_message_iter_init(result_msg, &args)) { @@ -628,17 +833,17 @@ int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_languag } if (0 == result) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get support languages : result = %d \n", result); + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get support languages : result = %d", result); /* Get voice size */ - int size ; + int size = 0; 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); + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt size of language error : size = %d", size); } else { int i=0; char* temp_lang; @@ -653,16 +858,16 @@ int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_languag } } } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get support languages : result = %d \n", result); + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get support languages : result = %d", result); } } dbus_message_unref(result_msg); } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get support languages : result message is NULL \n"); + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get support languages : result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; } - dbus_message_unref(msg); - return result; } @@ -673,7 +878,6 @@ int stt_dbus_request_get_default_lang(int uid, char** language) return STT_ERROR_INVALID_PARAMETER; } - DBusMessage* msg; msg = dbus_message_new_method_call( @@ -683,10 +887,16 @@ int stt_dbus_request_get_default_lang(int uid, char** language) STT_METHOD_GET_CURRENT_LANG); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get default language : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get default language : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get default language : uid(%d)", uid); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get default language : uid(%d)", uid); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; } dbus_message_append_args( msg, @@ -701,6 +911,11 @@ int stt_dbus_request_get_default_lang(int uid, char** language) char* temp_lang = NULL; result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -709,30 +924,105 @@ int stt_dbus_request_get_default_lang(int uid, char** language) DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { - printf("<<<< Get arguments error (%s)\n", err.message); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", err.message); dbus_error_free(&err); result = STT_ERROR_OPERATION_FAILED; } dbus_message_unref(result_msg); + + if (0 == result) { + *language = strdup(temp_lang); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get default language : result = %d, language = %s", result, *language); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get default language : result = %d", result); + } } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL \n"); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; + } + + return result; +} + +int stt_dbus_request_is_recognition_type_supported(int uid, const char* type, bool* support) +{ + if (NULL == support || NULL == type) { + SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL"); + return STT_ERROR_INVALID_PARAMETER; } - if (0 == result) { - *language = strdup(temp_lang); - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get default language : result = %d, language = %s \n", result, *language); + DBusMessage* msg; + + msg = dbus_message_new_method_call( + STT_SERVER_SERVICE_NAME, + STT_SERVER_SERVICE_OBJECT_PATH, + STT_SERVER_SERVICE_INTERFACE, + STT_METHOD_IS_TYPE_SUPPORTED); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt is partial result supported : Fail to make message"); + return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get default language : result = %d \n", result); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt is recognition type supported : uid(%d) type(%s)", uid, type); } + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; + } + + dbus_message_append_args( msg, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &type, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = STT_ERROR_OPERATION_FAILED; + int result_support = -1; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INT32, &result_support, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = STT_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + *support = (bool)result_support; + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt is recognition type supported : result = %d, support = %s", result, *support ? "true" : "false"); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt is recognition type supported : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; + } return result; } -int stt_dbus_request_is_partial_result_supported(int uid, bool* partial_result) +int stt_dbus_request_set_start_sound(int uid, const char* file) { - if (NULL == partial_result) { + if (NULL == file) { SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } @@ -743,17 +1033,24 @@ int stt_dbus_request_is_partial_result_supported(int uid, bool* partial_result) STT_SERVER_SERVICE_NAME, STT_SERVER_SERVICE_OBJECT_PATH, STT_SERVER_SERVICE_INTERFACE, - STT_METHOD_IS_PARTIAL_SUPPORTED); + STT_METHOD_SET_START_SOUND); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> stt is partial result supported : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt set start sound : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt is partial result supported : uid(%d)", uid); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt set start sound : uid(%d) file(%s)", uid, file); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; } dbus_message_append_args( msg, DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &file, DBUS_TYPE_INVALID); DBusError err; @@ -761,77 +1058,151 @@ int stt_dbus_request_is_partial_result_supported(int uid, bool* partial_result) DBusMessage* result_msg; int result = STT_ERROR_OPERATION_FAILED; - int support = -1; result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&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); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", err.message); dbus_error_free(&err); result = STT_ERROR_OPERATION_FAILED; } dbus_message_unref(result_msg); + + if (0 == result) { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set start sound : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt set start sound : result = %d", result); + } } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL \n"); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; } - 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"); + return result; +} + +int stt_dbus_request_unset_start_sound(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_UNSET_START_SOUND); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt unset start sound : Fail to make message"); + return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt is partial result supported : result = %d \n", result); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt unset start sound : uid(%d)", uid); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; } + dbus_message_append_args( msg, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_INVALID); + + 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, g_waiting_time, &err); dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&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)", err.message); + dbus_error_free(&err); + result = STT_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt unset start sound : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt unset start sound : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; + } return result; } -int stt_dbus_request_start(int uid, const char* lang, const char* type, int profanity, int punctuation, int silence) +int stt_dbus_request_set_stop_sound(int uid, const char* file) { - if (NULL == lang || NULL == type) { + if (NULL == file) { 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); + STT_SERVER_SERVICE_NAME, + STT_SERVER_SERVICE_OBJECT_PATH, + STT_SERVER_SERVICE_INTERFACE, + STT_METHOD_SET_STOP_SOUND); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> stt start : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt set stop sound : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt start : uid(%d), language(%s), type(%s)", uid, lang, type); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt set stop sound : uid(%d) file(%s)", uid, file); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; } dbus_message_append_args( msg, - DBUS_TYPE_INT32, &uid, - DBUS_TYPE_STRING, &lang, - DBUS_TYPE_STRING, &type, - DBUS_TYPE_INT32, &profanity, - DBUS_TYPE_INT32, &punctuation, - DBUS_TYPE_INT32, &silence, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &file, 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, g_waiting_start_time, &err); + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -839,28 +1210,99 @@ int stt_dbus_request_start(int uid, const char* lang, const char* type, int prof DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { - printf("<<<< Get arguments error (%s)\n", err.message); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", err.message); dbus_error_free(&err); result = STT_ERROR_OPERATION_FAILED; } dbus_message_unref(result_msg); + + if (0 == result) { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set stop sound : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt set stop sound : result = %d", result); + } } else { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< Result Message is NULL"); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; } - if (0 == result) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt start : result = %d ", result); + return result; +} + +int stt_dbus_request_unset_stop_sound(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_UNSET_STOP_SOUND); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt unset stop sound : Fail to make message"); + return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt start : result = %d ", result); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt unset stop sound : uid(%d)", uid); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; } + dbus_message_append_args( msg, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_INVALID); + + 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, g_waiting_time, &err); dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&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)", err.message); + dbus_error_free(&err); + result = STT_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt unset stop sound : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt unset stop sound : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; + } return result; } -int stt_dbus_request_stop(int uid) +int stt_dbus_request_start(int uid, const char* lang, const char* type, int silence, const char* appid) { + if (NULL == lang || NULL == type || NULL == appid) { + SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL"); + return STT_ERROR_INVALID_PARAMETER; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -868,19 +1310,29 @@ int stt_dbus_request_stop(int uid) STT_SERVER_SERVICE_NAME, STT_SERVER_SERVICE_OBJECT_PATH, STT_SERVER_SERVICE_INTERFACE, - STT_METHOD_STOP); + STT_METHOD_START); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> stt stop : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt start : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt stop : uid(%d)", uid); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt start : uid(%d), language(%s), type(%s)", uid, lang, type); } - dbus_message_append_args(msg, + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; + } + + dbus_message_append_args( msg, DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &lang, + DBUS_TYPE_STRING, &type, + DBUS_TYPE_INT32, &silence, + DBUS_TYPE_STRING, &appid, DBUS_TYPE_INVALID); - + DBusError err; dbus_error_init(&err); @@ -888,6 +1340,11 @@ int stt_dbus_request_stop(int uid) int result = STT_ERROR_OPERATION_FAILED; result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -895,42 +1352,48 @@ int stt_dbus_request_stop(int uid) DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { - printf("<<<< Get arguments error (%s)\n", err.message); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", 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); + if (0 == result) { + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt start : result = %d ", result); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt start : result = %d ", result); + } } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt stop : result = %d ", result); + SLOG(LOG_DEBUG, TAG_STTC, "<<<< Result Message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; } - dbus_message_unref(msg); - return result; } -int stt_dbus_request_cancel(int uid) +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, /* object name of the signal */ - STT_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - STT_METHOD_CANCEL); /* name of the signal */ + STT_SERVER_SERVICE_OBJECT_PATH, + STT_SERVER_SERVICE_INTERFACE, + STT_METHOD_STOP); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> stt cancel : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt stop : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt cancel : uid(%d)", uid); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt stop : uid(%d)", uid); + } + + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; } dbus_message_append_args(msg, @@ -944,6 +1407,11 @@ int stt_dbus_request_cancel(int uid) int result = STT_ERROR_OPERATION_FAILED; result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -951,57 +1419,52 @@ int stt_dbus_request_cancel(int uid) DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { - printf("<<<< Get arguments error (%s)\n", err.message); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", 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); + if (0 == result) { + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt stop : result = %d ", result); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt stop : result = %d ", result); + } } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt cancel : result = %d ", result); + SLOG(LOG_DEBUG, TAG_STTC, "<<<< Result Message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; } - dbus_message_unref(msg); - return result; } -int stt_dbus_request_start_file_recognition(int uid, const char* filepath, const char* lang, const char* type, int profanity, int punctuation) +int stt_dbus_request_cancel(int uid) { - if (NULL == filepath || 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_FILE_RECONITION); + 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 start file recognition : Fail to make message"); + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt cancel : Fail to make message"); return STT_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt start file recogntion : uid(%d), filepath(%s) language(%s), type(%s)", - uid, filepath, lang, type); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt cancel : uid(%d)", uid); } - dbus_message_append_args( msg, + if (NULL == g_conn) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Connection is NOT valid"); + dbus_message_unref(msg); + return STT_ERROR_INVALID_STATE; + } + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, - DBUS_TYPE_STRING, &filepath, - DBUS_TYPE_STRING, &lang, - DBUS_TYPE_STRING, &type, - DBUS_TYPE_INT32, &profanity, - DBUS_TYPE_INT32, &punctuation, DBUS_TYPE_INVALID); DBusError err; @@ -1010,7 +1473,12 @@ int stt_dbus_request_start_file_recognition(int uid, const char* filepath, const DBusMessage* result_msg; int result = STT_ERROR_OPERATION_FAILED; - result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_start_time, &err); + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -1018,22 +1486,22 @@ int stt_dbus_request_start_file_recognition(int uid, const char* filepath, const DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { - printf("<<<< Get arguments error (%s)", err.message); + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", 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 file recognition : result = %d ", result); + if (0 == result) { + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt cancel : result = %d ", result); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt cancel : result = %d ", result); + } } else { - SLOG(LOG_ERROR, TAG_STTC, "<<<< stt start file recognition : result = %d ", result); + SLOG(LOG_DEBUG, TAG_STTC, "<<<< Result Message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; } - dbus_message_unref(msg); - return result; -} \ No newline at end of file +} diff --git a/client/stt_dbus.h b/client/stt_dbus.h index 4208232..5c2ad00 100644 --- a/client/stt_dbus.h +++ b/client/stt_dbus.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2014 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 @@ -29,23 +29,35 @@ int stt_dbus_close_connection(); int stt_dbus_request_hello(); -int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* profanity_supported, bool* punctuation_supported); +int stt_dbus_request_initialize(int uid, bool* silence_supported); int stt_dbus_request_finalize(int uid); +int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* silence_supported); + +int stt_dbus_request_check_app_agreed(int uid, const char* appid, bool* value); + 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_is_partial_result_supported(int uid, bool* partial_result); +int stt_dbus_request_is_recognition_type_supported(int uid, const char* type, bool* support); + +int stt_dbus_request_set_start_sound(int uid, const char* file); + +int stt_dbus_request_unset_start_sound(int uid); + +int stt_dbus_request_set_stop_sound(int uid, const char* file); + +int stt_dbus_request_unset_stop_sound(int uid); + -int stt_dbus_request_start(int uid, const char* lang, const char* type, int profanity, int punctuation, int silence); +int stt_dbus_request_start(int uid, const char* lang, const char* type, int silence, const char* appid); int stt_dbus_request_stop(int uid); int stt_dbus_request_cancel(int uid); -int stt_dbus_request_start_file_recognition(int uid, const char* filepath, const char* lang, const char* type, int profanity, int punctuation); #ifdef __cplusplus } diff --git a/client/stt_file.c b/client/stt_file.c new file mode 100644 index 0000000..00fccd2 --- /dev/null +++ b/client/stt_file.c @@ -0,0 +1,1076 @@ +/* +* Copyright (c) 2011-2014 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stt_config_mgr.h" +#include "stt_defs.h" +#include "stt_engine.h" +#include "stt_file.h" +#include "stt_file_client.h" +#include "stt_network.h" + + +typedef struct _sttengine_info { + int engine_id; + + char* engine_uuid; + char* engine_path; + char* engine_name; + char* engine_setting_path; + bool use_network; + + bool is_loaded; +}sttengine_info_s; + +static GSList* g_engine_list; + +static int g_engine_id_count = 0; + + +#define STT_FILE_CONFIG_HANDLE 100000 + + +const char* stt_tag() +{ + return TAG_STTFC; +} + +static const char* __stt_file_get_error_code(stt_file_error_e err) +{ + switch(err) { + case STT_FILE_ERROR_NONE: return "STT_FILE_ERROR_NONE"; + case STT_FILE_ERROR_OUT_OF_MEMORY: return "STT_FILE_ERROR_OUT_OF_MEMORY"; + case STT_FILE_ERROR_IO_ERROR: return "STT_FILE_ERROR_IO_ERROR"; + case STT_FILE_ERROR_INVALID_PARAMETER: return "STT_FILE_ERROR_INVALID_PARAMETER"; + case STT_FILE_ERROR_OUT_OF_NETWORK: return "STT_FILE_ERROR_OUT_OF_NETWORK"; + case STT_FILE_ERROR_INVALID_STATE: return "STT_FILE_ERROR_INVALID_STATE"; + case STT_FILE_ERROR_INVALID_LANGUAGE: return "STT_FILE_ERROR_INVALID_LANGUAGE"; + case STT_FILE_ERROR_ENGINE_NOT_FOUND: return "STT_FILE_ERROR_ENGINE_NOT_FOUND"; + case STT_FILE_ERROR_OPERATION_FAILED: return "STT_FILE_ERROR_OPERATION_FAILED"; + case STT_FILE_ERROR_NOT_SUPPORTED_FEATURE: return "STT_FILE_ERROR_NOT_SUPPORTED_FEATURE"; + case STT_FILE_ERROR_NOT_AGREE_SERVICE: return "STT_FILE_ERROR_NOT_AGREE_SERVICE"; + default: + return "Invalid error code"; + } +} + +void __stt_file_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->engine_setting_path = g_strdup(setting_ug_name); + temp->use_network = use_network; +} + +static int __stt_file_get_engine_info(const char* filepath, sttengine_info_s** info) +{ + if (NULL == filepath || NULL == info) { + SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Invalid Parameter"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + /* load engine */ + char *error; + void* handle; + + handle = dlopen (filepath, RTLD_LAZY); + + if (!handle) { + SECURE_SLOG(LOG_WARN, TAG_STTFC, "[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_STTFC, "[Engine Agent] Invalid engine. Fail to open sttp_load_engine : %s", error); + dlclose(handle); + return -1; + } + + dlsym(handle, "sttp_unload_engine"); + if ((error = dlerror()) != NULL) { + SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Invalid engine. Fail to open sttp_unload_engine : %s", error); + dlclose(handle); + return -1; + } + + 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 || NULL == get_engine_info) { + SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent WARNING] Invalid engine. Fail to open sttp_get_engine_info : %s", error); + dlclose(handle); + return -1; + } + + sttengine_info_s* temp; + temp = (sttengine_info_s*)calloc(1, sizeof(sttengine_info_s)); + + /* get engine info */ + if (0 != get_engine_info(__stt_file_engine_info_cb, (void*)temp)) { + SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Fail to get engine info from engine"); + dlclose(handle); + free(temp); + return -1; + } + + /* close engine */ + dlclose(handle); + + temp->engine_id = g_engine_id_count; + g_engine_id_count++; + + temp->engine_path = g_strdup(filepath); + temp->is_loaded = false; + + SLOG(LOG_DEBUG, TAG_STTFC, "----- Valid Engine"); + SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "Engine id : %d", temp->engine_id); + SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "Engine uuid : %s", temp->engine_uuid); + SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "Engine name : %s", temp->engine_name); + SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "Engine path : %s", temp->engine_path); + SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "Engine setting path : %s", temp->engine_setting_path); + SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "Use network : %s", temp->use_network ? "true":"false"); + SLOG(LOG_DEBUG, TAG_STTFC, "-----"); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + *info = temp; + + return 0; +} + +static bool __stt_file_is_engine(const char* filepath) +{ + GSList *iter = NULL; + sttengine_info_s *engine = NULL; + + if (0 < g_slist_length(g_engine_list)) { + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + /* Get handle data from list */ + engine = iter->data; + + if (0 == strcmp(engine->engine_path, filepath)) { + return true; + } + + iter = g_slist_next(iter); + } + } + + return false; +} + +void __stt_file_relseae_engine_info() +{ + GSList *iter = NULL; + + /* Release engine list */ + sttengine_info_s *engine = NULL; + + if (0 < g_slist_length(g_engine_list)) { + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + /* Get handle data from list */ + engine = iter->data; + g_engine_list = g_slist_remove_link(g_engine_list, iter); + + /* Check engine unload */ + if (NULL != engine) { + if (engine->is_loaded) { + SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "[Engine Agent] Unload engine id(%d)", engine->engine_id); + + if (0 != stt_engine_deinitialize(engine->engine_id)) + SECURE_SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Fail to deinitialize engine id(%d)", engine->engine_id); + + if (0 != stt_engine_unload(engine->engine_id)) + SECURE_SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Fail to unload engine id(%d)", engine->engine_id); + + engine->is_loaded = false; + } + + if (NULL != engine->engine_uuid) free(engine->engine_uuid); + if (NULL != engine->engine_path) free(engine->engine_path); + if (NULL != engine->engine_name) free(engine->engine_name); + if (NULL != engine->engine_setting_path)free(engine->engine_setting_path); + + free(engine); + } + + iter = g_slist_nth(g_engine_list, 0); + } + } +} + +static sttengine_info_s* __stt_file_get_engine_by_id(int engine_id) +{ + GSList *iter = NULL; + sttengine_info_s *data = NULL; + + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + + data = iter->data; + + if (data->engine_id == engine_id) + return data; + + iter = g_slist_next(iter); + } + + return NULL; +} + +void __stt_file_result_cb(sttp_result_event_e event, const char* type, const char** data, int data_count, + const char* msg, void* time_info, void *user_data) +{ + + SLOG(LOG_DEBUG, TAG_STTFC, "[STT FILE] Result event(%d) type(%s) msg(%s)", event, type, msg); + + if (NULL != data) { + int i = 0; + for (i = 0;i < data_count;i++) { + if (NULL != data[i]) { + SLOG(LOG_DEBUG, TAG_STTFC, "[STT FILE] [%d] %s", i, data[i]); + } + } + } + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to notify error : A handle is not valid"); + return; + } + + if (NULL != time_info) { + client->time_info = time_info; + } + + if (NULL != client->recognition_result_cb) { + stt_file_client_use_callback(client); + client->recognition_result_cb(event, data, data_count, msg, client->recognition_result_user_data); + stt_file_client_not_use_callback(client); + SLOG(LOG_DEBUG, TAG_STTFC, "client recognition result callback called"); + } else { + SLOG(LOG_WARN, TAG_STTFC, "[WARNING] User recognition result callback is NULL"); + } + + client->time_info = NULL; + + if (STTP_RESULT_EVENT_FINAL_RESULT == event || STTP_RESULT_EVENT_ERROR == event) { + SLOG(LOG_DEBUG, TAG_STTFC, "[STT FILE] State change : 'Ready'"); + + client->before_state = client->current_state; + client->current_state = STT_FILE_STATE_READY; + + if (NULL != client->state_changed_cb) { + stt_file_client_use_callback(client); + client->state_changed_cb(client->before_state, client->current_state, client->state_changed_user_data); + stt_file_client_not_use_callback(client); + SLOG(LOG_DEBUG, TAG_STTFC, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_STTFC, "[WARNING] State changed callback is null"); + } + } + + return; +} + +void __stt_file_silence_cb(sttp_silence_type_e type, void *user_data) +{ + SLOG(LOG_WARN, TAG_STTFC, "[WARNING] This callback should NOT be called."); + return; +} + +static int __stt_file_load_engine(sttengine_info_s* engine) +{ + if (NULL == engine) { + SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Input engine is NULL"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + if (0 != stt_engine_load(engine->engine_id, engine->engine_path)) { + SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Fail to load engine(%s)", engine->engine_path); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + int ret = stt_engine_initialize(engine->engine_id, __stt_file_result_cb, __stt_file_silence_cb); + if (0 != ret) { + SECURE_SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Fail to initialize engine : id(%d) path(%s)", engine->engine_id, engine->engine_path); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + engine->is_loaded = true; + + SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "[STT FILE Success] Load engine id(%d) path(%s)", engine->engine_id, engine->engine_path); + + return STT_FILE_ERROR_NONE; +} + +int stt_file_initialize() +{ + SLOG(LOG_DEBUG, TAG_STTFC, "===== Initialize STT FILE"); + + stt_file_client_s* client = stt_file_client_get(); + if (NULL != client) { + SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Already initialized"); + return STT_FILE_ERROR_INVALID_STATE; + } + + /* Get file name from default engine directory */ + DIR *dp = NULL; + int ret = -1; + struct dirent entry; + struct dirent *dirp = NULL; + dp = opendir(STT_DEFAULT_ENGINE); + if (NULL != dp) { + do { + ret = readdir_r(dp, &entry, &dirp); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTFC, "[File ERROR] Fail to read directory"); + break; + } + + if (NULL != dirp) { + sttengine_info_s* info; + char* filepath; + int filesize; + + filesize = strlen(STT_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5; + filepath = (char*)calloc(filesize, sizeof(char)); + + + if (NULL != filepath) { + snprintf(filepath, filesize, "%s/%s", STT_DEFAULT_ENGINE, dirp->d_name); + } else { + SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Memory not enough!!"); + continue; + } + + if (false == __stt_file_is_engine(filepath)) { + /* get its and update engine list */ + if (0 == __stt_file_get_engine_info(filepath, &info)) { + /* add engine info to g_engine_list */ + g_engine_list = g_slist_append(g_engine_list, info); + } + } + + if (NULL != filepath) + free(filepath); + } + } while (NULL != dirp); + + closedir(dp); + } else { + SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent WARNING] Fail to open default directory"); + } + + if (0 >= g_slist_length(g_engine_list)) { + SLOG(LOG_WARN, TAG_STTFC, "[STT FILE WARNING] Not found engine"); + return STT_FILE_ERROR_ENGINE_NOT_FOUND; + } + + ret = stt_file_client_new(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Fail to create client : %s", __stt_file_get_error_code(ret)); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + client = stt_file_client_get(); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Not initialized"); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + ret = stt_config_mgr_initialize(getpid() + STT_FILE_CONFIG_HANDLE); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Fail to init config manager : %s", __stt_file_get_error_code(ret)); + stt_file_client_destroy(); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + /* Get engine */ + char* engine_id = NULL; + ret = stt_config_mgr_get_engine(&engine_id); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Fail to get engine id : %s", __stt_file_get_error_code(ret)); + stt_file_client_destroy(); + stt_config_mgr_finalize(getpid() + STT_FILE_CONFIG_HANDLE); + __stt_file_relseae_engine_info(); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + SLOG(LOG_DEBUG, TAG_STTFC, "[STT FILE] Get engine id : %s", engine_id); + + bool is_found = false; + + sttengine_info_s* engine = NULL; + GSList *iter = NULL; + /* load engine */ + if (0 < g_slist_length(g_engine_list)) { + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + /* Get handle data from list */ + engine = iter->data; + + if (0 == strcmp(engine->engine_uuid, engine_id)) { + is_found = true; + break; + } + + iter = g_slist_next(iter); + } + } + + if (NULL != engine_id) free(engine_id); + + if (false == is_found) { + SLOG(LOG_WARN, TAG_STTFC, "[STT FILE WARNING] Fail to find default engine"); + iter = g_slist_nth(g_engine_list, 0); + engine = iter->data; + + if (NULL == engine) { + SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Fail to initialize engine"); + stt_file_client_destroy(); + stt_config_mgr_finalize(getpid() + STT_FILE_CONFIG_HANDLE); + __stt_file_relseae_engine_info(); + return STT_FILE_ERROR_OPERATION_FAILED; + } + SLOG(LOG_WARN, TAG_STTFC, "[STT FILE WARNING] Set default engine (%s)", engine->engine_name); + } + + ret = __stt_file_load_engine(engine); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Fail to initialize engine"); + stt_file_client_destroy(); + stt_config_mgr_finalize(getpid() + STT_FILE_CONFIG_HANDLE); + __stt_file_relseae_engine_info(); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + client->current_engine_id = engine->engine_id; + + stt_network_initialize(); + + SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "[STT FILE Success] Initialize : pid(%d)", getpid()); + + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + return STT_FILE_ERROR_NONE; +} + +int stt_file_deinitialize() +{ + SLOG(LOG_DEBUG, TAG_STTFC, "===== Deinitialize STT FILE"); + + stt_file_client_s* client = stt_file_client_get(); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Not initialized"); + return STT_FILE_ERROR_INVALID_STATE; + } + + /* check used callback */ + if (0 != stt_file_client_get_use_callback(client)) { + SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Client should NOT deinitialize STT FILE in callback function"); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + stt_network_finalize(); + + stt_config_mgr_finalize(getpid() + STT_FILE_CONFIG_HANDLE); + + /* check state */ + switch (client->current_state) { + case STT_FILE_STATE_PROCESSING: + /* Cancel file recognition */ + stt_engine_recognize_cancel_file(client->current_engine_id); + + case STT_FILE_STATE_READY: + /* Unload engine */ + __stt_file_relseae_engine_info(); + + /* Free resources */ + stt_file_client_destroy(); + break; + + case STT_FILE_STATE_NONE: + SLOG(LOG_WARN, TAG_STTFC, "[STT FILE WARNING] NOT initialized"); + return 0; + default: + break; + } + + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + return STT_FILE_ERROR_NONE; +} + +int stt_file_get_state(stt_file_state_e* state) +{ + if (NULL == state) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Input parameter is NULL"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + stt_file_client_s* client = stt_file_client_get(); + + if (NULL == client) { + SLOG(LOG_DEBUG, TAG_STTFC, "[STT FILE] Not initialized"); + *state = STT_FILE_STATE_NONE; + return STT_FILE_ERROR_NONE; + } + + *state = client->current_state; + + switch(*state) { + case STT_FILE_STATE_NONE: SLOG(LOG_DEBUG, TAG_STTFC, "Current state is 'NONE'"); break; + case STT_FILE_STATE_READY: SLOG(LOG_DEBUG, TAG_STTFC, "Current state is 'Ready'"); break; + case STT_FILE_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTFC, "Current state is 'Processing'"); break; + default: SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid value"); break; + } + + return STT_FILE_ERROR_NONE; +} + +int stt_file_foreach_supported_engines(stt_file_supported_engine_cb callback, void* user_data) +{ + SLOG(LOG_DEBUG, TAG_STTFC, "===== Foreach Supported engine"); + + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Input parameter is NULL"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + if (client->current_state != STT_FILE_STATE_READY) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state is not 'Ready'"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_STATE; + } + + GSList *iter = NULL; + sttengine_info_s *engine = NULL; + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + /* Get handle data from list */ + engine = iter->data; + + if (NULL != engine) { + if (false == callback(engine->engine_uuid, engine->engine_name, user_data)) { + break; + } + } + iter = g_slist_next(iter); + } + + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + return STT_FILE_ERROR_NONE; +} + +int stt_file_get_engine(char** engine_id) +{ + SLOG(LOG_DEBUG, TAG_STTFC, "===== Get current engine"); + + if (NULL == engine_id) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Input parameter is NULL"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + if (client->current_state != STT_FILE_STATE_READY) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state is not 'Ready'"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_STATE; + } + + sttengine_info_s* engine = NULL; + engine = __stt_file_get_engine_by_id(client->current_engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to get engine info(%d)", client->current_engine_id); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + *engine_id = strdup(engine->engine_uuid); + + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + return STT_FILE_ERROR_NONE; +} + +int stt_file_set_engine(const char* engine_id) +{ + SLOG(LOG_DEBUG, TAG_STTFC, "===== Set current engine"); + + if (NULL == engine_id) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Input parameter is NULL"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + /* check state */ + if (client->current_state != STT_FILE_STATE_READY) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state is not 'Ready'"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_STATE; + } + + GSList *iter = NULL; + sttengine_info_s *engine = NULL; + + int temp_old_engine = -1; + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + /* Get handle data from list */ + engine = iter->data; + + if (0 == strcmp(engine->engine_uuid, engine_id)) { + if (client->current_engine_id != engine->engine_id) { + temp_old_engine = client->current_engine_id; + } else { + SLOG(LOG_DEBUG, TAG_STTFC, "Already loaded engine : %s", engine_id); + return 0; + } + + break; + } + + iter = g_slist_next(iter); + engine = NULL; + } + + if (NULL == engine) { + SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Engine id is NOT valid"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + int ret = __stt_file_load_engine(engine); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Fail to initialize engine"); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + client->current_engine_id = engine->engine_id; + + if (-1 != temp_old_engine) { + stt_engine_deinitialize(temp_old_engine); + stt_engine_unload(temp_old_engine); + } + + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + return 0; +} + +bool __stt_config_supported_language_cb(const char* engine_id, const char* language, void* user_data) +{ + stt_file_client_s* client = stt_file_client_get(); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[WARNING] A handle is not valid"); + return false; + } + + /* call callback function */ + if (NULL != client->supported_lang_cb) { + return client->supported_lang_cb(language, client->supported_lang_user_data); + } else { + SLOG(LOG_WARN, TAG_STTFC, "No registered callback function of supported languages"); + } + + return false; +} + +int stt_file_foreach_supported_languages(stt_file_supported_language_cb callback, void* user_data) +{ + SLOG(LOG_DEBUG, TAG_STTFC, "===== Foreach Supported Language"); + + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Input parameter is NULL"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + sttengine_info_s* engine = NULL; + engine = __stt_file_get_engine_by_id(client->current_engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to get engine info(%d)", client->current_engine_id); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + client->supported_lang_cb = callback; + client->supported_lang_user_data = user_data; + + int ret = -1; + ret = stt_config_mgr_get_language_list(engine->engine_uuid, __stt_config_supported_language_cb, NULL); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to get languages"); + } + + client->supported_lang_cb = NULL; + client->supported_lang_user_data = NULL; + + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + return STT_FILE_ERROR_NONE; +} + +int stt_file_start(const char* language, const char* type, const char* filepath, + stt_file_audio_type_e audio_type, int sample_rate) +{ + SLOG(LOG_DEBUG, TAG_STTFC, "===== STT FILE START"); + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_STATE; + } + + /* check state */ + if (client->current_state != STT_FILE_STATE_READY) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_STATE; + } + + if (NULL == language || NULL == filepath) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Input parameter is NULL"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + /* check if engine use network */ + sttengine_info_s* engine = NULL; + engine = __stt_file_get_engine_by_id(client->current_engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to get engine info(%d)", client->current_engine_id); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + if (true == engine->use_network) { + if (false == stt_network_is_connected()) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Disconnect network. Current engine needs to network connection."); + return STT_FILE_ERROR_OUT_OF_NETWORK; + } + } + + SLOG(LOG_DEBUG, TAG_STTFC, "[START Info] Engine(%d) Lang(%s) Type(%s) Filepath(%s) Audio(%d) Sample rate(%d)" + ,client->current_engine_id, language, type, filepath, audio_type, sample_rate); + + int ret = -1; + ret = stt_engine_recognize_start_file(client->current_engine_id, language, type, filepath, audio_type, sample_rate, NULL); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to start file recognition"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + client->before_state = client->current_state; + client->current_state = STT_FILE_STATE_PROCESSING; + + if (NULL != client->state_changed_cb) { + stt_file_client_use_callback(client); + client->state_changed_cb(client->before_state, client->current_state, client->state_changed_user_data); + stt_file_client_not_use_callback(client); + SLOG(LOG_DEBUG, TAG_STTFC, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_STTFC, "[WARNING] State changed callback is null"); + } + + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + return STT_FILE_ERROR_NONE; +} + +int stt_file_cancel() +{ + SLOG(LOG_DEBUG, TAG_STTFC, "===== STT FILE CANCEL"); + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + /* check state */ + if (STT_FILE_STATE_PROCESSING != client->current_state) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid state : Current state is NOT 'Processing'"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_INVALID_STATE; + } + + int ret = -1; + ret = stt_engine_recognize_cancel_file(client->current_engine_id); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to cancel file recognition"); + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + return STT_FILE_ERROR_OPERATION_FAILED; + } + + client->before_state = client->current_state; + client->current_state = STT_FILE_STATE_READY; + + if (NULL != client->state_changed_cb) { + stt_file_client_use_callback(client); + client->state_changed_cb(client->before_state, client->current_state, client->state_changed_user_data); + stt_file_client_not_use_callback(client); + SLOG(LOG_DEBUG, TAG_STTFC, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_STTFC, "[WARNING] State changed callback is null"); + } + + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + return STT_FILE_ERROR_NONE; +} + +bool __stt_file_result_time_cb(int index, sttp_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data) +{ + SLOG(LOG_DEBUG, TAG_STTFC, "(%d) event(%d) text(%s) start(%ld) end(%ld)", + index, event, text, start_time, end_time); + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to notify error : A handle is not valid"); + return EINA_FALSE; + } + + if (NULL != client->result_time_cb) { + client->result_time_cb(index, (stt_file_result_time_event_e)event, + text, start_time, end_time, client->result_time_user_data); + } else { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Callback is NULL"); + return false; + } + + return true; +} + +int stt_file_foreach_detailed_result(stt_file_result_time_cb callback, void* user_data) +{ + SLOG(LOG_DEBUG, TAG_STTFC, "===== STT FILE FOREACH DETAILED RESULT"); + + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Input parameter is NULL"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail : A handle is not valid"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + client->result_time_cb = callback; + client->result_time_user_data = user_data; + + stt_engine_foreach_result_time(client->current_engine_id, client->time_info, __stt_file_result_time_cb, NULL); + + client->result_time_cb = NULL; + client->result_time_user_data = NULL; + + SLOG(LOG_DEBUG, TAG_STTFC, "====="); + SLOG(LOG_DEBUG, TAG_STTFC, " "); + + return STT_FILE_ERROR_NONE; +} + +int stt_file_set_recognition_result_cb(stt_file_recognition_result_cb callback, void* user_data) +{ + if (NULL == callback) + return STT_FILE_ERROR_INVALID_PARAMETER; + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + if (STT_FILE_STATE_READY != client->current_state) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state is not 'ready'"); + return STT_FILE_ERROR_INVALID_STATE; + } + + client->recognition_result_cb = callback; + client->recognition_result_user_data = user_data; + + return 0; +} + +int stt_file_unset_recognition_result_cb() +{ + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + if (STT_FILE_STATE_READY != client->current_state) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state is not 'ready'"); + return STT_FILE_ERROR_INVALID_STATE; + } + + client->recognition_result_cb = NULL; + client->recognition_result_user_data = NULL; + + return 0; +} + +int stt_file_set_state_changed_cb(stt_file_state_changed_cb callback, void* user_data) +{ + if (NULL == callback) + return STT_FILE_ERROR_INVALID_PARAMETER; + + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + if (STT_FILE_STATE_READY != client->current_state) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state is not 'ready'"); + return STT_FILE_ERROR_INVALID_STATE; + } + + client->state_changed_cb = callback; + client->state_changed_user_data = user_data; + + return 0; +} + +int stt_file_unset_state_changed_cb() +{ + stt_file_client_s* client = stt_file_client_get(); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] A handle is not available"); + return STT_FILE_ERROR_INVALID_PARAMETER; + } + + if (STT_FILE_STATE_READY != client->current_state) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state is not 'ready'"); + return STT_FILE_ERROR_INVALID_STATE; + } + + client->state_changed_cb = NULL; + client->state_changed_user_data = NULL; + + return 0; +} diff --git a/client/stt_file_client.c b/client/stt_file_client.c new file mode 100644 index 0000000..893c920 --- /dev/null +++ b/client/stt_file_client.c @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2011-2014 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 +#include +#include +#include + +#include "stt_file_client.h" + +static stt_file_client_s* g_client_info = NULL; + +int stt_file_client_new() +{ + if (NULL != g_client_info) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Already allocated client info"); + return STT_FILE_ERROR_INVALID_STATE; + } + + g_client_info = (stt_file_client_s*)calloc(1, sizeof(stt_file_client_s)); + + /* initialize client data */ + g_client_info->recognition_result_cb = NULL; + g_client_info->recognition_result_user_data = NULL; + + g_client_info->result_time_cb = NULL; + g_client_info->result_time_user_data = NULL; + + g_client_info->state_changed_cb = NULL; + g_client_info->state_changed_user_data = NULL; + + g_client_info->supported_lang_cb = NULL; + g_client_info->supported_lang_user_data = NULL; + + g_client_info->current_engine_id = -1; + + g_client_info->time_info = NULL; + + g_client_info->before_state = STT_FILE_STATE_READY; + g_client_info->current_state = STT_FILE_STATE_READY; + + g_client_info->cb_ref_count = 0; + + return 0; +} + +int stt_file_client_destroy() +{ + if (NULL == g_client_info) { + SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Client info is NULL"); + return STT_FILE_ERROR_INVALID_STATE; + } else { + while (0 != g_client_info->cb_ref_count) { + /* wait for release callback function */ + } + + free(g_client_info); + + g_client_info = NULL; + } + + return 0; +} + +stt_file_client_s* stt_file_client_get() +{ + return g_client_info; +} + +int stt_file_client_use_callback(stt_file_client_s* client) +{ + client->cb_ref_count++; + return 0; +} + +int stt_file_client_not_use_callback(stt_file_client_s* client) +{ + client->cb_ref_count--; + return 0; +} + +int stt_file_client_get_use_callback(stt_file_client_s* client) +{ + return client->cb_ref_count; +} diff --git a/client/stt_file_client.h b/client/stt_file_client.h new file mode 100644 index 0000000..5db6fed --- /dev/null +++ b/client/stt_file_client.h @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2011-2014 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_FILE_CLIENT_H_ +#define __STT_FILE_CLIENT_H_ + + +#include "stt_file.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define TAG_STTFC "sttfile" + +typedef struct { + /* callback functions */ + stt_file_recognition_result_cb recognition_result_cb; + void* recognition_result_user_data; + + stt_file_result_time_cb result_time_cb; + void* result_time_user_data; + + stt_file_state_changed_cb state_changed_cb; + void* state_changed_user_data; + + stt_file_supported_language_cb supported_lang_cb; + void* supported_lang_user_data; + + /* current engine */ + int current_engine_id; + + /* state */ + stt_file_state_e before_state; + stt_file_state_e current_state; + + /* mutex */ + int cb_ref_count; + + /* result data */ + void* time_info; + + /* error data */ + int reason; +}stt_file_client_s; + + +int stt_file_client_new(); + +int stt_file_client_destroy(); + +stt_file_client_s* stt_file_client_get(); + +int stt_file_client_use_callback(stt_file_client_s* client); + +int stt_file_client_not_use_callback(stt_file_client_s* client); + +int stt_file_client_get_use_callback(stt_file_client_s* client); + + + +#ifdef __cplusplus +} +#endif + +#endif /* __STT_FILE_CLIENT_H_ */ diff --git a/client/stt_main.h b/client/stt_main.h index 57fd273..b10e429 100644 --- a/client/stt_main.h +++ b/client/stt_main.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2014 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 @@ -15,14 +15,15 @@ #ifndef __STT_MAIN_H_ #define __STT_MAIN_H_ +#include +#include +#include +#include #include #include #include #include #include -#include -#include -#include #include "stt_defs.h" @@ -39,6 +40,15 @@ struct stt_s { int handle; }; +typedef enum { + STT_DAEMON_NORMAL = 0, + STT_DAEMON_ON_TERMINATING = -1 +} stt_daemon_status_e; + +typedef enum { + STT_RESULT_STATE_DONE = 0, /**< Sync state change */ + STT_RESULT_STATE_NOT_DONE = 1 /**< Async state change */ +} stt_result_state_e; #ifdef __cplusplus } diff --git a/client/stt_setting.c b/client/stt_setting.c index f6347b3..15452e9 100644 --- a/client/stt_setting.c +++ b/client/stt_setting.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2014 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 @@ -11,101 +11,91 @@ * limitations under the License. */ - -#include +#include #include -#include +#include #include -#include +#include +#include +#include "stt_config_mgr.h" #include "stt_main.h" #include "stt_setting.h" -#include "stt_setting_dbus.h" - - -static int __check_setting_stt_daemon(); -static bool g_is_daemon_started = false; - -static Ecore_Timer* g_setting_connect_timer = NULL; static stt_setting_state_e g_state = STT_SETTING_STATE_NONE; -static stt_setting_initialized_cb g_initialized_cb; - +static stt_setting_supported_engine_cb g_engine_cb; static void* g_user_data; -static int g_reason; +static stt_setting_config_changed_cb g_config_changed_cb; +static void* g_config_changed_user_data; -/* API Implementation */ -static Eina_Bool __stt_setting_initialized(void *data) -{ - g_initialized_cb(g_state, g_reason, g_user_data); +static stt_setting_engine_changed_cb g_engine_changed_cb; +static void* g_engine_changed_user_data; - return EINA_FALSE; +const char* stt_tag() +{ + return "sttc"; } -static Eina_Bool __stt_setting_connect_daemon(void *data) +void __config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, bool support_silence, void* user_data) { - /* Send hello */ - if (0 != stt_setting_dbus_request_hello()) { - if (false == g_is_daemon_started) { - g_is_daemon_started = true; - __check_setting_stt_daemon(); - } - return EINA_TRUE; - } - - SLOG(LOG_DEBUG, TAG_STTC, "===== Connect daemon"); + if (NULL != engine_id) SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Engine id(%s)", engine_id); + if (NULL != setting) SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Engine setting(%s)", setting); + if (NULL != language) SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Language(%s)", language); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Silence(%s)", support_silence ? "on" : "off"); - /* do request initialize */ - int ret = -1; - - ret = stt_setting_dbus_request_initialize(); - - if (STT_SETTING_ERROR_ENGINE_NOT_FOUND == ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Engine not found"); - } else if (STT_SETTING_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to connection : %d", ret); - } else { - /* success to connect stt-daemon */ - g_state = STT_SETTING_STATE_READY; - } - - g_reason = ret; + if (NULL != g_config_changed_cb) + g_engine_changed_cb(g_config_changed_user_data); +} - ecore_timer_add(0, __stt_setting_initialized, NULL); +void __config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data) +{ + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Lang changed : lang(%s)", current_language); - g_setting_connect_timer = NULL; + if (NULL != g_config_changed_cb) + g_config_changed_cb(g_config_changed_user_data); +} - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); +void __config_bool_changed_cb(stt_config_type_e type, bool bool_value, void* user_data) +{ + SECURE_SLOG(LOG_DEBUG, TAG_STTC, " type(%d) bool(%s)", type, bool_value ? "on" : "off"); - return EINA_FALSE; + if (NULL != g_config_changed_cb) + g_config_changed_cb(g_config_changed_user_data); } -int stt_setting_initialize(stt_setting_initialized_cb callback, void* user_data) +int stt_setting_initialize(void) { SLOG(LOG_DEBUG, TAG_STTC, "===== Initialize STT Setting"); if (STT_SETTING_STATE_READY == g_state) { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] STT Setting has already been initialized. \n"); + SLOG(LOG_WARN, TAG_STTC, "[WARNING] STT Setting has already been initialized. "); SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); return STT_SETTING_ERROR_NONE; } - 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, " "); + int ret = stt_config_mgr_initialize(getpid()); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize config manager : %d", ret); return STT_SETTING_ERROR_OPERATION_FAILED; } - g_initialized_cb = callback; - g_user_data = user_data; + ret = stt_config_mgr_set_callback(getpid(), __config_engine_changed_cb, __config_lang_changed_cb, __config_bool_changed_cb, NULL); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set config changed : %d", ret); + return STT_SETTING_ERROR_OPERATION_FAILED; + } + + g_state = STT_SETTING_STATE_READY; + + g_engine_changed_cb = NULL; + g_engine_changed_user_data = NULL; - g_setting_connect_timer = ecore_timer_add(0, __stt_setting_connect_daemon, NULL); + g_config_changed_cb = NULL; + g_config_changed_user_data = NULL; SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -117,27 +107,7 @@ int stt_setting_finalize () { SLOG(LOG_DEBUG, TAG_STTC, "===== Finalize STT Setting"); - int ret = 0; - - if (STT_SETTING_STATE_READY == g_state) { - ret = stt_setting_dbus_request_finalilze(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTC, "Fail : finialize(%d)", ret); - } - } - - if (NULL != g_setting_connect_timer) { - SLOG(LOG_DEBUG, TAG_STTC, "Setting Connect Timer is deleted"); - ecore_timer_del(g_setting_connect_timer); - } - - g_is_daemon_started = false; - - 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"); - } + stt_config_mgr_finalize(getpid()); g_state = STT_SETTING_STATE_NONE; @@ -147,6 +117,11 @@ int stt_setting_finalize () return STT_SETTING_ERROR_NONE; } +bool __config_mgr_get_engine_list(const char* engine_id, const char* engine_name, const char* setting, bool support_silence, void* user_data) +{ + return g_engine_cb(engine_id, engine_name, setting, g_user_data); +} + int stt_setting_foreach_supported_engines(stt_setting_supported_engine_cb callback, void* user_data) { SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach supported engines"); @@ -165,13 +140,16 @@ int stt_setting_foreach_supported_engines(stt_setting_supported_engine_cb callba return STT_SETTING_ERROR_INVALID_PARAMETER; } - int ret = stt_setting_dbus_request_get_engine_list(callback, user_data); + g_engine_cb = callback; + g_user_data = user_data; + + int ret = stt_config_mgr_get_engine_list(__config_mgr_get_engine_list, NULL); 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, " "); @@ -196,7 +174,7 @@ int stt_setting_get_engine(char** engine_id) return STT_SETTING_ERROR_INVALID_PARAMETER; } - int ret = stt_setting_dbus_request_get_engine(engine_id); + int ret = stt_config_mgr_get_engine(engine_id); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret); } else { @@ -227,7 +205,9 @@ int stt_setting_set_engine(const char* engine_id) return STT_SETTING_ERROR_INVALID_PARAMETER; } - int ret = stt_setting_dbus_request_set_engine(engine_id); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "New engine id : %s", engine_id); + + int ret = stt_config_mgr_set_engine(engine_id); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret); } else { @@ -258,7 +238,17 @@ int stt_setting_foreach_supported_languages(stt_setting_supported_language_cb ca return STT_SETTING_ERROR_INVALID_PARAMETER; } - int ret = stt_setting_dbus_request_get_language_list(callback, user_data); + char* current_engine; + int ret = stt_config_mgr_get_engine(¤t_engine); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get current engine : %d", ret); + return -1; + } + + ret = stt_config_mgr_get_language_list(current_engine, (stt_config_supported_langauge_cb)callback, user_data); + + if (NULL != current_engine) + free(current_engine); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret); @@ -290,11 +280,11 @@ int stt_setting_get_default_language(char** language) return STT_SETTING_ERROR_INVALID_PARAMETER; } - int ret = stt_setting_dbus_request_get_default_language(language); + int ret = stt_config_mgr_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"); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Default language : %s", *language); } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -321,11 +311,11 @@ int stt_setting_set_default_language(const char* language) return STT_SETTING_ERROR_INVALID_PARAMETER; } - int ret = stt_setting_dbus_request_set_default_language(language); + int ret = stt_config_mgr_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"); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set default language : %s", language); } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -334,11 +324,9 @@ int stt_setting_set_default_language(const char* language) return ret; } -int stt_setting_get_profanity_filter(bool* value) +int stt_setting_set_auto_language(bool value) { - SLOG(LOG_DEBUG, TAG_STTC, "===== Get profanity filter"); - - int ret = 0; + SLOG(LOG_DEBUG, TAG_STTC, "===== Set auto voice"); if (STT_SETTING_STATE_NONE == g_state) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Not initialized"); @@ -347,44 +335,18 @@ int stt_setting_get_profanity_filter(bool* value) return STT_SETTING_ERROR_INVALID_STATE; } - if (NULL == value) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); + if (value != true && value != false) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); 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); + int ret = stt_config_mgr_set_auto_language(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 (STT_SETTING_STATE_NONE == g_state) { - 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); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret); } else { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set profanity filter(%s)", value ? "true":"false"); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set auto language (%s)", value ? "on" : "off"); } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -393,71 +355,42 @@ int stt_setting_set_profanity_filter(const bool value) return ret; } -int stt_setting_get_punctuation_override(bool* value) +int stt_setting_get_auto_language(bool* value) { - SLOG(LOG_DEBUG, TAG_STTC, "===== Get punctuation override"); - - int ret = 0; + SLOG(LOG_DEBUG, TAG_STTC, "===== Get auto language"); if (STT_SETTING_STATE_NONE == g_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not 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_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 (STT_SETTING_STATE_NONE == g_state) { - 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); + int ret = stt_config_mgr_get_auto_language(value); if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result (%d)", ret); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result : %d", ret); } else { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set punctuation override(%s)", value ? "true":"false"); + /* Copy value */ + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Get auto language (%s)", *value ? "true":"false"); } SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); - return ret; + return 0; } int stt_setting_get_silence_detection(bool* value) { SLOG(LOG_DEBUG, TAG_STTC, "===== Get silence detection"); - int ret = 0; - if (STT_SETTING_STATE_NONE == g_state) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not initialized"); SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -472,11 +405,11 @@ int stt_setting_get_silence_detection(bool* value) return STT_SETTING_ERROR_INVALID_PARAMETER; } - ret = stt_setting_dbus_request_get_silence_detection(value); + int ret = stt_config_mgr_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"); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Get silence detection(%s)", *value ? "true":"false"); } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -489,8 +422,6 @@ int stt_setting_set_silence_detection(bool value) { SLOG(LOG_DEBUG, TAG_STTC, "===== Set silence detection"); - int ret = 0; - if (STT_SETTING_STATE_NONE == g_state) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] not initialized"); SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -498,11 +429,11 @@ int stt_setting_set_silence_detection(bool value) return STT_SETTING_ERROR_INVALID_STATE; } - ret = stt_setting_dbus_request_set_silence_detection(value); + int ret = stt_config_mgr_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"); + SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set silence detection(%s)", value ? "true":"false"); } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -511,159 +442,44 @@ int stt_setting_set_silence_detection(bool value) return ret; } -int stt_setting_foreach_engine_settings(stt_setting_engine_setting_cb callback, void* user_data) +int stt_setting_set_engine_changed_cb(stt_setting_engine_changed_cb callback, void* user_data) { - SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach engine setting"); - - int ret = 0; - - if (STT_SETTING_STATE_NONE == g_state) { - 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, " "); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input param is NULL"); 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; + g_engine_changed_cb = callback; + g_engine_changed_user_data = user_data; - if (STT_SETTING_STATE_NONE == g_state) { - 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; + return STT_SETTING_ERROR_NONE; } -int __setting_get_cmd_line(char *file, char *buf) +int stt_setting_unset_engine_changed_cb() { - FILE *fp = NULL; - int i; + g_engine_changed_cb = NULL; + g_engine_changed_user_data = NULL; - fp = fopen(file, "r"); - if (fp == NULL) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get command line"); - return -1; - } - - memset(buf, 0, 256); - fgets(buf, 256, fp); - fclose(fp); - - return 0; + return STT_SETTING_ERROR_NONE; } -static bool __stt_setting_is_alive() +int stt_setting_set_config_changed_cb(stt_setting_config_changed_cb callback, void* user_data) { - DIR *dir; - struct dirent *entry; - struct stat filestat; - - int pid; - char cmdLine[256]; - char tempPath[256]; - - dir = opendir("/proc"); - if (NULL == dir) { - SLOG(LOG_ERROR, TAG_STTC, "process checking is FAILED"); - return FALSE; - } - - while ((entry = readdir(dir)) != NULL) { - if (0 != lstat(entry->d_name, &filestat)) - continue; - - if (!S_ISDIR(filestat.st_mode)) - continue; - - pid = atoi(entry->d_name); - if (pid <= 0) continue; - - sprintf(tempPath, "/proc/%d/cmdline", pid); - if (0 != __setting_get_cmd_line(tempPath, cmdLine)) { - continue; - } - - if ( 0 == strncmp(cmdLine, "[stt-daemon]", strlen("[stt-daemon]")) || - 0 == strncmp(cmdLine, "stt-daemon", strlen("stt-daemon")) || - 0 == strncmp(cmdLine, "/usr/bin/stt-daemon", strlen("/usr/bin/stt-daemon"))) { - SLOG(LOG_DEBUG, TAG_STTC, "stt-daemon is ALIVE !! \n"); - closedir(dir); - return TRUE; - } + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input param is NULL"); + return STT_SETTING_ERROR_INVALID_PARAMETER; } - SLOG(LOG_DEBUG, TAG_STTC, "THERE IS NO stt-daemon !! \n"); - closedir(dir); - return FALSE; + g_config_changed_cb = callback; + g_config_changed_user_data = user_data; + return STT_SETTING_ERROR_NONE; } -int __check_setting_stt_daemon() +int stt_setting_unset_config_changed_cb() { - if (TRUE == __stt_setting_is_alive()) - return 0; - - /* fork-exec stt-daemom */ - int pid = 0, i = 0; - - pid = fork(); - - switch(pid) { - case -1: - SLOG(LOG_DEBUG, TAG_STTC, "Fail to create stt-daemon"); - break; - - case 0: - setsid(); - for( i = 0 ; i < _NSIG ; i++ ) - signal(i, SIG_DFL); - - execl("/usr/bin/stt-daemon", "/usr/bin/stt-daemon", NULL); - break; - - default: - break; - } - - return 0; -} + g_config_changed_cb = NULL; + g_config_changed_user_data = NULL; + return STT_SETTING_ERROR_NONE; +} \ No newline at end of file diff --git a/client/stt_setting_dbus.c b/client/stt_setting_dbus.c deleted file mode 100644 index 2ce9faa..0000000 --- a/client/stt_setting_dbus.c +++ /dev/null @@ -1,1175 +0,0 @@ -/* -* Copyright (c) 2012, 2013 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 int g_waiting_time = 1500; - -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); - - dbus_connection_close(g_conn); - - g_conn = NULL; - - return 0; -} - - -int stt_setting_dbus_request_hello() -{ - DBusMessage* msg; - - msg = dbus_message_new_method_call( - STT_SERVER_SERVICE_NAME, - STT_SERVER_SERVICE_OBJECT_PATH, - STT_SERVER_SERVICE_INTERFACE, - STT_SETTING_METHOD_HELLO); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_STTC, ">>>> Request setting hello : Fail to make message \n"); - return STT_SETTING_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg = NULL; - int result = 0; - - result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 500, &err); - - dbus_message_unref(msg); - - if (NULL != result_msg) { - dbus_message_unref(result_msg); - - SLOG(LOG_DEBUG, TAG_STTC, "<<<< setting hello"); - result = 0; - } else { - result = -1; - } - - return result; -} - -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, g_waiting_time, &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, g_waiting_time, &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, g_waiting_time, &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>>> 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, g_waiting_time, &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, g_waiting_time, &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, g_waiting_time, &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>>> 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, g_waiting_time, &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, g_waiting_time, &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, g_waiting_time, &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>>> 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, g_waiting_time, &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, g_waiting_time, &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, g_waiting_time, &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, g_waiting_time, &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, g_waiting_time, &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, g_waiting_time, &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, g_waiting_time, &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 deleted file mode 100644 index c642359..0000000 --- a/client/stt_setting_dbus.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -* Copyright (c) 2012, 2013 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_hello(); - -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_config_mgr.c b/common/stt_config_mgr.c new file mode 100644 index 0000000..8d44b98 --- /dev/null +++ b/common/stt_config_mgr.c @@ -0,0 +1,1441 @@ +/* +* Copyright (c) 2011-2014 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 +#include +#include +#include +#include +#include +#include +#include + +#include "stt_config_mgr.h" +#include "stt_defs.h" +#include "stt_config_parser.h" + +#define VCONFKEY_VOICE_INPUT_LANGUAGE "db/voice_input/language" + +typedef struct { + int uid; + stt_config_engine_changed_cb engine_cb; + stt_config_lang_changed_cb lang_cb; + stt_config_bool_changed_cb bool_cb; + void* user_data; +}stt_config_client_s; + + +extern const char* stt_tag(); + +static GSList* g_engine_list = NULL; + +static GSList* g_config_client_list = NULL; + +static stt_config_s* g_config_info; + +static Ecore_Fd_Handler* g_fd_handler_noti = NULL; +static int g_fd_noti; +static int g_wd_noti; + +int __stt_config_mgr_print_engine_info(); + +bool __stt_config_mgr_check_lang_is_valid(const char* engine_id, const char* language) +{ + if (NULL == engine_id || NULL == language) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); + return false; + } + + GSList *iter = NULL; + stt_engine_info_s *engine_info = NULL; + + if (0 >= g_slist_length(g_engine_list)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] There is no engine!!"); + return false; + } + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + engine_info = iter->data; + + if (NULL == engine_info) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Engine info is NULL"); + return false; + } + + if (0 != strcmp(engine_id, engine_info->uuid)) { + iter = g_slist_next(iter); + continue; + } + + GSList *iter_lang = NULL; + char* engine_lang; + if (g_slist_length(engine_info->languages) > 0) { + /* Get a first item */ + iter_lang = g_slist_nth(engine_info->languages, 0); + + int i = 1; + while (NULL != iter_lang) { + /*Get handle data from list*/ + engine_lang = iter_lang->data; + + SECURE_SLOG(LOG_DEBUG, stt_tag(), " [%dth] %s", i, engine_lang); + + if (0 == strcmp(language, engine_lang)) { + return true; + } + + /*Get next item*/ + iter_lang = g_slist_next(iter_lang); + i++; + } + } + break; + } + + return false; +} + +int __stt_config_mgr_select_lang(const char* engine_id, char** language) +{ + if (NULL == engine_id || NULL == language) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); + return false; + } + + GSList *iter = NULL; + stt_engine_info_s *engine_info = NULL; + + if (0 >= g_slist_length(g_engine_list)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] There is no engine!!"); + return false; + } + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + engine_info = iter->data; + + if (NULL == engine_info) { + SLOG(LOG_ERROR, stt_tag(), "engine info is NULL"); + return false; + } + + if (0 != strcmp(engine_id, engine_info->uuid)) { + iter = g_slist_next(iter); + continue; + } + + GSList *iter_lang = NULL; + char* engine_lang = NULL; + if (g_slist_length(engine_info->languages) > 0) { + /* Get a first item */ + iter_lang = g_slist_nth(engine_info->languages, 0); + + while (NULL != iter_lang) { + engine_lang = iter_lang->data; + if (NULL != engine_lang) { + /* Default language is STT_BASE_LANGUAGE */ + if (0 == strcmp(STT_BASE_LANGUAGE, engine_lang)) { + *language = strdup(engine_lang); + SECURE_SLOG(LOG_DEBUG, stt_tag(), "Selected language : %s", *language); + return 0; + } + } + + iter_lang = g_slist_next(iter_lang); + } + + /* Not support STT_BASE_LANGUAGE */ + if (NULL != engine_lang) { + *language = strdup(engine_lang); + SECURE_SLOG(LOG_DEBUG, stt_tag(), "Selected language : %s", *language); + return 0; + } + } + break; + } + + return -1; +} + +Eina_Bool stt_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handler) +{ + SLOG(LOG_DEBUG, stt_tag(), "===== Config changed callback event"); + + int length; + struct inotify_event event; + memset(&event, '\0', sizeof(struct inotify_event)); + + length = read(g_fd_noti, &event, sizeof(struct inotify_event)); + if (0 > length) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty Inotify event"); + SLOG(LOG_DEBUG, stt_tag(), "====="); + SLOG(LOG_DEBUG, stt_tag(), " "); + return ECORE_CALLBACK_PASS_ON; + } + + if (IN_MODIFY == event.mask) { + char* engine = NULL; + char* setting = NULL; + char* lang = NULL; + int auto_lang = -1; + int silence = -1; + + GSList *iter = NULL; + stt_config_client_s* temp_client = NULL; + + if (0 != stt_parser_find_config_changed(&engine, &setting, &auto_lang, &lang, &silence)) + return ECORE_CALLBACK_PASS_ON; + + /* Engine changed */ + if (NULL != engine || NULL != setting) { + /* engine changed */ + if (NULL != engine) { + if (NULL != g_config_info->engine_id) free(g_config_info->engine_id); + g_config_info->engine_id = strdup(engine); + } + + if (NULL != setting) { + if (NULL != g_config_info->setting) free(g_config_info->setting); + g_config_info->setting = strdup(setting); + } + + if (NULL != lang) { + if (NULL != g_config_info->language) free(g_config_info->language); + g_config_info->language = strdup(lang); + } + + if (-1 != silence) g_config_info->silence_detection = silence; + + /* Call all callbacks of client*/ + iter = g_slist_nth(g_config_client_list, 0); + + while (NULL != iter) { + temp_client = iter->data; + + if (NULL != temp_client) { + if (NULL != temp_client->engine_cb) { + temp_client->engine_cb(g_config_info->engine_id, g_config_info->setting, g_config_info->language, + g_config_info->silence_detection, temp_client->user_data); + } + } + + iter = g_slist_next(iter); + } + } + + if (-1 != auto_lang) { + g_config_info->auto_lang = auto_lang; + } + + /* Only language changed */ + if (NULL == engine && NULL != lang) { + char* before_lang = NULL; + before_lang = strdup(g_config_info->language); + + if (NULL != lang) { + if (NULL != g_config_info->language) free(g_config_info->language); + g_config_info->language = strdup(lang); + } + + /* Call all callbacks of client*/ + iter = g_slist_nth(g_config_client_list, 0); + + while (NULL != iter) { + temp_client = iter->data; + + if (NULL != temp_client) { + if (NULL != temp_client->lang_cb) { + temp_client->lang_cb(before_lang, g_config_info->language, temp_client->user_data); + } + } + + iter = g_slist_next(iter); + } + + if (NULL != before_lang) { + free(before_lang); + } + } + + if (-1 != silence) { + /* silence detection changed */ + g_config_info->silence_detection = silence; + + /* Call all callbacks of client*/ + iter = g_slist_nth(g_config_client_list, 0); + + while (NULL != iter) { + temp_client = iter->data; + + if (NULL != temp_client) { + if (NULL != temp_client->bool_cb) { + temp_client->bool_cb(STT_CONFIG_TYPE_OPTION_SILENCE_DETECTION, silence, temp_client->user_data); + } + } + + iter = g_slist_next(iter); + } + } + + if (NULL != engine) free(engine); + if (NULL != setting) free(setting); + if (NULL != lang) free(lang); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Undefined event"); + } + + SLOG(LOG_DEBUG, stt_tag(), "====="); + SLOG(LOG_DEBUG, stt_tag(), " "); + + return ECORE_CALLBACK_PASS_ON; +} + +int __stt_config_mgr_register_config_event() +{ + /* get file notification handler */ + int fd; + int wd; + + fd = inotify_init(); + if (fd < 0) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail get inotify fd"); + return -1; + } + g_fd_noti = fd; + + wd = inotify_add_watch(fd, STT_CONFIG, IN_MODIFY); + g_wd_noti = wd; + + g_fd_handler_noti = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)stt_config_mgr_inotify_event_cb, NULL, NULL, NULL); + if (NULL == g_fd_handler_noti) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to get handler_noti"); + return -1; + } + + return 0; +} + +int __stt_config_mgr_unregister_config_event() +{ + /* delete inotify variable */ + ecore_main_fd_handler_del(g_fd_handler_noti); + inotify_rm_watch(g_fd_noti, g_wd_noti); + close(g_fd_noti); + + return 0; +} + +int __stt_config_set_auto_language() +{ + char* value = NULL; + value = vconf_get_str(VCONFKEY_VOICE_INPUT_LANGUAGE); + if (NULL == value) { + SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Fail to get voice input language"); + return -1; + } + + char candidate_lang[6] = {'\0', }; + + /* Check auto is on or not */ + if (0 == strncmp(value, "auto", 4)) { + free(value); + + value = vconf_get_str(VCONFKEY_LANGSET); + if (NULL == value) { + SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Fail to get display language"); + return -1; + } + + strncpy(candidate_lang, value, 5); + free(value); + + /* Check current language */ + if (0 == strncmp(g_config_info->language, candidate_lang, 5)) { + SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Config] Language is auto. STT language(%s) is same with display lang", g_config_info->language); + return 0; + } else { + SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Config] Display language : %s", candidate_lang); + } + } else { + strncpy(candidate_lang, value, 5); + SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Config] Voice input language is NOT auto. Voice input language : %s", candidate_lang); + + free(value); + } + + if (true == __stt_config_mgr_check_lang_is_valid(g_config_info->engine_id, candidate_lang)) { + /* stt default language change */ + if (NULL == g_config_info->language) { + SLOG(LOG_ERROR, stt_tag(), "Current config language is NULL"); + return -1; + } + + char* before_lang = NULL; + if (0 != stt_parser_set_language(candidate_lang)) { + SLOG(LOG_ERROR, stt_tag(), "Fail to save default language"); + return -1; + } + + before_lang = strdup(g_config_info->language); + + free(g_config_info->language); + g_config_info->language = strdup(candidate_lang); + + SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Config] Language is auto. Set default language(%s)", g_config_info->language); + + /* Call all callbacks of client*/ + GSList *iter = NULL; + stt_config_client_s* temp_client = NULL; + + iter = g_slist_nth(g_config_client_list, 0); + + while (NULL != iter) { + temp_client = iter->data; + + if (NULL != temp_client) { + if (NULL != temp_client->lang_cb) { + temp_client->lang_cb(before_lang, g_config_info->language, temp_client->user_data); + } + } + + iter = g_slist_next(iter); + } + + if (NULL != before_lang) { + free(before_lang); + } + } else { + /* Candidate language is not valid */ + char* tmp_language = NULL; + if (0 != __stt_config_mgr_select_lang(g_config_info->engine_id, &tmp_language)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to select language"); + return -1; + } + + if (NULL == tmp_language) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Selected language is NULL"); + return -1; + } + + if (0 != stt_parser_set_language(tmp_language)) { + free(tmp_language); + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to save config"); + return -1; + } + + SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Config] Language is auto but display lang is not supported. Default language change(%s)", tmp_language); + + /* Call all callbacks of client*/ + GSList *iter = NULL; + stt_config_client_s* temp_client = NULL; + + iter = g_slist_nth(g_config_client_list, 0); + + while (NULL != iter) { + temp_client = iter->data; + + if (NULL != temp_client) { + if (NULL != temp_client->lang_cb) { + temp_client->lang_cb(g_config_info->language, tmp_language, temp_client->user_data); + } + } + + iter = g_slist_next(iter); + } + + if (NULL != g_config_info->language) { + free(g_config_info->language); + g_config_info->language = strdup(tmp_language); + } + + free(tmp_language); + } + + return 0; +} + +void __stt_config_language_changed_cb(keynode_t *key, void *data) +{ + if (true == g_config_info->auto_lang) { + /* Get voice input vconf key */ + __stt_config_set_auto_language(); + } + + return; +} + +int stt_config_mgr_initialize(int uid) +{ + GSList *iter = NULL; + int* get_uid; + stt_config_client_s* temp_client = NULL; + + if (0 < g_slist_length(g_config_client_list)) { + /* Check uid */ + iter = g_slist_nth(g_config_client_list, 0); + + while (NULL != iter) { + get_uid = iter->data; + + if (uid == *get_uid) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[CONFIG] uid(%d) has already registered", uid); + return 0; + } + + iter = g_slist_next(iter); + } + + temp_client = (stt_config_client_s*)calloc(1, sizeof(stt_config_client_s)); + temp_client->uid = uid; + temp_client->bool_cb = NULL; + temp_client->engine_cb = NULL; + temp_client->lang_cb = NULL; + temp_client->user_data = NULL; + + /* Add uid */ + g_config_client_list = g_slist_append(g_config_client_list, temp_client); + + SECURE_SLOG(LOG_WARN, stt_tag(), "[CONFIG] Add uid(%d) but config has already initialized", uid); + return STT_CONFIG_ERROR_NONE; + } + + /* Get file name from default engine directory */ + DIR *dp = NULL; + int ret = -1; + struct dirent entry; + struct dirent *dirp = NULL; + + g_engine_list = NULL; + + dp = opendir(STT_DEFAULT_ENGINE_INFO); + if (NULL != dp) { + do { + ret = readdir_r(dp, &entry, &dirp); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[File ERROR] Fail to read directory"); + break; + } + + if (NULL != dirp) { + if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name)) + continue; + + stt_engine_info_s* info; + char* filepath; + int filesize; + + filesize = strlen(STT_DEFAULT_ENGINE_INFO) + strlen(dirp->d_name) + 5; + filepath = (char*)calloc(filesize, sizeof(char)); + + if (NULL != filepath) { + snprintf(filepath, filesize, "%s/%s", STT_DEFAULT_ENGINE_INFO, dirp->d_name); + } else { + SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Memory not enough!!"); + continue; + } + + if (0 == stt_parser_get_engine_info(filepath, &info)) { + g_engine_list = g_slist_append(g_engine_list, info); + } + + if (NULL != filepath) + free(filepath); + } + } while (NULL != dirp); + + closedir(dp); + } else { + SLOG(LOG_WARN, stt_tag(), "[Config WARNING] Fail to open default directory"); + } + + __stt_config_mgr_print_engine_info(); + + if (0 != stt_parser_load_config(&g_config_info)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse configure information"); + return -1; + } + + if (true == g_config_info->auto_lang) { + /* Check language with display language */ + __stt_config_set_auto_language(); + } else { + if (false == __stt_config_mgr_check_lang_is_valid(g_config_info->engine_id, g_config_info->language)) { + /* Default language is not valid */ + char* tmp_language; + if (0 != __stt_config_mgr_select_lang(g_config_info->engine_id, &tmp_language)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to select language"); + return -1; + } + + if (NULL != tmp_language) { + if (NULL != g_config_info->language) { + free(g_config_info->language); + g_config_info->language = strdup(tmp_language); + } + + free(tmp_language); + } + } + } + + /* print daemon config */ + SLOG(LOG_DEBUG, stt_tag(), "== Daemon config =="); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " engine : %s", g_config_info->engine_id); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " setting : %s", g_config_info->setting); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " auto language : %s", g_config_info->auto_lang ? "on" : "off"); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " language : %s", g_config_info->language); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " silence detection : %s", g_config_info->silence_detection ? "on" : "off"); + SLOG(LOG_DEBUG, stt_tag(), "==================="); + + if (0 != __stt_config_mgr_register_config_event()) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to register config event"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + /* Register to detect display language change */ + vconf_notify_key_changed(VCONFKEY_LANGSET, __stt_config_language_changed_cb, NULL); + vconf_notify_key_changed(VCONFKEY_VOICE_INPUT_LANGUAGE, __stt_config_language_changed_cb, NULL); + + temp_client = (stt_config_client_s*)calloc(1, sizeof(stt_config_client_s)); + temp_client->uid = uid; + temp_client->bool_cb = NULL; + temp_client->engine_cb = NULL; + temp_client->lang_cb = NULL; + temp_client->user_data = NULL; + + /* Add uid */ + g_config_client_list = g_slist_append(g_config_client_list, temp_client); + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_finalize(int uid) +{ + GSList *iter = NULL; + stt_config_client_s* temp_client = NULL; + + if (0 < g_slist_length(g_config_client_list)) { + /* Check uid */ + iter = g_slist_nth(g_config_client_list, 0); + + while (NULL != iter) { + temp_client = iter->data; + + if (NULL != temp_client) { + if (uid == temp_client->uid) { + g_config_client_list = g_slist_remove(g_config_client_list, temp_client); + free(temp_client); + temp_client = NULL; + break; + } + } + + iter = g_slist_next(iter); + } + } + + if (0 < g_slist_length(g_config_client_list)) { + SLOG(LOG_DEBUG, stt_tag(), "Client count (%d)", g_slist_length(g_config_client_list)); + return STT_CONFIG_ERROR_NONE; + } + + stt_engine_info_s *engine_info = NULL; + + if (0 < g_slist_length(g_engine_list)) { + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + engine_info = iter->data; + + if (NULL != engine_info) { + g_engine_list = g_slist_remove(g_engine_list, engine_info); + + stt_parser_free_engine_info(engine_info); + } + + iter = g_slist_nth(g_engine_list, 0); + } + } + + vconf_ignore_key_changed(VCONFKEY_LANGSET, __stt_config_language_changed_cb); + vconf_ignore_key_changed(VCONFKEY_VOICE_INPUT_LANGUAGE, __stt_config_language_changed_cb); + + __stt_config_mgr_unregister_config_event(); + + if (NULL != g_config_info) { + stt_parser_unload_config(g_config_info); + g_config_info = NULL; + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_set_callback(int uid, stt_config_engine_changed_cb engine_cb, stt_config_lang_changed_cb lang_cb, stt_config_bool_changed_cb bool_cb, void* user_data) +{ + GSList *iter = NULL; + stt_config_client_s* temp_client = NULL; + + /* Call all callbacks of client*/ + iter = g_slist_nth(g_config_client_list, 0); + + while (NULL != iter) { + temp_client = iter->data; + + if (NULL != temp_client) { + if (uid == temp_client->uid) { + temp_client->engine_cb = engine_cb; + temp_client->lang_cb = lang_cb; + temp_client->bool_cb = bool_cb; + temp_client->user_data = user_data; + } + } + + iter = g_slist_next(iter); + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_unset_callback(int uid) +{ + GSList *iter = NULL; + stt_config_client_s* temp_client = NULL; + + /* Call all callbacks of client*/ + iter = g_slist_nth(g_config_client_list, 0); + + while (NULL != iter) { + temp_client = iter->data; + + if (NULL != temp_client) { + if (uid == temp_client->uid) { + temp_client->engine_cb = NULL; + temp_client->lang_cb = NULL; + temp_client->bool_cb = NULL; + temp_client->user_data = NULL; + } + } + + iter = g_slist_next(iter); + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_get_engine_list(stt_config_supported_engine_cb callback, void* user_data) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (NULL == callback) { + return STT_CONFIG_ERROR_INVALID_PARAMETER; + } + + GSList *iter = NULL; + stt_engine_info_s *engine_info = NULL; + + if (0 >= g_slist_length(g_engine_list)) { + SLOG(LOG_WARN, stt_tag(), "[ERROR] Engine list is NULL"); + return STT_CONFIG_ERROR_ENGINE_NOT_FOUND; + } + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + engine_info = iter->data; + + if (NULL == engine_info) { + SLOG(LOG_ERROR, stt_tag(), " Engine info is NULL"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + if (false == callback(engine_info->uuid, engine_info->name, + engine_info->setting, engine_info->support_silence_detection, user_data)) { + break; + } + + iter = g_slist_next(iter); + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_get_engine(char** engine) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (NULL == engine) { + return STT_CONFIG_ERROR_INVALID_PARAMETER; + } + + if (NULL != g_config_info->engine_id) { + *engine = strdup(g_config_info->engine_id); + } else { + SLOG(LOG_ERROR, stt_tag(), " Engine id is NULL"); + return STT_CONFIG_ERROR_ENGINE_NOT_FOUND; + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_set_engine(const char* engine) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (NULL == g_config_info) { + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + if (NULL == engine || NULL == g_config_info->engine_id) { + return STT_CONFIG_ERROR_INVALID_PARAMETER; + } + + /* Check current engine id with new engine id */ + if (0 == strcmp(g_config_info->engine_id, engine)) { + return 0; + } + + SECURE_SLOG(LOG_DEBUG, stt_tag(), "New engine id : %s", engine); + + GSList *iter = NULL; + stt_engine_info_s *engine_info = NULL; + bool is_valid_engine = false; + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + engine_info = iter->data; + + if (NULL == engine_info) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Engine info is NULL"); + iter = g_slist_next(iter); + continue; + } + + /* Check engine id is valid */ + if (0 != strcmp(engine, engine_info->uuid)) { + iter = g_slist_next(iter); + continue; + } + + if (NULL != g_config_info->engine_id) + free(g_config_info->engine_id); + + g_config_info->engine_id = strdup(engine); + + if (NULL != g_config_info->setting) { + free(g_config_info->setting); + } + + if (NULL != engine_info->setting) { + g_config_info->setting = strdup(engine_info->setting); + } else { + g_config_info->setting = NULL; + } + + /* Engine is valid*/ + GSList *iter_lang = NULL; + char* lang; + bool is_valid_lang = false; + + /* Get a first item */ + iter_lang = g_slist_nth(engine_info->languages, 0); + + while (NULL != iter_lang) { + /*Get handle data from list*/ + lang = iter_lang->data; + + SECURE_SLOG(LOG_DEBUG, stt_tag(), " %s", lang); + if (NULL != lang) { + if (0 == strcmp(lang, g_config_info->language)) { + /* language is valid */ + is_valid_lang = true; + + if (NULL != g_config_info->language) { + free(g_config_info->language); + + g_config_info->language = strdup(lang); + } + break; + } + } + + /*Get next item*/ + iter_lang = g_slist_next(iter_lang); + } + + if (false == is_valid_lang) { + if (NULL != g_config_info->language) { + free(g_config_info->language); + + iter_lang = g_slist_nth(engine_info->languages, 0); + lang = iter_lang->data; + + g_config_info->language = strdup(lang); + } + } + + /* Check options */ + if (false == engine_info->support_silence_detection) { + if (true == g_config_info->silence_detection) + g_config_info->silence_detection = false; + } + + is_valid_engine = true; + break; + } + + if (true == is_valid_engine) { + SLOG(LOG_DEBUG, stt_tag(), "[Config] Engine changed"); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " Engine : %s", g_config_info->engine_id); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " Setting : %s", g_config_info->setting); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " language : %s", g_config_info->language); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " Silence detection : %s", g_config_info->silence_detection ? "on" : "off"); + + if ( 0 != stt_parser_set_engine(g_config_info->engine_id, g_config_info->setting, g_config_info->language, + g_config_info->silence_detection)) { + SLOG(LOG_ERROR, stt_tag(), " Fail to save config"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Engine id is not valid"); + return STT_CONFIG_ERROR_INVALID_PARAMETER; + } + + return 0; +} + +int stt_config_mgr_get_engine_agreement(const char* engine, char** agreement) +{ + if (0 >= g_slist_length(g_engine_list)) { + SLOG(LOG_ERROR, stt_tag(), "There is no engine"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (NULL == agreement) { + SLOG(LOG_ERROR, stt_tag(), "Input parameter is NULL"); + return STT_CONFIG_ERROR_INVALID_PARAMETER; + } + + GSList *iter = NULL; + stt_engine_info_s *engine_info = NULL; + char* current_engine = NULL; + + if (NULL == engine) { + current_engine = strdup(g_config_info->engine_id); + } else { + current_engine = strdup(engine); + } + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + engine_info = iter->data; + + if (NULL == engine_info) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] engine info is NULL"); + if (NULL != current_engine) free(current_engine); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + if (0 != strcmp(current_engine, engine_info->uuid)) { + iter = g_slist_next(iter); + continue; + } + + if (NULL != engine_info->agreement) { + *agreement = strdup(engine_info->agreement); + } else { + SLOG(LOG_WARN, stt_tag(), "[WARNING] engine agreement is not support"); + } + break; + } + + if (NULL != current_engine) free(current_engine); + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_get_language_list(const char* engine_id, stt_config_supported_langauge_cb callback, void* user_data) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (0 >= g_slist_length(g_engine_list)) { + SLOG(LOG_ERROR, stt_tag(), "There is no engine"); + return STT_CONFIG_ERROR_ENGINE_NOT_FOUND; + } + + GSList *iter = NULL; + stt_engine_info_s *engine_info = NULL; + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + engine_info = iter->data; + + if (NULL == engine_info) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] engine info is NULL"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + if (0 != strcmp(engine_id, engine_info->uuid)) { + iter = g_slist_next(iter); + continue; + } + + GSList *iter_lang = NULL; + char* lang; + + /* Get a first item */ + iter_lang = g_slist_nth(engine_info->languages, 0); + + while (NULL != iter_lang) { + /*Get handle data from list*/ + lang = iter_lang->data; + + SECURE_SLOG(LOG_DEBUG, stt_tag(), " %s", lang); + if (NULL != lang) { + if (false == callback(engine_info->uuid, lang, user_data)) + break; + } + + /*Get next item*/ + iter_lang = g_slist_next(iter_lang); + } + break; + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_get_default_language(char** language) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (NULL == language) { + return STT_CONFIG_ERROR_INVALID_PARAMETER; + } + + if (NULL != g_config_info->language) { + *language = strdup(g_config_info->language); + } else { + SLOG(LOG_ERROR, stt_tag(), " language is NULL"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_set_default_language(const char* language) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (NULL == language) { + return STT_CONFIG_ERROR_INVALID_PARAMETER; + } + + /* Check language is valid */ + if (NULL != g_config_info->language) { + if (0 != stt_parser_set_language(language)) { + SLOG(LOG_ERROR, stt_tag(), "Fail to save engine id"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + free(g_config_info->language); + g_config_info->language = strdup(language); + } else { + SLOG(LOG_ERROR, stt_tag(), " language is NULL"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_get_auto_language(bool* value) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (NULL == value) { + return STT_CONFIG_ERROR_INVALID_PARAMETER; + } + + *value = g_config_info->auto_lang; + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_set_auto_language(bool value) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (g_config_info->auto_lang != value) { + /* Check language is valid */ + if (0 != stt_parser_set_auto_lang(value)) { + SLOG(LOG_ERROR, stt_tag(), "Fail to save engine id"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + g_config_info->auto_lang = value; + + if (true == g_config_info->auto_lang) { + __stt_config_set_auto_language(); + } + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_get_silence_detection(bool* value) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (NULL == value) + return STT_CONFIG_ERROR_INVALID_PARAMETER; + + *value = g_config_info->silence_detection; + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_set_silence_detection(bool value) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return STT_CONFIG_ERROR_INVALID_STATE; + } + + if (0 != stt_parser_set_silence_detection(value)) { + SLOG(LOG_ERROR, stt_tag(), "Fail to save engine id"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + g_config_info->silence_detection = value; + + return STT_CONFIG_ERROR_NONE; +} + +bool stt_config_check_default_engine_is_valid(const char* engine) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return false; + } + + if (NULL == engine) { + return false; + } + + if (0 >= g_slist_length(g_engine_list)) + return false; + + GSList *iter = NULL; + stt_engine_info_s *engine_info = NULL; + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + engine_info = iter->data; + + if (NULL != engine_info) { + if (0 == strcmp(engine, engine_info->uuid)) { + return true; + } + } + iter = g_slist_next(iter); + } + + return false; +} + +bool stt_config_check_default_language_is_valid(const char* language) +{ + if (0 >= g_slist_length(g_config_client_list)) { + SLOG(LOG_ERROR, stt_tag(), "Not initialized"); + return false; + } + + if (NULL == language) { + return false; + } + + if (NULL == g_config_info->engine_id) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Default engine id is NULL"); + return false; + } + + if (0 >= g_slist_length(g_engine_list)) + return false; + + GSList *iter = NULL; + stt_engine_info_s *engine_info = NULL; + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + engine_info = iter->data; + + if (NULL == engine_info) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Engine info is NULL"); + iter = g_slist_next(iter); + continue; + } + + if (0 != strcmp(g_config_info->engine_id, engine_info->uuid)) { + iter = g_slist_next(iter); + continue; + } + + GSList *iter_lang = NULL; + char* lang; + + /* Get a first item */ + iter_lang = g_slist_nth(engine_info->languages, 0); + + while (NULL != iter_lang) { + lang = iter_lang->data; + + if (0 == strcmp(language, lang)) + return true; + + /*Get next item*/ + iter_lang = g_slist_next(iter_lang); + } + break; + } + + return false; +} + +int __stt_config_mgr_print_engine_info() +{ + GSList *iter = NULL; + stt_engine_info_s *engine_info = NULL; + + if (0 >= g_slist_length(g_engine_list)) { + SLOG(LOG_DEBUG, stt_tag(), "-------------- engine list -----------------"); + SLOG(LOG_DEBUG, stt_tag(), " No Engine in engine directory"); + SLOG(LOG_DEBUG, stt_tag(), "--------------------------------------------"); + return 0; + } + + /* Get a first item */ + iter = g_slist_nth(g_engine_list, 0); + + SLOG(LOG_DEBUG, stt_tag(), "--------------- engine list -----------------"); + + int i = 1; + while (NULL != iter) { + engine_info = iter->data; + + SECURE_SLOG(LOG_DEBUG, stt_tag(), "[%dth]", i); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " name : %s", engine_info->name); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " id : %s", engine_info->uuid); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " setting : %s", engine_info->setting); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " agreement : %s", engine_info->agreement); + + SLOG(LOG_DEBUG, stt_tag(), " languages"); + GSList *iter_lang = NULL; + char* lang; + if (g_slist_length(engine_info->languages) > 0) { + /* Get a first item */ + iter_lang = g_slist_nth(engine_info->languages, 0); + + int j = 1; + while (NULL != iter_lang) { + /*Get handle data from list*/ + lang = iter_lang->data; + + SECURE_SLOG(LOG_DEBUG, stt_tag(), " [%dth] %s", j, lang); + + /*Get next item*/ + iter_lang = g_slist_next(iter_lang); + j++; + } + } else { + SLOG(LOG_ERROR, stt_tag(), " language is NONE"); + } + SECURE_SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", + engine_info->support_silence_detection ? "true" : "false"); + iter = g_slist_next(iter); + i++; + } + SLOG(LOG_DEBUG, stt_tag(), "--------------------------------------------"); + + return 0; +} + + + +/** +* time info functions +*/ +static GSList* g_time_list = NULL; + +int stt_config_mgr_reset_time_info() +{ + /* Remove time info */ + GSList *iter = NULL; + stt_result_time_info_s *data = NULL; + + /* Remove time info */ + iter = g_slist_nth(g_time_list, 0); + while (NULL != iter) { + data = iter->data; + + g_time_list = g_slist_remove(g_time_list, data); + if (NULL != data) { + if (NULL == data->text) free(data->text); + free(data); + } + + /*Get next item*/ + iter = g_slist_nth(g_time_list, 0); + } + + return 0; +} + +int stt_config_mgr_add_time_info(int index, int event, const char* text, long start_time, long end_time) +{ + if (NULL == text) { + SLOG(LOG_ERROR, stt_tag(), "Invalid paramter : text is NULL"); + return -1; + } + + stt_result_time_info_s *info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s)); + + info->index = index; + info->event = event; + if (NULL != text) { + info->text = strdup(text); + } + info->start_time = start_time; + info->end_time = end_time; + + /* Add item to global list */ + g_time_list = g_slist_append(g_time_list, info); + + return 0; +} + +int stt_config_mgr_foreach_time_info(stt_config_result_time_cb callback, void* user_data) +{ + if (NULL == callback) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input paramter is NULL : callback function"); + return STT_CONFIG_ERROR_INVALID_PARAMETER; + } + + GSList* temp_time = NULL; + int ret; + ret = stt_parser_get_time_info(&temp_time); + if (0 != ret) { + SLOG(LOG_WARN, stt_tag(), "[WARNING] Fail to get time info : %d", ret); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + GSList *iter = NULL; + stt_result_time_info_s *data = NULL; + + /* Get a first item */ + iter = g_slist_nth(temp_time, 0); + while (NULL != iter) { + data = iter->data; + + if (false == callback(data->index, data->event, data->text, + data->start_time, data->end_time, user_data)) { + break; + } + + /*Get next item*/ + iter = g_slist_next(iter); + } + + /* Remove time info */ + iter = g_slist_nth(temp_time, 0); + while (NULL != iter) { + data = iter->data; + + if (NULL != data) { + temp_time = g_slist_remove(temp_time, data); + + if (NULL == data->text) free(data->text); + free(data); + } + + /*Get next item*/ + iter = g_slist_nth(temp_time, 0); + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_save_time_info_file() +{ + if (0 == g_slist_length(g_time_list)) { + SLOG(LOG_WARN, stt_tag(), "[WARNING] There is no time info to save"); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + int ret = 0; + ret = stt_parser_set_time_info(g_time_list); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to save time info : %d", ret); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + + return STT_CONFIG_ERROR_NONE; +} + +int stt_config_mgr_remove_time_info_file() +{ + stt_parser_clear_time_info(); + + return STT_CONFIG_ERROR_NONE; +} \ No newline at end of file diff --git a/common/stt_config_mgr.h b/common/stt_config_mgr.h new file mode 100644 index 0000000..010f80e --- /dev/null +++ b/common/stt_config_mgr.h @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2011-2014 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_CONFIG_MANAGER_H_ +#define __STT_CONFIG_MANAGER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + STT_CONFIG_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + STT_CONFIG_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */ + STT_CONFIG_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ + STT_CONFIG_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */ + STT_CONFIG_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,/**< Permission denied */ + STT_CONFIG_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< STT NOT supported */ + STT_CONFIG_ERROR_INVALID_STATE = TIZEN_ERROR_STT | 0x01, /**< Invalid state */ + STT_CONFIG_ERROR_INVALID_LANGUAGE = TIZEN_ERROR_STT | 0x02, /**< Invalid language */ + STT_CONFIG_ERROR_ENGINE_NOT_FOUND = TIZEN_ERROR_STT | 0x03, /**< No available engine */ + STT_CONFIG_ERROR_OPERATION_FAILED = TIZEN_ERROR_STT | 0x04, /**< Operation failed */ +}stt_config_error_e; + +typedef enum { + STT_CONFIG_TYPE_OPTION_SILENCE_DETECTION +}stt_config_type_e; + +typedef bool (*stt_config_supported_engine_cb)(const char* engine_id, const char* engine_name, const char* setting, bool support_silence, void* user_data); + +typedef bool (*stt_config_supported_langauge_cb)(const char* engine_id, const char* language, void* user_data); + +typedef void (*stt_config_engine_changed_cb)(const char* engine_id, const char* setting, const char* language, bool support_silence, void* user_data); + +typedef void (*stt_config_lang_changed_cb)(const char* before_language, const char* current_language, void* user_data); + +typedef void (*stt_config_bool_changed_cb)(stt_config_type_e type, bool bool_value, void* user_data); + +typedef bool (*stt_config_result_time_cb)(int index, int event, const char* text, long start_time, long end_time, void* user_data); + + +int stt_config_mgr_initialize(int uid); + +int stt_config_mgr_finalize(int uid); + + +int stt_config_mgr_set_callback(int uid, stt_config_engine_changed_cb engine_cb, stt_config_lang_changed_cb lang_cb, stt_config_bool_changed_cb bool_cb, void* user_data); + +int stt_config_mgr_unset_callback(int uid); + + +int stt_config_mgr_get_engine_list(stt_config_supported_engine_cb callback, void* user_data); + +int stt_config_mgr_get_engine(char** engine); + +int stt_config_mgr_set_engine(const char* engine); + +int stt_config_mgr_get_engine_agreement(const char* engine, char** agreement); + +int stt_config_mgr_get_language_list(const char* engine_id, stt_config_supported_langauge_cb callback, void* user_data); + +int stt_config_mgr_get_default_language(char** language); + +int stt_config_mgr_set_default_language(const char* language); + +int stt_config_mgr_get_auto_language(bool* value); + +int stt_config_mgr_set_auto_language(bool value); + +int stt_config_mgr_get_silence_detection(bool* value); + +int stt_config_mgr_set_silence_detection(bool value); + +bool stt_config_check_default_engine_is_valid(const char* engine); + +bool stt_config_check_default_language_is_valid(const char* language); + + +int stt_config_mgr_reset_time_info(); + +int stt_config_mgr_add_time_info(int index, int event, const char* text, long start_time, long end_time); + +int stt_config_mgr_foreach_time_info(stt_config_result_time_cb callback, void* user_data); + + +int stt_config_mgr_save_time_info_file(); + +int stt_config_mgr_remove_time_info_file(); + + +#ifdef __cplusplus +} +#endif + +#endif /* __STT_CONFIG_MANAGER_H_ */ diff --git a/common/stt_config_parser.c b/common/stt_config_parser.c new file mode 100644 index 0000000..564705d --- /dev/null +++ b/common/stt_config_parser.c @@ -0,0 +1,970 @@ +/* +* Copyright (c) 2011-2014 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 +#include + +#include "stt_defs.h" +#include "stt_config_parser.h" + + +#define STT_TAG_ENGINE_BASE_TAG "stt-engine" +#define STT_TAG_ENGINE_NAME "name" +#define STT_TAG_ENGINE_ID "id" +#define STT_TAG_ENGINE_SETTING "setting" +#define STT_TAG_ENGINE_AGREEMENT "agreement" +#define STT_TAG_ENGINE_LANGUAGE_SET "languages" +#define STT_TAG_ENGINE_LANGUAGE "lang" +#define STT_TAG_ENGINE_SILENCE_SUPPORT "silence-detection-support" + +#define STT_TAG_CONFIG_BASE_TAG "stt-config" +#define STT_TAG_CONFIG_ENGINE_ID "engine" +#define STT_TAG_CONFIG_ENGINE_SETTING "engine-setting" +#define STT_TAG_CONFIG_AUTO_LANGUAGE "auto" +#define STT_TAG_CONFIG_LANGUAGE "language" +#define STT_TAG_CONFIG_SILENCE_DETECTION "silence-detection" + + +#define STT_TAG_TIME_BASE_TAG "stt-time" +#define STT_TAG_TIME_INDEX "index" +#define STT_TAG_TIME_COUNT "count" +#define STT_TAG_TIME_TIME_INFO "time-info" +#define STT_TAG_TIME_TEXT "text-info" +#define STT_TAG_TIME_START "start" +#define STT_TAG_TIME_END "end" + +extern const char* stt_tag(); + +static xmlDocPtr g_config_doc = NULL; + +int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info) +{ + if (NULL == path || NULL == engine_info) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); + return -1; + } + + xmlDocPtr doc = NULL; + xmlNodePtr cur = NULL; + xmlChar *key; + + doc = xmlParseFile(path); + if (doc == NULL) { + return -1; + } + + cur = xmlDocGetRootElement(doc); + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + xmlFreeDoc(doc); + return -1; + } + + if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_BASE_TAG)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT 'stt-engine'"); + xmlFreeDoc(doc); + return -1; + } + + cur = cur->xmlChildrenNode; + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + xmlFreeDoc(doc); + return -1; + } + + /* alloc engine info */ + stt_engine_info_s* temp; + temp = (stt_engine_info_s*)calloc(1, sizeof(stt_engine_info_s)); + + temp->name = NULL; + temp->uuid = NULL; + temp->setting = NULL; + temp->agreement = NULL; + temp->languages = NULL; + temp->support_silence_detection = false; + + while (cur != NULL) { + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + // SLOG(LOG_DEBUG, stt_tag(), "Engine name : %s", (char *)key); + if (NULL != temp->name) free(temp->name); + temp->name = strdup((char*)key); + xmlFree(key); + } else { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_NAME); + } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_ID)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + // SLOG(LOG_DEBUG, stt_tag(), "Engine uuid : %s", (char *)key); + if (NULL != temp->uuid) free(temp->uuid); + temp->uuid = strdup((char*)key); + xmlFree(key); + } else { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_ID); + } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SETTING)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + SLOG(LOG_DEBUG, stt_tag(), "Engine setting : %s", (char *)key); + if (NULL != temp->setting) free(temp->setting); + temp->setting = strdup((char*)key); + xmlFree(key); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SETTING); + } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_AGREEMENT)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + SLOG(LOG_DEBUG, stt_tag(), "Engine agreement : %s", (char *)key); + if (NULL != temp->agreement) free(temp->agreement); + temp->agreement = strdup((char*)key); + xmlFree(key); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT); + } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE_SET)) { + xmlNodePtr lang_node = NULL; + char* temp_lang = NULL; + + lang_node = cur->xmlChildrenNode; + + while (lang_node != NULL) { + if (0 == xmlStrcmp(lang_node->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE)){ + key = xmlNodeGetContent(lang_node); + if (NULL != key) { + // SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); + temp_lang = strdup((char*)key); + temp->languages = g_slist_append(temp->languages, temp_lang); + xmlFree(key); + } else { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_LANGUAGE); + } + } + + lang_node = lang_node->next; + } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SILENCE_SUPPORT)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + //SLOG(LOG_DEBUG, stt_tag(), "silence-detection-support : %s", (char *)key); + + if (0 == xmlStrcmp(key, (const xmlChar *)"true")) + temp->support_silence_detection = true; + else + temp->support_silence_detection = false; + + xmlFree(key); + } else { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT); + } + } else { + + } + + cur = cur->next; + } + + xmlFreeDoc(doc); + + if (NULL == temp->name || NULL == temp->uuid) { + /* Invalid engine */ + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Invalid engine : %s", path); + stt_parser_free_engine_info(temp); + return -1; + } + + *engine_info = temp; + + return 0; +} + +int stt_parser_free_engine_info(stt_engine_info_s* engine_info) +{ + if (NULL == engine_info) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); + return -1; + } + + if (NULL != engine_info->name) free(engine_info->name); + if (NULL != engine_info->uuid) free(engine_info->uuid); + if (NULL != engine_info->setting) free(engine_info->setting); + if (NULL != engine_info->agreement) free(engine_info->agreement); + + int count = g_slist_length(engine_info->languages); + + int i ; + char *temp_lang; + + for (i = 0;i < count ;i++) { + temp_lang = g_slist_nth_data(engine_info->languages, 0); + + if (NULL != temp_lang) { + engine_info->languages = g_slist_remove(engine_info->languages, temp_lang); + + if (NULL != temp_lang) + free(temp_lang); + } + } + + if (NULL != engine_info) free(engine_info); + + return 0; +} + +int stt_parser_print_engine_info(stt_engine_info_s* engine_info) +{ + if (NULL == engine_info) + return -1; + + SLOG(LOG_DEBUG, stt_tag(), "== get engine info =="); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " name : %s", engine_info->name); + SECURE_SLOG(LOG_DEBUG, stt_tag(), " id : %s", engine_info->uuid); + if (NULL != engine_info->setting) SECURE_SLOG(LOG_DEBUG, stt_tag(), " setting : %s", engine_info->setting); + + SLOG(LOG_DEBUG, stt_tag(), " languages"); + GSList *iter = NULL; + char* lang; + if (g_slist_length(engine_info->languages) > 0) { + /* Get a first item */ + iter = g_slist_nth(engine_info->languages, 0); + + int i = 1; + while (NULL != iter) { + /*Get handle data from list*/ + lang = iter->data; + + SECURE_SLOG(LOG_DEBUG, stt_tag(), " [%dth] %s", i, lang); + + /*Get next item*/ + iter = g_slist_next(iter); + i++; + } + } else { + SLOG(LOG_ERROR, stt_tag(), " language is NONE"); + } + SECURE_SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", engine_info->support_silence_detection ? "true" : "false"); + SLOG(LOG_DEBUG, stt_tag(), "====================="); + + return 0; +} + +int stt_parser_load_config(stt_config_s** config_info) +{ + if (NULL == config_info) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); + return -1; + } + + xmlDocPtr doc = NULL; + xmlNodePtr cur = NULL; + xmlChar *key; + bool is_default_open = false; + + doc = xmlParseFile(STT_CONFIG); + if (doc == NULL) { + doc = xmlParseFile(STT_DEFAULT_CONFIG); + if (doc == NULL) { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG); + return -1; + } + is_default_open = true; + } + + cur = xmlDocGetRootElement(doc); + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + xmlFreeDoc(doc); + return -1; + } + + if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); + xmlFreeDoc(doc); + return -1; + } + + cur = cur->xmlChildrenNode; + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + xmlFreeDoc(doc); + return -1; + } + + /* alloc engine info */ + stt_config_s* temp; + temp = (stt_config_s*)calloc(1, sizeof(stt_config_s)); + + temp->engine_id = NULL; + temp->setting = NULL; + temp->language = NULL; + + while (cur != NULL) { + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + //SLOG(LOG_DEBUG, stt_tag(), "Engine id : %s", (char *)key); + if (NULL != temp->engine_id) free(temp->engine_id); + temp->engine_id = strdup((char*)key); + xmlFree(key); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] engine id is NULL"); + } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + //SECURE_SLOG(LOG_DEBUG, stt_tag(), "Setting path : %s", (char *)key); + if (NULL != temp->setting) free(temp->setting); + temp->setting = strdup((char*)key); + xmlFree(key); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] setting path is NULL"); + } + + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + //SECURE_SLOG(LOG_DEBUG, stt_tag(), "Auto language : %s", (char *)key); + + if (0 == xmlStrcmp(key, (const xmlChar *)"on")) { + temp->auto_lang = true; + } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) { + temp->auto_lang = false; + } else { + SLOG(LOG_ERROR, stt_tag(), "Auto voice is wrong"); + temp->auto_lang = true; + } + + xmlFree(key); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] auto langauge is NULL"); + } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + //SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); + if (NULL != temp->language) free(temp->language); + temp->language = strdup((char*)key); + xmlFree(key); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] language is NULL"); + } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + //SLOG(LOG_DEBUG, stt_tag(), "silence-detection : %s", (char *)key); + + if (0 == xmlStrcmp(key, (const xmlChar *)"on")) + temp->silence_detection = true; + else + temp->silence_detection = false; + + xmlFree(key); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] silence-detection is NULL"); + } + } else { + + } + + cur = cur->next; + } + + *config_info = temp; + g_config_doc = doc; + + if (is_default_open) + xmlSaveFile(STT_CONFIG, g_config_doc); + + return 0; +} + +int stt_parser_unload_config(stt_config_s* config_info) +{ + if (NULL != g_config_doc) xmlFreeDoc(g_config_doc); + if (NULL != config_info) { + if (NULL != config_info->engine_id) free(config_info->engine_id); + if (NULL != config_info->setting) free(config_info->setting); + if (NULL != config_info->language) free(config_info->language); + + free(config_info); + } + + return 0; +} + +int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence) +{ + if (NULL == g_config_doc || NULL == engine_id) + return -1; + + xmlNodePtr cur = NULL; + cur = xmlDocGetRootElement(g_config_doc); + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + return -1; + } + + if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); + return -1; + } + + cur = cur->xmlChildrenNode; + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + return -1; + } + + while (cur != NULL) { + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) { + xmlNodeSetContent(cur, (const xmlChar *)engine_id); + } + + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) { + xmlNodeSetContent(cur, (const xmlChar *)language); + } + + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) { + xmlNodeSetContent(cur, (const xmlChar *)setting); + } + + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) { + if (true == silence) + xmlNodeSetContent(cur, (const xmlChar *)"on"); + else + xmlNodeSetContent(cur, (const xmlChar *)"off"); + } + + cur = cur->next; + } + + int ret = xmlSaveFile(STT_CONFIG, g_config_doc); + SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret); + + return 0; +} + +int stt_parser_set_language(const char* language) +{ + if (NULL == g_config_doc || NULL == language) + return -1; + + xmlNodePtr cur = NULL; + cur = xmlDocGetRootElement(g_config_doc); + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + return -1; + } + + if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); + return -1; + } + + cur = cur->xmlChildrenNode; + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + return -1; + } + + while (cur != NULL) { + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) { + xmlNodeSetContent(cur, (const xmlChar *)language); + } + + cur = cur->next; + } + + int ret = xmlSaveFile(STT_CONFIG, g_config_doc); + SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret); + + + return 0; +} + +int stt_parser_set_auto_lang(bool value) +{ + if (NULL == g_config_doc) + return -1; + + xmlNodePtr cur = NULL; + cur = xmlDocGetRootElement(g_config_doc); + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + return -1; + } + + if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); + return -1; + } + + cur = cur->xmlChildrenNode; + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + return -1; + } + + while (cur != NULL) { + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) { + if (true == value) { + xmlNodeSetContent(cur, (const xmlChar *)"on"); + } else if (false == value) { + xmlNodeSetContent(cur, (const xmlChar *)"off"); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong value of auto voice"); + return -1; + } + break; + } + cur = cur->next; + } + + int ret = xmlSaveFile(STT_CONFIG, g_config_doc); + SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret); + + return 0; +} + +int stt_parser_set_silence_detection(bool value) +{ + if (NULL == g_config_doc) + return -1; + + xmlNodePtr cur = NULL; + cur = xmlDocGetRootElement(g_config_doc); + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + return -1; + } + + if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); + return -1; + } + + cur = cur->xmlChildrenNode; + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + return -1; + } + + while (cur != NULL) { + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) { + if (true == value) + xmlNodeSetContent(cur, (const xmlChar *)"on"); + else + xmlNodeSetContent(cur, (const xmlChar *)"off"); + } + + cur = cur->next; + } + + int ret = xmlSaveFile(STT_CONFIG, g_config_doc); + SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret); + + return 0; +} + +int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence) +{ + if (NULL == engine || NULL == language || NULL == silence) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); + return -1; + } + + xmlDocPtr doc = NULL; + xmlNodePtr cur_new = NULL; + xmlNodePtr cur_old = NULL; + + xmlChar *key_new; + xmlChar *key_old; + + doc = xmlParseFile(STT_CONFIG); + if (doc == NULL) { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG); + return -1; + } + + cur_new = xmlDocGetRootElement(doc); + cur_old = xmlDocGetRootElement(g_config_doc); + if (cur_new == NULL || cur_old == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + xmlFreeDoc(doc); + return -1; + } + + if (xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG)) { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); + xmlFreeDoc(doc); + return -1; + } + + cur_new = cur_new->xmlChildrenNode; + cur_old = cur_old->xmlChildrenNode; + if (cur_new == NULL || cur_old == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + xmlFreeDoc(doc); + return -1; + } + + *engine = NULL; + *setting = NULL; + *language = NULL; + + while (cur_new != NULL && cur_old != NULL) { + if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) { + if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) { + key_old = xmlNodeGetContent(cur_old); + if (NULL != key_old) { + key_new = xmlNodeGetContent(cur_new); + if (NULL != key_new) { + if (0 != xmlStrcmp(key_old, key_new)) { + SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new); + if (NULL != *engine) free(*engine); + *engine = strdup((char*)key_new); + } + xmlFree(key_new); + } + xmlFree(key_old); + } + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different"); + } + } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) { + if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) { + key_old = xmlNodeGetContent(cur_old); + if (NULL != key_old) { + key_new = xmlNodeGetContent(cur_new); + if (NULL != key_new) { + if (0 != xmlStrcmp(key_old, key_new)) { + SLOG(LOG_DEBUG, stt_tag(), "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new); + if (NULL != *setting) free(*setting); + *setting = strdup((char*)key_new); + } + xmlFree(key_new); + } + xmlFree(key_old); + } + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different"); + } + } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) { + if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) { + key_old = xmlNodeGetContent(cur_old); + if (NULL != key_old) { + key_new = xmlNodeGetContent(cur_new); + if (NULL != key_new) { + if (0 != xmlStrcmp(key_old, key_new)) { + SLOG(LOG_DEBUG, stt_tag(), "Old auto lang(%s), New auto lang(%s)", (char*)key_old, (char*)key_new); + if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) { + *auto_lang = (int)true; + } else { + *auto_lang = (int)false; + } + } + + xmlFree(key_new); + } + xmlFree(key_old); + } + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different"); + } + } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) { + if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) { + key_old = xmlNodeGetContent(cur_old); + if (NULL != key_old) { + key_new = xmlNodeGetContent(cur_new); + if (NULL != key_new) { + if (0 != xmlStrcmp(key_old, key_new)) { + SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new); + if (NULL != *language) free(*language); + *language = strdup((char*)key_new); + } + xmlFree(key_new); + } + xmlFree(key_old); + } + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different"); + } + } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) { + if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) { + key_old = xmlNodeGetContent(cur_old); + if (NULL != key_old) { + key_new = xmlNodeGetContent(cur_new); + if (NULL != key_new) { + if (0 != xmlStrcmp(key_old, key_new)) { + SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old silence(%s), New silence(%s)", (char*)key_old, (char*)key_new); + if (0 == xmlStrcmp(key_new, (const xmlChar*)"on")) { + *silence = 1; + } else { + *silence = 0; + } + } + + xmlFree(key_new); + } + xmlFree(key_old); + } + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different"); + } + } else { + + } + + cur_new = cur_new->next; + cur_old = cur_old->next; + } + + xmlFreeDoc(g_config_doc); + g_config_doc = doc; + + return 0; +} + +/** +* time function +*/ + +int stt_parser_set_time_info(GSList* time_list) +{ + if (0 == g_slist_length(time_list)) { + SLOG(LOG_WARN, stt_tag(), "[WARNING] There is no time info to save"); + return -1; + } + + if (-1 == remove(STT_TIME_INFO_PATH)) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); + } + + xmlDocPtr doc = NULL; + xmlNodePtr cur = NULL; + + doc = xmlNewDoc((const xmlChar*)"1.0"); + if (doc == NULL) { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make new doc"); + return -1; + } + + cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_BASE_TAG); + xmlDocSetRootElement(doc, cur); + + xmlNodePtr inode = NULL; + GSList *iter = NULL; + stt_result_time_info_s *data = NULL; + char temp_str[256]; + + snprintf(temp_str, 256, "%d", g_slist_length(time_list)); + + inode = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_INDEX); + xmlNewProp(inode, (const xmlChar*)STT_TAG_TIME_COUNT, (const xmlChar*)temp_str); + xmlAddChild(cur, inode); + + /* Get a first item */ + iter = g_slist_nth(time_list, 0); + while (NULL != iter) { + data = iter->data; + + xmlNodePtr temp_node = NULL; + + SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%d) e(%d)", + data->index, data->event, data->text, data->start_time, data->end_time); + + temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_TEXT); + xmlNodeSetContent(temp_node, (const xmlChar*)data->text); + xmlAddChild(inode, temp_node); + + temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_START); + snprintf(temp_str, 256, "%ld", data->start_time); + xmlNodeSetContent(temp_node, (const xmlChar*)temp_str); + xmlAddChild(inode, temp_node); + + temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_END); + snprintf(temp_str, 256, "%ld", data->end_time); + xmlNodeSetContent(temp_node, (const xmlChar*)temp_str); + xmlAddChild(inode, temp_node); + + /*Get next item*/ + iter = g_slist_next(iter); + } + + int ret = xmlSaveFormatFile(STT_TIME_INFO_PATH, doc, 1); + SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret); + + xmlFreeDoc(doc); + return 0; +} + +int stt_parser_get_time_info(GSList** time_list) +{ + if (NULL == time_list) { + SLOG(LOG_ERROR, stt_tag(), "Invalid paramter : text is NULL"); + return -1; + } + + xmlDocPtr doc = NULL; + xmlNodePtr cur = NULL; + + doc = xmlParseFile(STT_TIME_INFO_PATH); + if (doc == NULL) { + SLOG(LOG_WARN, stt_tag(), "[WARNING] File is not exist"); + return -1; + } + + cur = xmlDocGetRootElement(doc); + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + xmlFreeDoc(doc); + return -1; + } + + if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_BASE_TAG)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT '%s'", STT_TAG_TIME_BASE_TAG); + xmlFreeDoc(doc); + return -1; + } + + cur = cur->xmlChildrenNode; + if (cur == NULL) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); + xmlFreeDoc(doc); + return -1; + } + + /* alloc time info */ + GSList *temp_time_list = NULL; + xmlChar *key = NULL; + int index = 0; + + while (cur != NULL) { + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_INDEX)) { + key = xmlGetProp(cur, (const xmlChar*)STT_TAG_TIME_COUNT); + if (NULL == key) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_COUNT); + return -1; + } + + SLOG(LOG_DEBUG, stt_tag(), "Count : %s", (char *)key); + + /* Get time count */ + int count = 0; + count = atoi((char*)key); + xmlFree(key); + + if (count <= 0) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] count is invalid : %d", count); + break; + } + + xmlNodePtr time_node = NULL; + time_node = cur->xmlChildrenNode; + + int i = 0; + for (i = 0;i < count;i++) { + /* text */ + time_node = time_node->next; + + stt_result_time_info_s* temp_info; + temp_info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s)); + + if (NULL == temp_info) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!"); + return -1; + } + + temp_info->index = index; + SLOG(LOG_DEBUG, stt_tag(), "index : %d", temp_info->index); + + if (0 == i) temp_info->event = 0; + else if (count -1 == i) temp_info->event = 2; + else temp_info->event = 1; + + if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_TEXT)) { + key = xmlNodeGetContent(time_node); + if (NULL != key) { + SLOG(LOG_DEBUG, stt_tag(), "text : %s", (char *)key); + temp_info->text = strdup((char*)key); + xmlFree(key); + } else { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_TEXT); + free(temp_info); + break; + } + } + + /* text */ + time_node = time_node->next; + time_node = time_node->next; + + if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_START)) { + key = xmlNodeGetContent(time_node); + if (NULL != key) { + SLOG(LOG_DEBUG, stt_tag(), "Start time : %s", (char *)key); + temp_info->start_time = atoi((char*)key); + xmlFree(key); + } else { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_START); + if (NULL != temp_info->text) free(temp_info->text); + free(temp_info); + break; + } + } + + /* text */ + time_node = time_node->next; + time_node = time_node->next; + + if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_END)) { + key = xmlNodeGetContent(time_node); + if (NULL != key) { + SLOG(LOG_DEBUG, stt_tag(), "End time : %s", (char *)key); + temp_info->end_time = atoi((char*)key); + xmlFree(key); + } else { + SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_END); + if (NULL != temp_info->text) free(temp_info->text); + free(temp_info); + break; + } + } + + time_node = time_node->next; + + temp_time_list = g_slist_append(temp_time_list, temp_info); + } /* for */ + index++; + } /* if */ + cur = cur->next; + } + + xmlFreeDoc(doc); + + *time_list = temp_time_list; + + return 0; +} + +int stt_parser_clear_time_info() +{ + if (-1 == remove(STT_TIME_INFO_PATH)) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); + } + + return 0; +} diff --git a/common/stt_config_parser.h b/common/stt_config_parser.h new file mode 100644 index 0000000..6fa65ad --- /dev/null +++ b/common/stt_config_parser.h @@ -0,0 +1,84 @@ +/* +* Copyright (c) 2011-2014 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_CONFIG_PARSER_H_ +#define __STT_CONFIG_PARSER_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* name; + char* uuid; + char* setting; + char* agreement; + GSList* languages; + bool support_silence_detection; +}stt_engine_info_s; + +typedef struct { + char* engine_id; + char* setting; + bool auto_lang; + char* language; + bool silence_detection; +}stt_config_s; + +typedef struct { + int index; + int event; + char* text; + long start_time; + long end_time; +}stt_result_time_info_s; + +/* Get engine information */ +int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info); + +int stt_parser_free_engine_info(stt_engine_info_s* engine_info); + + +int stt_parser_load_config(stt_config_s** config_info); + +int stt_parser_unload_config(stt_config_s* config_info); + +int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence); + +int stt_parser_set_language(const char* language); + +int stt_parser_set_auto_lang(bool value); + +int stt_parser_set_silence_detection(bool value); + +int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence); + + +/* Time info */ +int stt_parser_set_time_info(GSList* time_list); + +int stt_parser_get_time_info(GSList** time_list); + +int stt_parser_clear_time_info(); + + +#ifdef __cplusplus +} +#endif + +#endif /* __STT_CONFIG_PARSER_H_ */ diff --git a/common/stt_defs.h b/common/stt_defs.h index b97f9ab..4f6fb23 100644 --- a/common/stt_defs.h +++ b/common/stt_defs.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2014 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 @@ -23,17 +23,13 @@ extern "C" { * 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_CLIENT_SERVICE_NAME "org.tizen.voice.sttclient" +#define STT_CLIENT_SERVICE_OBJECT_PATH "/org/tizen/voice/sttclient" +#define STT_CLIENT_SERVICE_INTERFACE "org.tizen.voice.sttclient" #define STT_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" +#define STT_SERVER_SERVICE_OBJECT_PATH "/org/tizen/voice/sttserver" +#define STT_SERVER_SERVICE_INTERFACE "org.tizen.voice.sttserver" /****************************************************************************************** @@ -43,9 +39,16 @@ extern "C" { #define STT_METHOD_HELLO "stt_method_hello" #define STT_METHOD_INITIALIZE "stt_method_initialize" #define STT_METHOD_FINALIZE "stt_method_finalilze" +#define STT_METHOD_SET_CURRENT_ENGINE "stt_method_set_current_engine" #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_IS_TYPE_SUPPORTED "stt_method_is_recognition_type_supported" +#define STT_METHOD_CHECK_APP_AGREED "stt_method_check_app_agreed" + +#define STT_METHOD_SET_START_SOUND "stt_method_set_start_sound" +#define STT_METHOD_UNSET_START_SOUND "stt_method_unset_start_sound" +#define STT_METHOD_SET_STOP_SOUND "stt_method_set_stop_sound" +#define STT_METHOD_UNSET_STOP_SOUND "stt_method_unset_stop_sound" #define STT_METHOD_START "stt_method_start" #define STT_METHOD_STOP "stt_method_stop" @@ -53,39 +56,40 @@ extern "C" { #define STT_METHOD_START_FILE_RECONITION "stt_method_start_recognition" #define STTD_METHOD_RESULT "sttd_method_result" -#define STTD_METHOD_PARTIAL_RESULT "sttd_method_partial_result" #define STTD_METHOD_ERROR "sttd_method_error" #define STTD_METHOD_HELLO "sttd_method_hello" #define STTD_METHOD_SET_STATE "sttd_method_set_state" #define STTD_METHOD_GET_STATE "sttd_method_get_state" /****************************************************************************************** -* Message Definition for Setting +* Defines for configuration *******************************************************************************************/ -#define STT_SETTING_METHOD_HELLO "stt_setting_method_hello" -#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" +#define STT_AUDIO_VOLUME_PATH "/tmp/stt_vol" -/****************************************************************************************** -* Temp file for audio volume -*******************************************************************************************/ +#define STT_PID_FILE_PATH "/opt/home/app/.voice/sttd_info" + +#define STT_TIME_INFO_PATH "/opt/home/app/.voice/stt-time.xml" + +#define STT_USR_BASE "/usr/lib/voice" +#define STT_OPT_BASE "/opt/usr/data/voice" + +#define STT_DEFAULT_CONFIG STT_USR_BASE"/stt/1.0/stt-config.xml" +#define STT_CONFIG "/opt/home/app/.voice/stt-config.xml" + +#define STT_DEFAULT_ENGINE STT_USR_BASE"/stt/1.0/engine" +#define STT_DOWNLOAD_ENGINE STT_OPT_BASE"/stt/1.0/engine" + +#define STT_DEFAULT_ENGINE_INFO STT_USR_BASE"/stt/1.0/engine-info" +#define STT_DOWNLOAD_ENGINE_INFO STT_OPT_BASE"/stt/1.0/engine-info" + +#define STT_DEFAULT_ENGINE_SETTING STT_USR_BASE"/stt/1.0/engine-setting" +#define STT_DOWNLOAD_ENGINE_SETTING STT_OPT_BASE"/stt/1.0/engine-setting" + +#define STT_BASE_LANGUAGE "en_US" -#define STT_AUDIO_VOLUME_PATH "/tmp/stt_vol" +#define STT_FEATURE_PATH "tizen.org/feature/speech.recognition" +#define STT_MIC_FEATURE_PATH "tizen.org/feature/microphone" #ifdef __cplusplus } diff --git a/common/stt_engine.c b/common/stt_engine.c new file mode 100644 index 0000000..3ddc644 --- /dev/null +++ b/common/stt_engine.c @@ -0,0 +1,654 @@ +/* +* Copyright (c) 2011-2014 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 +#include +#include +#include +#include +#include + +#include "stt_engine.h" + +/* +* Internal data structure +*/ + +typedef struct { + int engine_id; + char* engine_path; + void *handle; + + 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; + +extern const char* stt_tag(); + +/** stt engine list */ +static GSList *g_engine_list; + +static const char* __stt_get_engine_error_code(sttp_error_e err) +{ + switch(err) { + case STTP_ERROR_NONE: return "STTP_ERROR_NONE"; + case STTP_ERROR_OUT_OF_MEMORY: return "STTP_ERROR_OUT_OF_MEMORY"; + case STTP_ERROR_IO_ERROR: return "STTP_ERROR_IO_ERROR"; + case STTP_ERROR_INVALID_PARAMETER: return "STTP_ERROR_INVALID_PARAMETER"; + case STTP_ERROR_OUT_OF_NETWORK: return "STTP_ERROR_OUT_OF_NETWORK"; + case STTP_ERROR_INVALID_STATE: return "STTP_ERROR_INVALID_STATE"; + case STTP_ERROR_INVALID_LANGUAGE: return "STTP_ERROR_INVALID_LANGUAGE"; + case STTP_ERROR_OPERATION_FAILED: return "STTP_ERROR_OPERATION_FAILED"; + case STTP_ERROR_NOT_SUPPORTED_FEATURE: return "STTP_ERROR_NOT_SUPPORTED_FEATURE"; + default: + return "Invalid error code"; + } +} + +static sttengine_s* __get_engine(int engine_id) +{ + /* check whether engine id is valid or not.*/ + GSList *iter = NULL; + sttengine_s *engine = NULL; + + if (g_slist_length(g_engine_list) > 0) { + /*Get a first item*/ + iter = g_slist_nth(g_engine_list, 0); + + while (NULL != iter) { + /*Get handle data from list*/ + engine = iter->data; + + if (engine_id == engine->engine_id) { + return engine; + } + + /*Get next item*/ + iter = g_slist_next(iter); + } + } + + return NULL; +} + +/* Register engine id */ +int stt_engine_load(int engine_id, const char* filepath) +{ + if (NULL == filepath || engine_id < 0) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL != engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is already loaded", engine_id); + return 0; + } + + SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Engine] Load engine id(%d), path(%s)", engine_id, filepath); + + /* allocation memory */ + engine = (sttengine_s*)calloc(1, sizeof(sttengine_s)); + + /* load engine */ + char *error; + + engine->handle = dlopen(filepath, RTLD_LAZY); + if (!engine->handle) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine] Invalid engine (Fail dlopen) : %s", filepath); + free(engine); + return STTP_ERROR_OPERATION_FAILED; + } + + engine->pefuncs = (sttpe_funcs_s*)calloc(1, sizeof(sttpe_funcs_s)); + engine->pdfuncs = (sttpd_funcs_s*)calloc(1, sizeof(sttpd_funcs_s)); + + engine->sttp_unload_engine = NULL; + engine->sttp_load_engine = NULL; + + engine->sttp_unload_engine = (int (*)())dlsym(engine->handle, "sttp_unload_engine"); + if (NULL != (error = dlerror()) || NULL == engine->sttp_unload_engine) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to link daemon to sttp_unload_engine() : %s", error); + dlclose(engine->handle); + free(engine->pefuncs); + free(engine->pdfuncs); + free(engine); + return STTP_ERROR_OPERATION_FAILED; + } + + engine->sttp_load_engine = (int (*)(sttpd_funcs_s*, sttpe_funcs_s*) )dlsym(engine->handle, "sttp_load_engine"); + if (NULL != (error = dlerror()) || NULL == engine->sttp_load_engine) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to link daemon to sttp_load_engine() : %s", error); + dlclose(engine->handle); + free(engine->pefuncs); + free(engine->pdfuncs); + free(engine); + return STTP_ERROR_OPERATION_FAILED; + } + + engine->engine_id = engine_id; + engine->engine_path = strdup(filepath); + + engine->pdfuncs->version = 1; + engine->pdfuncs->size = sizeof(sttpd_funcs_s); + + int ret = engine->sttp_load_engine(engine->pdfuncs, engine->pefuncs); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail sttp_load_engine() : %s", __stt_get_engine_error_code(ret)); + dlclose(engine->handle); + free(engine->pefuncs); + free(engine->pdfuncs); + free(engine->engine_path); + free(engine); + return STTP_ERROR_OPERATION_FAILED; + } + + /* engine error check */ + if (engine->pefuncs->size != sizeof(sttpe_funcs_s)) { + SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine is not valid : function size is not matched"); + } + + if (NULL == engine->pefuncs->initialize || + NULL == engine->pefuncs->deinitialize || + NULL == engine->pefuncs->foreach_langs || + NULL == engine->pefuncs->is_valid_lang || + NULL == engine->pefuncs->support_silence || + NULL == engine->pefuncs->support_recognition_type || + NULL == engine->pefuncs->get_audio_format || + NULL == engine->pefuncs->set_silence_detection || + NULL == engine->pefuncs->start || + NULL == engine->pefuncs->set_recording || + NULL == engine->pefuncs->stop || + NULL == engine->pefuncs->cancel || + NULL == engine->pefuncs->foreach_result_time) + /* Current unused functions + NULL == engine->pefuncs->start_file_recognition || + */ + { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] The engine functions are NOT valid"); + dlclose(engine->handle); + free(engine->pefuncs); + free(engine->pdfuncs); + free(engine->engine_path); + free(engine); + + return STTP_ERROR_OPERATION_FAILED; + } + + SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Engine Success] Load engine : version(%d), size(%d)",engine->pefuncs->version, engine->pefuncs->size); + + g_engine_list = g_slist_append(g_engine_list, engine); + + return 0; +} + +/* Unregister engine id */ +int stt_engine_unload(int engine_id) +{ + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + /* unload engine */ + engine->sttp_unload_engine(); + dlclose(engine->handle); + + if (NULL != engine->engine_path) free(engine->engine_path); + if (NULL != engine->pefuncs) free(engine->pefuncs); + if (NULL != engine->pdfuncs) free(engine->pdfuncs); + + g_engine_list = g_slist_remove(g_engine_list, engine); + + free(engine); + + return 0; +} + + +/* Initialize / Deinitialize */ +int stt_engine_initialize(int engine_id, sttpe_result_cb result_cb, sttpe_silence_detected_cb silence_cb) +{ + if (NULL == result_cb || NULL == silence_cb) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret; + ret = engine->pefuncs->initialize(result_cb, silence_cb); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to initialize : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +int stt_engine_deinitialize(int engine_id) +{ + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret; + ret = engine->pefuncs->deinitialize(); + if (0 != ret) { + SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Fail to deinitialize : %s", __stt_get_engine_error_code(ret)); + } + + return 0; +} + +static bool __supported_language_cb(const char* language, void* user_data) +{ + GSList** lang_list = (GSList**)user_data; + + if (NULL == language || NULL == lang_list) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Input parameter is NULL in callback!!!!"); + return false; + } + + char* temp_lang = g_strdup(language); + + *lang_list = g_slist_append(*lang_list, temp_lang); + + return true; +} + +/* Get option */ +int stt_engine_get_supported_langs(int engine_id, GSList** lang_list) +{ + if (NULL == lang_list) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret; + ret = engine->pefuncs->foreach_langs(__supported_language_cb, (void*)lang_list); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] get language list error : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +int stt_engine_is_valid_language(int engine_id, const char* language, bool *is_valid) +{ + if (NULL == language || NULL == is_valid) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + bool result; + result = engine->pefuncs->is_valid_lang(language); + + *is_valid = result; + + return 0; +} + +int stt_engine_get_first_language(int engine_id, char** language) +{ + if (NULL == language) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + GSList* lang_list = NULL; + int ret; + ret = engine->pefuncs->foreach_langs(__supported_language_cb, &lang_list); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] get language list error : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + GSList *iter = NULL; + char* data = NULL; + + iter = g_slist_nth(lang_list, 0); + if (NULL != iter) { + data = iter->data; + + if (true == engine->pefuncs->is_valid_lang(data)) { + *language = strdup(data); + } else { + ret = STTP_ERROR_OPERATION_FAILED; + } + } + + /* if list have item */ + if (g_slist_length(lang_list) > 0) { + /* Get a first item */ + iter = g_slist_nth(lang_list, 0); + + while (NULL != iter) { + data = iter->data; + + if (NULL != data) + free(data); + + lang_list = g_slist_remove_link(lang_list, iter); + + iter = g_slist_nth(lang_list, 0); + } + } + + return ret; +} + +int stt_engine_support_silence(int engine_id, bool* support) +{ + if (NULL == support) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + bool result; + result = engine->pefuncs->support_silence(); + *support = result; + + return 0; +} + +int stt_engine_support_recognition_type(int engine_id, const char* type, bool* support) +{ + if (NULL == type || NULL == support) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + bool result; + if (NULL != engine->pefuncs->support_recognition_type) { + result = engine->pefuncs->support_recognition_type(type); + *support = result; + return 0; + } + + return STTP_ERROR_OPERATION_FAILED; +} + +int stt_engine_get_audio_type(int engine_id, sttp_audio_type_e* types, int* rate, int* channels) +{ + if (NULL == types || NULL == rate || NULL == channels) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret; + ret = engine->pefuncs->get_audio_format(types, rate, channels); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get audio format : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +/* Set option */ +int stt_engine_set_silence_detection(int engine_id, bool value) +{ + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret = engine->pefuncs->set_silence_detection(value); + if (STTP_ERROR_NOT_SUPPORTED_FEATURE == ret) { + SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Not support silence detection"); + return STTP_ERROR_NOT_SUPPORTED_FEATURE; + } else if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set silence detection : %d", ret); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +int stt_engine_check_app_agreed(int engine_id, const char* appid, bool* value) +{ + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + if (NULL == engine->pefuncs->check_app_agreed) { + SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Not support app agreement. All app is available"); + *value = true; + return 0; + } + + int ret = engine->pefuncs->check_app_agreed(appid, value); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get app agreement : %s", __stt_get_engine_error_code(ret)); + *value = false; + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +/* Recognition */ +int stt_engine_recognize_start(int engine_id, const char* lang, const char* recognition_type, void* user_param) +{ + if (NULL == lang || NULL == recognition_type) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret = engine->pefuncs->start(lang, recognition_type, user_param); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start recognition : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +int stt_engine_set_recording_data(int engine_id, const void* data, unsigned int length) +{ + if (NULL == data) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret = engine->pefuncs->set_recording(data, length); + if (0 != ret) { + SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Fail to set recording : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +int stt_engine_recognize_stop(int engine_id) +{ + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret = engine->pefuncs->stop(); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to stop : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +int stt_engine_recognize_cancel(int engine_id) +{ + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret = engine->pefuncs->cancel(); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to cancel : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +int stt_engine_foreach_result_time(int engine_id, void* time_info, sttpe_result_time_cb callback, void* user_data) +{ + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + int ret = engine->pefuncs->foreach_result_time(time_info, callback, user_data); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to foreach result time : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +int stt_engine_recognize_start_file(int engine_id, const char* lang, const char* recognition_type, + const char* filepath, sttp_audio_type_e audio_type, int sample_rate, void* user_param) +{ + if (NULL == filepath || NULL == lang || NULL == recognition_type) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + if (NULL == engine->pefuncs->start_file) { + SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine API is invalid"); + return STTP_ERROR_NOT_SUPPORTED_FEATURE; + } + + int ret = engine->pefuncs->start_file(lang, recognition_type, filepath, audio_type, sample_rate, user_param); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start file recognition : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} + +int stt_engine_recognize_cancel_file(int engine_id) +{ + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + if (NULL == engine->pefuncs->cancel_file) { + SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine API is invalid"); + return STTP_ERROR_NOT_SUPPORTED_FEATURE; + } + + int ret = engine->pefuncs->cancel_file(); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start file recognition : %s", __stt_get_engine_error_code(ret)); + return STTP_ERROR_OPERATION_FAILED; + } + + return 0; +} \ No newline at end of file diff --git a/common/stt_engine.h b/common/stt_engine.h new file mode 100644 index 0000000..2e80eb1 --- /dev/null +++ b/common/stt_engine.h @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2011-2014 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_ENGINE_H_ +#define __STT_ENGINE_H_ + +#include +#include "sttp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* +* STT Engine Interfaces +*/ + + +/* Register engine id */ +int stt_engine_load(int engine_id, const char* filepath); + +/* Unregister engine id */ +int stt_engine_unload(int engine_id); + + +/* Init / Deinit */ +int stt_engine_initialize(int engine_id, sttpe_result_cb result_cb, sttpe_silence_detected_cb silence_cb); + +int stt_engine_deinitialize(int engine_id); + +/* Get option */ +int stt_engine_get_supported_langs(int engine_id, GSList** lang_list); + +int stt_engine_is_valid_language(int engine_id, const char* language, bool *is_valid); + +int stt_engine_get_first_language(int engine_id, char** language); + +int stt_engine_support_silence(int engine_id, bool* support); + +int stt_engine_support_recognition_type(int engine_id, const char* type, bool* support); + +int stt_engine_get_audio_type(int engine_id, sttp_audio_type_e* types, int* rate, int* channels); + +/* Set option */ +int stt_engine_set_silence_detection(int engine_id, bool value); + +/* Get right */ +int stt_engine_check_app_agreed(int engine_id, const char* appid, bool* value); + +/* Recognition */ +int stt_engine_recognize_start(int engine_id, const char* lang, const char* recognition_type, void* user_param); + +int stt_engine_set_recording_data(int engine_id, const void* data, unsigned int length); + +int stt_engine_recognize_stop(int engine_id); + +int stt_engine_recognize_cancel(int engine_id); + +int stt_engine_foreach_result_time(int engine_id, void* time_info, sttpe_result_time_cb callback, void* user_data); + + +/* File recognition */ +int stt_engine_recognize_start_file(int engine_id, const char* lang, const char* recognition_type, + const char* filepath, sttp_audio_type_e audio_type, int sample_rate, void* user_param); + +int stt_engine_recognize_cancel_file(int engine_id); + + +#ifdef __cplusplus +} +#endif + +#endif /* __STT_ENGINE_H_ */ diff --git a/common/stt_network.c b/common/stt_network.c new file mode 100644 index 0000000..ac3210f --- /dev/null +++ b/common/stt_network.c @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2011-2014 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 +#include + +#include "stt_network.h" + +extern const char* stt_tag(); + +int stt_network_initialize() +{ + return 0; +} + +int stt_network_finalize() +{ + return 0; +} + +bool stt_network_is_connected() +{ + /* Check network */ + int network_status = 0; + vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status); + + if(network_status == VCONFKEY_NETWORK_OFF){ + SLOG(LOG_WARN, stt_tag(), "[Network] Current network connection is OFF."); + return false; + } + + SLOG(LOG_DEBUG, stt_tag(), "[Network] Network status is %d", network_status); + + return true; +} \ No newline at end of file diff --git a/server/sttd_network.h b/common/stt_network.h similarity index 69% rename from server/sttd_network.h rename to common/stt_network.h index 659b69f..fbda52d 100644 --- a/server/sttd_network.h +++ b/common/stt_network.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2014 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 @@ -12,18 +12,20 @@ */ -#ifndef __STTD_NETWORK_H_ -#define __STTD_NETWORK_H_ +#ifndef __STT_NETWORK_H_ +#define __STT_NETWORK_H_ + +#include #ifdef __cplusplus extern "C" { #endif -int sttd_network_initialize(); +int stt_network_initialize(); -int sttd_network_finalize(); +int stt_network_finalize(); -bool sttd_network_is_connected(); +bool stt_network_is_connected(); #ifdef __cplusplus @@ -31,4 +33,4 @@ bool sttd_network_is_connected(); #endif -#endif /* __STTD_NETWORK_H_ */ +#endif /* __STT_NETWORK_H_ */ diff --git a/doc/doxyfile b/doc/doxyfile new file mode 100644 index 0000000..c061f3d --- /dev/null +++ b/doc/doxyfile @@ -0,0 +1,2370 @@ +# Doxyfile 1.8.7 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = STT + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify an logo or icon that is included in +# the documentation. The maximum height of the logo should not exceed 55 pixels +# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo +# to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = . + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a +# new page for each member. If set to NO, the documentation of a member will be +# part of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, Javascript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# +# Note For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by by putting a % sign in front of the word +# or globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO these classes will be included in the various overviews. This option has +# no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO these declarations will be +# included in the documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. +# The default value is: system dependent. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the +# todo list. This list is created by putting \todo commands in the +# documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the +# test list. This list is created by putting \test commands in the +# documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES the list +# will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. Do not use file names with spaces, bibtex cannot handle them. See +# also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO doxygen will only warn about wrong or incomplete parameter +# documentation, but not about the absence of documentation. +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. +# Note: If this tag is empty the current directory is searched. + +INPUT = ../include/stt.h \ + uix_stt_doc.h + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank the +# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, +# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, +# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, +# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, +# *.qsf, *.as and *.js. + +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.d \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.idl \ + *.odl \ + *.cs \ + *.php \ + *.php3 \ + *.inc \ + *.m \ + *.mm \ + *.dox \ + *.py \ + *.f90 \ + *.f \ + *.vhd \ + *.vhdl + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = images/capi_uix_stt_state_diagram.png + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER ) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES, then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +# If the CLANG_ASSISTED_PARSING tag is set to YES, then doxygen will use the +# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the +# cost of reduced performance. This can be particularly helpful with template +# rich C++ code for which doxygen's built-in parser lacks the necessary type +# information. +# Note: The availability of this option depends on whether or not doxygen was +# compiled with the --with-libclang option. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user- +# defined cascading style sheet that is included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefor more robust against future updates. +# Doxygen will copy the style sheet file to the output directory. For an example +# see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the stylesheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to NO can help when comparing the output of multiple runs. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler ( hhc.exe). If non-empty +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated ( +# YES) or that it should be included in the master .chm file ( NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated ( +# YES) or a normal table of contents ( NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using prerendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /