| Index: runtime/vm/service.cc
|
| diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc
|
| index ca8a3a758234473c2a80612e4d958c0eca27267f..4237a79d0e53f82e05be171f932cdad2937c8fab 100644
|
| --- a/runtime/vm/service.cc
|
| +++ b/runtime/vm/service.cc
|
| @@ -74,54 +74,6 @@ EmbedderServiceHandler* Service::root_service_handler_head_ = NULL;
|
| struct ServiceMethodDescriptor;
|
| ServiceMethodDescriptor* FindMethod(const char* method_name);
|
|
|
| -// TODO(turnidge): Build a general framework later. For now, we have
|
| -// a small set of well-known streams.
|
| -bool Service::needs_isolate_events_ = false;
|
| -bool Service::needs_debug_events_ = false;
|
| -bool Service::needs_gc_events_ = false;
|
| -bool Service::needs_echo_events_ = false;
|
| -bool Service::needs_graph_events_ = false;
|
| -
|
| -void Service::ListenStream(const char* stream_id) {
|
| - if (FLAG_trace_service) {
|
| - OS::Print("vm-service: starting stream '%s'\n",
|
| - stream_id);
|
| - }
|
| - if (strcmp(stream_id, "Isolate") == 0) {
|
| - needs_isolate_events_ = true;
|
| - } else if (strcmp(stream_id, "Debug") == 0) {
|
| - needs_debug_events_ = true;
|
| - } else if (strcmp(stream_id, "GC") == 0) {
|
| - needs_gc_events_ = true;
|
| - } else if (strcmp(stream_id, "_Echo") == 0) {
|
| - needs_echo_events_ = true;
|
| - } else if (strcmp(stream_id, "_Graph") == 0) {
|
| - needs_graph_events_ = true;
|
| - } else {
|
| - UNREACHABLE();
|
| - }
|
| -}
|
| -
|
| -void Service::CancelStream(const char* stream_id) {
|
| - if (FLAG_trace_service) {
|
| - OS::Print("vm-service: stopping stream '%s'\n",
|
| - stream_id);
|
| - }
|
| - if (strcmp(stream_id, "Isolate") == 0) {
|
| - needs_isolate_events_ = false;
|
| - } else if (strcmp(stream_id, "Debug") == 0) {
|
| - needs_debug_events_ = false;
|
| - } else if (strcmp(stream_id, "GC") == 0) {
|
| - needs_gc_events_ = false;
|
| - } else if (strcmp(stream_id, "_Echo") == 0) {
|
| - needs_echo_events_ = false;
|
| - } else if (strcmp(stream_id, "_Graph") == 0) {
|
| - needs_graph_events_ = false;
|
| - } else {
|
| - UNREACHABLE();
|
| - }
|
| -}
|
| -
|
| static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
|
| void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
|
| return reinterpret_cast<uint8_t*>(new_ptr);
|
| @@ -540,9 +492,13 @@ void Service::HandleIsolateMessage(Isolate* isolate, const Array& msg) {
|
| }
|
|
|
|
|
| -void Service::SendEvent(const char* stream_id,
|
| - const char* event_type,
|
| - const Object& event_message) {
|
| +bool Service::NeedsEvents() {
|
| + return ServiceIsolate::IsRunning();
|
| +}
|
| +
|
| +
|
| +void Service::SendEvent(intptr_t eventType,
|
| + const Object& eventMessage) {
|
| ASSERT(!ServiceIsolate::IsServiceIsolateDescendant(Isolate::Current()));
|
| if (!ServiceIsolate::IsRunning()) {
|
| return;
|
| @@ -551,21 +507,14 @@ void Service::SendEvent(const char* stream_id,
|
| ASSERT(isolate != NULL);
|
| HANDLESCOPE(isolate);
|
|
|
| - const Array& list = Array::Handle(Array::New(2));
|
| - ASSERT(!list.IsNull());
|
| - const String& stream_id_str = String::Handle(String::New(stream_id));
|
| - list.SetAt(0, stream_id_str);
|
| - list.SetAt(1, event_message);
|
| -
|
| // Push the event to port_.
|
| uint8_t* data = NULL;
|
| MessageWriter writer(&data, &allocator, false);
|
| - writer.WriteMessage(list);
|
| + writer.WriteMessage(eventMessage);
|
| intptr_t len = writer.BytesWritten();
|
| if (FLAG_trace_service) {
|
| - OS::Print(
|
| - "vm-service: Pushing event of type %s to stream %s, len %" Pd "\n",
|
| - event_type, stream_id, len);
|
| + OS::Print("vm-service: Pushing event of type %" Pd ", len %" Pd "\n",
|
| + eventType, len);
|
| }
|
| // TODO(turnidge): For now we ignore failure to send an event. Revisit?
|
| PortMap::PostMessage(
|
| @@ -573,11 +522,9 @@ void Service::SendEvent(const char* stream_id,
|
| }
|
|
|
|
|
| -void Service::SendEventWithData(const char* stream_id,
|
| - const char* event_type,
|
| - const String& meta,
|
| - const uint8_t* data,
|
| - intptr_t size) {
|
| +void Service::SendEvent(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;
|
| @@ -600,7 +547,8 @@ void Service::SendEventWithData(const char* stream_id,
|
| offset += size;
|
| }
|
| ASSERT(offset == total_bytes);
|
| - SendEvent(stream_id, event_type, message);
|
| + // TODO(turnidge): Pass the real eventType here.
|
| + SendEvent(0, message);
|
| }
|
|
|
|
|
| @@ -609,16 +557,12 @@ void Service::HandleEvent(ServiceEvent* event) {
|
| return;
|
| }
|
| JSONStream js;
|
| - const char* stream_id = event->stream_id();
|
| - ASSERT(stream_id != NULL);
|
| {
|
| JSONObject jsobj(&js);
|
| jsobj.AddProperty("event", event);
|
| - jsobj.AddProperty("streamId", stream_id);
|
| }
|
| const String& message = String::Handle(String::New(js.ToCString()));
|
| - SendEvent(stream_id, ServiceEvent::EventTypeToCString(event->type()),
|
| - message);
|
| + SendEvent(event->type(), message);
|
| }
|
|
|
|
|
| @@ -667,10 +611,10 @@ void Service::EmbedderHandleMessage(EmbedderServiceHandler* handler,
|
| Dart_ServiceRequestCallback callback = handler->callback();
|
| ASSERT(callback != NULL);
|
| const char* r = NULL;
|
| - const char* method = js->method();
|
| + const char* name = js->method();
|
| const char** keys = js->param_keys();
|
| const char** values = js->param_values();
|
| - r = callback(method, keys, values, js->num_params(), handler->user_data());
|
| + r = callback(name, keys, values, js->num_params(), handler->user_data());
|
| ASSERT(r != NULL);
|
| // TODO(johnmccutchan): Allow for NULL returns?
|
| TextBuffer* buffer = js->buffer();
|
| @@ -827,11 +771,10 @@ void Service::SendEchoEvent(Isolate* isolate, const char* text) {
|
| event.AddProperty("text", text);
|
| }
|
| }
|
| - jsobj.AddProperty("streamId", "_Echo");
|
| }
|
| const String& message = String::Handle(String::New(js.ToCString()));
|
| uint8_t data[] = {0, 128, 255};
|
| - SendEventWithData("_Echo", "_Echo", message, data, sizeof(data));
|
| + SendEvent(message, data, sizeof(data));
|
| }
|
|
|
|
|
| @@ -2123,7 +2066,7 @@ static bool Resume(Isolate* isolate, JSONStream* js) {
|
| isolate->message_handler()->set_pause_on_start(false);
|
| JSONObject jsobj(js);
|
| jsobj.AddProperty("type", "Success");
|
| - if (Service::NeedsDebugEvents()) {
|
| + {
|
| ServiceEvent event(isolate, ServiceEvent::kResume);
|
| Service::HandleEvent(&event);
|
| }
|
| @@ -2340,15 +2283,12 @@ void Service::SendGraphEvent(Isolate* isolate) {
|
| ? stream.bytes_written() - (i * kChunkSize)
|
| : kChunkSize;
|
|
|
| - SendEventWithData("_Graph", "_Graph", message, chunk_start, chunk_size);
|
| + SendEvent(message, chunk_start, chunk_size);
|
| }
|
| }
|
|
|
|
|
| void Service::SendInspectEvent(Isolate* isolate, const Object& inspectee) {
|
| - if (!Service::NeedsDebugEvents()) {
|
| - return;
|
| - }
|
| ServiceEvent event(isolate, ServiceEvent::kInspect);
|
| event.set_inspectee(&inspectee);
|
| Service::HandleEvent(&event);
|
| @@ -2630,7 +2570,7 @@ static const MethodParameter* set_name_params[] = {
|
|
|
| static bool SetName(Isolate* isolate, JSONStream* js) {
|
| isolate->set_debugger_name(js->LookupParam("name"));
|
| - if (Service::NeedsIsolateEvents()) {
|
| + {
|
| ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate);
|
| Service::HandleEvent(&event);
|
| }
|
|
|