Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: native_client_sdk/src/libraries/ppapi_simple/ps_instance.h

Issue 23005005: [NaCl SDK] nacl_io: Add initial implementations of kill and signal (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_SIMPLE_PS_INSTANCE_H_ 5 #ifndef PPAPI_SIMPLE_PS_INSTANCE_H_
6 #define PPAPI_SIMPLE_PS_INSTANCE_H_ 6 #define PPAPI_SIMPLE_PS_INSTANCE_H_
7 7
8 #include <stdarg.h> 8 #include <stdarg.h>
9 9
10 #include "ppapi/c/pp_instance.h" 10 #include "ppapi/c/pp_instance.h"
11 #include "ppapi/c/pp_stdint.h" 11 #include "ppapi/c/pp_stdint.h"
12 #include "ppapi/c/ppb_core.h" 12 #include "ppapi/c/ppb_core.h"
13 #include "ppapi/c/ppb_var.h" 13 #include "ppapi/c/ppb_var.h"
14 #include "ppapi/c/ppb_view.h" 14 #include "ppapi/c/ppb_view.h"
15 15
16 #include "ppapi/cpp/fullscreen.h" 16 #include "ppapi/cpp/fullscreen.h"
17 #include "ppapi/cpp/graphics_3d_client.h" 17 #include "ppapi/cpp/graphics_3d_client.h"
18 #include "ppapi/cpp/instance.h" 18 #include "ppapi/cpp/instance.h"
19 #include "ppapi/cpp/message_loop.h" 19 #include "ppapi/cpp/message_loop.h"
20 #include "ppapi/cpp/mouse_lock.h" 20 #include "ppapi/cpp/mouse_lock.h"
21 21
22 #include "ppapi/utility/completion_callback_factory.h" 22 #include "ppapi/utility/completion_callback_factory.h"
23 23
24 #include "ppapi_simple/ps_event.h" 24 #include "ppapi_simple/ps_event.h"
25 #include "ppapi_simple/ps_main.h" 25 #include "ppapi_simple/ps_main.h"
26 26
27 #include "sdk_util/thread_safe_queue.h" 27 #include "sdk_util/thread_safe_queue.h"
28 28
29 typedef void (*MessageHandler_t)(const pp::Var& key,
30 const pp::Var& value,
31 void* user_data);
32
33 struct MessageHandler {
34 MessageHandler_t handler;
35 void* user_data;
36 };
29 37
30 // The basic instance class which also inherits the MouseLock and 38 // The basic instance class which also inherits the MouseLock and
31 // Graphics3DClient interfaces. 39 // Graphics3DClient interfaces.
32 class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient { 40 class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
33 public: 41 public:
34 // Verbosity levels, ecplicitly numbered since we pass these 42 // Verbosity levels, ecplicitly numbered since we pass these
35 // in from html attributes as numberic values. 43 // in from html attributes as numberic values.
36 enum Verbosity { 44 enum Verbosity {
37 PSV_SILENT = 0, 45 PSV_SILENT = 0,
38 PSV_ERROR = 1, 46 PSV_ERROR = 1,
(...skipping 27 matching lines...) Expand all
66 void SetEnabledEvents(uint32_t mask); 74 void SetEnabledEvents(uint32_t mask);
67 void PostEvent(PSEventType type); 75 void PostEvent(PSEventType type);
68 void PostEvent(PSEventType type, PP_Bool bool_value); 76 void PostEvent(PSEventType type, PP_Bool bool_value);
69 void PostEvent(PSEventType type, PP_Resource resource); 77 void PostEvent(PSEventType type, PP_Resource resource);
70 void PostEvent(PSEventType type, const PP_Var& var); 78 void PostEvent(PSEventType type, const PP_Var& var);
71 79
72 PSEvent* TryAcquireEvent(); 80 PSEvent* TryAcquireEvent();
73 PSEvent* WaitAcquireEvent(); 81 PSEvent* WaitAcquireEvent();
74 void ReleaseEvent(PSEvent* event); 82 void ReleaseEvent(PSEvent* event);
75 83
84 // Register a message handler for messages that arrive
85 // from JavaScript with a give names. Messages are of the
86 // form: { message_name : <value> }.
87 //
88 // PSInstance will then not generate events but instead
89 // cause the handler to be called upon message arrival.
90 // If handler is NULL then the current handler will be
91 // removed. Example usage:
92 //
93 // JavaScript:
94 // nacl_module.postMessage({'foo': 123});
95 //
96 // C++:
97 // void MyMessageHandler(const pp::Var& key,
98 // const pp::Var& value,
99 // void* user_data) {
100 // assert(key.is_string());
101 // assert(key.AsString() == "foo");
102 // assert(value.is_int());
103 // assert(value.AsInt() == 123);
104 // }
105 // ...
106 // instance_->RegisterMessageHandler("foo", &MyMessageHandler, NULL);
107 //
108 void RegisterMessageHandler(std::string message_name,
109 MessageHandler_t handler,
110 void* user_data);
111
76 protected: 112 protected:
113 typedef std::map<std::string, MessageHandler> MessageHandlerMap;
114
77 // Callback functions triggered by Pepper 115 // Callback functions triggered by Pepper
78 // 116 //
79 // These functions are called on the main pepper thread, so they must 117 // These functions are called on the main pepper thread, so they must
80 // not block. 118 // not block.
81 // 119 //
82 // Called by the browser when the NaCl module is loaded and all ready to go. 120 // Called by the browser when the NaCl module is loaded and all ready to go.
83 // This function will create a new thread which will run the pseudo main. 121 // This function will create a new thread which will run the pseudo main.
84 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); 122 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
85 123
86 // Output log message to stderr if the current verbosity is set 124 // Output log message to stderr if the current verbosity is set
(...skipping 19 matching lines...) Expand all
106 144
107 // Called by the browser when the mouselock is lost. 145 // Called by the browser when the mouselock is lost.
108 virtual void MouseLockLost(); 146 virtual void MouseLockLost();
109 147
110 // Called by Init to processes default and embed tag arguments prior to 148 // Called by Init to processes default and embed tag arguments prior to
111 // launching the 'ppapi_main' thread. 149 // launching the 'ppapi_main' thread.
112 virtual bool ProcessProperties(); 150 virtual bool ProcessProperties();
113 151
114 private: 152 private:
115 static void* MainThreadThunk(void *start_info); 153 static void* MainThreadThunk(void *start_info);
154 ssize_t TtyOutputHandler(const char* buf, size_t count);
155 void MessageHandlerInput(const pp::Var& message);
156 void MessageHandlerResize(const pp::Var& message);
157
158 static ssize_t TtyOutputHandlerStatic(const char* buf, size_t count,
159 void* user_data);
160
161 /// Handle input message from JavaScript. The value is
162 /// expected to be of type string.
163 static void MessageHandlerInputStatic(const pp::Var& key,
164 const pp::Var& value,
165 void* user_data);
166
167
168 /// Handle resizs message from JavaScript. The value is
169 /// expected to be an array of 2 integers representing the
170 /// number of columns and rows in the TTY.
171 static void MessageHandlerResizeStatic(const pp::Var& key,
172 const pp::Var& value,
173 void* user_data);
116 174
117 protected: 175 protected:
118 pp::MessageLoop* main_loop_; 176 pp::MessageLoop* main_loop_;
119 177
120 sdk_util::ThreadSafeQueue<PSEvent> event_queue_; 178 sdk_util::ThreadSafeQueue<PSEvent> event_queue_;
121 uint32_t events_enabled_; 179 uint32_t events_enabled_;
122 Verbosity verbosity_; 180 Verbosity verbosity_;
123 int fd_tty_; 181
182 // TTY handling
183 int tty_fd_;
184 const char* tty_prefix_;
185 MessageHandlerMap message_handlers_;
124 186
125 PSMainFunc_t main_cb_; 187 PSMainFunc_t main_cb_;
126 188
127 const PPB_Core* ppb_core_; 189 const PPB_Core* ppb_core_;
128 const PPB_Var* ppb_var_; 190 const PPB_Var* ppb_var_;
129 const PPB_View* ppb_view_; 191 const PPB_View* ppb_view_;
130 }; 192 };
131 193
132 #endif // PPAPI_MAIN_PS_INSTANCE_H_ 194 #endif // PPAPI_MAIN_PS_INSTANCE_H_
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/mount_node_tty.cc ('k') | native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698