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