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/file.h" | 5 #include "bin/file.h" |
6 | 6 |
7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
8 #include "bin/dartutils.h" | 8 #include "bin/dartutils.h" |
9 #include "bin/io_buffer.h" | 9 #include "bin/io_buffer.h" |
10 #include "bin/thread.h" | 10 #include "bin/thread.h" |
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 return CObject::NewOSError(); | 1006 return CObject::NewOSError(); |
1007 } | 1007 } |
1008 } else { | 1008 } else { |
1009 return CObject::FileClosedError(); | 1009 return CObject::FileClosedError(); |
1010 } | 1010 } |
1011 } | 1011 } |
1012 return CObject::IllegalArgumentError(); | 1012 return CObject::IllegalArgumentError(); |
1013 } | 1013 } |
1014 | 1014 |
1015 | 1015 |
| 1016 static CObject* FileCreateLinkRequest(const CObjectArray& request) { |
| 1017 if (request.Length() != 3 || |
| 1018 !request[1]->IsString() || |
| 1019 !request[2]->IsString()) { |
| 1020 return CObject::IllegalArgumentError(); |
| 1021 } |
| 1022 CObjectString link_name(request[1]); |
| 1023 CObjectString target_name(request[2]); |
| 1024 if (File::CreateLink(link_name.CString(), target_name.CString())) { |
| 1025 return CObject::True(); |
| 1026 } else { |
| 1027 return CObject::NewOSError(); |
| 1028 } |
| 1029 } |
| 1030 |
| 1031 |
1016 static CObject* FileDeleteLinkRequest(const CObjectArray& request) { | 1032 static CObject* FileDeleteLinkRequest(const CObjectArray& request) { |
1017 if (request.Length() == 2 && request[1]->IsString()) { | 1033 if (request.Length() == 2 && request[1]->IsString()) { |
1018 CObjectString filename(request[1]); | 1034 CObjectString filename(request[1]); |
1019 bool result = File::DeleteLink(filename.CString()); | 1035 bool result = File::DeleteLink(filename.CString()); |
1020 if (result) { | 1036 if (result) { |
1021 return CObject::True(); | 1037 return CObject::True(); |
1022 } else { | 1038 } else { |
1023 return CObject::NewOSError(); | 1039 return CObject::NewOSError(); |
1024 } | 1040 } |
1025 } | 1041 } |
1026 return CObject::False(); | 1042 return CObject::IllegalArgumentError(); |
1027 } | 1043 } |
1028 | 1044 |
1029 | 1045 |
1030 static void FileService(Dart_Port dest_port_id, | 1046 static void FileService(Dart_Port dest_port_id, |
1031 Dart_Port reply_port_id, | 1047 Dart_Port reply_port_id, |
1032 Dart_CObject* message) { | 1048 Dart_CObject* message) { |
1033 CObject* response = CObject::IllegalArgumentError(); | 1049 CObject* response = CObject::IllegalArgumentError(); |
1034 CObjectArray request(message); | 1050 CObjectArray request(message); |
1035 if (message->type == Dart_CObject::kArray) { | 1051 if (message->type == Dart_CObject::kArray) { |
1036 if (request.Length() > 1 && request[0]->IsInt32()) { | 1052 if (request.Length() > 1 && request[0]->IsInt32()) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 break; | 1105 break; |
1090 case File::kReadListRequest: | 1106 case File::kReadListRequest: |
1091 response = FileReadListRequest(request); | 1107 response = FileReadListRequest(request); |
1092 break; | 1108 break; |
1093 case File::kWriteListRequest: | 1109 case File::kWriteListRequest: |
1094 response = FileWriteListRequest(request); | 1110 response = FileWriteListRequest(request); |
1095 break; | 1111 break; |
1096 case File::kDeleteLinkRequest: | 1112 case File::kDeleteLinkRequest: |
1097 response = FileDeleteLinkRequest(request); | 1113 response = FileDeleteLinkRequest(request); |
1098 break; | 1114 break; |
| 1115 case File::kCreateLinkRequest: |
| 1116 response = FileCreateLinkRequest(request); |
| 1117 break; |
1099 default: | 1118 default: |
1100 UNREACHABLE(); | 1119 UNREACHABLE(); |
1101 } | 1120 } |
1102 } | 1121 } |
1103 } | 1122 } |
1104 | 1123 |
1105 Dart_PostCObject(reply_port_id, response->AsApiCObject()); | 1124 Dart_PostCObject(reply_port_id, response->AsApiCObject()); |
1106 } | 1125 } |
1107 | 1126 |
1108 | 1127 |
1109 Dart_Port File::GetServicePort() { | 1128 Dart_Port File::GetServicePort() { |
1110 return file_service_.GetServicePort(); | 1129 return file_service_.GetServicePort(); |
1111 } | 1130 } |
1112 | 1131 |
1113 | 1132 |
1114 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { | 1133 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { |
1115 Dart_EnterScope(); | 1134 Dart_EnterScope(); |
1116 Dart_SetReturnValue(args, Dart_Null()); | 1135 Dart_SetReturnValue(args, Dart_Null()); |
1117 Dart_Port service_port = File::GetServicePort(); | 1136 Dart_Port service_port = File::GetServicePort(); |
1118 if (service_port != ILLEGAL_PORT) { | 1137 if (service_port != ILLEGAL_PORT) { |
1119 // Return a send port for the service port. | 1138 // Return a send port for the service port. |
1120 Dart_Handle send_port = Dart_NewSendPort(service_port); | 1139 Dart_Handle send_port = Dart_NewSendPort(service_port); |
1121 Dart_SetReturnValue(args, send_port); | 1140 Dart_SetReturnValue(args, send_port); |
1122 } | 1141 } |
1123 Dart_ExitScope(); | 1142 Dart_ExitScope(); |
1124 } | 1143 } |
OLD | NEW |