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