Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / ppapi_simple / ps_instance.h
index 4138982..21209d1 100644 (file)
@@ -109,6 +109,11 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
                               MessageHandler_t handler,
                               void* user_data);
 
+  // Perform exit handshake with JavaScript.
+  // This is called by _exit before the process is terminated to ensure
+  // that all messages sent prior to _exit arrive at the JavaScript side.
+  void ExitHandshake(int status);
+
  protected:
   typedef std::map<std::string, MessageHandler> MessageHandlerMap;
 
@@ -152,17 +157,25 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
  private:
   static void* MainThreadThunk(void *start_info);
   ssize_t TtyOutputHandler(const char* buf, size_t count);
-  void MessageHandlerInput(const pp::Var& message);
+  void MessageHandlerExit(const pp::Var& message);
+  void MessageHandlerInput(const pp::Var& key, const pp::Var& message);
   void MessageHandlerResize(const pp::Var& message);
   void HandleResize(int width, int height);
 
+  static void HandleExitStatic(int status, void* user_data);
+
   static ssize_t TtyOutputHandlerStatic(const char* buf, size_t count,
                                         void* user_data);
 
+  /// Handle exit confirmation message from JavaScript.
+  static void MessageHandlerExitStatic(const pp::Var& key,
+                                       const pp::Var& message,
+                                       void* user_data);
+
   /// Handle input message from JavaScript.  The value is
   /// expected to be of type string.
   static void MessageHandlerInputStatic(const pp::Var& key,
-                                        const pp::Var& value,
+                                        const pp::Var& message,
                                         void* user_data);
 
 
@@ -170,7 +183,7 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
   /// expected to be an array of 2 integers representing the
   /// number of columns and rows in the TTY.
   static void MessageHandlerResizeStatic(const pp::Var& key,
-                                         const pp::Var& value,
+                                         const pp::Var& message,
                                          void* user_data);
 
  protected:
@@ -185,15 +198,20 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
   const char* tty_prefix_;
   MessageHandlerMap message_handlers_;
 
-  // A message to Post to JavaScript instead of exiting, or NULL if exit()
-  // should be called instead.
-  char* exit_message_;
-
   PSMainFunc_t main_cb_;
 
   const PPB_Core* ppb_core_;
   const PPB_Var* ppb_var_;
   const PPB_View* ppb_view_;
+
+  // Condition variable and lock used to wait for exit confirmation from
+  // JavaScript.
+  pthread_cond_t exit_cond_;
+  pthread_mutex_t exit_lock_;
+
+  // A message to Post to JavaScript instead of exiting, or NULL if exit()
+  // should be called instead.
+  char* exit_message_;
 };
 
-#endif  // PPAPI_MAIN_PS_INSTANCE_H_
+#endif  // PPAPI_SIMPLE_PS_INSTANCE_H_