| OLD | NEW |
| 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" |
| 11 #include "bin/isolate_data.h" | 11 #include "bin/isolate_data.h" |
| 12 #include "bin/platform.h" | 12 #include "bin/platform.h" |
| 13 #include "bin/thread.h" | 13 #include "bin/thread.h" |
| 14 #include "bin/utils.h" | 14 #include "bin/utils.h" |
| 15 #include "platform/text_buffer.h" | 15 #include "platform/text_buffer.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 namespace bin { | 18 namespace bin { |
| 19 | 19 |
| 20 #define RETURN_ERROR_HANDLE(handle) \ | 20 #define RETURN_ERROR_HANDLE(handle) \ |
| 21 if (Dart_IsError(handle)) { \ | 21 if (Dart_IsError(handle)) { \ |
| 22 return handle; \ | 22 return handle; \ |
| 23 } | 23 } |
| 24 | 24 |
| 25 #define SHUTDOWN_ON_ERROR(handle) \ | 25 #define SHUTDOWN_ON_ERROR(handle) \ |
| 26 if (Dart_IsError(handle)) { \ | 26 if (Dart_IsError(handle)) { \ |
| 27 error_msg_ = strdup(Dart_GetError(handle)); \ | 27 error_msg_ = strdup(Dart_GetError(handle)); \ |
| 28 Dart_ExitScope(); \ | 28 Dart_ExitScope(); \ |
| 29 Dart_ShutdownIsolate(); \ | 29 Dart_ShutdownIsolate(); \ |
| 30 return false; \ | 30 return false; \ |
| 31 } | 31 } |
| 32 | 32 |
| 33 #define kLibrarySourceNamePrefix "/vmservice" | 33 #define kLibrarySourceNamePrefix "/vmservice" |
| 34 static const char* const kVMServiceIOLibraryUri = "dart:vmservice_io"; | 34 static const char* const kVMServiceIOLibraryUri = "dart:vmservice_io"; |
| 35 static const char* const kVMServiceIOLibraryScriptResourceName = | 35 static const char* const kVMServiceIOLibraryScriptResourceName = |
| 36 "vmservice_io.dart"; | 36 "vmservice_io.dart"; |
| 37 | 37 |
| 38 struct ResourcesEntry { | 38 struct ResourcesEntry { |
| 39 const char* path_; | 39 const char* path_; |
| 40 const char* resource_; | 40 const char* resource_; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 | 116 |
| 117 struct VmServiceIONativeEntry { | 117 struct VmServiceIONativeEntry { |
| 118 const char* name; | 118 const char* name; |
| 119 int num_arguments; | 119 int num_arguments; |
| 120 Dart_NativeFunction function; | 120 Dart_NativeFunction function; |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 | 123 |
| 124 static VmServiceIONativeEntry _VmServiceIONativeEntries[] = { | 124 static VmServiceIONativeEntry _VmServiceIONativeEntries[] = { |
| 125 {"VMServiceIO_NotifyServerState", 1, NotifyServerState}, | 125 {"VMServiceIO_NotifyServerState", 1, NotifyServerState}, |
| 126 {"VMServiceIO_Shutdown", 0, Shutdown }, | 126 {"VMServiceIO_Shutdown", 0, Shutdown}, |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 | 129 |
| 130 static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name, | 130 static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name, |
| 131 int num_arguments, | 131 int num_arguments, |
| 132 bool* auto_setup_scope) { | 132 bool* auto_setup_scope) { |
| 133 const char* function_name = NULL; | 133 const char* function_name = NULL; |
| 134 Dart_Handle result = Dart_StringToCString(name, &function_name); | 134 Dart_Handle result = Dart_StringToCString(name, &function_name); |
| 135 ASSERT(!Dart_IsError(result)); | 135 ASSERT(!Dart_IsError(result)); |
| 136 ASSERT(function_name != NULL); | 136 ASSERT(function_name != NULL); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 SHUTDOWN_ON_ERROR(result); | 223 SHUTDOWN_ON_ERROR(result); |
| 224 // If we have a port specified, start the server immediately. | 224 // If we have a port specified, start the server immediately. |
| 225 bool auto_start = server_port >= 0; | 225 bool auto_start = server_port >= 0; |
| 226 if (server_port < 0) { | 226 if (server_port < 0) { |
| 227 // Adjust server_port to port 0 which will result in the first available | 227 // Adjust server_port to port 0 which will result in the first available |
| 228 // port when the HTTP server is started. | 228 // port when the HTTP server is started. |
| 229 server_port = 0; | 229 server_port = 0; |
| 230 } | 230 } |
| 231 result = DartUtils::SetIntegerField(library, "_port", server_port); | 231 result = DartUtils::SetIntegerField(library, "_port", server_port); |
| 232 SHUTDOWN_ON_ERROR(result); | 232 SHUTDOWN_ON_ERROR(result); |
| 233 result = Dart_SetField(library, | 233 result = Dart_SetField(library, DartUtils::NewString("_autoStart"), |
| 234 DartUtils::NewString("_autoStart"), | |
| 235 Dart_NewBoolean(auto_start)); | 234 Dart_NewBoolean(auto_start)); |
| 236 SHUTDOWN_ON_ERROR(result); | 235 SHUTDOWN_ON_ERROR(result); |
| 237 result = Dart_SetField(library, | 236 result = Dart_SetField(library, DartUtils::NewString("_originCheckDisabled"), |
| 238 DartUtils::NewString("_originCheckDisabled"), | |
| 239 Dart_NewBoolean(dev_mode_server)); | 237 Dart_NewBoolean(dev_mode_server)); |
| 240 | 238 |
| 241 // Are we running on Windows? | 239 // Are we running on Windows? |
| 242 #if defined(TARGET_OS_WINDOWS) | 240 #if defined(TARGET_OS_WINDOWS) |
| 243 Dart_Handle is_windows = Dart_True(); | 241 Dart_Handle is_windows = Dart_True(); |
| 244 #else | 242 #else |
| 245 Dart_Handle is_windows = Dart_False(); | 243 Dart_Handle is_windows = Dart_False(); |
| 246 #endif | 244 #endif |
| 247 result = | 245 result = |
| 248 Dart_SetField(library, DartUtils::NewString("_isWindows"), is_windows); | 246 Dart_SetField(library, DartUtils::NewString("_isWindows"), is_windows); |
| 249 SHUTDOWN_ON_ERROR(result); | 247 SHUTDOWN_ON_ERROR(result); |
| 250 | 248 |
| 251 // Are we running on Fuchsia? | 249 // Are we running on Fuchsia? |
| 252 #if defined(TARGET_OS_FUCHSIA) | 250 #if defined(TARGET_OS_FUCHSIA) |
| 253 Dart_Handle is_fuchsia = Dart_True(); | 251 Dart_Handle is_fuchsia = Dart_True(); |
| 254 #else | 252 #else |
| 255 Dart_Handle is_fuchsia = Dart_False(); | 253 Dart_Handle is_fuchsia = Dart_False(); |
| 256 #endif | 254 #endif |
| 257 result = | 255 result = |
| 258 Dart_SetField(library, DartUtils::NewString("_isFuchsia"), is_fuchsia); | 256 Dart_SetField(library, DartUtils::NewString("_isFuchsia"), is_fuchsia); |
| 259 SHUTDOWN_ON_ERROR(result); | 257 SHUTDOWN_ON_ERROR(result); |
| 260 | 258 |
| 261 // Get _getWatchSignalInternal from dart:io. | 259 // Get _getWatchSignalInternal from dart:io. |
| 262 Dart_Handle dart_io_str = Dart_NewStringFromCString(DartUtils::kIOLibURL); | 260 Dart_Handle dart_io_str = Dart_NewStringFromCString(DartUtils::kIOLibURL); |
| 263 SHUTDOWN_ON_ERROR(dart_io_str); | 261 SHUTDOWN_ON_ERROR(dart_io_str); |
| 264 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str); | 262 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str); |
| 265 SHUTDOWN_ON_ERROR(io_lib); | 263 SHUTDOWN_ON_ERROR(io_lib); |
| 266 Dart_Handle function_name = | 264 Dart_Handle function_name = |
| 267 Dart_NewStringFromCString("_getWatchSignalInternal"); | 265 Dart_NewStringFromCString("_getWatchSignalInternal"); |
| 268 SHUTDOWN_ON_ERROR(function_name); | 266 SHUTDOWN_ON_ERROR(function_name); |
| 269 Dart_Handle signal_watch = Dart_Invoke(io_lib, function_name, 0, NULL); | 267 Dart_Handle signal_watch = Dart_Invoke(io_lib, function_name, 0, NULL); |
| 270 SHUTDOWN_ON_ERROR(signal_watch); | 268 SHUTDOWN_ON_ERROR(signal_watch); |
| 271 Dart_Handle field_name = Dart_NewStringFromCString("_signalWatch"); | 269 Dart_Handle field_name = Dart_NewStringFromCString("_signalWatch"); |
| 272 SHUTDOWN_ON_ERROR(field_name); | 270 SHUTDOWN_ON_ERROR(field_name); |
| 273 result = | 271 result = Dart_SetField(library, field_name, signal_watch); |
| 274 Dart_SetField(library, field_name, signal_watch); | |
| 275 SHUTDOWN_ON_ERROR(field_name); | 272 SHUTDOWN_ON_ERROR(field_name); |
| 276 return true; | 273 return true; |
| 277 } | 274 } |
| 278 | 275 |
| 279 | 276 |
| 280 const char* VmService::GetErrorMessage() { | 277 const char* VmService::GetErrorMessage() { |
| 281 return (error_msg_ == NULL) ? "No error." : error_msg_; | 278 return (error_msg_ == NULL) ? "No error." : error_msg_; |
| 282 } | 279 } |
| 283 | 280 |
| 284 | 281 |
| 285 void VmService::SetServerAddress(const char* server_uri) { | 282 void VmService::SetServerAddress(const char* server_uri) { |
| 286 if (server_uri == NULL) { | 283 if (server_uri == NULL) { |
| 287 server_uri = ""; | 284 server_uri = ""; |
| 288 } | 285 } |
| 289 const intptr_t server_uri_len = strlen(server_uri); | 286 const intptr_t server_uri_len = strlen(server_uri); |
| 290 if (server_uri_len >= (kServerUriStringBufferSize - 1)) { | 287 if (server_uri_len >= (kServerUriStringBufferSize - 1)) { |
| 291 FATAL1("vm-service: Server URI exceeded length: %s\n", server_uri); | 288 FATAL1("vm-service: Server URI exceeded length: %s\n", server_uri); |
| 292 } | 289 } |
| 293 strncpy(server_uri_, server_uri, kServerUriStringBufferSize); | 290 strncpy(server_uri_, server_uri, kServerUriStringBufferSize); |
| 294 server_uri_[kServerUriStringBufferSize - 1] = '\0'; | 291 server_uri_[kServerUriStringBufferSize - 1] = '\0'; |
| 295 } | 292 } |
| 296 | 293 |
| 297 | 294 |
| 298 Dart_Handle VmService::GetSource(const char* name) { | 295 Dart_Handle VmService::GetSource(const char* name) { |
| 299 const intptr_t kBufferSize = 512; | 296 const intptr_t kBufferSize = 512; |
| 300 char buffer[kBufferSize]; | 297 char buffer[kBufferSize]; |
| 301 snprintf(&buffer[0], kBufferSize-1, "%s/%s", kLibrarySourceNamePrefix, name); | 298 snprintf(&buffer[0], kBufferSize - 1, "%s/%s", kLibrarySourceNamePrefix, |
| 299 name); |
| 302 const char* vmservice_source = NULL; | 300 const char* vmservice_source = NULL; |
| 303 int r = Resources::ResourceLookup(buffer, &vmservice_source); | 301 int r = Resources::ResourceLookup(buffer, &vmservice_source); |
| 304 if (r == Resources::kNoSuchInstance) { | 302 if (r == Resources::kNoSuchInstance) { |
| 305 FATAL1("vm-service: Could not find embedded source file: %s ", buffer); | 303 FATAL1("vm-service: Could not find embedded source file: %s ", buffer); |
| 306 } | 304 } |
| 307 ASSERT(r != Resources::kNoSuchInstance); | 305 ASSERT(r != Resources::kNoSuchInstance); |
| 308 return Dart_NewStringFromCString(vmservice_source); | 306 return Dart_NewStringFromCString(vmservice_source); |
| 309 } | 307 } |
| 310 | 308 |
| 311 | 309 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 Dart_Handle source = GetSource(url_string); | 360 Dart_Handle source = GetSource(url_string); |
| 363 if (Dart_IsError(source)) { | 361 if (Dart_IsError(source)) { |
| 364 return source; | 362 return source; |
| 365 } | 363 } |
| 366 return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0); | 364 return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0); |
| 367 } | 365 } |
| 368 | 366 |
| 369 | 367 |
| 370 } // namespace bin | 368 } // namespace bin |
| 371 } // namespace dart | 369 } // namespace dart |
| OLD | NEW |