065be50e5926e00134b8e0d99182ef9e25cff0a1
[profile/ivi/speech-recognition.git] / src / plugins / client-api / w3c-speech / crosswalk-extension / speech_instance.h
1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SPEECH_SPEECH_INSTANCE_H_
6 #define SPEECH_SPEECH_INSTANCE_H_
7
8 #include <glib.h>
9 #include <thread>  // NOLINT
10 #include <queue>
11 #include <string>
12
13 #include "common/extension.h"
14 #include "common/picojson.h"
15
16 class SpeechInstance : public common::Instance {
17  public:
18   SpeechInstance();
19   virtual ~SpeechInstance();
20
21  protected:
22   static gboolean IOWatchCb(GIOChannel* source,
23                             GIOCondition condition,
24                             gpointer data);
25   static gboolean ProcessPendingRequestsCb(gpointer data);
26   static gboolean ProcessPendingRepliesCb(gpointer data);
27
28  private:
29   // common::Instance implementation.
30   virtual void HandleMessage(const char* msg);
31   virtual void HandleSyncMessage(const char* message);
32
33   void QueueReply(const std::string& reply);
34   void QueueRequest(const std::string& req);
35   bool SendRequest(const char* message);
36   uint32_t ReadReply(char** reply);
37
38   std::queue<std::string> pending_replies_;
39   std::queue<std::string> pending_requests_;
40   int fd_;
41   GIOChannel *channel_;
42   guint watcher_id_;
43   guint pending_request_timer_;
44   guint pending_reply_timer_;
45 };
46 #endif  // SPEECH_SPEECH_INSTANCE_H_