| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/native_message_handler.h" | 5 #include "vm/native_message_handler.h" |
| 6 | 6 |
| 7 #include "vm/dart_api_message.h" | 7 #include "vm/dart_api_message.h" |
| 8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 9 #include "vm/message.h" | 9 #include "vm/message.h" |
| 10 #include "vm/snapshot.h" | 10 #include "vm/snapshot.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 NativeMessageHandler::NativeMessageHandler(const char* name, | 14 NativeMessageHandler::NativeMessageHandler(const char* name, |
| 15 Dart_NativeMessageHandler func) | 15 Dart_NativeMessageHandler func) |
| 16 : name_(strdup(name)), func_(func) {} | 16 : name_(strdup(name)), func_(func) {} |
| 17 | 17 |
| 18 | |
| 19 NativeMessageHandler::~NativeMessageHandler() { | 18 NativeMessageHandler::~NativeMessageHandler() { |
| 20 free(name_); | 19 free(name_); |
| 21 } | 20 } |
| 22 | 21 |
| 23 | |
| 24 #if defined(DEBUG) | 22 #if defined(DEBUG) |
| 25 void NativeMessageHandler::CheckAccess() { | 23 void NativeMessageHandler::CheckAccess() { |
| 26 ASSERT(Isolate::Current() == NULL); | 24 ASSERT(Isolate::Current() == NULL); |
| 27 } | 25 } |
| 28 #endif | 26 #endif |
| 29 | 27 |
| 30 | |
| 31 MessageHandler::MessageStatus NativeMessageHandler::HandleMessage( | 28 MessageHandler::MessageStatus NativeMessageHandler::HandleMessage( |
| 32 Message* message) { | 29 Message* message) { |
| 33 if (message->IsOOB()) { | 30 if (message->IsOOB()) { |
| 34 // We currently do not use OOB messages for native ports. | 31 // We currently do not use OOB messages for native ports. |
| 35 UNREACHABLE(); | 32 UNREACHABLE(); |
| 36 } | 33 } |
| 37 // We create a native scope for handling the message. | 34 // We create a native scope for handling the message. |
| 38 // All allocation of objects for decoding the message is done in the | 35 // All allocation of objects for decoding the message is done in the |
| 39 // zone associated with this scope. | 36 // zone associated with this scope. |
| 40 ApiNativeScope scope; | 37 ApiNativeScope scope; |
| 41 Dart_CObject* object; | 38 Dart_CObject* object; |
| 42 ApiMessageReader reader(message); | 39 ApiMessageReader reader(message); |
| 43 object = reader.ReadMessage(); | 40 object = reader.ReadMessage(); |
| 44 (*func())(message->dest_port(), object); | 41 (*func())(message->dest_port(), object); |
| 45 delete message; | 42 delete message; |
| 46 return kOK; | 43 return kOK; |
| 47 } | 44 } |
| 48 | 45 |
| 49 } // namespace dart | 46 } // namespace dart |
| OLD | NEW |