| Index: runtime/vm/service.cc
|
| ===================================================================
|
| --- runtime/vm/service.cc (revision 39330)
|
| +++ runtime/vm/service.cc (working copy)
|
| @@ -27,6 +27,7 @@
|
| #include "vm/reusable_handles.h"
|
| #include "vm/stack_frame.h"
|
| #include "vm/symbols.h"
|
| +#include "vm/unicode.h"
|
| #include "vm/version.h"
|
|
|
|
|
| @@ -789,14 +790,39 @@
|
| }
|
|
|
|
|
| -static bool HandleIsolateEcho(Isolate* isolate, JSONStream* js) {
|
| - JSONObject jsobj(js);
|
| - jsobj.AddProperty("type", "message");
|
| - PrintArgumentsAndOptions(jsobj, js);
|
| +static bool HandleCommonEcho(JSONObject* jsobj, JSONStream* js) {
|
| + jsobj->AddProperty("type", "message");
|
| + PrintArgumentsAndOptions(*jsobj, js);
|
| return true;
|
| }
|
|
|
|
|
| +void Service::SendEchoEvent(Isolate* isolate) {
|
| + JSONStream js;
|
| + {
|
| + JSONObject jsobj(&js);
|
| + jsobj.AddProperty("type", "ServiceEvent");
|
| + jsobj.AddPropertyF("id", "_echoEvent");
|
| + jsobj.AddProperty("eventType", "_Echo");
|
| + jsobj.AddProperty("isolate", isolate);
|
| + }
|
| + const String& message = String::Handle(String::New(js.ToCString()));
|
| + uint8_t data[] = {0, 128, 255};
|
| + // TODO(koda): Add 'testing' event family.
|
| + SendEvent(kEventFamilyDebug, message, data, sizeof(data));
|
| +}
|
| +
|
| +
|
| +bool HandleIsolateEcho(Isolate* isolate, JSONStream* js) {
|
| + JSONObject jsobj(js);
|
| + jsobj.AddProperty("id", "_echo");
|
| + if (js->num_arguments() == 2 && strcmp(js->GetArgument(1), "event") == 0) {
|
| + Service::SendEchoEvent(isolate);
|
| + }
|
| + return HandleCommonEcho(&jsobj, js);
|
| +}
|
| +
|
| +
|
| // Print an error message if there is no ID argument.
|
| #define REQUIRE_COLLECTION_ID(collection) \
|
| if (js->num_arguments() == 1) { \
|
| @@ -2323,9 +2349,8 @@
|
|
|
| static bool HandleRootEcho(JSONStream* js) {
|
| JSONObject jsobj(js);
|
| - jsobj.AddProperty("type", "message");
|
| - PrintArgumentsAndOptions(jsobj, js);
|
| - return true;
|
| + jsobj.AddProperty("id", "_echo");
|
| + return HandleCommonEcho(&jsobj, js);
|
| }
|
|
|
|
|
| @@ -2438,7 +2463,7 @@
|
| }
|
|
|
|
|
| -void Service::SendEvent(intptr_t eventId, const String& eventMessage) {
|
| +void Service::SendEvent(intptr_t eventId, const Object& eventMessage) {
|
| if (!IsRunning()) {
|
| return;
|
| }
|
| @@ -2466,6 +2491,33 @@
|
| }
|
|
|
|
|
| +void Service::SendEvent(intptr_t eventId,
|
| + const String& meta,
|
| + const uint8_t* data,
|
| + intptr_t size) {
|
| + // Bitstream: [meta data size (big-endian 64 bit)] [meta data (UTF-8)] [data]
|
| + const intptr_t meta_bytes = Utf8::Length(meta);
|
| + const intptr_t total_bytes = sizeof(uint64_t) + meta_bytes + size;
|
| + const TypedData& message = TypedData::Handle(
|
| + TypedData::New(kTypedDataUint8ArrayCid, total_bytes));
|
| + intptr_t offset = 0;
|
| + // TODO(koda): Rename these methods SetHostUint64, etc.
|
| + message.SetUint64(0, Utils::HostToBigEndian64(meta_bytes));
|
| + offset += sizeof(uint64_t);
|
| + {
|
| + NoGCScope no_gc;
|
| + meta.ToUTF8(static_cast<uint8_t*>(message.DataAddr(offset)), meta_bytes);
|
| + offset += meta_bytes;
|
| + }
|
| + // TODO(koda): It would be nice to avoid this copy (requires changes to
|
| + // MessageWriter code).
|
| + memmove(message.DataAddr(offset), data, size);
|
| + offset += size;
|
| + ASSERT(offset == total_bytes);
|
| + SendEvent(eventId, message);
|
| +}
|
| +
|
| +
|
| void Service::HandleGCEvent(GCEvent* event) {
|
| JSONStream js;
|
| event->PrintJSON(&js);
|
|
|