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

Side by Side Diff: native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc

Issue 11592003: Add support for simple run of "main" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace missing stdio Created 8 years 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 <fcntl.h>
5 #include <pthread.h> 6 #include <pthread.h>
6 #include <stdio.h> 7 #include <stdio.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
7 10
8 #include <cstdlib> 11 #include <cstdlib>
9 #include <cstring> 12 #include <cstring>
10 #include <map> 13 #include <map>
11 #include <string> 14 #include <string>
12 #include <vector> 15 #include <vector>
13 16
17 #include "nacl_mounts/kernel_intercept.h"
18
14 #include "ppapi/cpp/input_event.h" 19 #include "ppapi/cpp/input_event.h"
15 #include "ppapi/cpp/rect.h" 20 #include "ppapi/cpp/rect.h"
16 #include "ppapi/cpp/size.h" 21 #include "ppapi/cpp/size.h"
17 #include "ppapi/cpp/var.h" 22 #include "ppapi/cpp/var.h"
18 23
19 #include "ppapi_main/ppapi_instance.h" 24 #include "ppapi_main/ppapi_instance.h"
20 #include "ppapi_main/ppapi_main.h" 25 #include "ppapi_main/ppapi_main.h"
21 26
27
22 struct StartInfo { 28 struct StartInfo {
23 uint32_t argc_; 29 uint32_t argc_;
24 const char** argv_; 30 const char** argv_;
25 }; 31 };
26 32
27 static void* StartMain(void *info) { 33 static void* StartMain(void *info) {
28 StartInfo* si = static_cast<StartInfo*>(info); 34 StartInfo* si = static_cast<StartInfo*>(info);
29 35
30 if (NULL != info) { 36 if (NULL != info) {
31 ppapi_main(si->argc_, si->argv_); 37 ppapi_main(si->argc_, si->argv_);
(...skipping 28 matching lines...) Expand all
60 PPAPIInstance::~PPAPIInstance() { 66 PPAPIInstance::~PPAPIInstance() {
61 } 67 }
62 68
63 bool PPAPIInstance::Init(uint32_t arg, 69 bool PPAPIInstance::Init(uint32_t arg,
64 const char* argn[], 70 const char* argn[],
65 const char* argv[]) { 71 const char* argv[]) {
66 StartInfo* si = new StartInfo; 72 StartInfo* si = new StartInfo;
67 73
68 si->argc_ = 1; 74 si->argc_ = 1;
69 si->argv_ = new const char *[arg*2+1]; 75 si->argv_ = new const char *[arg*2+1];
70 76 si->argv_[0] = NULL;
71 char *name = new char[5];
72 strcpy(name, "NEXE");
73 si->argv_[0] = name;
74 77
75 for (uint32_t i=0; i < arg; i++) { 78 for (uint32_t i=0; i < arg; i++) {
76 // If we start with PM prefix set the instance argument map 79 // If we start with PM prefix set the instance argument map
77 if (0 == strncmp(argn[i], "PM_", 3)) { 80 if (0 == strncmp(argn[i], "PM_", 3)) {
78 std::string key = argn[i]; 81 std::string key = argn[i];
79 std::string val = argv[i]; 82 std::string val = argv[i];
80 properties_[key] = val; 83 properties_[key] = val;
84 continue;
81 } 85 }
82 // Otherwise turn it into arguments 86
87 // If this is the 'src' tag, then get the NMF name.
88 if (!strcmp("src", argn[i])) {
89 char *name = new char[strlen(argv[i]) + 1];
90 strcpy(name, argv[i]);
91 si->argv_[0] = name;
92 }
83 else { 93 else {
94 // Otherwise turn it into arguments
84 char *key = new char[strlen(argn[i]) + 3]; 95 char *key = new char[strlen(argn[i]) + 3];
85 key[0] = '-'; 96 key[0] = '-';
86 key[1] = '-'; 97 key[1] = '-';
87 strcpy(&key[2], argn[i]); 98 strcpy(&key[2], argn[i]);
88 99
89 si->argv_[si->argc_++] = key; 100 si->argv_[si->argc_++] = key;
90 if (argv[i] && argv[i][0]) { 101 if (argv[i] && argv[i][0]) {
91 char *val = new char[strlen(argv[i]) + 1]; 102 char *val = new char[strlen(argv[i]) + 1];
92 strcpy(val, argv[i]); 103 strcpy(val, argv[i]);
93 si->argv_[si->argc_++] = val; 104 si->argv_[si->argc_++] = val;
94 } 105 }
95 } 106 }
96 } 107 }
97 108
98 // ki_init(); 109 // If src was not found, set the first arg to something
110 if (NULL == si->argv_[0]) {
111 char *name = new char[5];
112 strcpy(name, "NMF?");
113 si->argv_[0] = name;
114 }
99 115
100 if (ProcessProperties()) { 116 if (ProcessProperties()) {
101 pthread_t main_thread; 117 pthread_t main_thread;
102 int ret = pthread_create(&main_thread, NULL, StartMain, 118 int ret = pthread_create(&main_thread, NULL, StartMain,
103 static_cast<void*>(si)); 119 static_cast<void*>(si));
104 return ret == 0; 120 return ret == 0;
105 } 121 }
106 122
107 return false; 123 return false;
108 } 124 }
109 125
110 const char* PPAPIInstance::GetProperty(const char* key, const char* def) { 126 const char* PPAPIInstance::GetProperty(const char* key, const char* def) {
111 PropteryMap_t::iterator it = properties_.find(key); 127 PropteryMap_t::iterator it = properties_.find(key);
112 if (it != properties_.end()) { 128 if (it != properties_.end()) {
113 return it->second.c_str(); 129 return it->second.c_str();
114 } 130 }
115 return def; 131 return def;
116 } 132 }
117 133
118 bool PPAPIInstance::ProcessProperties() { 134 bool PPAPIInstance::ProcessProperties() {
119 #if 0 135 const char* stdin_path = GetProperty("PM_STDIO", "/dev/null");
120 const char* stdin_path = GetProperty("PM_STDIO", "/dev/tty"); 136 const char* stdout_path = GetProperty("PM_STDOUT", "/dev/tty");
121 const char* stdout_path = GetProperty("PM_STDOUT", "/dev/console0");
122 const char* stderr_path = GetProperty("PM_STDERR", "/dev/console3"); 137 const char* stderr_path = GetProperty("PM_STDERR", "/dev/console3");
123 #endif 138
139 ki_init_ppapi(NULL, PPAPI_GetInstanceId(), PPAPI_GetInterface);
140 int f1 = open(stdin_path, O_RDONLY);
141 int f2 = open(stdout_path, O_WRONLY);
142 int f3 = open(stderr_path, O_WRONLY);
143
144 return true;
124 } 145 }
125 146
126 void PPAPIInstance::HandleMessage(const pp::Var& message) { 147 void PPAPIInstance::HandleMessage(const pp::Var& message) {
127 } 148 }
128 149
129 150
130 bool PPAPIInstance::HandleInputEvent(const pp::InputEvent& event) { 151 bool PPAPIInstance::HandleInputEvent(const pp::InputEvent& event) {
131 switch (event.GetType()) { 152 switch (event.GetType()) {
132 case PP_INPUTEVENT_TYPE_UNDEFINED: 153 case PP_INPUTEVENT_TYPE_UNDEFINED:
133 break; 154 break;
(...skipping 26 matching lines...) Expand all
160 } 181 }
161 return false; 182 return false;
162 } 183 }
163 184
164 void PPAPIInstance::DidChangeView(const pp::View&) { 185 void PPAPIInstance::DidChangeView(const pp::View&) {
165 } 186 }
166 187
167 void PPAPIInstance::DidChangeFocus(bool focus) { 188 void PPAPIInstance::DidChangeFocus(bool focus) {
168 has_focus_ = focus; 189 has_focus_ = focus;
169 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698