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