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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 50 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
51 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 51 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
52 return reinterpret_cast<uint8_t*>(new_ptr); | 52 return reinterpret_cast<uint8_t*>(new_ptr); |
53 } | 53 } |
54 | 54 |
55 static void PrintRequest(const JSONObject& obj, JSONStream* js) { | 55 static void PrintRequest(const JSONObject& obj, JSONStream* js) { |
56 JSONObject jsobj(&obj, "request"); | 56 JSONObject jsobj(&obj, "request"); |
57 jsobj.AddProperty("method", js->method()); | 57 jsobj.AddProperty("method", js->method()); |
58 { | 58 { |
59 JSONArray jsarr(&jsobj, "param_keys"); | 59 JSONObject params(&jsobj, "params"); |
60 for (intptr_t i = 0; i < js->num_params(); i++) { | 60 for (intptr_t i = 0; i < js->num_params(); i++) { |
61 jsarr.AddValue(js->GetParamKey(i)); | 61 params.AddProperty(js->GetParamKey(i), js->GetParamValue(i)); |
62 } | |
63 } | |
64 { | |
65 JSONArray jsarr(&jsobj, "param_values"); | |
66 for (intptr_t i = 0; i < js->num_params(); i++) { | |
67 jsarr.AddValue(js->GetParamValue(i)); | |
68 } | 62 } |
69 } | 63 } |
70 } | 64 } |
71 | 65 |
72 | 66 |
73 static void PrintError(JSONStream* js, | 67 static void PrintError(JSONStream* js, |
74 const char* format, ...) { | 68 const char* format, ...) { |
75 Isolate* isolate = Isolate::Current(); | 69 Isolate* isolate = Isolate::Current(); |
76 | 70 |
77 va_list args; | 71 va_list args; |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 return false; | 411 return false; |
418 } | 412 } |
419 } | 413 } |
420 return true; | 414 return true; |
421 } | 415 } |
422 | 416 |
423 | 417 |
424 void Service::InvokeMethod(Isolate* isolate, const Array& msg) { | 418 void Service::InvokeMethod(Isolate* isolate, const Array& msg) { |
425 ASSERT(isolate != NULL); | 419 ASSERT(isolate != NULL); |
426 ASSERT(!msg.IsNull()); | 420 ASSERT(!msg.IsNull()); |
427 ASSERT(msg.Length() == 5); | 421 ASSERT(msg.Length() == 6); |
428 | 422 |
429 { | 423 { |
430 StackZone zone(isolate); | 424 StackZone zone(isolate); |
431 HANDLESCOPE(isolate); | 425 HANDLESCOPE(isolate); |
432 | 426 |
433 Instance& reply_port = Instance::Handle(isolate); | 427 Instance& reply_port = Instance::Handle(isolate); |
| 428 String& seq = String::Handle(isolate); |
434 String& method_name = String::Handle(isolate); | 429 String& method_name = String::Handle(isolate); |
435 Array& param_keys = Array::Handle(isolate); | 430 Array& param_keys = Array::Handle(isolate); |
436 Array& param_values = Array::Handle(isolate); | 431 Array& param_values = Array::Handle(isolate); |
437 reply_port ^= msg.At(1); | 432 reply_port ^= msg.At(1); |
438 method_name ^= msg.At(2); | 433 seq ^= msg.At(2); |
439 param_keys ^= msg.At(3); | 434 method_name ^= msg.At(3); |
440 param_values ^= msg.At(4); | 435 param_keys ^= msg.At(4); |
| 436 param_values ^= msg.At(5); |
441 | 437 |
442 ASSERT(!method_name.IsNull()); | 438 ASSERT(!method_name.IsNull()); |
| 439 ASSERT(!seq.IsNull()); |
443 ASSERT(!param_keys.IsNull()); | 440 ASSERT(!param_keys.IsNull()); |
444 ASSERT(!param_values.IsNull()); | 441 ASSERT(!param_values.IsNull()); |
445 ASSERT(param_keys.Length() == param_values.Length()); | 442 ASSERT(param_keys.Length() == param_values.Length()); |
446 | 443 |
447 if (!reply_port.IsSendPort()) { | 444 if (!reply_port.IsSendPort()) { |
448 FATAL("SendPort expected."); | 445 FATAL("SendPort expected."); |
449 } | 446 } |
450 | 447 |
451 JSONStream js; | 448 JSONStream js; |
452 js.Setup(zone.GetZone(), SendPort::Cast(reply_port).Id(), | 449 js.Setup(zone.GetZone(), SendPort::Cast(reply_port).Id(), |
453 method_name, param_keys, param_values); | 450 seq, method_name, param_keys, param_values); |
454 | 451 |
455 const char* c_method_name = method_name.ToCString(); | 452 const char* c_method_name = method_name.ToCString(); |
456 | 453 |
457 ServiceMethodDescriptor* method = FindMethod(c_method_name); | 454 ServiceMethodDescriptor* method = FindMethod(c_method_name); |
458 if (method != NULL) { | 455 if (method != NULL) { |
459 if (!ValidateParameters(method->parameters, &js)) { | 456 if (!ValidateParameters(method->parameters, &js)) { |
460 js.PostReply(); | 457 js.PostReply(); |
461 return; | 458 return; |
462 } | 459 } |
463 if (method->entry(isolate, &js)) { | 460 if (method->entry(isolate, &js)) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 NoSafepointScope no_safepoint; | 550 NoSafepointScope no_safepoint; |
554 memmove(message.DataAddr(offset), data, size); | 551 memmove(message.DataAddr(offset), data, size); |
555 offset += size; | 552 offset += size; |
556 } | 553 } |
557 ASSERT(offset == total_bytes); | 554 ASSERT(offset == total_bytes); |
558 // TODO(turnidge): Pass the real eventType here. | 555 // TODO(turnidge): Pass the real eventType here. |
559 SendEvent(0, message); | 556 SendEvent(0, message); |
560 } | 557 } |
561 | 558 |
562 | 559 |
563 void Service::HandleGCEvent(GCEvent* event) { | |
564 if (ServiceIsolate::IsServiceIsolateDescendant(Isolate::Current())) { | |
565 return; | |
566 } | |
567 JSONStream js; | |
568 event->PrintJSON(&js); | |
569 const String& message = String::Handle(String::New(js.ToCString())); | |
570 // TODO(turnidge): Pass the real eventType here. | |
571 SendEvent(0, message); | |
572 } | |
573 | |
574 | |
575 void Service::HandleEvent(ServiceEvent* event) { | 560 void Service::HandleEvent(ServiceEvent* event) { |
| 561 if (ServiceIsolate::IsServiceIsolateDescendant(event->isolate())) { |
| 562 return; |
| 563 } |
576 JSONStream js; | 564 JSONStream js; |
577 event->PrintJSON(&js); | 565 { |
| 566 JSONObject jsobj(&js); |
| 567 jsobj.AddProperty("event", event); |
| 568 } |
578 const String& message = String::Handle(String::New(js.ToCString())); | 569 const String& message = String::Handle(String::New(js.ToCString())); |
579 SendEvent(event->type(), message); | 570 SendEvent(event->type(), message); |
580 } | 571 } |
581 | 572 |
582 | 573 |
583 class EmbedderServiceHandler { | 574 class EmbedderServiceHandler { |
584 public: | 575 public: |
585 explicit EmbedderServiceHandler(const char* name) : name_(NULL), | 576 explicit EmbedderServiceHandler(const char* name) : name_(NULL), |
586 callback_(NULL), | 577 callback_(NULL), |
587 user_data_(NULL), | 578 user_data_(NULL), |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 jsobj->AddProperty("text", js->LookupParam("text")); | 746 jsobj->AddProperty("text", js->LookupParam("text")); |
756 } | 747 } |
757 return true; | 748 return true; |
758 } | 749 } |
759 | 750 |
760 | 751 |
761 void Service::SendEchoEvent(Isolate* isolate, const char* text) { | 752 void Service::SendEchoEvent(Isolate* isolate, const char* text) { |
762 JSONStream js; | 753 JSONStream js; |
763 { | 754 { |
764 JSONObject jsobj(&js); | 755 JSONObject jsobj(&js); |
765 jsobj.AddProperty("type", "ServiceEvent"); | 756 { |
766 jsobj.AddProperty("eventType", "_Echo"); | 757 JSONObject event(&jsobj, "event"); |
767 jsobj.AddProperty("isolate", isolate); | 758 event.AddProperty("type", "ServiceEvent"); |
768 if (text != NULL) { | 759 event.AddProperty("eventType", "_Echo"); |
769 jsobj.AddProperty("text", text); | 760 event.AddProperty("isolate", isolate); |
| 761 if (text != NULL) { |
| 762 event.AddProperty("text", text); |
| 763 } |
770 } | 764 } |
771 } | 765 } |
772 const String& message = String::Handle(String::New(js.ToCString())); | 766 const String& message = String::Handle(String::New(js.ToCString())); |
773 uint8_t data[] = {0, 128, 255}; | 767 uint8_t data[] = {0, 128, 255}; |
774 SendEvent(message, data, sizeof(data)); | 768 SendEvent(message, data, sizeof(data)); |
775 } | 769 } |
776 | 770 |
777 | 771 |
778 static bool _TriggerEchoEvent(Isolate* isolate, JSONStream* js) { | 772 static bool _TriggerEchoEvent(Isolate* isolate, JSONStream* js) { |
779 Service::SendEchoEvent(isolate, js->LookupParam("text")); | 773 Service::SendEchoEvent(isolate, js->LookupParam("text")); |
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 | 2189 |
2196 | 2190 |
2197 void Service::SendGraphEvent(Isolate* isolate) { | 2191 void Service::SendGraphEvent(Isolate* isolate) { |
2198 uint8_t* buffer = NULL; | 2192 uint8_t* buffer = NULL; |
2199 WriteStream stream(&buffer, &allocator, 1 * MB); | 2193 WriteStream stream(&buffer, &allocator, 1 * MB); |
2200 ObjectGraph graph(isolate); | 2194 ObjectGraph graph(isolate); |
2201 graph.Serialize(&stream); | 2195 graph.Serialize(&stream); |
2202 JSONStream js; | 2196 JSONStream js; |
2203 { | 2197 { |
2204 JSONObject jsobj(&js); | 2198 JSONObject jsobj(&js); |
2205 jsobj.AddProperty("type", "ServiceEvent"); | 2199 { |
2206 jsobj.AddProperty("eventType", "_Graph"); | 2200 JSONObject event(&jsobj, "event"); |
2207 jsobj.AddProperty("isolate", isolate); | 2201 event.AddProperty("type", "ServiceEvent"); |
| 2202 event.AddProperty("eventType", "_Graph"); |
| 2203 event.AddProperty("isolate", isolate); |
| 2204 } |
2208 } | 2205 } |
2209 const String& message = String::Handle(String::New(js.ToCString())); | 2206 const String& message = String::Handle(String::New(js.ToCString())); |
2210 SendEvent(message, buffer, stream.bytes_written()); | 2207 SendEvent(message, buffer, stream.bytes_written()); |
2211 } | 2208 } |
2212 | 2209 |
2213 | 2210 |
2214 class ContainsAddressVisitor : public FindObjectVisitor { | 2211 class ContainsAddressVisitor : public FindObjectVisitor { |
2215 public: | 2212 public: |
2216 ContainsAddressVisitor(Isolate* isolate, uword addr) | 2213 ContainsAddressVisitor(Isolate* isolate, uword addr) |
2217 : FindObjectVisitor(isolate), addr_(addr) { } | 2214 : FindObjectVisitor(isolate), addr_(addr) { } |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2577 ServiceMethodDescriptor& method = service_methods_[i]; | 2574 ServiceMethodDescriptor& method = service_methods_[i]; |
2578 if (strcmp(method_name, method.name) == 0) { | 2575 if (strcmp(method_name, method.name) == 0) { |
2579 return &method; | 2576 return &method; |
2580 } | 2577 } |
2581 } | 2578 } |
2582 return NULL; | 2579 return NULL; |
2583 } | 2580 } |
2584 | 2581 |
2585 | 2582 |
2586 } // namespace dart | 2583 } // namespace dart |
OLD | NEW |