From 40f02bfccbdecb2fa1be122759ff730fc447b76f Mon Sep 17 00:00:00 2001 From: Amarnath Valluri Date: Tue, 25 Nov 2014 10:59:59 +0200 Subject: [PATCH] [Speech API]: running mainloop in crosswalk extension Change-Id: I8975e7e5cd1fadf1dad493ee63d61d8f3f94862a --- packaging/speech-recognition.spec | 1 + .../crosswalk-extension/speech_instance.cc | 24 +++++++++++++++++++++- .../crosswalk-extension/speech_instance.h | 5 +++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packaging/speech-recognition.spec b/packaging/speech-recognition.spec index b6da917..41d23f7 100644 --- a/packaging/speech-recognition.spec +++ b/packaging/speech-recognition.spec @@ -68,6 +68,7 @@ export CFLAGS="-O0 -g3" export CXXFLAGS="-O0 -g3" V="V=1" %endif +export CXXFLAGS=$CXXFLAGS" -DTIZEN=1" CONFIG_OPTIONS="" diff --git a/src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.cc b/src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.cc index 65424c4..0428d5c 100644 --- a/src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.cc +++ b/src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.cc @@ -20,13 +20,30 @@ #include "speech_logs.h" #define WINTHORP_SERVER_SOCKET "@winthorpe.w3c-speech" +#ifdef TIZEN +// static +void SpeechInstance::SetupMainloop(void* data) { + SpeechInstance* self = reinterpret_cast(data); + + g_main_loop_run(self->main_loop_); +} +#endif // TIZEN SpeechInstance::SpeechInstance() - : fd_(-1) +#ifdef TIZEN + : main_loop_(g_main_loop_new(0, FALSE)) + , thread_(SpeechInstance::SetupMainloop, this) + , fd_(-1) +#else + : fd_(-1) +#endif // TIZEN , channel_(NULL) , watcher_id_(0) , pending_request_timer_(0) , pending_reply_timer_(0) { +#ifdef TIZEN + thread_.detach(); +#endif // TIZEN if ((fd_ = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { ERR("Failed to create socket: %s", strerror(errno)); fd_ = -1; @@ -67,6 +84,11 @@ SpeechInstance::~SpeechInstance() { close(fd_); if (channel_) g_io_channel_unref(channel_); + +#ifdef TIZEN + g_main_loop_quit(main_loop_); + g_main_loop_unref(main_loop_); +#endif // TIZEN } // static diff --git a/src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.h b/src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.h index 065be50..c15b813 100644 --- a/src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.h +++ b/src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.h @@ -34,6 +34,11 @@ class SpeechInstance : public common::Instance { void QueueRequest(const std::string& req); bool SendRequest(const char* message); uint32_t ReadReply(char** reply); +#ifdef TIZEN + static void SetupMainloop(void *data); + GMainLoop* main_loop_; + std::thread thread_; +#endif // TIZEN std::queue pending_replies_; std::queue pending_requests_; -- 2.7.4