diff --git a/ttsclient/CMakeLists.txt b/ttsclient/CMakeLists.txt index 9167ee9..c39052b 100644 --- a/ttsclient/CMakeLists.txt +++ b/ttsclient/CMakeLists.txt @@ -22,21 +22,30 @@ pkg_check_modules(WPEFRAMEWORK_SECURITYUTIL WPEFrameworkSecurityUtil) # Build TTS Service Client library set(TextToSpeechServiceClient_SOURCES - TextToSpeechServiceCOMRPC.cpp - TextToSpeechService.cpp - Service.cpp - ../common/logger.cpp - TextToSpeechServiceFirebolt.cpp - ) + TextToSpeechServiceCOMRPC.cpp + TextToSpeechService.cpp + Service.cpp + ../common/logger.cpp +) + +if(TTS_DEFAULT_BACKEND STREQUAL "firebolt") + list(APPEND TextToSpeechServiceClient_SOURCES TextToSpeechServiceFirebolt.cpp) +endif() + add_library(TextToSpeechServiceClient SHARED ${TextToSpeechServiceClient_SOURCES}) # Build TTS Service Client library set(TTSClient_SOURCES - TTSClient.cpp - TTSClientPrivateJsonRPC.cpp - TTSClientPrivateCOMRPC.cpp - TTSClientPrivateFirebolt.cpp - ) + TTSClient.cpp + TTSClientPrivateJsonRPC.cpp + TTSClientPrivateCOMRPC.cpp +) + +if(TTS_DEFAULT_BACKEND STREQUAL "firebolt") + add_definitions(-DTTS_DEFAULT_BACKEND_FIREBOLT) + list(APPEND TTSClient_SOURCES TTSClientPrivateFirebolt.cpp) +endif() + add_library(TTSClient SHARED ${TTSClient_SOURCES}) target_include_directories(TextToSpeechServiceClient PUBLIC ${WPEFRAMEWORK_PLUGINS_INCLUDE_DIRS}) @@ -50,18 +59,26 @@ if(TTS_DEFAULT_BACKEND) add_definitions(-DTTS_DEFAULT_BACKEND="${TTS_DEFAULT_BACKEND}") endif() -target_link_libraries(TextToSpeechServiceClient PUBLIC +if(TTS_DEFAULT_BACKEND STREQUAL "firebolt") + target_link_libraries(TextToSpeechServiceClient PUBLIC ${WPEFRAMEWORK_PLUGINS_LIBRARIES} ${WPEFRAMEWORK_SECURITYUTIL_LIBRARIES} -lpthread - FireboltSDK + FireboltSDK ) +else() + target_link_libraries(TextToSpeechServiceClient PUBLIC + ${WPEFRAMEWORK_PLUGINS_LIBRARIES} + ${WPEFRAMEWORK_SECURITYUTIL_LIBRARIES} + -lpthread + ) +endif() target_link_libraries(TTSClient PUBLIC - ${GLIB_LIBRARIES} - ${LIBS} - TextToSpeechServiceClient - ) + ${GLIB_LIBRARIES} + ${LIBS} + TextToSpeechServiceClient +) install(TARGETS TTSClient TextToSpeechServiceClient LIBRARY DESTINATION lib) install(FILES TTSClient.h ../common/TTSCommon.h TextToSpeechService.h Service.h DESTINATION include) diff --git a/ttsclient/TTSClient.cpp b/ttsclient/TTSClient.cpp index 605c201..f62fbff 100644 --- a/ttsclient/TTSClient.cpp +++ b/ttsclient/TTSClient.cpp @@ -1,4 +1,4 @@ -/* +/*#ifdef TTS_DEFAULT_BACKEND_FIREBOLT * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * @@ -19,7 +19,9 @@ #include "TTSClientPrivateCOMRPC.h" #include "TTSClientPrivateJsonRPC.h" +#ifdef TTS_DEFAULT_BACKEND_FIREBOLT #include "TTSClientPrivateFirebolt.h" +#endif #include "logger.h" #include // --- // @@ -36,7 +38,9 @@ namespace TTS { TTSClient::Backend getTTSBackend() { static const char *kCOMRPC = "comrpc"; +#ifdef TTS_DEFAULT_BACKEND_FIREBOLT static const char *kFIREBOLT = "firebolt"; +#endif static const char *backendEnv = getenv("TTS_CLIENT_BACKEND"); static const char *thunderClientEnv = getenv("TTS_USE_THUNDER_CLIENT"); // will go away eventually @@ -56,8 +60,11 @@ TTSClient::Backend getTTSBackend() { if(backendConfig) { if(strncasecmp(backendConfig, kCOMRPC, strlen(kCOMRPC)) == 0) backend = TTSClient::COM; - else if (strncasecmp(backendConfig, kFIREBOLT, strlen(kFIREBOLT)) == 0) - backend = TTSClient::FIREBOLT; +#ifdef TTS_DEFAULT_BACKEND_FIREBOLT + else if (strncasecmp(backendConfig, kFIREBOLT, strlen(kFIREBOLT)) == 0){ + backend = TTSClient::FIREBOLT; + } +#endif } if(thunderClientEnv) @@ -86,10 +93,12 @@ TTSClient::TTSClient(Backend backend, TTSConnectionCallback *callback, bool disc TTSLOG_INFO("TTSClient is using JSONRPC"); m_priv = new TTSClientPrivateJsonRPC(callback, discardRtDispatching); break; - case FIREBOLT: - TTSLOG_INFO("TTSClient is using FIREBOLT"); - m_priv = new TTSClientPrivateFirebolt(callback, discardRtDispatching); - break; +#ifdef TTS_DEFAULT_BACKEND_FIREBOLT + case FIREBOLT: + TTSLOG_INFO("TTSClient is using FIREBOLT"); + m_priv = new TTSClientPrivateFirebolt(callback, discardRtDispatching); + break; +#endif } } diff --git a/ttsclient/TTSClient.h b/ttsclient/TTSClient.h index ab9fae8..f9f0e27 100644 --- a/ttsclient/TTSClient.h +++ b/ttsclient/TTSClient.h @@ -92,7 +92,9 @@ class TTSClient { enum Backend { COM, JSON, - FIREBOLT +#ifdef TTS_DEFAULT_BACKEND_FIREBOLT + FIREBOLT +#endif }; static TTSClient *create(TTSConnectionCallback *connCallback, bool discardRtDispatching=false); diff --git a/ttsclient/TextToSpeechServiceFirebolt.cpp b/ttsclient/TextToSpeechServiceFirebolt.cpp index 340ee00..b5e0d8a 100644 --- a/ttsclient/TextToSpeechServiceFirebolt.cpp +++ b/ttsclient/TextToSpeechServiceFirebolt.cpp @@ -29,7 +29,7 @@ static std::mutex __mutex; std::condition_variable cv; std::mutex mtx; -namespace TTSFirebolt{ +namespace TTSFirebolt { bool TextToSpeechServiceFirebolt::isConnected; @@ -53,18 +53,22 @@ void TextToSpeechServiceFirebolt::initialize() { if(initialized()) return; const char* firebolt_endpoint = std::getenv("FIREBOLT_ENDPOINT"); - //const char* firebolt_endpoint = "ws://127.0.0.1:3474"; if(firebolt_endpoint != nullptr) { std::string url = firebolt_endpoint; - if(!createFireboltInstance(url)){ + if(!createFireboltInstance(url)) { TTSLOG_ERROR("Failed to create FireboltInstance URL: [%s]", url.c_str()); return; } std::unique_lock lock(mtx); - cv.wait(lock, [this]{ return isConnected; }); - m_initialized = true; - subscribeEvents(); - TTSLOG_INFO("Firebolt Core Intiailized URL: [%s]", url.c_str()); + /*Wait Time is 200 millisecond*/ + if (cv.wait_for(lock, std::chrono::milliseconds(200), [this] { return isConnected; })) { + m_initialized = true; + subscribeEvents(); + TTSLOG_INFO("Firebolt Core Intiailized URL: [%s]", url.c_str()); + } + else { + TTSLOG_ERROR("Firebolt Core Intiailized URL: [%s] Failed(Timeout)", url.c_str()); + } } else { TTSLOG_ERROR("No Firebolt endpoint; initialization failed");