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

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: 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,
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...
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 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.
85 // with a give names. Messages of the form:
86 // 'name' { <var> }
binji 2013/08/22 18:09:36 {message_name: value}
Sam Clegg 2013/08/22 19:52:25 Done.
87 // will then not generate events but instead cause the
88 // handler to be called upon message arrival.
89 // If handler is NULL then the current handler will be
90 // 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.
91 void RegisterMessageHandler(std::string message_name,
92 MessageHandler_t handler,
93 void* user_data);
94
76 protected: 95 protected:
77 // Callback functions triggered by Pepper 96 // Callback functions triggered by Pepper
78 // 97 //
79 // These functions are called on the main pepper thread, so they must 98 // These functions are called on the main pepper thread, so they must
80 // not block. 99 // not block.
81 // 100 //
82 // Called by the browser when the NaCl module is loaded and all ready to go. 101 // 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. 102 // 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[]); 103 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
85 104
(...skipping 20 matching lines...) Expand all
106 125
107 // Called by the browser when the mouselock is lost. 126 // Called by the browser when the mouselock is lost.
108 virtual void MouseLockLost(); 127 virtual void MouseLockLost();
109 128
110 // Called by Init to processes default and embed tag arguments prior to 129 // Called by Init to processes default and embed tag arguments prior to
111 // launching the 'ppapi_main' thread. 130 // launching the 'ppapi_main' thread.
112 virtual bool ProcessProperties(); 131 virtual bool ProcessProperties();
113 132
114 private: 133 private:
115 static void* MainThreadThunk(void *start_info); 134 static void* MainThreadThunk(void *start_info);
135 int TtyOutputHandler(const char* buf, int count);
136 void MessageHandlerInput(const pp::Var& message);
137 void MessageHandlerResize(const pp::Var& message);
138
139 static int TtyOutputHandlerStatic(const char* buf, int count);
140 static void MessageHandlerResizeStatic(const pp::Var& key,
141 const pp::Var& value,
142 void* user_data);
143 static void MessageHandlerInputStatic(const pp::Var& key,
144 const pp::Var& value,
145 void* user_data);
116 146
117 protected: 147 protected:
118 pp::MessageLoop* main_loop_; 148 pp::MessageLoop* main_loop_;
119 149
120 sdk_util::ThreadSafeQueue<PSEvent> event_queue_; 150 sdk_util::ThreadSafeQueue<PSEvent> event_queue_;
121 uint32_t events_enabled_; 151 uint32_t events_enabled_;
122 Verbosity verbosity_; 152 Verbosity verbosity_;
123 int fd_tty_; 153
154 // TTY handling
155 int tty_fd_;
156 const char* tty_prefix_;
157 const char* tty_resize_;
158 std::map<std::string, MessageHandler> message_handlers_;
124 159
125 PSMainFunc_t main_cb_; 160 PSMainFunc_t main_cb_;
126 161
127 const PPB_Core* ppb_core_; 162 const PPB_Core* ppb_core_;
128 const PPB_Var* ppb_var_; 163 const PPB_Var* ppb_var_;
129 const PPB_View* ppb_view_; 164 const PPB_View* ppb_view_;
130 }; 165 };
131 166
132 #endif // PPAPI_MAIN_PS_INSTANCE_H_ 167 #endif // PPAPI_MAIN_PS_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698