Chromium Code Reviews| Index: native_client_sdk/src/libraries/ppapi_simple/ps_instance.h |
| diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h |
| index 2df1550dbbd24c4b3deb78abefb62522d6c16c34..40db8bd0e0a4d24a9baf41c6ad3668e8dbc510c1 100644 |
| --- a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h |
| +++ b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h |
| @@ -26,6 +26,14 @@ |
| #include "sdk_util/thread_safe_queue.h" |
| +typedef void (*MessageHandler_t)(const pp::Var& key, |
|
binji
2013/08/22 18:09:36
ps_main.h defines PsMainFunc_t for a function type
Sam Clegg
2013/08/22 19:52:25
I think the handler part implied its a function...
|
| + const pp::Var& value, |
| + void* user_data); |
| + |
| +struct MessageHandler { |
| + MessageHandler_t handler; |
| + void* user_data; |
| +}; |
| // The basic instance class which also inherits the MouseLock and |
| // Graphics3DClient interfaces. |
| @@ -73,6 +81,17 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient { |
| PSEvent* WaitAcquireEvent(); |
| void ReleaseEvent(PSEvent* event); |
| + // Register a message handler for messages that are arrive |
|
binji
2013/08/22 18:09:36
Register a message handler for messages that arriv
Sam Clegg
2013/08/22 19:52:25
Done.
|
| + // with a give names. Messages of the form: |
| + // 'name' { <var> } |
|
binji
2013/08/22 18:09:36
{message_name: value}
Sam Clegg
2013/08/22 19:52:25
Done.
|
| + // will then not generate events but instead cause the |
| + // handler to be called upon message arrival. |
| + // If handler is NULL then the current handler will be |
| + // removed. |
|
binji
2013/08/22 18:09:36
Probably worthwhile to have an example:
JavaScrip
binji
2013/08/22 20:10:55
WDYT? This would make the connection a lot clearer
Sam Clegg
2013/08/22 20:19:03
Done.
|
| + void RegisterMessageHandler(std::string message_name, |
| + MessageHandler_t handler, |
| + void* user_data); |
| + |
| protected: |
| // Callback functions triggered by Pepper |
| // |
| @@ -113,6 +132,17 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient { |
| private: |
| static void* MainThreadThunk(void *start_info); |
| + int TtyOutputHandler(const char* buf, int count); |
| + void MessageHandlerInput(const pp::Var& message); |
| + void MessageHandlerResize(const pp::Var& message); |
| + |
| + static int TtyOutputHandlerStatic(const char* buf, int count); |
| + static void MessageHandlerResizeStatic(const pp::Var& key, |
| + const pp::Var& value, |
| + void* user_data); |
| + static void MessageHandlerInputStatic(const pp::Var& key, |
| + const pp::Var& value, |
| + void* user_data); |
| protected: |
| pp::MessageLoop* main_loop_; |
| @@ -120,7 +150,12 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient { |
| sdk_util::ThreadSafeQueue<PSEvent> event_queue_; |
| uint32_t events_enabled_; |
| Verbosity verbosity_; |
| - int fd_tty_; |
| + |
| + // TTY handling |
| + int tty_fd_; |
| + const char* tty_prefix_; |
| + const char* tty_resize_; |
| + std::map<std::string, MessageHandler> message_handlers_; |
| PSMainFunc_t main_cb_; |