Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: runtime/vm/service_isolate.cc

Issue 2438613002: Provide an API to dart:developer to control the web server hosting the Service Protocol (Closed)
Patch Set: CHANGELOG.md merge and fatal error Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/service_isolate.h ('k') | sdk/lib/_internal/js_runtime/lib/developer_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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 "vm/service_isolate.h" 5 #include "vm/service_isolate.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 25 matching lines...) Expand all
36 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 36 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
37 return reinterpret_cast<uint8_t*>(new_ptr); 37 return reinterpret_cast<uint8_t*>(new_ptr);
38 } 38 }
39 39
40 40
41 // These must be kept in sync with service/constants.dart 41 // These must be kept in sync with service/constants.dart
42 #define VM_SERVICE_ISOLATE_EXIT_MESSAGE_ID 0 42 #define VM_SERVICE_ISOLATE_EXIT_MESSAGE_ID 0
43 #define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1 43 #define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1
44 #define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2 44 #define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2
45 45
46 #define VM_SERVICE_WEB_SERVER_CONTROL_MESSAGE_ID 3
47 #define VM_SERVICE_SERVER_INFO_MESSAGE_ID 4
48
46 static RawArray* MakeServiceControlMessage(Dart_Port port_id, intptr_t code, 49 static RawArray* MakeServiceControlMessage(Dart_Port port_id, intptr_t code,
47 const String& name) { 50 const String& name) {
48 const Array& list = Array::Handle(Array::New(4)); 51 const Array& list = Array::Handle(Array::New(4));
49 ASSERT(!list.IsNull()); 52 ASSERT(!list.IsNull());
50 const Integer& code_int = Integer::Handle(Integer::New(code)); 53 const Integer& code_int = Integer::Handle(Integer::New(code));
51 const Integer& port_int = Integer::Handle(Integer::New(port_id)); 54 const Integer& port_int = Integer::Handle(Integer::New(port_id));
52 const SendPort& send_port = SendPort::Handle(SendPort::New(port_id)); 55 const SendPort& send_port = SendPort::Handle(SendPort::New(port_id));
53 list.SetAt(0, code_int); 56 list.SetAt(0, code_int);
54 list.SetAt(1, port_int); 57 list.SetAt(1, port_int);
55 list.SetAt(2, send_port); 58 list.SetAt(2, send_port);
56 list.SetAt(3, name); 59 list.SetAt(3, name);
57 return list.raw(); 60 return list.raw();
58 } 61 }
59 62
60 63
64 static RawArray* MakeServerControlMessage(const SendPort& sp,
65 intptr_t code,
66 bool enable = false) {
67 const Array& list = Array::Handle(Array::New(3));
68 ASSERT(!list.IsNull());
69 list.SetAt(0, Integer::Handle(Integer::New(code)));
70 list.SetAt(1, sp);
71 list.SetAt(2, Bool::Get(enable));
72 return list.raw();
73 }
74
75
61 static RawArray* MakeServiceExitMessage() { 76 static RawArray* MakeServiceExitMessage() {
62 const Array& list = Array::Handle(Array::New(1)); 77 const Array& list = Array::Handle(Array::New(1));
63 ASSERT(!list.IsNull()); 78 ASSERT(!list.IsNull());
64 const intptr_t code = VM_SERVICE_ISOLATE_EXIT_MESSAGE_ID; 79 const intptr_t code = VM_SERVICE_ISOLATE_EXIT_MESSAGE_ID;
65 const Integer& code_int = Integer::Handle(Integer::New(code)); 80 const Integer& code_int = Integer::Handle(Integer::New(code));
66 list.SetAt(0, code_int); 81 list.SetAt(0, code_int);
67 return list.raw(); 82 return list.raw();
68 } 83 }
69 84
70 85
71 const char* ServiceIsolate::kName = "vm-service"; 86 const char* ServiceIsolate::kName = "vm-service";
72 Isolate* ServiceIsolate::isolate_ = NULL; 87 Isolate* ServiceIsolate::isolate_ = NULL;
73 Dart_Port ServiceIsolate::port_ = ILLEGAL_PORT; 88 Dart_Port ServiceIsolate::port_ = ILLEGAL_PORT;
74 Dart_Port ServiceIsolate::load_port_ = ILLEGAL_PORT; 89 Dart_Port ServiceIsolate::load_port_ = ILLEGAL_PORT;
75 Dart_Port ServiceIsolate::origin_ = ILLEGAL_PORT; 90 Dart_Port ServiceIsolate::origin_ = ILLEGAL_PORT;
76 Dart_IsolateCreateCallback ServiceIsolate::create_callback_ = NULL; 91 Dart_IsolateCreateCallback ServiceIsolate::create_callback_ = NULL;
77 uint8_t* ServiceIsolate::exit_message_ = NULL; 92 uint8_t* ServiceIsolate::exit_message_ = NULL;
78 intptr_t ServiceIsolate::exit_message_length_ = 0; 93 intptr_t ServiceIsolate::exit_message_length_ = 0;
79 Monitor* ServiceIsolate::monitor_ = NULL; 94 Monitor* ServiceIsolate::monitor_ = NULL;
80 bool ServiceIsolate::initializing_ = true; 95 bool ServiceIsolate::initializing_ = true;
81 bool ServiceIsolate::shutting_down_ = false; 96 bool ServiceIsolate::shutting_down_ = false;
82 char* ServiceIsolate::server_address_ = NULL; 97 char* ServiceIsolate::server_address_ = NULL;
83 98
99 void ServiceIsolate::RequestServerInfo(const SendPort& sp) {
100 const Array& message =
101 Array::Handle(
102 MakeServerControlMessage(sp,
103 VM_SERVICE_SERVER_INFO_MESSAGE_ID,
104 false /* ignored */));
105 ASSERT(!message.IsNull());
106 uint8_t* data = NULL;
107 MessageWriter writer(&data, &allocator, false);
108 writer.WriteMessage(message);
109 intptr_t len = writer.BytesWritten();
110 PortMap::PostMessage(new Message(port_, data, len, Message::kNormalPriority));
111 }
112
113
114 void ServiceIsolate::ControlWebServer(const SendPort& sp, bool enable) {
115 const Array& message =
116 Array::Handle(
117 MakeServerControlMessage(sp,
118 VM_SERVICE_WEB_SERVER_CONTROL_MESSAGE_ID,
119 enable));
120 ASSERT(!message.IsNull());
121 uint8_t* data = NULL;
122 MessageWriter writer(&data, &allocator, false);
123 writer.WriteMessage(message);
124 intptr_t len = writer.BytesWritten();
125 PortMap::PostMessage(new Message(port_, data, len, Message::kNormalPriority));
126 }
127
128
84 void ServiceIsolate::SetServerAddress(const char* address) { 129 void ServiceIsolate::SetServerAddress(const char* address) {
85 if (server_address_ != NULL) { 130 if (server_address_ != NULL) {
86 free(server_address_); 131 free(server_address_);
87 server_address_ = NULL; 132 server_address_ = NULL;
88 } 133 }
89 if (address == NULL) { 134 if (address == NULL) {
90 return; 135 return;
91 } 136 }
92 server_address_ = strdup(address); 137 server_address_ = strdup(address);
93 } 138 }
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 570 }
526 ASSERT(port != ILLEGAL_PORT); 571 ASSERT(port != ILLEGAL_PORT);
527 ServiceIsolate::SetServicePort(port); 572 ServiceIsolate::SetServicePort(port);
528 } 573 }
529 574
530 575
531 void ServiceIsolate::VisitObjectPointers(ObjectPointerVisitor* visitor) { 576 void ServiceIsolate::VisitObjectPointers(ObjectPointerVisitor* visitor) {
532 } 577 }
533 578
534 } // namespace dart 579 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service_isolate.h ('k') | sdk/lib/_internal/js_runtime/lib/developer_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698