| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/service.h" |
| 6 |
| 7 #include "vm/dart_entry.h" |
| 5 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
| 6 #include "vm/heap_histogram.h" | 9 #include "vm/heap_histogram.h" |
| 7 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| 8 #include "vm/message.h" | 11 #include "vm/message.h" |
| 9 #include "vm/object.h" | 12 #include "vm/object.h" |
| 10 #include "vm/object_id_ring.h" | 13 #include "vm/object_id_ring.h" |
| 11 #include "vm/object_store.h" | 14 #include "vm/object_store.h" |
| 12 #include "vm/port.h" | 15 #include "vm/port.h" |
| 13 #include "vm/service.h" | |
| 14 | 16 |
| 15 namespace dart { | 17 namespace dart { |
| 16 | 18 |
| 17 typedef void (*ServiceMessageHandler)(Isolate* isolate, JSONStream* stream); | 19 typedef void (*ServiceMessageHandler)(Isolate* isolate, JSONStream* stream); |
| 18 | 20 |
| 19 struct ServiceMessageHandlerEntry { | 21 struct ServiceMessageHandlerEntry { |
| 20 const char* command; | 22 const char* command; |
| 21 ServiceMessageHandler handler; | 23 ServiceMessageHandler handler; |
| 22 }; | 24 }; |
| 23 | 25 |
| 24 static ServiceMessageHandler FindServiceMessageHandler(const char* command); | 26 static ServiceMessageHandler FindServiceMessageHandler(const char* command); |
| 25 | 27 |
| 26 | 28 |
| 27 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 29 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 28 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 30 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 29 return reinterpret_cast<uint8_t*>(new_ptr); | 31 return reinterpret_cast<uint8_t*>(new_ptr); |
| 30 } | 32 } |
| 31 | 33 |
| 32 | 34 |
| 33 static void PostReply(const String& reply, Dart_Port reply_port) { | 35 static void PostReply(const String& reply, const Instance& reply_port) { |
| 36 const Object& id_obj = Object::Handle( |
| 37 DartLibraryCalls::PortGetId(reply_port)); |
| 38 if (id_obj.IsError()) { |
| 39 Exceptions::PropagateError(Error::Cast(id_obj)); |
| 40 } |
| 41 const Integer& id = Integer::Cast(id_obj); |
| 42 Dart_Port port = static_cast<Dart_Port>(id.AsInt64Value()); |
| 43 ASSERT(port != ILLEGAL_PORT); |
| 44 |
| 34 uint8_t* data = NULL; | 45 uint8_t* data = NULL; |
| 35 MessageWriter writer(&data, &allocator); | 46 MessageWriter writer(&data, &allocator); |
| 36 writer.WriteMessage(reply); | 47 writer.WriteMessage(reply); |
| 37 PortMap::PostMessage(new Message(reply_port, Message::kIllegalPort, data, | 48 PortMap::PostMessage(new Message(port, data, |
| 38 writer.BytesWritten(), | 49 writer.BytesWritten(), |
| 39 Message::kNormalPriority)); | 50 Message::kNormalPriority)); |
| 40 } | 51 } |
| 41 | 52 |
| 42 | 53 |
| 43 void Service::HandleServiceMessage(Isolate* isolate, Dart_Port reply_port, | 54 void Service::HandleServiceMessage(Isolate* isolate, const Instance& msg) { |
| 44 const Instance& msg) { | |
| 45 ASSERT(isolate != NULL); | 55 ASSERT(isolate != NULL); |
| 46 ASSERT(reply_port != ILLEGAL_PORT); | |
| 47 ASSERT(!msg.IsNull()); | 56 ASSERT(!msg.IsNull()); |
| 48 ASSERT(msg.IsGrowableObjectArray()); | 57 ASSERT(msg.IsGrowableObjectArray()); |
| 49 | 58 |
| 50 { | 59 { |
| 51 StackZone zone(isolate); | 60 StackZone zone(isolate); |
| 52 HANDLESCOPE(isolate); | 61 HANDLESCOPE(isolate); |
| 62 |
| 53 const GrowableObjectArray& message = GrowableObjectArray::Cast(msg); | 63 const GrowableObjectArray& message = GrowableObjectArray::Cast(msg); |
| 54 // Message is a list with three entries. | 64 // Message is a list with three entries. |
| 55 ASSERT(message.Length() == 3); | 65 ASSERT(message.Length() == 4); |
| 56 | 66 |
| 57 GrowableObjectArray& path = GrowableObjectArray::Handle(); | 67 Instance& reply_port = Instance::Handle(isolate); |
| 58 GrowableObjectArray& option_keys = GrowableObjectArray::Handle(); | 68 GrowableObjectArray& path = GrowableObjectArray::Handle(isolate); |
| 59 GrowableObjectArray& option_values = GrowableObjectArray::Handle(); | 69 GrowableObjectArray& option_keys = GrowableObjectArray::Handle(isolate); |
| 60 path ^= message.At(0); | 70 GrowableObjectArray& option_values = GrowableObjectArray::Handle(isolate); |
| 61 option_keys ^= message.At(1); | 71 reply_port ^= message.At(0); |
| 62 option_values ^= message.At(2); | 72 path ^= message.At(1); |
| 73 option_keys ^= message.At(2); |
| 74 option_values ^= message.At(3); |
| 63 | 75 |
| 64 ASSERT(!path.IsNull()); | 76 ASSERT(!path.IsNull()); |
| 65 ASSERT(!option_keys.IsNull()); | 77 ASSERT(!option_keys.IsNull()); |
| 66 ASSERT(!option_values.IsNull()); | 78 ASSERT(!option_values.IsNull()); |
| 67 // Path always has at least one entry in it. | 79 // Path always has at least one entry in it. |
| 68 ASSERT(path.Length() > 0); | 80 ASSERT(path.Length() > 0); |
| 69 // Same number of option keys as values. | 81 // Same number of option keys as values. |
| 70 ASSERT(option_keys.Length() == option_values.Length()); | 82 ASSERT(option_keys.Length() == option_values.Length()); |
| 71 | 83 |
| 72 String& pathSegment = String::Handle(); | 84 String& pathSegment = String::Handle(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 for (intptr_t i = 0; i < num_message_handlers; i++) { | 291 for (intptr_t i = 0; i < num_message_handlers; i++) { |
| 280 const ServiceMessageHandlerEntry& entry = __message_handlers[i]; | 292 const ServiceMessageHandlerEntry& entry = __message_handlers[i]; |
| 281 if (!strcmp(command, entry.command)) { | 293 if (!strcmp(command, entry.command)) { |
| 282 return entry.handler; | 294 return entry.handler; |
| 283 } | 295 } |
| 284 } | 296 } |
| 285 return HandleFallthrough; | 297 return HandleFallthrough; |
| 286 } | 298 } |
| 287 | 299 |
| 288 } // namespace dart | 300 } // namespace dart |
| OLD | NEW |