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

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, 4 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 };
37
38 typedef std::map<std::string, MessageHandler> MessageHandlerMap;
binji 2013/08/22 20:10:55 put this inside the PSInstance
Sam Clegg 2013/08/22 20:19:03 Done.
29 39
30 // The basic instance class which also inherits the MouseLock and 40 // The basic instance class which also inherits the MouseLock and
31 // Graphics3DClient interfaces. 41 // Graphics3DClient interfaces.
32 class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient { 42 class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
33 public: 43 public:
34 // Verbosity levels, ecplicitly numbered since we pass these 44 // Verbosity levels, ecplicitly numbered since we pass these
35 // in from html attributes as numberic values. 45 // in from html attributes as numberic values.
36 enum Verbosity { 46 enum Verbosity {
37 PSV_SILENT = 0, 47 PSV_SILENT = 0,
38 PSV_ERROR = 1, 48 PSV_ERROR = 1,
(...skipping 27 matching lines...) Expand all
66 void SetEnabledEvents(uint32_t mask); 76 void SetEnabledEvents(uint32_t mask);
67 void PostEvent(PSEventType type); 77 void PostEvent(PSEventType type);
68 void PostEvent(PSEventType type, PP_Bool bool_value); 78 void PostEvent(PSEventType type, PP_Bool bool_value);
69 void PostEvent(PSEventType type, PP_Resource resource); 79 void PostEvent(PSEventType type, PP_Resource resource);
70 void PostEvent(PSEventType type, const PP_Var& var); 80 void PostEvent(PSEventType type, const PP_Var& var);
71 81
72 PSEvent* TryAcquireEvent(); 82 PSEvent* TryAcquireEvent();
73 PSEvent* WaitAcquireEvent(); 83 PSEvent* WaitAcquireEvent();
74 void ReleaseEvent(PSEvent* event); 84 void ReleaseEvent(PSEvent* event);
75 85
86 // Register a message handler for messages that arrive
87 // from JavaScript with a give names. Messages are of the
88 // form:
89 // message_name { <value> }
binji 2013/08/22 20:10:55 this still looks weird to me. You'd never write f
Sam Clegg 2013/08/22 20:19:03 Oops. Fixed. (do you object to the <> too?)
90 // PSInstance wht then not generate events but instead
binji 2013/08/22 20:10:55 s/wht/will/
Sam Clegg 2013/08/22 20:19:03 Done.
91 // cause the handler to be called upon message arrival.
92 // If handler is NULL then the current handler will be
93 // removed.
94 void RegisterMessageHandler(std::string message_name,
95 MessageHandler_t handler,
96 void* user_data);
97
76 protected: 98 protected:
77 // Callback functions triggered by Pepper 99 // Callback functions triggered by Pepper
78 // 100 //
79 // These functions are called on the main pepper thread, so they must 101 // These functions are called on the main pepper thread, so they must
80 // not block. 102 // not block.
81 // 103 //
82 // Called by the browser when the NaCl module is loaded and all ready to go. 104 // 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. 105 // 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[]); 106 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
85 107
(...skipping 20 matching lines...) Expand all
106 128
107 // Called by the browser when the mouselock is lost. 129 // Called by the browser when the mouselock is lost.
108 virtual void MouseLockLost(); 130 virtual void MouseLockLost();
109 131
110 // Called by Init to processes default and embed tag arguments prior to 132 // Called by Init to processes default and embed tag arguments prior to
111 // launching the 'ppapi_main' thread. 133 // launching the 'ppapi_main' thread.
112 virtual bool ProcessProperties(); 134 virtual bool ProcessProperties();
113 135
114 private: 136 private:
115 static void* MainThreadThunk(void *start_info); 137 static void* MainThreadThunk(void *start_info);
138 ssize_t TtyOutputHandler(const char* buf, size_t count);
139 void MessageHandlerInput(const pp::Var& message);
140 void MessageHandlerResize(const pp::Var& message);
141
142 static ssize_t TtyOutputHandlerStatic(const char* buf, size_t count,
143 void* user_data);
144
145 /// Handle input message from JavaScript. The valu is
binji 2013/08/22 20:10:55 value
Sam Clegg 2013/08/22 20:19:03 Done.
146 /// expected to be of type string.
147 static void MessageHandlerInputStatic(const pp::Var& key,
148 const pp::Var& value,
149 void* user_data);
150
151
152 /// Handle resizs message from JavaScript. The value is
153 /// expected to be an array of 2 integers representing the
154 /// number of columns and rows in the TTY.
155 static void MessageHandlerResizeStatic(const pp::Var& key,
156 const pp::Var& value,
157 void* user_data);
116 158
117 protected: 159 protected:
118 pp::MessageLoop* main_loop_; 160 pp::MessageLoop* main_loop_;
119 161
120 sdk_util::ThreadSafeQueue<PSEvent> event_queue_; 162 sdk_util::ThreadSafeQueue<PSEvent> event_queue_;
121 uint32_t events_enabled_; 163 uint32_t events_enabled_;
122 Verbosity verbosity_; 164 Verbosity verbosity_;
123 int fd_tty_; 165
166 // TTY handling
167 int tty_fd_;
168 const char* tty_prefix_;
169 MessageHandlerMap message_handlers_;
124 170
125 PSMainFunc_t main_cb_; 171 PSMainFunc_t main_cb_;
126 172
127 const PPB_Core* ppb_core_; 173 const PPB_Core* ppb_core_;
128 const PPB_Var* ppb_var_; 174 const PPB_Var* ppb_var_;
129 const PPB_View* ppb_view_; 175 const PPB_View* ppb_view_;
130 }; 176 };
131 177
132 #endif // PPAPI_MAIN_PS_INSTANCE_H_ 178 #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