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

Side by Side Diff: runtime/bin/vmservice_impl.cc

Issue 584023004: Service isolate rework (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/vmservice_impl.h" 5 #include "bin/vmservice_impl.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 (num_arguments == entry.num_arguments)) { 123 (num_arguments == entry.num_arguments)) {
124 return entry.function; 124 return entry.function;
125 } 125 }
126 } 126 }
127 return NULL; 127 return NULL;
128 } 128 }
129 129
130 130
131 const char* VmService::error_msg_ = NULL; 131 const char* VmService::error_msg_ = NULL;
132 132
133 bool VmService::Start(const char *server_ip, intptr_t server_port) {
134 bool r = _Start(server_ip, server_port);
135 if (!r) {
136 return r;
137 }
138 // Start processing messages in a new thread.
139 Thread::Start(ThreadMain, static_cast<uword>(NULL));
140 return true;
141 }
142 133
143 134 bool VmService::SetupIsolate(const char* server_ip, intptr_t server_port) {
144 bool VmService::_Start(const char *server_ip, intptr_t server_port) { 135 Dart_Isolate isolate = Dart_CurrentIsolate();
145 ASSERT(Dart_CurrentIsolate() == NULL); 136 ASSERT(isolate != NULL);
146 Dart_Isolate isolate = Dart_GetServiceIsolate(NULL); 137 // Install our own library tag handler.
147 if (isolate == NULL) {
148 error_msg_ = "Dart_GetServiceIsolate failed.";
149 return false;
150 }
151 Dart_EnterIsolate(isolate);
152 Dart_EnterScope();
153 // Install our own library tag handler.
154 Dart_SetLibraryTagHandler(LibraryTagHandler); 138 Dart_SetLibraryTagHandler(LibraryTagHandler);
155 Dart_Handle result; 139 Dart_Handle result;
156 Dart_Handle library; 140 Dart_Handle library;
157 library = LoadScript(kVMServiceIOLibraryScriptResourceName); 141 library = LoadScript(kVMServiceIOLibraryScriptResourceName);
158 // Expect a library. 142 // Expect a library.
159 ASSERT(library != Dart_Null()); 143 ASSERT(library != Dart_Null());
160 SHUTDOWN_ON_ERROR(library); 144 SHUTDOWN_ON_ERROR(library);
161 result = Dart_FinalizeLoading(false); 145 result = Dart_FinalizeLoading(false);
162 ASSERT(!Dart_IsError(result)); 146 ASSERT(!Dart_IsError(result));
163 Dart_ExitScope(); 147 Dart_ExitScope();
164 Dart_ExitIsolate(); 148 Dart_ExitIsolate();
165 bool retval = Dart_IsolateMakeRunnable(isolate); 149 bool retval = Dart_IsolateMakeRunnable(isolate);
166 if (!retval) { 150 if (!retval) {
167 Dart_EnterIsolate(isolate); 151 Dart_EnterIsolate(isolate);
168 Dart_ShutdownIsolate(); 152 Dart_ShutdownIsolate();
169 error_msg_ = "Invalid isolate state - Unable to make it runnable."; 153 error_msg_ = "Invalid isolate state - Unable to make it runnable.";
170 return false; 154 return false;
171 } 155 }
172 156
173 Dart_EnterIsolate(isolate); 157 Dart_EnterIsolate(isolate);
174 Dart_EnterScope(); 158 Dart_EnterScope();
175 library = Dart_RootLibrary(); 159 library = Dart_RootLibrary();
160 SHUTDOWN_ON_ERROR(library);
176 result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL); 161 result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL);
177 ASSERT(!Dart_IsError(result)); 162 SHUTDOWN_ON_ERROR(result);
178 // Set requested TCP port. 163 // Set requested TCP port.
179 DartUtils::SetStringField(library, "_ip", server_ip); 164 DartUtils::SetStringField(library, "_ip", server_ip);
180 // If we have a port specified, start the server immediately. 165 // If we have a port specified, start the server immediately.
181 bool auto_start = server_port >= 0; 166 bool auto_start = server_port >= 0;
182 if (server_port < 0) { 167 if (server_port < 0) {
183 // Adjust server_port to port 0 which will result in the first available 168 // Adjust server_port to port 0 which will result in the first available
184 // port when the HTTP server is started. 169 // port when the HTTP server is started.
185 server_port = 0; 170 server_port = 0;
186 } 171 }
187 // Set initial state. 172 // Set initial state.
188 DartUtils::SetIntegerField(library, "_port", server_port); 173 DartUtils::SetIntegerField(library, "_port", server_port);
189 Dart_SetField(library, 174 result = Dart_SetField(library,
190 DartUtils::NewString("_autoStart"), 175 DartUtils::NewString("_autoStart"),
191 Dart_NewBoolean(auto_start)); 176 Dart_NewBoolean(auto_start));
177 SHUTDOWN_ON_ERROR(result);
192 // We cannot register for signals on windows. 178 // We cannot register for signals on windows.
193 #if defined(TARGET_OS_WINDOWS) 179 #if defined(TARGET_OS_WINDOWS)
194 Dart_Handle is_windows = Dart_True(); 180 Dart_Handle is_windows = Dart_True();
195 #else 181 #else
196 Dart_Handle is_windows = Dart_False(); 182 Dart_Handle is_windows = Dart_False();
197 #endif 183 #endif
198 Dart_SetField(library, DartUtils::NewString("_isWindows"), is_windows); 184 result =
199 185 Dart_SetField(library, DartUtils::NewString("_isWindows"), is_windows);
186 SHUTDOWN_ON_ERROR(result);
200 187
201 // Get _getWatchSignalInternal from dart:io. 188 // Get _getWatchSignalInternal from dart:io.
202 Dart_Handle dart_io_str = Dart_NewStringFromCString(DartUtils::kIOLibURL); 189 Dart_Handle dart_io_str = Dart_NewStringFromCString(DartUtils::kIOLibURL);
190 SHUTDOWN_ON_ERROR(dart_io_str);
203 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str); 191 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str);
192 SHUTDOWN_ON_ERROR(io_lib);
204 Dart_Handle function_name = 193 Dart_Handle function_name =
205 Dart_NewStringFromCString("_getWatchSignalInternal"); 194 Dart_NewStringFromCString("_getWatchSignalInternal");
195 SHUTDOWN_ON_ERROR(function_name);
206 Dart_Handle signal_watch = Dart_Invoke(io_lib, function_name, 0, NULL); 196 Dart_Handle signal_watch = Dart_Invoke(io_lib, function_name, 0, NULL);
207 // Invoke main. 197 SHUTDOWN_ON_ERROR(signal_watch);
208 result = Dart_Invoke(library, DartUtils::NewString("main"), 1, &signal_watch); 198 Dart_Handle field_name = Dart_NewStringFromCString("_signalWatch");
209 SHUTDOWN_ON_ERROR(result); 199 SHUTDOWN_ON_ERROR(field_name);
210 200 result =
211 Dart_ExitScope(); 201 Dart_SetField(library, field_name, signal_watch);
212 Dart_ExitIsolate(); 202 SHUTDOWN_ON_ERROR(field_name);
213
214 return true; 203 return true;
215 } 204 }
216 205
217 206
218 const char* VmService::GetErrorMessage() { 207 const char* VmService::GetErrorMessage() {
219 return error_msg_ == NULL ? "No error." : error_msg_; 208 return error_msg_ == NULL ? "No error." : error_msg_;
220 } 209 }
221 210
222 211
223 Dart_Handle VmService::GetSource(const char* name) { 212 Dart_Handle VmService::GetSource(const char* name) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 return url; 320 return url;
332 } 321 }
333 Dart_Handle source = GetSource(url_string); 322 Dart_Handle source = GetSource(url_string);
334 if (Dart_IsError(source)) { 323 if (Dart_IsError(source)) {
335 return source; 324 return source;
336 } 325 }
337 return Dart_LoadSource(library, url, source, 0, 0); 326 return Dart_LoadSource(library, url, source, 0, 0);
338 } 327 }
339 328
340 329
341 void VmService::ThreadMain(uword parameters) {
342 ASSERT(Dart_CurrentIsolate() == NULL);
343 Dart_Isolate service_isolate = Dart_GetServiceIsolate(NULL);
344 Dart_EnterIsolate(service_isolate);
345 Dart_EnterScope();
346 Dart_Handle result = Dart_RunLoop();
347 if (Dart_IsError(result)) {
348 printf("Service exited with an error:\n%s\n", Dart_GetError(result));
349 }
350 Dart_ExitScope();
351 Dart_ExitIsolate();
352 }
353
354
355
356 } // namespace bin 330 } // namespace bin
357 } // namespace dart 331 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698