Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: runtime/bin/file.cc

Issue 10443008: Implement File.lastModified. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Return ms from C Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/file.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/thread.h" 9 #include "bin/thread.h"
10 #include "bin/utils.h" 10 #include "bin/utils.h"
11 11
12 #include "include/dart_api.h" 12 #include "include/dart_api.h"
13 13
14 static const int kMSPerSecond = 1000;
15
14 dart::Mutex File::mutex_; 16 dart::Mutex File::mutex_;
15 int File::service_ports_size_ = 0; 17 int File::service_ports_size_ = 0;
16 Dart_Port* File::service_ports_ = NULL; 18 Dart_Port* File::service_ports_ = NULL;
17 int File::service_ports_index_ = 0; 19 int File::service_ports_index_ = 0;
18 20
19 bool File::ReadFully(void* buffer, int64_t num_bytes) { 21 bool File::ReadFully(void* buffer, int64_t num_bytes) {
20 int64_t remaining = num_bytes; 22 int64_t remaining = num_bytes;
21 char* current_buffer = reinterpret_cast<char*>(buffer); 23 char* current_buffer = reinterpret_cast<char*>(buffer);
22 while (remaining > 0) { 24 while (remaining > 0) {
23 int bytes_read = Read(current_buffer, remaining); 25 int bytes_read = Read(current_buffer, remaining);
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); 352 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
351 } else { 353 } else {
352 Dart_Handle err = DartUtils::NewDartOSError(); 354 Dart_Handle err = DartUtils::NewDartOSError();
353 if (Dart_IsError(err)) Dart_PropagateError(err); 355 if (Dart_IsError(err)) Dart_PropagateError(err);
354 Dart_SetReturnValue(args, err); 356 Dart_SetReturnValue(args, err);
355 } 357 }
356 Dart_ExitScope(); 358 Dart_ExitScope();
357 } 359 }
358 360
359 361
362 void FUNCTION_NAME(File_LastModified)(Dart_NativeArguments args) {
363 Dart_EnterScope();
364 const char* name =
365 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
366 int64_t return_value = File::LastModified(name);
367 if (return_value >= 0) {
368 Dart_SetReturnValue(args, Dart_NewInteger(return_value * kMSPerSecond));
369 } else {
370 Dart_Handle err = DartUtils::NewDartOSError();
371 if (Dart_IsError(err)) Dart_PropagateError(err);
372 Dart_SetReturnValue(args, err);
373 }
374 Dart_ExitScope();
375 }
376
377
360 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { 378 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) {
361 Dart_EnterScope(); 379 Dart_EnterScope();
362 intptr_t value = 380 intptr_t value =
363 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); 381 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
364 File* file = reinterpret_cast<File*>(value); 382 File* file = reinterpret_cast<File*>(value);
365 ASSERT(file != NULL); 383 ASSERT(file != NULL);
366 if (file->Flush()) { 384 if (file->Flush()) {
367 Dart_SetReturnValue(args, Dart_True()); 385 Dart_SetReturnValue(args, Dart_True());
368 } else { 386 } else {
369 Dart_Handle err = DartUtils::NewDartOSError(); 387 Dart_Handle err = DartUtils::NewDartOSError();
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 if (return_value >= 0) { 690 if (return_value >= 0) {
673 return new CObjectIntptr(CObject::NewIntptr(return_value)); 691 return new CObjectIntptr(CObject::NewIntptr(return_value));
674 } else { 692 } else {
675 return CObject::NewOSError(); 693 return CObject::NewOSError();
676 } 694 }
677 } 695 }
678 return CObject::IllegalArgumentError(); 696 return CObject::IllegalArgumentError();
679 } 697 }
680 698
681 699
700 static CObject* FileLastModifiedRequest(const CObjectArray& request) {
701 if (request.Length() == 2 && request[1]->IsString()) {
702 CObjectString filename(request[1]);
703 int64_t return_value = File::LastModified(filename.CString());
704 if (return_value >= 0) {
705 return new CObjectIntptr(CObject::NewInt64(return_value * kMSPerSecond));
706 } else {
707 return CObject::NewOSError();
708 }
709 }
710 return CObject::IllegalArgumentError();
711 }
712
713
682 static CObject* FileFlushRequest(const CObjectArray& request) { 714 static CObject* FileFlushRequest(const CObjectArray& request) {
683 if (request.Length() == 2 && request[1]->IsIntptr()) { 715 if (request.Length() == 2 && request[1]->IsIntptr()) {
684 File* file = CObjectToFilePointer(request[1]); 716 File* file = CObjectToFilePointer(request[1]);
685 ASSERT(file != NULL); 717 ASSERT(file != NULL);
686 if (!file->IsClosed()) { 718 if (!file->IsClosed()) {
687 if (file->Flush()) { 719 if (file->Flush()) {
688 return CObject::True(); 720 return CObject::True();
689 } else { 721 } else {
690 return CObject::NewOSError(); 722 return CObject::NewOSError();
691 } 723 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 break; 908 break;
877 case File::kTruncateRequest: 909 case File::kTruncateRequest:
878 response = FileTruncateRequest(request); 910 response = FileTruncateRequest(request);
879 break; 911 break;
880 case File::kLengthRequest: 912 case File::kLengthRequest:
881 response = FileLengthRequest(request); 913 response = FileLengthRequest(request);
882 break; 914 break;
883 case File::kLengthFromNameRequest: 915 case File::kLengthFromNameRequest:
884 response = FileLengthFromNameRequest(request); 916 response = FileLengthFromNameRequest(request);
885 break; 917 break;
918 case File::kLastModifiedRequest:
919 response = FileLastModifiedRequest(request);
920 break;
886 case File::kFlushRequest: 921 case File::kFlushRequest:
887 response = FileFlushRequest(request); 922 response = FileFlushRequest(request);
888 break; 923 break;
889 case File::kReadByteRequest: 924 case File::kReadByteRequest:
890 response = FileReadByteRequest(request); 925 response = FileReadByteRequest(request);
891 break; 926 break;
892 case File::kWriteByteRequest: 927 case File::kWriteByteRequest:
893 response = FileWriteByteRequest(request); 928 response = FileWriteByteRequest(request);
894 break; 929 break;
895 case File::kReadListRequest: 930 case File::kReadListRequest:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 Dart_EnterScope(); 975 Dart_EnterScope();
941 Dart_SetReturnValue(args, Dart_Null()); 976 Dart_SetReturnValue(args, Dart_Null());
942 Dart_Port service_port = File::GetServicePort(); 977 Dart_Port service_port = File::GetServicePort();
943 if (service_port != kIllegalPort) { 978 if (service_port != kIllegalPort) {
944 // Return a send port for the service port. 979 // Return a send port for the service port.
945 Dart_Handle send_port = Dart_NewSendPort(service_port); 980 Dart_Handle send_port = Dart_NewSendPort(service_port);
946 Dart_SetReturnValue(args, send_port); 981 Dart_SetReturnValue(args, send_port);
947 } 982 }
948 Dart_ExitScope(); 983 Dart_ExitScope();
949 } 984 }
OLDNEW
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/file.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698