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_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 | 1573 |
1574 | 1574 |
1575 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 1575 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
1576 Isolate* isolate = Isolate::Current(); | 1576 Isolate* isolate = Isolate::Current(); |
1577 DARTSCOPE(isolate); | 1577 DARTSCOPE(isolate); |
1578 CHECK_CALLBACK_STATE(isolate); | 1578 CHECK_CALLBACK_STATE(isolate); |
1579 return Api::NewHandle(isolate, SendPort::New(port_id)); | 1579 return Api::NewHandle(isolate, SendPort::New(port_id)); |
1580 } | 1580 } |
1581 | 1581 |
1582 | 1582 |
1583 DART_EXPORT Dart_Handle Dart_ReceivePortGetId(Dart_Handle port, | 1583 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, |
1584 Dart_Port* port_id) { | 1584 Dart_Port* port_id) { |
1585 Isolate* isolate = Isolate::Current(); | 1585 Isolate* isolate = Isolate::Current(); |
1586 DARTSCOPE(isolate); | 1586 DARTSCOPE(isolate); |
1587 CHECK_CALLBACK_STATE(isolate); | 1587 CHECK_CALLBACK_STATE(isolate); |
1588 const ReceivePort& receive_port = Api::UnwrapReceivePortHandle(isolate, port); | 1588 const SendPort& send_port = Api::UnwrapSendPortHandle(isolate, port); |
1589 if (receive_port.IsNull()) { | 1589 if (send_port.IsNull()) { |
1590 RETURN_TYPE_ERROR(isolate, port, ReceivePort); | 1590 RETURN_TYPE_ERROR(isolate, port, SendPort); |
1591 } | 1591 } |
1592 if (port_id == NULL) { | 1592 if (port_id == NULL) { |
1593 RETURN_NULL_ERROR(port_id); | 1593 RETURN_NULL_ERROR(port_id); |
1594 } | 1594 } |
1595 *port_id = receive_port.Id(); | 1595 *port_id = send_port.Id(); |
1596 return Api::Success(); | 1596 return Api::Success(); |
1597 } | 1597 } |
1598 | 1598 |
1599 | 1599 |
1600 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { | |
1601 Isolate* isolate = Isolate::Current(); | |
1602 DARTSCOPE(isolate); | |
1603 CHECK_CALLBACK_STATE(isolate); | |
1604 | |
1605 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); | |
1606 ASSERT(!isolate_lib.IsNull()); | |
1607 const String& class_name = String::Handle( | |
1608 isolate, isolate_lib.PrivateName(Symbols::_RawReceivePortImpl())); | |
1609 // TODO(asiva): Symbols should contain private keys. | |
1610 const String& function_name = | |
1611 String::Handle(isolate_lib.PrivateName(Symbols::_get())); | |
1612 const int kNumArguments = 1; | |
1613 const Function& function = Function::Handle( | |
1614 isolate, | |
1615 Resolver::ResolveStatic(isolate_lib, | |
1616 class_name, | |
1617 function_name, | |
1618 kNumArguments, | |
1619 Object::empty_array())); | |
1620 ASSERT(!function.IsNull()); | |
1621 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); | |
1622 args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id))); | |
1623 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, args)); | |
1624 } | |
1625 | |
1626 | |
1627 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 1600 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
1628 Isolate* isolate = Isolate::Current(); | 1601 Isolate* isolate = Isolate::Current(); |
1629 CHECK_ISOLATE(isolate); | 1602 CHECK_ISOLATE(isolate); |
1630 return isolate->main_port(); | 1603 return isolate->main_port(); |
1631 } | 1604 } |
1632 | 1605 |
1633 | 1606 |
1634 DART_EXPORT Dart_Handle Dart_PostMessage(Dart_Handle port, | |
1635 Dart_Handle object) { | |
1636 Isolate* isolate = Isolate::Current(); | |
1637 DARTSCOPE(isolate); | |
1638 const SendPort& send_port = Api::UnwrapSendPortHandle(isolate, port); | |
1639 if (send_port.IsNull()) { | |
1640 RETURN_TYPE_ERROR(isolate, port, SendPort); | |
1641 } | |
1642 Dart_Port port_id = send_port.Id(); | |
1643 uint8_t* data = NULL; | |
1644 MessageWriter writer(&data, &allocator); | |
1645 Object& msg_object = Object::Handle(Api::UnwrapHandle(object)); | |
1646 writer.WriteMessage(msg_object); | |
1647 intptr_t len = writer.BytesWritten(); | |
1648 bool r = PortMap::PostMessage( | |
1649 new Message(port_id, data, len, Message::kNormalPriority)); | |
1650 if (r) { | |
1651 return Api::Success(); | |
1652 } | |
1653 return Api::NewError("Dart_PostMessage failed."); | |
1654 } | |
1655 | |
1656 // --- Scopes ---- | 1607 // --- Scopes ---- |
1657 | 1608 |
1658 DART_EXPORT void Dart_EnterScope() { | 1609 DART_EXPORT void Dart_EnterScope() { |
1659 Isolate* isolate = Isolate::Current(); | 1610 Isolate* isolate = Isolate::Current(); |
1660 CHECK_ISOLATE(isolate); | 1611 CHECK_ISOLATE(isolate); |
1661 ApiState* state = isolate->api_state(); | 1612 ApiState* state = isolate->api_state(); |
1662 ASSERT(state != NULL); | 1613 ASSERT(state != NULL); |
1663 ApiLocalScope* new_scope = state->reusable_scope(); | 1614 ApiLocalScope* new_scope = state->reusable_scope(); |
1664 if (new_scope == NULL) { | 1615 if (new_scope == NULL) { |
1665 new_scope = new ApiLocalScope(state->top_scope(), | 1616 new_scope = new ApiLocalScope(state->top_scope(), |
(...skipping 3591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5257 | 5208 |
5258 | 5209 |
5259 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5210 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
5260 const char* name, | 5211 const char* name, |
5261 Dart_ServiceRequestCallback callback, | 5212 Dart_ServiceRequestCallback callback, |
5262 void* user_data) { | 5213 void* user_data) { |
5263 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5214 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
5264 } | 5215 } |
5265 | 5216 |
5266 } // namespace dart | 5217 } // namespace dart |
OLD | NEW |