Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Unified Diff: runtime/vm/service.cc

Issue 19622003: VM Service isolate listing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/service.h ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/service.cc
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a27c19c85e6d08c67202e44d3ffb31221c8ea4b
--- /dev/null
+++ b/runtime/vm/service.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "vm/isolate.h"
+#include "vm/message.h"
+#include "vm/object.h"
+#include "vm/port.h"
+#include "vm/service.h"
+
+namespace dart {
+
+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);
+}
+
+
+static void PostReply(const String& reply, Dart_Port reply_port) {
+ uint8_t* data = NULL;
+ MessageWriter writer(&data, &allocator);
+ writer.WriteMessage(reply);
+ PortMap::PostMessage(new Message(reply_port, Message::kIllegalPort, data,
+ writer.BytesWritten(),
+ Message::kNormalPriority));
+}
+
+
+static RawString* HandleIdMessage(Isolate* isolate, Dart_Port reply_port) {
+ TextBuffer buffer(256);
+ buffer.Printf("{ \"id\": \"%s\" }", isolate->name());
+ return String::New(buffer.buf());
+}
+
+
+void Service::HandleServiceMessage(Isolate* isolate, Dart_Port reply_port,
+ const Instance& message) {
+ ASSERT(isolate != NULL);
+ ASSERT(reply_port != ILLEGAL_PORT);
+ ASSERT(!message.IsNull());
+ ASSERT(message.IsString());
+
+ String& reply = String::Handle();
+
+ // For now, assume service message is always an id check.
+ reply = HandleIdMessage(isolate, reply_port);
+
+ ASSERT(!reply.IsNull());
+
+ PostReply(reply, reply_port);
+}
+
+} // namespace dart
« no previous file with comments | « runtime/vm/service.h ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698