Chromium Code Reviews| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 return NULL; | 79 return NULL; |
| 80 } | 80 } |
| 81 static ResourcesEntry* ResourcesTable() { | 81 static ResourcesEntry* ResourcesTable() { |
| 82 return &__service_bin_resources_[0]; | 82 return &__service_bin_resources_[0]; |
| 83 } | 83 } |
| 84 | 84 |
| 85 DISALLOW_ALLOCATION(); | 85 DISALLOW_ALLOCATION(); |
| 86 DISALLOW_IMPLICIT_CONSTRUCTORS(Resources); | 86 DISALLOW_IMPLICIT_CONSTRUCTORS(Resources); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 | |
| 90 void TriggerResourceLoad(Dart_NativeArguments args) { | |
| 91 Dart_Handle library = Dart_RootLibrary(); | |
| 92 ASSERT(!Dart_IsError(library)); | |
| 93 Dart_Handle result = VmService::LoadResources(library); | |
| 94 ASSERT(!Dart_IsError(result)); | |
| 95 } | |
| 96 | |
| 97 | |
| 98 struct VmServiceIONativeEntry { | |
| 99 const char* name; | |
| 100 int num_arguments; | |
| 101 Dart_NativeFunction function; | |
| 102 }; | |
| 103 | |
| 104 | |
| 105 static VmServiceIONativeEntry _VmServiceIONativeEntries[] = { | |
| 106 {"VMServiceIO_TriggerResourceLoad", 0, TriggerResourceLoad}, | |
|
siva
2014/09/09 00:40:58
in resources.dart triggerResourceLoad is not decla
| |
| 107 }; | |
| 108 | |
| 109 | |
| 110 static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name, | |
| 111 int num_arguments, | |
| 112 bool* auto_setup_scope) { | |
| 113 const char* function_name = NULL; | |
| 114 Dart_Handle result = Dart_StringToCString(name, &function_name); | |
| 115 ASSERT(!Dart_IsError(result)); | |
| 116 ASSERT(function_name != NULL); | |
| 117 *auto_setup_scope = true; | |
| 118 intptr_t n = | |
| 119 sizeof(_VmServiceIONativeEntries) / sizeof(_VmServiceIONativeEntries[0]); | |
| 120 for (intptr_t i = 0; i < n; i++) { | |
| 121 VmServiceIONativeEntry entry = _VmServiceIONativeEntries[i]; | |
| 122 if ((strcmp(function_name, entry.name) == 0) && | |
| 123 (num_arguments == entry.num_arguments)) { | |
| 124 return entry.function; | |
| 125 } | |
| 126 } | |
| 127 return NULL; | |
| 128 } | |
| 129 | |
| 130 | |
| 89 const char* VmService::error_msg_ = NULL; | 131 const char* VmService::error_msg_ = NULL; |
| 90 | 132 |
| 91 bool VmService::Start(const char *server_ip, intptr_t server_port) { | 133 bool VmService::Start(const char *server_ip, intptr_t server_port) { |
| 92 bool r = _Start(server_ip, server_port); | 134 bool r = _Start(server_ip, server_port); |
| 93 if (!r) { | 135 if (!r) { |
| 94 return r; | 136 return r; |
| 95 } | 137 } |
| 96 // Start processing messages in a new thread. | 138 // Start processing messages in a new thread. |
| 97 Thread::Start(ThreadMain, static_cast<uword>(NULL)); | 139 Thread::Start(ThreadMain, static_cast<uword>(NULL)); |
| 98 return true; | 140 return true; |
| 99 } | 141 } |
| 100 | 142 |
| 101 | 143 |
| 102 bool VmService::_Start(const char *server_ip, intptr_t server_port) { | 144 bool VmService::_Start(const char *server_ip, intptr_t server_port) { |
| 103 ASSERT(Dart_CurrentIsolate() == NULL); | 145 ASSERT(Dart_CurrentIsolate() == NULL); |
| 104 Dart_Isolate isolate = Dart_GetServiceIsolate(NULL); | 146 Dart_Isolate isolate = Dart_GetServiceIsolate(NULL); |
| 105 if (isolate == NULL) { | 147 if (isolate == NULL) { |
| 106 error_msg_ = "Internal error."; | 148 error_msg_ = "Dart_GetServiceIsolate failed."; |
| 107 return false; | 149 return false; |
| 108 } | 150 } |
| 109 Dart_EnterIsolate(isolate); | 151 Dart_EnterIsolate(isolate); |
| 110 Dart_EnterScope(); | 152 Dart_EnterScope(); |
| 111 // Install our own library tag handler. | 153 // Install our own library tag handler. |
| 112 Dart_SetLibraryTagHandler(LibraryTagHandler); | 154 Dart_SetLibraryTagHandler(LibraryTagHandler); |
| 113 Dart_Handle result; | 155 Dart_Handle result; |
| 114 Dart_Handle library = LoadScript(kVMServiceIOLibraryScriptResourceName); | 156 Dart_Handle library; |
| 115 // Expect a library. | 157 { |
| 116 ASSERT(library != Dart_Null()); | 158 library = LoadScript(kVMServiceIOLibraryScriptResourceName); |
| 117 SHUTDOWN_ON_ERROR(library); | 159 // Expect a library. |
| 118 result = Dart_FinalizeLoading(false); | 160 ASSERT(library != Dart_Null()); |
| 119 ASSERT(!Dart_IsError(result)); | 161 SHUTDOWN_ON_ERROR(library); |
| 162 result = Dart_FinalizeLoading(false); | |
| 163 ASSERT(!Dart_IsError(result)); | |
| 164 } | |
|
siva
2014/09/09 00:40:58
Why is this is a special scope?
Cutch
2014/09/10 15:11:23
I was using scoped timers. Removing extra scopes.
| |
| 120 Dart_ExitScope(); | 165 Dart_ExitScope(); |
| 121 Dart_ExitIsolate(); | 166 Dart_ExitIsolate(); |
| 122 bool retval = Dart_IsolateMakeRunnable(isolate); | 167 bool retval = Dart_IsolateMakeRunnable(isolate); |
| 123 if (!retval) { | 168 if (!retval) { |
| 124 Dart_EnterIsolate(isolate); | 169 Dart_EnterIsolate(isolate); |
| 125 Dart_ShutdownIsolate(); | 170 Dart_ShutdownIsolate(); |
| 126 error_msg_ = "Invalid isolate state - Unable to make it runnable."; | 171 error_msg_ = "Invalid isolate state - Unable to make it runnable."; |
| 127 return false; | 172 return false; |
| 128 } | 173 } |
| 129 | 174 |
| 130 Dart_EnterIsolate(isolate); | 175 { |
| 131 Dart_EnterScope(); | 176 Dart_EnterIsolate(isolate); |
| 132 library = Dart_RootLibrary(); | 177 Dart_EnterScope(); |
| 133 // Set requested TCP port. | 178 library = Dart_RootLibrary(); |
| 134 DartUtils::SetStringField(library, "_ip", server_ip); | 179 result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL); |
| 135 // If we have a port specified, start the server immediately. | 180 ASSERT(!Dart_IsError(result)); |
| 136 bool auto_start = server_port >= 0; | 181 // Set requested TCP port. |
| 137 if (server_port < 0) { | 182 DartUtils::SetStringField(library, "_ip", server_ip); |
| 138 // Adjust server_port to port 0 which will result in the first available | 183 // If we have a port specified, start the server immediately. |
| 139 // port when the HTTP server is started. | 184 bool auto_start = server_port >= 0; |
| 140 server_port = 0; | 185 if (server_port < 0) { |
| 186 // Adjust server_port to port 0 which will result in the first available | |
| 187 // port when the HTTP server is started. | |
| 188 server_port = 0; | |
| 189 } | |
| 190 // Set initial state. | |
| 191 DartUtils::SetIntegerField(library, "_port", server_port); | |
| 192 Dart_SetField(library, | |
| 193 DartUtils::NewString("_autoStart"), | |
| 194 Dart_NewBoolean(auto_start)); | |
| 195 // We cannot register for signals on windows. | |
| 196 #if defined(TARGET_OS_WINDOWS) | |
| 197 const bool is_windows = true; | |
| 198 #else | |
| 199 const bool is_windows = false; | |
| 200 #endif | |
| 201 Dart_SetField(library, | |
| 202 DartUtils::NewString("_isWindows"), | |
| 203 Dart_NewBoolean(is_windows)); | |
|
siva
2014/09/09 00:40:58
Can write this:
#if defined(TARGET_OS_WINDOWS)
Dar
Cutch
2014/09/10 15:11:23
Done.
| |
| 141 } | 204 } |
| 142 // Set initial state. | |
| 143 DartUtils::SetIntegerField(library, "_port", server_port); | |
| 144 Dart_SetField(library, | |
| 145 DartUtils::NewString("_autoStart"), | |
| 146 Dart_NewBoolean(auto_start)); | |
| 147 // We cannot register for signals on windows. | |
| 148 #if defined(TARGET_OS_WINDOWS) | |
| 149 const bool is_windows = true; | |
| 150 #else | |
| 151 const bool is_windows = false; | |
| 152 #endif | |
| 153 Dart_SetField(library, | |
| 154 DartUtils::NewString("_isWindows"), | |
| 155 Dart_NewBoolean(is_windows)); | |
| 156 | 205 |
| 157 // Invoke main. | 206 |
| 158 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); | 207 { |
| 159 SHUTDOWN_ON_ERROR(result); | 208 // Get _getWatchSignalInternal from dart:io. |
| 160 // Load resources. | 209 Dart_Handle dart_io_str = Dart_NewStringFromCString("dart:io"); |
|
siva
2014/09/09 00:40:58
use DartUtils::kIOLibURL instead of "dart:io"
Cutch
2014/09/10 15:11:23
Done.
| |
| 161 result = LoadResources(library); | 210 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str); |
| 162 SHUTDOWN_ON_ERROR(result); | 211 Dart_Handle function_name = |
| 212 Dart_NewStringFromCString("_getWatchSignalInternal"); | |
| 213 Dart_Handle signal_watch = Dart_Invoke(io_lib, function_name, 0, NULL); | |
| 214 // Invoke main. | |
| 215 result = | |
| 216 Dart_Invoke(library, DartUtils::NewString("main"), 1, &signal_watch); | |
| 217 SHUTDOWN_ON_ERROR(result); | |
| 218 } | |
|
siva
2014/09/09 00:40:58
Ditto question about why these two blocks are setu
Cutch
2014/09/10 15:11:23
Done here and elsewhere.
| |
| 163 | 219 |
| 164 Dart_ExitScope(); | 220 Dart_ExitScope(); |
| 165 Dart_ExitIsolate(); | 221 Dart_ExitIsolate(); |
| 166 | 222 |
| 167 return true; | 223 return true; |
| 168 } | 224 } |
| 169 | 225 |
| 170 | 226 |
| 171 const char* VmService::GetErrorMessage() { | 227 const char* VmService::GetErrorMessage() { |
| 172 return error_msg_ == NULL ? "No error." : error_msg_; | 228 return error_msg_ == NULL ? "No error." : error_msg_; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 printf("Service exited with an error:\n%s\n", Dart_GetError(result)); | 357 printf("Service exited with an error:\n%s\n", Dart_GetError(result)); |
| 302 } | 358 } |
| 303 Dart_ExitScope(); | 359 Dart_ExitScope(); |
| 304 Dart_ExitIsolate(); | 360 Dart_ExitIsolate(); |
| 305 } | 361 } |
| 306 | 362 |
| 307 | 363 |
| 308 | 364 |
| 309 } // namespace bin | 365 } // namespace bin |
| 310 } // namespace dart | 366 } // namespace dart |
| OLD | NEW |