| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 static ResourcesEntry* ResourcesTable() { | 83 static ResourcesEntry* ResourcesTable() { |
| 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 TriggerResourceLoad(Dart_NativeArguments args) { | |
| 93 Dart_Handle library = Dart_RootLibrary(); | |
| 94 ASSERT(!Dart_IsError(library)); | |
| 95 Dart_Handle result = VmService::LoadResources(library); | |
| 96 ASSERT(!Dart_IsError(result)); | |
| 97 } | |
| 98 | |
| 99 | |
| 100 void NotifyServerState(Dart_NativeArguments args) { | 92 void NotifyServerState(Dart_NativeArguments args) { |
| 101 Dart_EnterScope(); | 93 Dart_EnterScope(); |
| 102 const char* ip_chars; | 94 const char* ip_chars; |
| 103 Dart_Handle ip_arg = Dart_GetNativeArgument(args, 0); | 95 Dart_Handle ip_arg = Dart_GetNativeArgument(args, 0); |
| 104 if (Dart_IsError(ip_arg)) { | 96 if (Dart_IsError(ip_arg)) { |
| 105 VmService::SetServerIPAndPort("", 0); | 97 VmService::SetServerIPAndPort("", 0); |
| 106 Dart_ExitScope(); | 98 Dart_ExitScope(); |
| 107 return; | 99 return; |
| 108 } | 100 } |
| 109 Dart_Handle result = Dart_StringToCString(ip_arg, &ip_chars); | 101 Dart_Handle result = Dart_StringToCString(ip_arg, &ip_chars); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 124 } | 116 } |
| 125 | 117 |
| 126 struct VmServiceIONativeEntry { | 118 struct VmServiceIONativeEntry { |
| 127 const char* name; | 119 const char* name; |
| 128 int num_arguments; | 120 int num_arguments; |
| 129 Dart_NativeFunction function; | 121 Dart_NativeFunction function; |
| 130 }; | 122 }; |
| 131 | 123 |
| 132 | 124 |
| 133 static VmServiceIONativeEntry _VmServiceIONativeEntries[] = { | 125 static VmServiceIONativeEntry _VmServiceIONativeEntries[] = { |
| 134 {"VMServiceIO_TriggerResourceLoad", 0, TriggerResourceLoad}, | |
| 135 {"VMServiceIO_NotifyServerState", 2, NotifyServerState}, | 126 {"VMServiceIO_NotifyServerState", 2, NotifyServerState}, |
| 136 }; | 127 }; |
| 137 | 128 |
| 138 | 129 |
| 139 static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name, | 130 static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name, |
| 140 int num_arguments, | 131 int num_arguments, |
| 141 bool* auto_setup_scope) { | 132 bool* auto_setup_scope) { |
| 142 const char* function_name = NULL; | 133 const char* function_name = NULL; |
| 143 Dart_Handle result = Dart_StringToCString(name, &function_name); | 134 Dart_Handle result = Dart_StringToCString(name, &function_name); |
| 144 ASSERT(!Dart_IsError(result)); | 135 ASSERT(!Dart_IsError(result)); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 } | 311 } |
| 321 | 312 |
| 322 | 313 |
| 323 Dart_Handle VmService::LoadSource(Dart_Handle library, const char* name) { | 314 Dart_Handle VmService::LoadSource(Dart_Handle library, const char* name) { |
| 324 Dart_Handle uri = Dart_NewStringFromCString(name); | 315 Dart_Handle uri = Dart_NewStringFromCString(name); |
| 325 Dart_Handle source = GetSource(name); | 316 Dart_Handle source = GetSource(name); |
| 326 return Dart_LoadSource(library, uri, source, 0, 0); | 317 return Dart_LoadSource(library, uri, source, 0, 0); |
| 327 } | 318 } |
| 328 | 319 |
| 329 | 320 |
| 330 Dart_Handle VmService::LoadResource(Dart_Handle library, | |
| 331 const char* resource_name) { | |
| 332 // Prepare for invoke call. | |
| 333 Dart_Handle name = Dart_NewStringFromCString(resource_name); | |
| 334 RETURN_ERROR_HANDLE(name); | |
| 335 const char* data_buffer = NULL; | |
| 336 int data_buffer_length = Resources::ResourceLookup(resource_name, | |
| 337 &data_buffer); | |
| 338 if (data_buffer_length == Resources::kNoSuchInstance) { | |
| 339 printf("Could not find %s %s\n", resource_name, resource_name); | |
| 340 } | |
| 341 ASSERT(data_buffer_length != Resources::kNoSuchInstance); | |
| 342 Dart_Handle data_list = Dart_NewTypedData(Dart_TypedData_kUint8, | |
| 343 data_buffer_length); | |
| 344 RETURN_ERROR_HANDLE(data_list); | |
| 345 Dart_TypedData_Type type = Dart_TypedData_kInvalid; | |
| 346 void* data_list_buffer = NULL; | |
| 347 intptr_t data_list_buffer_length = 0; | |
| 348 Dart_Handle result = Dart_TypedDataAcquireData(data_list, &type, | |
| 349 &data_list_buffer, | |
| 350 &data_list_buffer_length); | |
| 351 RETURN_ERROR_HANDLE(result); | |
| 352 ASSERT(data_buffer_length == data_list_buffer_length); | |
| 353 ASSERT(data_list_buffer != NULL); | |
| 354 ASSERT(type == Dart_TypedData_kUint8); | |
| 355 memmove(data_list_buffer, &data_buffer[0], data_buffer_length); | |
| 356 result = Dart_TypedDataReleaseData(data_list); | |
| 357 RETURN_ERROR_HANDLE(result); | |
| 358 | |
| 359 // Make invoke call. | |
| 360 const intptr_t kNumArgs = 3; | |
| 361 Dart_Handle compressed = Dart_True(); | |
| 362 Dart_Handle args[kNumArgs] = { name, data_list, compressed }; | |
| 363 result = Dart_Invoke(library, Dart_NewStringFromCString("_addResource"), | |
| 364 kNumArgs, args); | |
| 365 return result; | |
| 366 } | |
| 367 | |
| 368 | |
| 369 Dart_Handle VmService::LoadResources(Dart_Handle library) { | |
| 370 Dart_Handle result = Dart_Null(); | |
| 371 intptr_t prefixLen = strlen(kLibrarySourceNamePrefix); | |
| 372 for (intptr_t i = 0; Resources::Path(i) != NULL; i++) { | |
| 373 const char* path = Resources::Path(i); | |
| 374 // If it doesn't begin with kLibrarySourceNamePrefix it is a frontend | |
| 375 // resource. | |
| 376 if (strncmp(path, kLibrarySourceNamePrefix, prefixLen) != 0) { | |
| 377 result = LoadResource(library, path); | |
| 378 if (Dart_IsError(result)) { | |
| 379 break; | |
| 380 } | |
| 381 } | |
| 382 } | |
| 383 return result; | |
| 384 } | |
| 385 | |
| 386 | |
| 387 Dart_Handle VmService::LibraryTagHandler(Dart_LibraryTag tag, | 321 Dart_Handle VmService::LibraryTagHandler(Dart_LibraryTag tag, |
| 388 Dart_Handle library, | 322 Dart_Handle library, |
| 389 Dart_Handle url) { | 323 Dart_Handle url) { |
| 390 if (!Dart_IsLibrary(library)) { | 324 if (!Dart_IsLibrary(library)) { |
| 391 return Dart_NewApiError("not a library"); | 325 return Dart_NewApiError("not a library"); |
| 392 } | 326 } |
| 393 if (!Dart_IsString(url)) { | 327 if (!Dart_IsString(url)) { |
| 394 return Dart_NewApiError("url is not a string"); | 328 return Dart_NewApiError("url is not a string"); |
| 395 } | 329 } |
| 396 const char* url_string = NULL; | 330 const char* url_string = NULL; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 416 Dart_Handle source = GetSource(url_string); | 350 Dart_Handle source = GetSource(url_string); |
| 417 if (Dart_IsError(source)) { | 351 if (Dart_IsError(source)) { |
| 418 return source; | 352 return source; |
| 419 } | 353 } |
| 420 return Dart_LoadSource(library, url, source, 0, 0); | 354 return Dart_LoadSource(library, url, source, 0, 0); |
| 421 } | 355 } |
| 422 | 356 |
| 423 | 357 |
| 424 } // namespace bin | 358 } // namespace bin |
| 425 } // namespace dart | 359 } // namespace dart |
| OLD | NEW |