| 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 | #if !defined(DART_IO_SECURE_SOCKET_DISABLED) |
| 6 | |
| 7 | #include "bin/io_service.h" |
| 8 | |
| 9 | #include "bin/dartutils.h" |
| 10 | #include "bin/directory.h" |
| 11 | #include "bin/file.h" |
| 12 | #include "bin/io_buffer.h" |
| 13 | #include "bin/secure_socket_filter.h" |
| 14 | #include "bin/security_context.h" |
| 15 | #include "bin/socket.h" |
| 16 | #include "bin/utils.h" |
| 17 | |
| 18 | #include "include/dart_api.h" |
| 19 | |
| 20 | #include "platform/globals.h" |
| 21 | #include "platform/utils.h" |
| 22 | |
| 23 | namespace dart { |
| 24 | namespace bin { |
| 25 | |
| 26 | #define CASE_REQUEST(type, method, id) \ |
| 27 | case IOService::k##type##method##Request: \ |
| 28 | response = type::method##Request(data); \ |
| 29 | break; |
| 30 | |
| 31 | void IOServiceCallback(Dart_Port dest_port_id, Dart_CObject* message) { |
| 32 | Dart_Port reply_port_id = ILLEGAL_PORT; |
| 33 | CObject* response = CObject::IllegalArgumentError(); |
| 34 | CObjectArray request(message); |
| 35 | if ((message->type == Dart_CObject_kArray) && (request.Length() == 4) && |
| 36 | request[0]->IsInt32() && request[1]->IsSendPort() && |
| 37 | request[2]->IsInt32() && request[3]->IsArray()) { |
| 38 | CObjectInt32 message_id(request[0]); |
| 39 | CObjectSendPort reply_port(request[1]); |
| 40 | CObjectInt32 request_id(request[2]); |
| 41 | CObjectArray data(request[3]); |
| 42 | reply_port_id = reply_port.Value(); |
| 43 | switch (request_id.Value()) { |
| 44 | IO_SERVICE_REQUEST_LIST(CASE_REQUEST); |
| 45 | default: |
| 46 | UNREACHABLE(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | CObjectArray result(CObject::NewArray(2)); |
| 51 | result.SetAt(0, request[0]); |
| 52 | result.SetAt(1, response); |
| 53 | ASSERT(reply_port_id != ILLEGAL_PORT); |
| 54 | Dart_PostCObject(reply_port_id, result.AsApiCObject()); |
| 55 | } |
| 56 | |
| 57 | Dart_Port IOService::GetServicePort() { |
| 58 | return Dart_NewNativePort("IOService" , IOServiceCallback, true); |
| 59 | } |
| 60 | |
| 61 | void FUNCTION_NAME(IOService_NewServicePort)(Dart_NativeArguments args) { |
| 62 | Dart_SetReturnValue(args, Dart_Null()); |
| 63 | Dart_Port service_port = IOService::GetServicePort(); |
| 64 | if (service_port != ILLEGAL_PORT) { |
| 65 | // Return a send port for the service port. |
| 66 | Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 67 | Dart_SetReturnValue(args, send_port); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | } // namespace bin |
| 72 | } // namespace dart |
| 73 | |
| 74 | #endif // !defined(DART_IO_SECURE_SOCKET_DISABLED) |
| 75 | |