[Speech API]: running mainloop in crosswalk extension
authorAmarnath Valluri <amarnath.valluri@linux.intel.com>
Tue, 25 Nov 2014 08:59:59 +0000 (10:59 +0200)
committerKrisztian Litkey <krisztian.litkey@intel.com>
Tue, 16 Dec 2014 19:28:38 +0000 (21:28 +0200)
Change-Id: I8975e7e5cd1fadf1dad493ee63d61d8f3f94862a

packaging/speech-recognition.spec
src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.cc
src/plugins/client-api/w3c-speech/crosswalk-extension/speech_instance.h

index b6da917..41d23f7 100644 (file)
@@ -68,6 +68,7 @@ export CFLAGS="-O0 -g3"
 export CXXFLAGS="-O0 -g3"
 V="V=1"
 %endif
+export CXXFLAGS=$CXXFLAGS" -DTIZEN=1"
 
 CONFIG_OPTIONS=""
 
index 65424c4..0428d5c 100644 (file)
 #include "speech_logs.h"
 
 #define WINTHORP_SERVER_SOCKET "@winthorpe.w3c-speech"
+#ifdef TIZEN
+// static
+void SpeechInstance::SetupMainloop(void* data) {
+  SpeechInstance* self = reinterpret_cast<SpeechInstance*>(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
index 065be50..c15b813 100644 (file)
@@ -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<std::string> pending_replies_;
   std::queue<std::string> pending_requests_;