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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 } else { | 575 } else { |
576 Dart_Handle err = DartUtils::NewDartArgumentError( | 576 Dart_Handle err = DartUtils::NewDartArgumentError( |
577 "Non-string argument to FileSystemEntity.type"); | 577 "Non-string argument to FileSystemEntity.type"); |
578 if (Dart_IsError(err)) Dart_PropagateError(err); | 578 if (Dart_IsError(err)) Dart_PropagateError(err); |
579 Dart_SetReturnValue(args, err); | 579 Dart_SetReturnValue(args, err); |
580 } | 580 } |
581 Dart_ExitScope(); | 581 Dart_ExitScope(); |
582 } | 582 } |
583 | 583 |
584 | 584 |
| 585 void FUNCTION_NAME(File_Stat)(Dart_NativeArguments args) { |
| 586 Dart_EnterScope(); |
| 587 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) { |
| 588 const char* path = |
| 589 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 590 |
| 591 int64_t stat_data[File::kStatSize]; |
| 592 File::Stat(path, stat_data); |
| 593 Dart_Handle returned_data = Dart_NewTypedData(kInt64, File::kStatSize); |
| 594 if (Dart_IsError(returned_data)) Dart_PropagateError(returned_data); |
| 595 Dart_TypedData_Type data_type_unused; |
| 596 void* data_location; |
| 597 intptr_t data_length_unused; |
| 598 Dart_Handle status = Dart_TypedDataAcquireData(returned_data, |
| 599 &data_type_unused, |
| 600 &data_location, |
| 601 &data_length_unused); |
| 602 if (Dart_IsError(status)) Dart_PropagateError(status); |
| 603 memmove(data_location, stat_data, File::kStatSize * sizeof(int64_t)); |
| 604 status = Dart_TypedDataReleaseData(returned_data); |
| 605 if (Dart_IsError(status)) Dart_PropagateError(status); |
| 606 Dart_SetReturnValue(args, returned_data); |
| 607 } else { |
| 608 Dart_Handle err = DartUtils::NewDartArgumentError( |
| 609 "Non-string argument to FileSystemEntity.type"); |
| 610 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 611 Dart_SetReturnValue(args, err); |
| 612 } |
| 613 Dart_ExitScope(); |
| 614 } |
| 615 |
| 616 |
585 void FUNCTION_NAME(File_AreIdentical)(Dart_NativeArguments args) { | 617 void FUNCTION_NAME(File_AreIdentical)(Dart_NativeArguments args) { |
586 Dart_EnterScope(); | 618 Dart_EnterScope(); |
587 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) && | 619 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) && |
588 Dart_IsString(Dart_GetNativeArgument(args, 1))) { | 620 Dart_IsString(Dart_GetNativeArgument(args, 1))) { |
589 const char* path_1 = | 621 const char* path_1 = |
590 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 622 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
591 const char* path_2 = | 623 const char* path_2 = |
592 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); | 624 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
593 File::Identical result = File::AreIdentical(path_1, path_2); | 625 File::Identical result = File::AreIdentical(path_1, path_2); |
594 if (result == File::kError) { | 626 if (result == File::kError) { |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 } else if (result == File::kIdentical) { | 1147 } else if (result == File::kIdentical) { |
1116 return CObject::True(); | 1148 return CObject::True(); |
1117 } else { | 1149 } else { |
1118 return CObject::False(); | 1150 return CObject::False(); |
1119 } | 1151 } |
1120 } | 1152 } |
1121 return CObject::IllegalArgumentError(); | 1153 return CObject::IllegalArgumentError(); |
1122 } | 1154 } |
1123 | 1155 |
1124 | 1156 |
| 1157 static CObject* FileStatRequest(const CObjectArray& request) { |
| 1158 if (request.Length() == 2 && |
| 1159 request[1]->IsString()) { |
| 1160 int64_t data[File::kStatSize]; |
| 1161 CObjectString path(request[1]); |
| 1162 File::Stat(path.CString(), data); |
| 1163 CObjectArray* result = |
| 1164 new CObjectArray(CObject::NewArray(File::kStatSize)); |
| 1165 for (int i = 0; i < File::kStatSize; ++i) { |
| 1166 result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i]))); |
| 1167 } |
| 1168 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); |
| 1169 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); |
| 1170 wrapper->SetAt(1, result); |
| 1171 return wrapper; |
| 1172 } |
| 1173 return CObject::IllegalArgumentError(); |
| 1174 } |
| 1175 |
| 1176 |
1125 static void FileService(Dart_Port dest_port_id, | 1177 static void FileService(Dart_Port dest_port_id, |
1126 Dart_Port reply_port_id, | 1178 Dart_Port reply_port_id, |
1127 Dart_CObject* message) { | 1179 Dart_CObject* message) { |
1128 CObject* response = CObject::IllegalArgumentError(); | 1180 CObject* response = CObject::IllegalArgumentError(); |
1129 CObjectArray request(message); | 1181 CObjectArray request(message); |
1130 if (message->type == Dart_CObject::kArray) { | 1182 if (message->type == Dart_CObject::kArray) { |
1131 if (request.Length() > 1 && request[0]->IsInt32()) { | 1183 if (request.Length() > 1 && request[0]->IsInt32()) { |
1132 CObjectInt32 requestType(request[0]); | 1184 CObjectInt32 requestType(request[0]); |
1133 switch (requestType.Value()) { | 1185 switch (requestType.Value()) { |
1134 case File::kExistsRequest: | 1186 case File::kExistsRequest: |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 break; | 1248 break; |
1197 case File::kLinkTargetRequest: | 1249 case File::kLinkTargetRequest: |
1198 response = FileLinkTargetRequest(request); | 1250 response = FileLinkTargetRequest(request); |
1199 break; | 1251 break; |
1200 case File::kTypeRequest: | 1252 case File::kTypeRequest: |
1201 response = FileTypeRequest(request); | 1253 response = FileTypeRequest(request); |
1202 break; | 1254 break; |
1203 case File::kIdenticalRequest: | 1255 case File::kIdenticalRequest: |
1204 response = FileIdenticalRequest(request); | 1256 response = FileIdenticalRequest(request); |
1205 break; | 1257 break; |
| 1258 case File::kStatRequest: |
| 1259 response = FileStatRequest(request); |
| 1260 break; |
1206 default: | 1261 default: |
1207 UNREACHABLE(); | 1262 UNREACHABLE(); |
1208 } | 1263 } |
1209 } | 1264 } |
1210 } | 1265 } |
1211 | 1266 |
1212 Dart_PostCObject(reply_port_id, response->AsApiCObject()); | 1267 Dart_PostCObject(reply_port_id, response->AsApiCObject()); |
1213 } | 1268 } |
1214 | 1269 |
1215 | 1270 |
1216 Dart_Port File::GetServicePort() { | 1271 Dart_Port File::GetServicePort() { |
1217 return file_service_.GetServicePort(); | 1272 return file_service_.GetServicePort(); |
1218 } | 1273 } |
1219 | 1274 |
1220 | 1275 |
1221 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { | 1276 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { |
1222 Dart_EnterScope(); | 1277 Dart_EnterScope(); |
1223 Dart_SetReturnValue(args, Dart_Null()); | 1278 Dart_SetReturnValue(args, Dart_Null()); |
1224 Dart_Port service_port = File::GetServicePort(); | 1279 Dart_Port service_port = File::GetServicePort(); |
1225 if (service_port != ILLEGAL_PORT) { | 1280 if (service_port != ILLEGAL_PORT) { |
1226 // Return a send port for the service port. | 1281 // Return a send port for the service port. |
1227 Dart_Handle send_port = Dart_NewSendPort(service_port); | 1282 Dart_Handle send_port = Dart_NewSendPort(service_port); |
1228 Dart_SetReturnValue(args, send_port); | 1283 Dart_SetReturnValue(args, send_port); |
1229 } | 1284 } |
1230 Dart_ExitScope(); | 1285 Dart_ExitScope(); |
1231 } | 1286 } |
1232 | 1287 |
1233 } // namespace bin | 1288 } // namespace bin |
1234 } // namespace dart | 1289 } // namespace dart |
OLD | NEW |