| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 #include "bin/vmservice_dartium.h" | |
| 6 | |
| 7 #include "bin/builtin.h" | |
| 8 #include "bin/dartutils.h" | |
| 9 #include "bin/eventhandler.h" | |
| 10 #include "bin/platform.h" | |
| 11 #include "bin/thread.h" | |
| 12 #include "bin/vmservice_impl.h" | |
| 13 | |
| 14 namespace dart { | |
| 15 namespace bin { | |
| 16 | |
| 17 #define CHECK_RESULT(result) \ | |
| 18 if (Dart_IsError(result)) { \ | |
| 19 fprintf(stderr, "CHECK_RESULT failed: %s", Dart_GetError(result)); \ | |
| 20 Dart_ExitScope(); \ | |
| 21 Dart_ShutdownIsolate(); \ | |
| 22 return 0; \ | |
| 23 } \ | |
| 24 | |
| 25 | |
| 26 | |
| 27 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | |
| 28 // it is initialized to NULL. | |
| 29 extern const uint8_t* snapshot_buffer; | |
| 30 | |
| 31 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; | |
| 32 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 0; | |
| 33 | |
| 34 void VmServiceServer::Bootstrap() { | |
| 35 if (!Platform::Initialize()) { | |
| 36 fprintf(stderr, "Platform::Initialize() failed\n"); | |
| 37 } | |
| 38 DartUtils::SetOriginalWorkingDirectory(); | |
| 39 Thread::InitOnce(); | |
| 40 EventHandler::Start(); | |
| 41 } | |
| 42 | |
| 43 | |
| 44 Dart_Isolate VmServiceServer::CreateIsolate() { | |
| 45 ASSERT(snapshot_buffer != NULL); | |
| 46 // Create the isolate. | |
| 47 char* error = 0; | |
| 48 Dart_Isolate isolate = Dart_CreateIsolate(DART_VM_SERVICE_ISOLATE_NAME, | |
| 49 "main", | |
| 50 dart::bin::snapshot_buffer, | |
| 51 NULL, | |
| 52 &error); | |
| 53 if (!isolate) { | |
| 54 fprintf(stderr, "Dart_CreateIsolate failed: %s\n", error); | |
| 55 return 0; | |
| 56 } | |
| 57 | |
| 58 Dart_EnterScope(); | |
| 59 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | |
| 60 Builtin::SetNativeResolver(Builtin::kIOLibrary); | |
| 61 | |
| 62 Dart_Handle builtin_lib = | |
| 63 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
| 64 CHECK_RESULT(builtin_lib); | |
| 65 | |
| 66 Dart_Handle result; | |
| 67 | |
| 68 // Prepare for script loading by setting up the 'print' and 'timer' | |
| 69 // closures and setting up 'package root' for URI resolution. | |
| 70 result = DartUtils::PrepareForScriptLoading("", builtin_lib); | |
| 71 CHECK_RESULT(result); | |
| 72 | |
| 73 ASSERT(Dart_IsServiceIsolate(isolate)); | |
| 74 if (!VmService::Setup(DEFAULT_VM_SERVICE_SERVER_IP, | |
| 75 DEFAULT_VM_SERVICE_SERVER_PORT)) { | |
| 76 fprintf(stderr, | |
| 77 "Vmservice::Setup failed: %s\n", VmService::GetErrorMessage()); | |
| 78 isolate = NULL; | |
| 79 } | |
| 80 Dart_ExitScope(); | |
| 81 Dart_ExitIsolate(); | |
| 82 return isolate; | |
| 83 } | |
| 84 | |
| 85 | |
| 86 const char* VmServiceServer::GetServerIP() { | |
| 87 return VmService::GetServerIP(); | |
| 88 } | |
| 89 | |
| 90 | |
| 91 intptr_t VmServiceServer::GetServerPort() { | |
| 92 return VmService::GetServerPort(); | |
| 93 } | |
| 94 | |
| 95 | |
| 96 /* DISALLOW_ALLOCATION */ | |
| 97 void VmServiceServer::operator delete(void* pointer) { | |
| 98 fprintf(stderr, "unreachable code\n"); | |
| 99 abort(); | |
| 100 } | |
| 101 | |
| 102 } // namespace bin | |
| 103 } // namespace dart | |
| OLD | NEW |