| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "native_client/tests/fake_browser_ppapi/fake_file_io.h" | |
| 6 | |
| 7 #include <stdio.h> | |
| 8 | |
| 9 #include "native_client/src/include/nacl_macros.h" | |
| 10 #include "native_client/src/include/portability.h" | |
| 11 #include "native_client/src/include/portability_io.h" | |
| 12 | |
| 13 #include "native_client/tests/fake_browser_ppapi/fake_file_ref.h" | |
| 14 #include "native_client/tests/fake_browser_ppapi/fake_resource.h" | |
| 15 #include "native_client/tests/fake_browser_ppapi/utility.h" | |
| 16 | |
| 17 #include "ppapi/c/pp_errors.h" | |
| 18 #include "ppapi/c/pp_completion_callback.h" | |
| 19 #include "ppapi/c/pp_resource.h" | |
| 20 | |
| 21 using fake_browser_ppapi::DebugPrintf; | |
| 22 | |
| 23 namespace fake_browser_ppapi { | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 PP_Resource Create(PP_Instance instance_id) { | |
| 28 DebugPrintf("FileIO::Create: module_id=%"NACL_PRId32"\n", instance_id); | |
| 29 FileIO* file_io = new FileIO(instance_id); | |
| 30 PP_Resource resource_id = TrackResource(file_io); | |
| 31 DebugPrintf("FileIO::Create: resource_id=%"NACL_PRId32"\n", resource_id); | |
| 32 return resource_id; | |
| 33 } | |
| 34 | |
| 35 PP_Bool IsFileIO(PP_Resource resource_id) { | |
| 36 DebugPrintf("FileIO::IsFileIO: resource_id=%"NACL_PRId32"\n", resource_id); | |
| 37 NACL_UNIMPLEMENTED(); | |
| 38 return PP_FALSE; | |
| 39 } | |
| 40 | |
| 41 int32_t Open(PP_Resource file_io_id, | |
| 42 PP_Resource file_ref_id, | |
| 43 int32_t open_flags, | |
| 44 struct PP_CompletionCallback callback) { | |
| 45 DebugPrintf("FileIO::Open: file_io_id=%"NACL_PRId32 | |
| 46 " file_ref_id=%"NACL_PRId32" open_flags=%"NACL_PRId32"\n", | |
| 47 file_io_id, file_ref_id, open_flags); | |
| 48 FileIO* file_io = GetResource(file_io_id)->AsFileIO(); | |
| 49 FileRef* file_ref = GetResource(file_ref_id)->AsFileRef(); | |
| 50 if (file_io == NULL || file_ref == NULL) | |
| 51 return PP_ERROR_BADRESOURCE; | |
| 52 | |
| 53 // Open the file and store the file descriptor. | |
| 54 // At this point, the plugin only uses read-only access mode. Note that | |
| 55 // PPAPI file access flags are not the same as OPEN's file access modes. | |
| 56 CHECK(open_flags == PP_FILEOPENFLAG_READ); | |
| 57 const char* file_path = file_ref->path().c_str(); | |
| 58 int file_desc = OPEN(file_path, O_RDONLY); | |
| 59 file_io->set_file_desc(file_desc); | |
| 60 DebugPrintf("FileIO::Open: file=%s file_desc=%d\n", file_path, file_desc); | |
| 61 if (file_desc <= NACL_NO_FILE_DESC) | |
| 62 return PP_ERROR_FAILED; | |
| 63 | |
| 64 // Invoke the callback right away to simplify mocking. | |
| 65 if (callback.func == NULL) | |
| 66 return PP_ERROR_BADARGUMENT; | |
| 67 PP_RunCompletionCallback(&callback, PP_OK); | |
| 68 return PP_OK_COMPLETIONPENDING; // Fake successful async call. | |
| 69 } | |
| 70 | |
| 71 int32_t Query(PP_Resource file_io_id, | |
| 72 PP_FileInfo_Dev* info, | |
| 73 struct PP_CompletionCallback callback) { | |
| 74 DebugPrintf("FileIO::Query: file_io_id=%"NACL_PRId32"\n", file_io_id); | |
| 75 UNREFERENCED_PARAMETER(info); | |
| 76 UNREFERENCED_PARAMETER(callback); | |
| 77 NACL_UNIMPLEMENTED(); | |
| 78 return PP_ERROR_BADRESOURCE; | |
| 79 } | |
| 80 | |
| 81 int32_t Touch(PP_Resource file_io_id, | |
| 82 PP_Time last_access_time, | |
| 83 PP_Time last_modified_time, | |
| 84 struct PP_CompletionCallback callback) { | |
| 85 DebugPrintf("FileIO::Touch: file_io_id=%"NACL_PRId32"\n", file_io_id); | |
| 86 UNREFERENCED_PARAMETER(last_access_time); | |
| 87 UNREFERENCED_PARAMETER(last_modified_time); | |
| 88 UNREFERENCED_PARAMETER(callback); | |
| 89 NACL_UNIMPLEMENTED(); | |
| 90 return PP_ERROR_BADRESOURCE; | |
| 91 } | |
| 92 | |
| 93 int32_t Read(PP_Resource file_io_id, | |
| 94 int64_t offset, | |
| 95 char* buffer, | |
| 96 int32_t bytes_to_read, | |
| 97 struct PP_CompletionCallback callback) { | |
| 98 DebugPrintf("FileIO::Read: file_io_id=%"NACL_PRId32"\n", file_io_id); | |
| 99 UNREFERENCED_PARAMETER(offset); | |
| 100 UNREFERENCED_PARAMETER(buffer); | |
| 101 UNREFERENCED_PARAMETER(bytes_to_read); | |
| 102 UNREFERENCED_PARAMETER(callback); | |
| 103 NACL_UNIMPLEMENTED(); | |
| 104 return PP_ERROR_BADRESOURCE; | |
| 105 } | |
| 106 | |
| 107 int32_t Write(PP_Resource file_io_id, | |
| 108 int64_t offset, | |
| 109 const char* buffer, | |
| 110 int32_t bytes_to_write, | |
| 111 struct PP_CompletionCallback callback) { | |
| 112 DebugPrintf("FileIO::Write: file_io_id=%"NACL_PRId32"\n", file_io_id); | |
| 113 UNREFERENCED_PARAMETER(offset); | |
| 114 UNREFERENCED_PARAMETER(buffer); | |
| 115 UNREFERENCED_PARAMETER(bytes_to_write); | |
| 116 UNREFERENCED_PARAMETER(callback); | |
| 117 NACL_UNIMPLEMENTED(); | |
| 118 return PP_ERROR_BADRESOURCE; | |
| 119 } | |
| 120 | |
| 121 int32_t SetLength(PP_Resource file_io_id, | |
| 122 int64_t length, | |
| 123 struct PP_CompletionCallback callback) { | |
| 124 DebugPrintf("FileIO::SetLength: file_io_id=%"NACL_PRId32"\n", file_io_id); | |
| 125 UNREFERENCED_PARAMETER(length); | |
| 126 UNREFERENCED_PARAMETER(callback); | |
| 127 NACL_UNIMPLEMENTED(); | |
| 128 return PP_ERROR_BADRESOURCE; | |
| 129 } | |
| 130 | |
| 131 int32_t Flush(PP_Resource file_io_id, | |
| 132 struct PP_CompletionCallback callback) { | |
| 133 DebugPrintf("FileIO::Flush: file_io=%"NACL_PRId32"\n", file_io_id); | |
| 134 UNREFERENCED_PARAMETER(callback); | |
| 135 NACL_UNIMPLEMENTED(); | |
| 136 return PP_ERROR_BADRESOURCE; | |
| 137 } | |
| 138 | |
| 139 void Close(PP_Resource file_io_id) { | |
| 140 DebugPrintf("FileIO::Close: file_io=%"NACL_PRId32"\n", file_io_id); | |
| 141 NACL_UNIMPLEMENTED(); | |
| 142 } | |
| 143 | |
| 144 } // namespace | |
| 145 | |
| 146 | |
| 147 const PPB_FileIO_Dev* FileIO::GetInterface() { | |
| 148 static const PPB_FileIO_Dev file_io_interface = { | |
| 149 Create, | |
| 150 IsFileIO, | |
| 151 Open, | |
| 152 Query, | |
| 153 Touch, | |
| 154 Read, | |
| 155 Write, | |
| 156 SetLength, | |
| 157 Flush, | |
| 158 Close | |
| 159 }; | |
| 160 return &file_io_interface; | |
| 161 } | |
| 162 | |
| 163 } // namespace fake_browser_ppapi | |
| OLD | NEW |