| 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 "vm/service.h" | 5 #include "vm/service.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 | 9 |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 static void SendRootServiceMessage(Dart_NativeArguments args) { | 182 static void SendRootServiceMessage(Dart_NativeArguments args) { |
| 183 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 183 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 184 Isolate* isolate = arguments->isolate(); | 184 Isolate* isolate = arguments->isolate(); |
| 185 StackZone zone(isolate); | 185 StackZone zone(isolate); |
| 186 HANDLESCOPE(isolate); | 186 HANDLESCOPE(isolate); |
| 187 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(0)); | 187 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(0)); |
| 188 Service::HandleRootMessage(message); | 188 Service::HandleRootMessage(message); |
| 189 } | 189 } |
| 190 | 190 |
| 191 | 191 |
| 192 void Service::SetEventMask(uint32_t mask) { |
| 193 event_mask_ = mask; |
| 194 } |
| 195 |
| 196 |
| 197 void SetEventMask(Dart_NativeArguments args) { |
| 198 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 199 Isolate* isolate = arguments->isolate(); |
| 200 StackZone zone(isolate); |
| 201 HANDLESCOPE(isolate); |
| 202 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(0)); |
| 203 Service::SetEventMask(mask.AsTruncatedUint32Value()); |
| 204 } |
| 205 |
| 206 |
| 192 struct VmServiceNativeEntry { | 207 struct VmServiceNativeEntry { |
| 193 const char* name; | 208 const char* name; |
| 194 int num_arguments; | 209 int num_arguments; |
| 195 Dart_NativeFunction function; | 210 Dart_NativeFunction function; |
| 196 }; | 211 }; |
| 197 | 212 |
| 198 | 213 |
| 199 static VmServiceNativeEntry _VmServiceNativeEntries[] = { | 214 static VmServiceNativeEntry _VmServiceNativeEntries[] = { |
| 200 {"VMService_SendIsolateServiceMessage", 2, SendIsolateServiceMessage}, | 215 {"VMService_SendIsolateServiceMessage", 2, SendIsolateServiceMessage}, |
| 201 {"VMService_SendRootServiceMessage", 1, SendRootServiceMessage} | 216 {"VMService_SendRootServiceMessage", 1, SendRootServiceMessage}, |
| 217 {"VMService_SetEventMask", 1, SetEventMask}, |
| 202 }; | 218 }; |
| 203 | 219 |
| 204 | 220 |
| 205 static Dart_NativeFunction VmServiceNativeResolver(Dart_Handle name, | 221 static Dart_NativeFunction VmServiceNativeResolver(Dart_Handle name, |
| 206 int num_arguments, | 222 int num_arguments, |
| 207 bool* auto_setup_scope) { | 223 bool* auto_setup_scope) { |
| 208 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | 224 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); |
| 209 if (!obj.IsString()) { | 225 if (!obj.IsString()) { |
| 210 return NULL; | 226 return NULL; |
| 211 } | 227 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 224 } | 240 } |
| 225 return NULL; | 241 return NULL; |
| 226 } | 242 } |
| 227 | 243 |
| 228 | 244 |
| 229 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; | 245 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; |
| 230 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; | 246 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; |
| 231 Isolate* Service::service_isolate_ = NULL; | 247 Isolate* Service::service_isolate_ = NULL; |
| 232 Dart_LibraryTagHandler Service::default_handler_ = NULL; | 248 Dart_LibraryTagHandler Service::default_handler_ = NULL; |
| 233 Dart_Port Service::port_ = ILLEGAL_PORT; | 249 Dart_Port Service::port_ = ILLEGAL_PORT; |
| 250 uint32_t Service::event_mask_ = 0; |
| 234 | 251 |
| 235 | 252 |
| 236 static Dart_Port ExtractPort(Dart_Handle receivePort) { | 253 static Dart_Port ExtractPort(Dart_Handle receivePort) { |
| 237 HANDLESCOPE(Isolate::Current()); | 254 HANDLESCOPE(Isolate::Current()); |
| 238 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); | 255 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); |
| 239 const Instance& rp = Instance::Cast(unwrapped_rp); | 256 const Instance& rp = Instance::Cast(unwrapped_rp); |
| 240 // Extract RawReceivePort port id. | 257 // Extract RawReceivePort port id. |
| 241 if (!rp.IsReceivePort()) { | 258 if (!rp.IsReceivePort()) { |
| 242 return ILLEGAL_PORT; | 259 return ILLEGAL_PORT; |
| 243 } | 260 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (FLAG_trace_service) { | 469 if (FLAG_trace_service) { |
| 453 OS::Print("Isolate %s %" Pd64 " deregistered with service \n", | 470 OS::Print("Isolate %s %" Pd64 " deregistered with service \n", |
| 454 name.ToCString(), | 471 name.ToCString(), |
| 455 Dart_GetMainPortId()); | 472 Dart_GetMainPortId()); |
| 456 } | 473 } |
| 457 return PortMap::PostMessage( | 474 return PortMap::PostMessage( |
| 458 new Message(port_, data, len, Message::kNormalPriority)); | 475 new Message(port_, data, len, Message::kNormalPriority)); |
| 459 } | 476 } |
| 460 | 477 |
| 461 | 478 |
| 462 bool Service::IsRunning() { | |
| 463 return port_ != ILLEGAL_PORT; | |
| 464 } | |
| 465 | |
| 466 | |
| 467 Dart_Handle Service::GetSource(const char* name) { | 479 Dart_Handle Service::GetSource(const char* name) { |
| 468 ASSERT(name != NULL); | 480 ASSERT(name != NULL); |
| 469 int i = 0; | 481 int i = 0; |
| 470 while (true) { | 482 while (true) { |
| 471 const char* path = Resources::Path(i); | 483 const char* path = Resources::Path(i); |
| 472 if (path == NULL) { | 484 if (path == NULL) { |
| 473 break; | 485 break; |
| 474 } | 486 } |
| 475 ASSERT(*path != '\0'); | 487 ASSERT(*path != '\0'); |
| 476 // Skip the '/'. | 488 // Skip the '/'. |
| (...skipping 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2106 return entry.handler; | 2118 return entry.handler; |
| 2107 } | 2119 } |
| 2108 } | 2120 } |
| 2109 if (FLAG_trace_service) { | 2121 if (FLAG_trace_service) { |
| 2110 OS::Print("Service has no root message handler for <%s>\n", command); | 2122 OS::Print("Service has no root message handler for <%s>\n", command); |
| 2111 } | 2123 } |
| 2112 return NULL; | 2124 return NULL; |
| 2113 } | 2125 } |
| 2114 | 2126 |
| 2115 | 2127 |
| 2128 void Service::SendEvent(intptr_t eventId, const String& eventMessage) { |
| 2129 if (!IsRunning()) { |
| 2130 return; |
| 2131 } |
| 2132 Isolate* isolate = Isolate::Current(); |
| 2133 ASSERT(isolate != NULL); |
| 2134 HANDLESCOPE(isolate); |
| 2135 |
| 2136 // Construct a list of the form [eventId, eventMessage]. |
| 2137 const Array& list = Array::Handle(Array::New(2)); |
| 2138 ASSERT(!list.IsNull()); |
| 2139 list.SetAt(0, Integer::Handle(Integer::New(eventId))); |
| 2140 list.SetAt(1, eventMessage); |
| 2141 |
| 2142 // Push the event to port_. |
| 2143 uint8_t* data = NULL; |
| 2144 MessageWriter writer(&data, &allocator); |
| 2145 writer.WriteMessage(list); |
| 2146 intptr_t len = writer.BytesWritten(); |
| 2147 if (FLAG_trace_service) { |
| 2148 OS::Print("Pushing event of type %" Pd ", len %" Pd "\n", eventId, len); |
| 2149 } |
| 2150 // TODO(turnidge): For now we ignore failure to send an event. Revisit? |
| 2151 PortMap::PostMessage( |
| 2152 new Message(port_, data, len, Message::kNormalPriority)); |
| 2153 } |
| 2154 |
| 2155 |
| 2156 void Service::HandleDebuggerEvent(DebuggerEvent* event) { |
| 2157 JSONStream js; |
| 2158 event->PrintJSON(&js); |
| 2159 const String& message = String::Handle(String::New(js.ToCString())); |
| 2160 SendEvent(kEventFamilyDebug, message); |
| 2161 } |
| 2162 |
| 2163 |
| 2116 void Service::EmbedderHandleMessage(EmbedderServiceHandler* handler, | 2164 void Service::EmbedderHandleMessage(EmbedderServiceHandler* handler, |
| 2117 JSONStream* js) { | 2165 JSONStream* js) { |
| 2118 ASSERT(handler != NULL); | 2166 ASSERT(handler != NULL); |
| 2119 Dart_ServiceRequestCallback callback = handler->callback(); | 2167 Dart_ServiceRequestCallback callback = handler->callback(); |
| 2120 ASSERT(callback != NULL); | 2168 ASSERT(callback != NULL); |
| 2121 const char* r = NULL; | 2169 const char* r = NULL; |
| 2122 const char* name = js->command(); | 2170 const char* name = js->command(); |
| 2123 const char** arguments = js->arguments(); | 2171 const char** arguments = js->arguments(); |
| 2124 const char** keys = js->option_keys(); | 2172 const char** keys = js->option_keys(); |
| 2125 const char** values = js->option_values(); | 2173 const char** values = js->option_values(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2202 while (current != NULL) { | 2250 while (current != NULL) { |
| 2203 if (strcmp(name, current->name()) == 0) { | 2251 if (strcmp(name, current->name()) == 0) { |
| 2204 return current; | 2252 return current; |
| 2205 } | 2253 } |
| 2206 current = current->next(); | 2254 current = current->next(); |
| 2207 } | 2255 } |
| 2208 return NULL; | 2256 return NULL; |
| 2209 } | 2257 } |
| 2210 | 2258 |
| 2211 } // namespace dart | 2259 } // namespace dart |
| OLD | NEW |