| 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" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return &__service_bin_resources_[0]; | 84 return &__service_bin_resources_[0]; |
| 85 } | 85 } |
| 86 | 86 |
| 87 DISALLOW_ALLOCATION(); | 87 DISALLOW_ALLOCATION(); |
| 88 DISALLOW_IMPLICIT_CONSTRUCTORS(Resources); | 88 DISALLOW_IMPLICIT_CONSTRUCTORS(Resources); |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 | 91 |
| 92 void NotifyServerState(Dart_NativeArguments args) { | 92 void NotifyServerState(Dart_NativeArguments args) { |
| 93 Dart_EnterScope(); | 93 Dart_EnterScope(); |
| 94 const char* ip_chars; | 94 const char* uri_chars; |
| 95 Dart_Handle ip_arg = Dart_GetNativeArgument(args, 0); | 95 Dart_Handle uri_arg = Dart_GetNativeArgument(args, 0); |
| 96 if (Dart_IsError(ip_arg)) { | 96 if (Dart_IsError(uri_arg)) { |
| 97 VmService::SetServerIPAndPort("", 0); | 97 VmService::SetServerAddress(""); |
| 98 Dart_ExitScope(); | 98 Dart_ExitScope(); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 Dart_Handle result = Dart_StringToCString(ip_arg, &ip_chars); | 101 Dart_Handle result = Dart_StringToCString(uri_arg, &uri_chars); |
| 102 if (Dart_IsError(result)) { | 102 if (Dart_IsError(result)) { |
| 103 VmService::SetServerIPAndPort("", 0); | 103 VmService::SetServerAddress(""); |
| 104 Dart_ExitScope(); | 104 Dart_ExitScope(); |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 Dart_Handle port_arg = Dart_GetNativeArgument(args, 1); | 107 VmService::SetServerAddress(uri_chars); |
| 108 if (Dart_IsError(port_arg)) { | |
| 109 VmService::SetServerIPAndPort("", 0); | |
| 110 Dart_ExitScope(); | |
| 111 return; | |
| 112 } | |
| 113 int64_t port = DartUtils::GetInt64ValueCheckRange(port_arg, 0, 65535); | |
| 114 VmService::SetServerIPAndPort(ip_chars, port); | |
| 115 Dart_ExitScope(); | 108 Dart_ExitScope(); |
| 116 } | 109 } |
| 117 | 110 |
| 118 | 111 |
| 119 static void Shutdown(Dart_NativeArguments args) { | 112 static void Shutdown(Dart_NativeArguments args) { |
| 120 // NO-OP. | 113 // NO-OP. |
| 121 } | 114 } |
| 122 | 115 |
| 123 | 116 |
| 124 struct VmServiceIONativeEntry { | 117 struct VmServiceIONativeEntry { |
| 125 const char* name; | 118 const char* name; |
| 126 int num_arguments; | 119 int num_arguments; |
| 127 Dart_NativeFunction function; | 120 Dart_NativeFunction function; |
| 128 }; | 121 }; |
| 129 | 122 |
| 130 | 123 |
| 131 static VmServiceIONativeEntry _VmServiceIONativeEntries[] = { | 124 static VmServiceIONativeEntry _VmServiceIONativeEntries[] = { |
| 132 {"VMServiceIO_NotifyServerState", 2, NotifyServerState}, | 125 {"VMServiceIO_NotifyServerState", 1, NotifyServerState}, |
| 133 {"VMServiceIO_Shutdown", 0, Shutdown }, | 126 {"VMServiceIO_Shutdown", 0, Shutdown }, |
| 134 }; | 127 }; |
| 135 | 128 |
| 136 | 129 |
| 137 static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name, | 130 static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name, |
| 138 int num_arguments, | 131 int num_arguments, |
| 139 bool* auto_setup_scope) { | 132 bool* auto_setup_scope) { |
| 140 const char* function_name = NULL; | 133 const char* function_name = NULL; |
| 141 Dart_Handle result = Dart_StringToCString(name, &function_name); | 134 Dart_Handle result = Dart_StringToCString(name, &function_name); |
| 142 ASSERT(!Dart_IsError(result)); | 135 ASSERT(!Dart_IsError(result)); |
| 143 ASSERT(function_name != NULL); | 136 ASSERT(function_name != NULL); |
| 144 *auto_setup_scope = true; | 137 *auto_setup_scope = true; |
| 145 intptr_t n = | 138 intptr_t n = |
| 146 sizeof(_VmServiceIONativeEntries) / sizeof(_VmServiceIONativeEntries[0]); | 139 sizeof(_VmServiceIONativeEntries) / sizeof(_VmServiceIONativeEntries[0]); |
| 147 for (intptr_t i = 0; i < n; i++) { | 140 for (intptr_t i = 0; i < n; i++) { |
| 148 VmServiceIONativeEntry entry = _VmServiceIONativeEntries[i]; | 141 VmServiceIONativeEntry entry = _VmServiceIONativeEntries[i]; |
| 149 if ((strcmp(function_name, entry.name) == 0) && | 142 if ((strcmp(function_name, entry.name) == 0) && |
| 150 (num_arguments == entry.num_arguments)) { | 143 (num_arguments == entry.num_arguments)) { |
| 151 return entry.function; | 144 return entry.function; |
| 152 } | 145 } |
| 153 } | 146 } |
| 154 return NULL; | 147 return NULL; |
| 155 } | 148 } |
| 156 | 149 |
| 157 | 150 |
| 158 const char* VmService::error_msg_ = NULL; | 151 const char* VmService::error_msg_ = NULL; |
| 159 char VmService::server_ip_[kServerIpStringBufferSize]; | 152 char VmService::server_uri_[kServerUriStringBufferSize]; |
| 160 intptr_t VmService::server_port_ = 0; | |
| 161 | 153 |
| 162 | 154 |
| 163 bool VmService::LoadForGenPrecompiled() { | 155 bool VmService::LoadForGenPrecompiled() { |
| 164 Dart_Handle result; | 156 Dart_Handle result; |
| 165 Dart_SetLibraryTagHandler(LibraryTagHandler); | 157 Dart_SetLibraryTagHandler(LibraryTagHandler); |
| 166 Dart_Handle library = LoadLibrary(kVMServiceIOLibraryScriptResourceName); | 158 Dart_Handle library = LoadLibrary(kVMServiceIOLibraryScriptResourceName); |
| 167 ASSERT(library != Dart_Null()); | 159 ASSERT(library != Dart_Null()); |
| 168 SHUTDOWN_ON_ERROR(library); | 160 SHUTDOWN_ON_ERROR(library); |
| 169 result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL); | 161 result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL); |
| 170 SHUTDOWN_ON_ERROR(result); | 162 SHUTDOWN_ON_ERROR(result); |
| 171 result = Dart_FinalizeLoading(false); | 163 result = Dart_FinalizeLoading(false); |
| 172 SHUTDOWN_ON_ERROR(result); | 164 SHUTDOWN_ON_ERROR(result); |
| 173 return true; | 165 return true; |
| 174 } | 166 } |
| 175 | 167 |
| 176 | 168 |
| 177 bool VmService::Setup(const char* server_ip, | 169 bool VmService::Setup(const char* server_ip, |
| 178 intptr_t server_port, | 170 intptr_t server_port, |
| 179 bool running_precompiled, | 171 bool running_precompiled, |
| 180 bool dev_mode_server) { | 172 bool dev_mode_server) { |
| 181 Dart_Isolate isolate = Dart_CurrentIsolate(); | 173 Dart_Isolate isolate = Dart_CurrentIsolate(); |
| 182 ASSERT(isolate != NULL); | 174 ASSERT(isolate != NULL); |
| 183 SetServerIPAndPort("", 0); | 175 SetServerAddress(""); |
| 184 | 176 |
| 185 Dart_Handle result; | 177 Dart_Handle result; |
| 186 | 178 |
| 187 // Prepare builtin and its dependent libraries for use to resolve URIs. | 179 // Prepare builtin and its dependent libraries for use to resolve URIs. |
| 188 // Set up various closures, e.g: printing, timers etc. | 180 // Set up various closures, e.g: printing, timers etc. |
| 189 // Set up 'package root' for URI resolution. | 181 // Set up 'package root' for URI resolution. |
| 190 result = DartUtils::PrepareForScriptLoading(true, false); | 182 result = DartUtils::PrepareForScriptLoading(true, false); |
| 191 SHUTDOWN_ON_ERROR(result); | 183 SHUTDOWN_ON_ERROR(result); |
| 192 | 184 |
| 193 if (running_precompiled) { | 185 if (running_precompiled) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 SHUTDOWN_ON_ERROR(field_name); | 275 SHUTDOWN_ON_ERROR(field_name); |
| 284 return true; | 276 return true; |
| 285 } | 277 } |
| 286 | 278 |
| 287 | 279 |
| 288 const char* VmService::GetErrorMessage() { | 280 const char* VmService::GetErrorMessage() { |
| 289 return (error_msg_ == NULL) ? "No error." : error_msg_; | 281 return (error_msg_ == NULL) ? "No error." : error_msg_; |
| 290 } | 282 } |
| 291 | 283 |
| 292 | 284 |
| 293 void VmService::SetServerIPAndPort(const char* ip, intptr_t port) { | 285 void VmService::SetServerAddress(const char* server_uri) { |
| 294 if (ip == NULL) { | 286 if (server_uri == NULL) { |
| 295 ip = ""; | 287 server_uri = ""; |
| 296 } | 288 } |
| 297 strncpy(server_ip_, ip, kServerIpStringBufferSize); | 289 const intptr_t server_uri_len = strlen(server_uri); |
| 298 server_ip_[kServerIpStringBufferSize - 1] = '\0'; | 290 if (server_uri_len >= (kServerUriStringBufferSize - 1)) { |
| 299 server_port_ = port; | 291 FATAL1("vm-service: Server URI exceeded length: %s\n", server_uri); |
| 292 } |
| 293 strncpy(server_uri_, server_uri, kServerUriStringBufferSize); |
| 294 server_uri_[kServerUriStringBufferSize - 1] = '\0'; |
| 300 } | 295 } |
| 301 | 296 |
| 302 | 297 |
| 303 Dart_Handle VmService::GetSource(const char* name) { | 298 Dart_Handle VmService::GetSource(const char* name) { |
| 304 const intptr_t kBufferSize = 512; | 299 const intptr_t kBufferSize = 512; |
| 305 char buffer[kBufferSize]; | 300 char buffer[kBufferSize]; |
| 306 snprintf(&buffer[0], kBufferSize-1, "%s/%s", kLibrarySourceNamePrefix, name); | 301 snprintf(&buffer[0], kBufferSize-1, "%s/%s", kLibrarySourceNamePrefix, name); |
| 307 const char* vmservice_source = NULL; | 302 const char* vmservice_source = NULL; |
| 308 int r = Resources::ResourceLookup(buffer, &vmservice_source); | 303 int r = Resources::ResourceLookup(buffer, &vmservice_source); |
| 309 if (r == Resources::kNoSuchInstance) { | 304 if (r == Resources::kNoSuchInstance) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 Dart_Handle source = GetSource(url_string); | 362 Dart_Handle source = GetSource(url_string); |
| 368 if (Dart_IsError(source)) { | 363 if (Dart_IsError(source)) { |
| 369 return source; | 364 return source; |
| 370 } | 365 } |
| 371 return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0); | 366 return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0); |
| 372 } | 367 } |
| 373 | 368 |
| 374 | 369 |
| 375 } // namespace bin | 370 } // namespace bin |
| 376 } // namespace dart | 371 } // namespace dart |
| OLD | NEW |