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