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

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

Issue 61213002: [NaCl SDK] Run nacl_io_socket_test on the bots. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <pthread.h> 7 #include <pthread.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/ioctl.h> 10 #include <sys/ioctl.h>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 // The starting point for 'main'. We create this thread to hide the real 58 // The starting point for 'main'. We create this thread to hide the real
59 // main pepper thread which must never be blocked. 59 // main pepper thread which must never be blocked.
60 void* PSInstance::MainThreadThunk(void *info) { 60 void* PSInstance::MainThreadThunk(void *info) {
61 s_InstanceObject->Trace("Got MainThreadThunk.\n"); 61 s_InstanceObject->Trace("Got MainThreadThunk.\n");
62 StartInfo* si = static_cast<StartInfo*>(info); 62 StartInfo* si = static_cast<StartInfo*>(info);
63 si->inst_->main_loop_ = new pp::MessageLoop(si->inst_); 63 si->inst_->main_loop_ = new pp::MessageLoop(si->inst_);
64 si->inst_->main_loop_->AttachToCurrentThread(); 64 si->inst_->main_loop_->AttachToCurrentThread();
65 65
66 int ret = si->inst_->MainThread(si->argc_, si->argv_); 66 int ret = si->inst_->MainThread(si->argc_, si->argv_);
67
68 char* exit_message = si->inst_->exit_message_;
69 bool should_exit = exit_message == NULL;
70
71 if (exit_message) {
72 // Send the exit message to JavaScript. Don't call exit(), so the message
73 // doesn't get dropped.
74 si->inst_->Log("Posting exit message to JavaScript.\n");
75 si->inst_->PostMessage(exit_message);
76 free(exit_message);
77 exit_message = si->inst_->exit_message_ = NULL;
78 }
79
80 // Clean up StartInfo.
67 for (uint32_t i = 0; i < si->argc_; i++) { 81 for (uint32_t i = 0; i < si->argc_; i++) {
68 delete[] si->argv_[i]; 82 delete[] si->argv_[i];
69 } 83 }
70 delete[] si->argv_; 84 delete[] si->argv_;
71 delete si; 85 delete si;
72 86
73 // Exit the entire process once the 'main' thread returns. 87
74 // The error code will be available to javascript via 88 if (should_exit) {
75 // the exitcode paramater of the crash event. 89 // Exit the entire process once the 'main' thread returns.
76 exit(ret); 90 // The error code will be available to javascript via
91 // the exitcode parameter of the crash event.
92 exit(ret);
93 }
94
77 return NULL; 95 return NULL;
78 } 96 }
79 97
80 // The default implementation supports running a 'C' main. 98 // The default implementation supports running a 'C' main.
81 int PSInstance::MainThread(int argc, char *argv[]) { 99 int PSInstance::MainThread(int argc, char* argv[]) {
82 if (!main_cb_) { 100 if (!main_cb_) {
83 Error("No main defined.\n"); 101 Error("No main defined.\n");
84 return 0; 102 return 0;
85 } 103 }
86 104
87 Trace("Starting MAIN.\n"); 105 Trace("Starting MAIN.\n");
88 int ret = main_cb_(argc, argv); 106 int ret = main_cb_(argc, argv);
89 Log("Main thread returned with %d.\n", ret); 107 Log("Main thread returned with %d.\n", ret);
108
90 return ret; 109 return ret;
91 } 110 }
92 111
93 PSInstance::PSInstance(PP_Instance instance) 112 PSInstance::PSInstance(PP_Instance instance)
94 : pp::Instance(instance), 113 : pp::Instance(instance),
95 pp::MouseLock(this), 114 pp::MouseLock(this),
96 pp::Graphics3DClient(this), 115 pp::Graphics3DClient(this),
97 main_loop_(NULL), 116 main_loop_(NULL),
98 events_enabled_(PSE_NONE), 117 events_enabled_(PSE_NONE),
99 verbosity_(PSV_WARN), 118 verbosity_(PSV_WARN),
100 tty_fd_(-1), 119 tty_fd_(-1),
101 tty_prefix_(NULL) { 120 tty_prefix_(NULL),
121 exit_message_(NULL) {
102 // Set the single Instance object 122 // Set the single Instance object
103 s_InstanceObject = this; 123 s_InstanceObject = this;
104 124
105 #ifdef NACL_SDK_DEBUG 125 #ifdef NACL_SDK_DEBUG
106 SetVerbosity(PSV_LOG); 126 SetVerbosity(PSV_LOG);
107 #endif 127 #endif
108 128
109 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | 129 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE |
110 PP_INPUTEVENT_CLASS_KEYBOARD | 130 PP_INPUTEVENT_CLASS_KEYBOARD |
111 PP_INPUTEVENT_CLASS_WHEEL | 131 PP_INPUTEVENT_CLASS_WHEEL |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 240
221 tioc_nacl_output handler; 241 tioc_nacl_output handler;
222 handler.handler = TtyOutputHandlerStatic; 242 handler.handler = TtyOutputHandlerStatic;
223 handler.user_data = this; 243 handler.user_data = this;
224 ioctl(tty_fd_, TIOCNACLOUTPUT, reinterpret_cast<char*>(&handler)); 244 ioctl(tty_fd_, TIOCNACLOUTPUT, reinterpret_cast<char*>(&handler));
225 } else { 245 } else {
226 Error("Failed to open /dev/tty.\n"); 246 Error("Failed to open /dev/tty.\n");
227 } 247 }
228 } 248 }
229 249
250 const char* exit_message = getenv("PS_EXIT_MESSAGE");
251 if (exit_message) {
252 exit_message_ = strdup(exit_message);
253 }
254
230 // Set line buffering on stdout and stderr 255 // Set line buffering on stdout and stderr
231 #if !defined(WIN32) 256 #if !defined(WIN32)
232 setvbuf(stderr, NULL, _IOLBF, 0); 257 setvbuf(stderr, NULL, _IOLBF, 0);
233 setvbuf(stdout, NULL, _IOLBF, 0); 258 setvbuf(stdout, NULL, _IOLBF, 0);
234 #endif 259 #endif
235 return true; 260 return true;
236 } 261 }
237 262
238 void PSInstance::SetVerbosity(Verbosity verbosity) { 263 void PSInstance::SetVerbosity(Verbosity verbosity) {
239 verbosity_ = verbosity; 264 verbosity_ = verbosity;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 530
506 void PSInstance::Graphics3DContextLost() { 531 void PSInstance::Graphics3DContextLost() {
507 Log("Graphics3DContextLost\n"); 532 Log("Graphics3DContextLost\n");
508 PostEvent(PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST); 533 PostEvent(PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST);
509 } 534 }
510 535
511 void PSInstance::MouseLockLost() { 536 void PSInstance::MouseLockLost() {
512 Log("MouseLockLost\n"); 537 Log("MouseLockLost\n");
513 PostEvent(PSE_MOUSELOCK_MOUSELOCKLOST); 538 PostEvent(PSE_MOUSELOCK_MOUSELOCKLOST);
514 } 539 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/ppapi_simple/ps_instance.h ('k') | native_client_sdk/src/tests/nacl_io_socket_test/example.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698