OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "vm/isolate.h" |
| 6 #include "vm/message.h" |
| 7 #include "vm/object.h" |
| 8 #include "vm/port.h" |
| 9 #include "vm/service.h" |
| 10 |
| 11 namespace dart { |
| 12 |
| 13 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 14 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 15 return reinterpret_cast<uint8_t*>(new_ptr); |
| 16 } |
| 17 |
| 18 |
| 19 static void PostReply(const String& reply, Dart_Port reply_port) { |
| 20 uint8_t* data = NULL; |
| 21 MessageWriter writer(&data, &allocator); |
| 22 writer.WriteMessage(reply); |
| 23 PortMap::PostMessage(new Message(reply_port, Message::kIllegalPort, data, |
| 24 writer.BytesWritten(), |
| 25 Message::kNormalPriority)); |
| 26 } |
| 27 |
| 28 |
| 29 static RawString* HandleIdMessage(Isolate* isolate, Dart_Port reply_port) { |
| 30 TextBuffer buffer(256); |
| 31 buffer.Printf("{ \"id\": \"%s\" }", isolate->name()); |
| 32 return String::New(buffer.buf()); |
| 33 } |
| 34 |
| 35 |
| 36 void Service::HandleServiceMessage(Isolate* isolate, Dart_Port reply_port, |
| 37 const Instance& message) { |
| 38 ASSERT(isolate != NULL); |
| 39 ASSERT(reply_port != ILLEGAL_PORT); |
| 40 ASSERT(!message.IsNull()); |
| 41 ASSERT(message.IsString()); |
| 42 |
| 43 String& reply = String::Handle(); |
| 44 |
| 45 // For now, assume service message is always an id check. |
| 46 reply = HandleIdMessage(isolate, reply_port); |
| 47 |
| 48 ASSERT(!reply.IsNull()); |
| 49 |
| 50 PostReply(reply, reply_port); |
| 51 } |
| 52 |
| 53 } // namespace dart |
OLD | NEW |