| 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 "include/dart_native_api.h" | 5 #include "include/dart_native_api.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_api_message.h" | 9 #include "vm/dart_api_message.h" |
| 10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
| 11 #include "vm/message.h" | 11 #include "vm/message.h" |
| 12 #include "vm/native_message_handler.h" | 12 #include "vm/native_message_handler.h" |
| 13 #include "vm/port.h" | 13 #include "vm/port.h" |
| 14 #include "vm/precompiler.h" | 14 #include "vm/precompiler.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 // --- Message sending/receiving from native code --- | 18 // --- Message sending/receiving from native code --- |
| 19 | 19 |
| 20 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 20 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 21 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 21 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 22 return reinterpret_cast<uint8_t*>(new_ptr); | 22 return reinterpret_cast<uint8_t*>(new_ptr); |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { | 26 static bool PostCObject(Dart_Port port_id, |
| 27 Dart_CObject* message, |
| 28 Message::Priority priority) { |
| 27 uint8_t* buffer = NULL; | 29 uint8_t* buffer = NULL; |
| 28 ApiMessageWriter writer(&buffer, allocator); | 30 ApiMessageWriter writer(&buffer, allocator); |
| 29 bool success = writer.WriteCMessage(message); | 31 bool success = writer.WriteCMessage(message); |
| 30 | 32 |
| 31 if (!success) return success; | 33 if (!success) return success; |
| 32 | 34 |
| 33 // Post the message at the given port. | 35 // Post the message at the given port. |
| 34 return PortMap::PostMessage(new Message( | 36 return PortMap::PostMessage(new Message( |
| 35 port_id, buffer, writer.BytesWritten(), Message::kNormalPriority)); | 37 port_id, buffer, writer.BytesWritten(), priority)); |
| 36 } | 38 } |
| 37 | 39 |
| 38 | 40 |
| 41 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { |
| 42 return PostCObject(port_id, message, Message::kNormalPriority); |
| 43 } |
| 44 |
| 45 |
| 46 DART_EXPORT bool Dart_PostOOBCObject(Dart_Port port_id, Dart_CObject* message) { |
| 47 return PostCObject(port_id, message, Message::kOOBPriority); |
| 48 } |
| 49 |
| 50 |
| 39 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, | 51 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, |
| 40 Dart_NativeMessageHandler handler, | 52 Dart_NativeMessageHandler handler, |
| 41 bool handle_concurrently) { | 53 bool handle_concurrently) { |
| 42 if (name == NULL) { | 54 if (name == NULL) { |
| 43 name = "<UnnamedNativePort>"; | 55 name = "<UnnamedNativePort>"; |
| 44 } | 56 } |
| 45 if (handler == NULL) { | 57 if (handler == NULL) { |
| 46 OS::PrintErr("%s expects argument 'handler' to be non-null.\n", | 58 OS::PrintErr("%s expects argument 'handler' to be non-null.\n", |
| 47 CURRENT_FUNC); | 59 CURRENT_FUNC); |
| 48 return ILLEGAL_PORT; | 60 return ILLEGAL_PORT; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 Dart_Handle result = Api::CheckAndFinalizePendingClasses(isolate); | 122 Dart_Handle result = Api::CheckAndFinalizePendingClasses(isolate); |
| 111 if (::Dart_IsError(result)) { | 123 if (::Dart_IsError(result)) { |
| 112 return result; | 124 return result; |
| 113 } | 125 } |
| 114 CHECK_CALLBACK_STATE(isolate); | 126 CHECK_CALLBACK_STATE(isolate); |
| 115 Precompile(isolate, &result); | 127 Precompile(isolate, &result); |
| 116 return result; | 128 return result; |
| 117 } | 129 } |
| 118 | 130 |
| 119 } // namespace dart | 131 } // namespace dart |
| OLD | NEW |