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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 static void SendRootServiceMessage(Dart_NativeArguments args) { | 225 static void SendRootServiceMessage(Dart_NativeArguments args) { |
226 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 226 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
227 Isolate* isolate = arguments->isolate(); | 227 Isolate* isolate = arguments->isolate(); |
228 StackZone zone(isolate); | 228 StackZone zone(isolate); |
229 HANDLESCOPE(isolate); | 229 HANDLESCOPE(isolate); |
230 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(0)); | 230 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(0)); |
231 Service::HandleRootMessage(message); | 231 Service::HandleRootMessage(message); |
232 } | 232 } |
233 | 233 |
234 | 234 |
| 235 void Service::SetEventMask(uint32_t mask) { |
| 236 event_mask_ = mask; |
| 237 } |
| 238 |
| 239 |
| 240 void SetEventMask(Dart_NativeArguments args) { |
| 241 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 242 Isolate* isolate = arguments->isolate(); |
| 243 StackZone zone(isolate); |
| 244 HANDLESCOPE(isolate); |
| 245 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(0)); |
| 246 Service::SetEventMask(mask.AsTruncatedUint32Value()); |
| 247 } |
| 248 |
| 249 |
235 struct VmServiceNativeEntry { | 250 struct VmServiceNativeEntry { |
236 const char* name; | 251 const char* name; |
237 int num_arguments; | 252 int num_arguments; |
238 Dart_NativeFunction function; | 253 Dart_NativeFunction function; |
239 }; | 254 }; |
240 | 255 |
241 | 256 |
242 static VmServiceNativeEntry _VmServiceNativeEntries[] = { | 257 static VmServiceNativeEntry _VmServiceNativeEntries[] = { |
243 {"VMService_SendIsolateServiceMessage", 2, SendIsolateServiceMessage}, | 258 {"VMService_SendIsolateServiceMessage", 2, SendIsolateServiceMessage}, |
244 {"VMService_SendRootServiceMessage", 1, SendRootServiceMessage} | 259 {"VMService_SendRootServiceMessage", 1, SendRootServiceMessage}, |
| 260 {"VMService_SetEventMask", 1, SetEventMask}, |
245 }; | 261 }; |
246 | 262 |
247 | 263 |
248 static Dart_NativeFunction VmServiceNativeResolver(Dart_Handle name, | 264 static Dart_NativeFunction VmServiceNativeResolver(Dart_Handle name, |
249 int num_arguments, | 265 int num_arguments, |
250 bool* auto_setup_scope) { | 266 bool* auto_setup_scope) { |
251 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | 267 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); |
252 if (!obj.IsString()) { | 268 if (!obj.IsString()) { |
253 return NULL; | 269 return NULL; |
254 } | 270 } |
(...skipping 12 matching lines...) Expand all Loading... |
267 } | 283 } |
268 return NULL; | 284 return NULL; |
269 } | 285 } |
270 | 286 |
271 | 287 |
272 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; | 288 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; |
273 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; | 289 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; |
274 Isolate* Service::service_isolate_ = NULL; | 290 Isolate* Service::service_isolate_ = NULL; |
275 Dart_LibraryTagHandler Service::default_handler_ = NULL; | 291 Dart_LibraryTagHandler Service::default_handler_ = NULL; |
276 Dart_Port Service::port_ = ILLEGAL_PORT; | 292 Dart_Port Service::port_ = ILLEGAL_PORT; |
| 293 uint32_t Service::event_mask_ = 0; |
277 | 294 |
278 | 295 |
279 static Dart_Port ExtractPort(Dart_Handle receivePort) { | 296 static Dart_Port ExtractPort(Dart_Handle receivePort) { |
280 HANDLESCOPE(Isolate::Current()); | 297 HANDLESCOPE(Isolate::Current()); |
281 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); | 298 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); |
282 const Instance& rp = Instance::Cast(unwrapped_rp); | 299 const Instance& rp = Instance::Cast(unwrapped_rp); |
283 // Extract RawReceivePort port id. | 300 // Extract RawReceivePort port id. |
284 if (!rp.IsReceivePort()) { | 301 if (!rp.IsReceivePort()) { |
285 return ILLEGAL_PORT; | 302 return ILLEGAL_PORT; |
286 } | 303 } |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 if (FLAG_trace_service) { | 512 if (FLAG_trace_service) { |
496 OS::Print("Isolate %s %" Pd64 " deregistered with service \n", | 513 OS::Print("Isolate %s %" Pd64 " deregistered with service \n", |
497 name.ToCString(), | 514 name.ToCString(), |
498 Dart_GetMainPortId()); | 515 Dart_GetMainPortId()); |
499 } | 516 } |
500 return PortMap::PostMessage( | 517 return PortMap::PostMessage( |
501 new Message(port_, data, len, Message::kNormalPriority)); | 518 new Message(port_, data, len, Message::kNormalPriority)); |
502 } | 519 } |
503 | 520 |
504 | 521 |
505 bool Service::IsRunning() { | |
506 return port_ != ILLEGAL_PORT; | |
507 } | |
508 | |
509 | |
510 Dart_Handle Service::GetSource(const char* name) { | 522 Dart_Handle Service::GetSource(const char* name) { |
511 ASSERT(name != NULL); | 523 ASSERT(name != NULL); |
512 int i = 0; | 524 int i = 0; |
513 while (true) { | 525 while (true) { |
514 const char* path = Resources::Path(i); | 526 const char* path = Resources::Path(i); |
515 if (path == NULL) { | 527 if (path == NULL) { |
516 break; | 528 break; |
517 } | 529 } |
518 ASSERT(*path != '\0'); | 530 ASSERT(*path != '\0'); |
519 // Skip the '/'. | 531 // Skip the '/'. |
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2172 return entry.handler; | 2184 return entry.handler; |
2173 } | 2185 } |
2174 } | 2186 } |
2175 if (FLAG_trace_service) { | 2187 if (FLAG_trace_service) { |
2176 OS::Print("Service has no root message handler for <%s>\n", command); | 2188 OS::Print("Service has no root message handler for <%s>\n", command); |
2177 } | 2189 } |
2178 return NULL; | 2190 return NULL; |
2179 } | 2191 } |
2180 | 2192 |
2181 | 2193 |
| 2194 void Service::SendEvent(intptr_t eventId, const String& eventMessage) { |
| 2195 if (!IsRunning()) { |
| 2196 return; |
| 2197 } |
| 2198 Isolate* isolate = Isolate::Current(); |
| 2199 ASSERT(isolate != NULL); |
| 2200 HANDLESCOPE(isolate); |
| 2201 |
| 2202 // Construct a list of the form [eventId, eventMessage]. |
| 2203 const Array& list = Array::Handle(Array::New(2)); |
| 2204 ASSERT(!list.IsNull()); |
| 2205 list.SetAt(0, Integer::Handle(Integer::New(eventId))); |
| 2206 list.SetAt(1, eventMessage); |
| 2207 |
| 2208 // Push the event to port_. |
| 2209 uint8_t* data = NULL; |
| 2210 MessageWriter writer(&data, &allocator); |
| 2211 writer.WriteMessage(list); |
| 2212 intptr_t len = writer.BytesWritten(); |
| 2213 if (FLAG_trace_service) { |
| 2214 OS::Print("Pushing event of type %" Pd ", len %" Pd "\n", eventId, len); |
| 2215 } |
| 2216 // TODO(turnidge): For now we ignore failure to send an event. Revisit? |
| 2217 PortMap::PostMessage( |
| 2218 new Message(port_, data, len, Message::kNormalPriority)); |
| 2219 } |
| 2220 |
| 2221 |
| 2222 void Service::HandleDebuggerEvent(DebuggerEvent* event) { |
| 2223 JSONStream js; |
| 2224 event->PrintJSON(&js); |
| 2225 const String& message = String::Handle(String::New(js.ToCString())); |
| 2226 SendEvent(kEventFamilyDebug, message); |
| 2227 } |
| 2228 |
| 2229 |
2182 void Service::EmbedderHandleMessage(EmbedderServiceHandler* handler, | 2230 void Service::EmbedderHandleMessage(EmbedderServiceHandler* handler, |
2183 JSONStream* js) { | 2231 JSONStream* js) { |
2184 ASSERT(handler != NULL); | 2232 ASSERT(handler != NULL); |
2185 Dart_ServiceRequestCallback callback = handler->callback(); | 2233 Dart_ServiceRequestCallback callback = handler->callback(); |
2186 ASSERT(callback != NULL); | 2234 ASSERT(callback != NULL); |
2187 const char* r = NULL; | 2235 const char* r = NULL; |
2188 const char* name = js->command(); | 2236 const char* name = js->command(); |
2189 const char** arguments = js->arguments(); | 2237 const char** arguments = js->arguments(); |
2190 const char** keys = js->option_keys(); | 2238 const char** keys = js->option_keys(); |
2191 const char** values = js->option_values(); | 2239 const char** values = js->option_values(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 while (current != NULL) { | 2316 while (current != NULL) { |
2269 if (strcmp(name, current->name()) == 0) { | 2317 if (strcmp(name, current->name()) == 0) { |
2270 return current; | 2318 return current; |
2271 } | 2319 } |
2272 current = current->next(); | 2320 current = current->next(); |
2273 } | 2321 } |
2274 return NULL; | 2322 return NULL; |
2275 } | 2323 } |
2276 | 2324 |
2277 } // namespace dart | 2325 } // namespace dart |
OLD | NEW |