Chromium Code Reviews| Index: runtime/vm/service.cc |
| =================================================================== |
| --- runtime/vm/service.cc (revision 39217) |
| +++ 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", "_echo/event"); |
| + 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/isolate"); |
| + 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) { \ |
| @@ -2277,9 +2303,8 @@ |
| static bool HandleRootEcho(JSONStream* js) { |
| JSONObject jsobj(js); |
| - jsobj.AddProperty("type", "message"); |
| - PrintArgumentsAndOptions(jsobj, js); |
| - return true; |
| + jsobj.AddProperty("id", "_echo/root"); |
| + return HandleCommonEcho(&jsobj, js); |
| } |
| @@ -2392,7 +2417,7 @@ |
| } |
| -void Service::SendEvent(intptr_t eventId, const String& eventMessage) { |
| +void Service::SendEvent(intptr_t eventId, const Object& eventMessage) { |
| if (!IsRunning()) { |
| return; |
| } |
| @@ -2420,6 +2445,31 @@ |
| } |
| +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; |
|
Cutch
2014/08/15 21:33:58
Do we really need 64-bits to encode the meta-data
koda
2014/08/15 22:20:53
Do we really need more than 32 bits for IP address
|
| + 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; |
| + } |
| + 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); |