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