| OLD | NEW |
| 1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 |
| 6 /* From ppb_file_io.idl modified Wed Jul 13 16:41:25 2011. */ |
| 7 |
| 5 #ifndef PPAPI_C_PPB_FILE_IO_H_ | 8 #ifndef PPAPI_C_PPB_FILE_IO_H_ |
| 6 #define PPAPI_C_PPB_FILE_IO_H_ | 9 #define PPAPI_C_PPB_FILE_IO_H_ |
| 7 | 10 |
| 8 #include "ppapi/c/pp_bool.h" | 11 #include "ppapi/c/pp_bool.h" |
| 12 #include "ppapi/c/pp_completion_callback.h" |
| 13 #include "ppapi/c/pp_file_info.h" |
| 9 #include "ppapi/c/pp_instance.h" | 14 #include "ppapi/c/pp_instance.h" |
| 10 #include "ppapi/c/pp_macros.h" | 15 #include "ppapi/c/pp_macros.h" |
| 11 #include "ppapi/c/pp_resource.h" | 16 #include "ppapi/c/pp_resource.h" |
| 12 #include "ppapi/c/pp_stdint.h" | 17 #include "ppapi/c/pp_stdint.h" |
| 13 #include "ppapi/c/pp_time.h" | 18 #include "ppapi/c/pp_time.h" |
| 14 | 19 |
| 15 /** | 20 /** |
| 16 * @file | 21 * @file |
| 17 * This file defines the API to create a file i/o object. | 22 * This file defines the API to create a file i/o object. |
| 18 */ | 23 */ |
| 19 | 24 |
| 20 struct PP_CompletionCallback; | |
| 21 struct PP_FileInfo; | |
| 22 | 25 |
| 23 /** | 26 /** |
| 24 * @addtogroup Enums | 27 * @addtogroup Enums |
| 25 * @{ | 28 * @{ |
| 26 */ | 29 */ |
| 27 /** | 30 /** |
| 28 * The PP_FileOpenFlags enum contains file open constants. | 31 * The PP_FileOpenFlags enum contains file open constants. |
| 29 */ | 32 */ |
| 30 typedef enum { | 33 typedef enum { |
| 31 /** Requests read access to a file. */ | 34 /** Requests read access to a file. */ |
| 32 PP_FILEOPENFLAG_READ = 1 << 0, | 35 PP_FILEOPENFLAG_READ = 1 << 0, |
| 33 | |
| 34 /** | 36 /** |
| 35 * Requests write access to a file. May be combined with | 37 * Requests write access to a file. May be combined with |
| 36 * <code>PP_FILEOPENFLAG_READ</code> to request read and write access. | 38 * <code>PP_FILEOPENFLAG_READ</code> to request read and write access. |
| 37 */ | 39 */ |
| 38 PP_FILEOPENFLAG_WRITE = 1 << 1, | 40 PP_FILEOPENFLAG_WRITE = 1 << 1, |
| 39 | |
| 40 /** | 41 /** |
| 41 * Requests that the file be created if it does not exist. If the file | 42 * Requests that the file be created if it does not exist. If the file |
| 42 * already exists, then this flag is ignored unless | 43 * already exists, then this flag is ignored unless |
| 43 * <code>PP_FILEOPENFLAG_EXCLUSIVE</code> was also specified, in which case | 44 * <code>PP_FILEOPENFLAG_EXCLUSIVE</code> was also specified, in which case |
| 44 * FileIO::Open() will fail. | 45 * FileIO::Open() will fail. |
| 45 */ | 46 */ |
| 46 PP_FILEOPENFLAG_CREATE = 1 << 2, | 47 PP_FILEOPENFLAG_CREATE = 1 << 2, |
| 47 | |
| 48 /** | 48 /** |
| 49 * Requests that the file be truncated to length 0 if it exists and is a | 49 * Requests that the file be truncated to length 0 if it exists and is a |
| 50 * regular file. <code>PP_FILEOPENFLAG_WRITE</code> must also be specified. | 50 * regular file. <code>PP_FILEOPENFLAG_WRITE</code> must also be specified. |
| 51 */ | 51 */ |
| 52 PP_FILEOPENFLAG_TRUNCATE = 1 << 3, | 52 PP_FILEOPENFLAG_TRUNCATE = 1 << 3, |
| 53 | |
| 54 /** | 53 /** |
| 55 * Requests that the file is created when this flag is combined with | 54 * Requests that the file is created when this flag is combined with |
| 56 * <code>PP_FILEOPENFLAG_CREATE</code>. If this flag is specified, and the | 55 * <code>PP_FILEOPENFLAG_CREATE</code>. If this flag is specified, and the |
| 57 * file already exists, then the FileIO::Open() call will fail. | 56 * file already exists, then the FileIO::Open() call will fail. |
| 58 */ | 57 */ |
| 59 PP_FILEOPENFLAG_EXCLUSIVE = 1 << 4 | 58 PP_FILEOPENFLAG_EXCLUSIVE = 1 << 4 |
| 60 } PP_FileOpenFlags; | 59 } PP_FileOpenFlags; |
| 61 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FileOpenFlags, 4); | 60 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FileOpenFlags, 4); |
| 62 /** | 61 /** |
| 63 * @} | 62 * @} |
| 64 */ | 63 */ |
| 65 | 64 |
| 66 #define PPB_FILEIO_INTERFACE_0_5 "PPB_FileIO;0.5" | |
| 67 #define PPB_FILEIO_INTERFACE_1_0 "PPB_FileIO;1.0" | |
| 68 #define PPB_FILEIO_INTERFACE PPB_FILEIO_INTERFACE_1_0 | |
| 69 | |
| 70 /** | 65 /** |
| 71 * @addtogroup Interfaces | 66 * @addtogroup Interfaces |
| 72 * @{ | 67 * @{ |
| 73 */ | 68 */ |
| 74 /** | 69 /** |
| 75 * The <code>PPB_FileIO</code> struct is used to operate on a regular file | 70 * The <code>PPB_FileIO</code> struct is used to operate on a regular file |
| 76 * (PP_FileType_Regular). | 71 * (PP_FileType_Regular). |
| 77 */ | 72 */ |
| 73 #define PPB_FILEIO_INTERFACE_0_5 "PPB_FileIO;0.5" |
| 74 #define PPB_FILEIO_INTERFACE_1_0 "PPB_FileIO;1.0" |
| 75 #define PPB_FILEIO_INTERFACE PPB_FILEIO_INTERFACE_1_0 |
| 76 |
| 78 struct PPB_FileIO { | 77 struct PPB_FileIO { |
| 79 /** | 78 /** |
| 80 * Create() creates a new FileIO object. | 79 * Create() creates a new FileIO object. |
| 81 * | 80 * |
| 82 * @param[in] instance A <code>PP_Instance</code> indentifying the instance | 81 * @param[in] instance A <code>PP_Instance</code> indentifying the instance |
| 83 * with the file. | 82 * with the file. |
| 84 * | 83 * |
| 85 * @return A <code>PP_Resource</code> corresponding to a FileIO if | 84 * @return A <code>PP_Resource</code> corresponding to a FileIO if |
| 86 * successful or 0 if the module is invalid. | 85 * successful or 0 if the module is invalid. |
| 87 */ | 86 */ |
| 88 PP_Resource (*Create)(PP_Instance instance); | 87 PP_Resource (*Create)(PP_Instance instance); |
| 89 /** | 88 /** |
| 90 * IsFileIO() determines if the provided resource is a FileIO. | 89 * IsFileIO() determines if the provided resource is a FileIO. |
| 91 * | 90 * |
| 92 * @param[in] resource A <code>PP_Resource</code> corresponding to a FileIO. | 91 * @param[in] resource A <code>PP_Resource</code> corresponding to a FileIO. |
| 93 * | 92 * |
| 94 * @return <code>PP_TRUE</code> if the resource is a | 93 * @return <code>PP_TRUE</code> if the resource is a |
| 95 * <code>PPB_FileIO</code>, <code>PP_FALSE</code> if the resource is | 94 * <code>PPB_FileIO</code>, <code>PP_FALSE</code> if the resource is |
| 96 * invalid or some type other than <code>PPB_FileIO</code>. | 95 * invalid or some type other than <code>PPB_FileIO</code>. |
| 97 */ | 96 */ |
| 98 PP_Bool (*IsFileIO)(PP_Resource resource); | 97 PP_Bool (*IsFileIO)(PP_Resource resource); |
| 99 | |
| 100 /** | 98 /** |
| 101 * Open() opens the specified regular file for I/O according to the given | 99 * Open() opens the specified regular file for I/O according to the given |
| 102 * open flags, which is a bit-mask of the <code>PP_FileOpenFlags</code> | 100 * open flags, which is a bit-mask of the <code>PP_FileOpenFlags</code> |
| 103 * values. Upon success, the corresponding file is classified as "in use" | 101 * values. Upon success, the corresponding file is classified as "in use" |
| 104 * by this FileIO object until such time as the FileIO object is closed | 102 * by this FileIO object until such time as the FileIO object is closed |
| 105 * or destroyed. | 103 * or destroyed. |
| 106 * | 104 * |
| 107 * @param[in] file_io A <code>PP_Resource</code> corresponding to a | 105 * @param[in] file_io A <code>PP_Resource</code> corresponding to a |
| 108 * FileIO. | 106 * FileIO. |
| 109 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file | 107 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file |
| 110 * reference. | 108 * reference. |
| 111 * @param[in] open_flags A bit-mask of the <code>PP_FileOpenFlags</code> | 109 * @param[in] open_flags A bit-mask of the <code>PP_FileOpenFlags</code> |
| 112 * values. | 110 * values. |
| 113 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 111 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 114 * completion of Open(). | 112 * completion of Open(). |
| 115 * | 113 * |
| 116 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | 114 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 117 */ | 115 */ |
| 118 int32_t (*Open)(PP_Resource file_io, | 116 int32_t (*Open)(PP_Resource file_io, |
| 119 PP_Resource file_ref, | 117 PP_Resource file_ref, |
| 120 int32_t open_flags, | 118 int32_t open_flags, |
| 121 struct PP_CompletionCallback callback); | 119 struct PP_CompletionCallback callback); |
| 122 | |
| 123 /** | 120 /** |
| 124 * Query() queries info about the file opened by this FileIO object. This | 121 * Query() queries info about the file opened by this FileIO object. This |
| 125 * function will fail if the FileIO object has not been opened. | 122 * function will fail if the FileIO object has not been opened. |
| 126 * | 123 * |
| 127 * @param[in] file_io A <code>PP_Resource</code> corresponding to a | 124 * @param[in] file_io A <code>PP_Resource</code> corresponding to a |
| 128 * FileIO. | 125 * FileIO. |
| 129 * @param[out] info The <code>PP_FileInfo</code> structure representing all | 126 * @param[out] info The <code>PP_FileInfo</code> structure representing all |
| 130 * information about the file. | 127 * information about the file. |
| 131 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 128 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 132 * completion of Query(). | 129 * completion of Query(). |
| 133 * | 130 * |
| 134 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | 131 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 135 */ | 132 */ |
| 136 int32_t (*Query)(PP_Resource file_io, | 133 int32_t (*Query)(PP_Resource file_io, |
| 137 struct PP_FileInfo* info, | 134 struct PP_FileInfo* info, |
| 138 struct PP_CompletionCallback callback); | 135 struct PP_CompletionCallback callback); |
| 139 | |
| 140 /** | 136 /** |
| 141 * Touch() Updates time stamps for the file opened by this FileIO object. | 137 * Touch() Updates time stamps for the file opened by this FileIO object. |
| 142 * This function will fail if the FileIO object has not been opened. | 138 * This function will fail if the FileIO object has not been opened. |
| 143 * | 139 * |
| 144 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file | 140 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file |
| 145 * FileIO. | 141 * FileIO. |
| 146 * @param[in] last_access_time The last time the FileIO was accessed. | 142 * @param[in] last_access_time The last time the FileIO was accessed. |
| 147 * @param[in] last_modified_time The last time the FileIO was modified. | 143 * @param[in] last_modified_time The last time the FileIO was modified. |
| 148 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 144 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 149 * completion of Touch(). | 145 * completion of Touch(). |
| 150 * | 146 * |
| 151 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | 147 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 152 */ | 148 */ |
| 153 int32_t (*Touch)(PP_Resource file_io, | 149 int32_t (*Touch)(PP_Resource file_io, |
| 154 PP_Time last_access_time, | 150 PP_Time last_access_time, |
| 155 PP_Time last_modified_time, | 151 PP_Time last_modified_time, |
| 156 struct PP_CompletionCallback callback); | 152 struct PP_CompletionCallback callback); |
| 157 | |
| 158 /** | 153 /** |
| 159 * Read() reads from an offset in the file. The size of the buffer must be | 154 * Read() reads from an offset in the file. The size of the buffer must be |
| 160 * large enough to hold the specified number of bytes to read. This function | 155 * large enough to hold the specified number of bytes to read. This function |
| 161 * might perform a partial read. | 156 * might perform a partial read. |
| 162 * | 157 * |
| 163 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file | 158 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file |
| 164 * FileIO. | 159 * FileIO. |
| 165 * @param[in] offset The offset into the file. | 160 * @param[in] offset The offset into the file. |
| 166 * @param[in] buffer The buffer to hold the specified number of bytes read. | 161 * @param[in] buffer The buffer to hold the specified number of bytes read. |
| 167 * @param[in] bytes_to_read The number of bytes to read from | 162 * @param[in] bytes_to_read The number of bytes to read from |
| 168 * <code>offset</code>. | 163 * <code>offset</code>. |
| 169 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 164 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 170 * completion of Read(). | 165 * completion of Read(). |
| 171 * | 166 * |
| 172 * @return An The number of bytes read an error code from | 167 * @return An The number of bytes read an error code from |
| 173 * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was | 168 * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was |
| 174 * reached. It is valid to call Read() multiple times with a completion | 169 * reached. It is valid to call Read() multiple times with a completion |
| 175 * callback to queue up parallel reads from the file at different offsets. | 170 * callback to queue up parallel reads from the file at different offsets. |
| 176 */ | 171 */ |
| 177 int32_t (*Read)(PP_Resource file_io, | 172 int32_t (*Read)(PP_Resource file_io, |
| 178 int64_t offset, | 173 int64_t offset, |
| 179 char* buffer, | 174 char* buffer, |
| 180 int32_t bytes_to_read, | 175 int32_t bytes_to_read, |
| 181 struct PP_CompletionCallback callback); | 176 struct PP_CompletionCallback callback); |
| 182 | |
| 183 /** | 177 /** |
| 184 * Write() writes to an offset in the file. This function might perform a | 178 * Write() writes to an offset in the file. This function might perform a |
| 185 * partial write. The FileIO object must have been opened with write access. | 179 * partial write. The FileIO object must have been opened with write access. |
| 186 * | 180 * |
| 187 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file | 181 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file |
| 188 * FileIO. | 182 * FileIO. |
| 189 * @param[in] offset The offset into the file. | 183 * @param[in] offset The offset into the file. |
| 190 * @param[in] buffer The buffer to hold the specified number of bytes read. | 184 * @param[in] buffer The buffer to hold the specified number of bytes read. |
| 191 * @param[in] bytes_to_write The number of bytes to write to | 185 * @param[in] bytes_to_write The number of bytes to write to |
| 192 * <code>offset</code>. | 186 * <code>offset</code>. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 212 * FileIO. | 206 * FileIO. |
| 213 * @param[in] length The length of the file to be set. | 207 * @param[in] length The length of the file to be set. |
| 214 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 208 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 215 * completion of SetLength(). | 209 * completion of SetLength(). |
| 216 * | 210 * |
| 217 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | 211 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 218 */ | 212 */ |
| 219 int32_t (*SetLength)(PP_Resource file_io, | 213 int32_t (*SetLength)(PP_Resource file_io, |
| 220 int64_t length, | 214 int64_t length, |
| 221 struct PP_CompletionCallback callback); | 215 struct PP_CompletionCallback callback); |
| 222 | |
| 223 /** | 216 /** |
| 224 * Flush() flushes changes to disk. This call can be very expensive! | 217 * Flush() flushes changes to disk. This call can be very expensive! |
| 225 * | 218 * |
| 226 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file | 219 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file |
| 227 * FileIO. | 220 * FileIO. |
| 228 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 221 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 229 * completion of Flush(). | 222 * completion of Flush(). |
| 230 * | 223 * |
| 231 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | 224 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 232 */ | 225 */ |
| 233 int32_t (*Flush)(PP_Resource file_io, | 226 int32_t (*Flush)(PP_Resource file_io, struct PP_CompletionCallback callback); |
| 234 struct PP_CompletionCallback callback); | |
| 235 | |
| 236 /** | 227 /** |
| 237 * Close() cancels any IO that may be pending, and closes the FileIO object. | 228 * Close() cancels any IO that may be pending, and closes the FileIO object. |
| 238 * Any pending callbacks will still run, reporting | 229 * Any pending callbacks will still run, reporting |
| 239 * <code>PP_Error_Aborted</code> if pending IO was interrupted. It is not | 230 * <code>PP_Error_Aborted</code> if pending IO was interrupted. It is not |
| 240 * valid to call Open() again after a call to this method. | 231 * valid to call Open() again after a call to this method. |
| 241 * <strong>Note:</strong> If the FileIO object is destroyed, and it is still | 232 * <strong>Note:</strong> If the FileIO object is destroyed, and it is still |
| 242 * open, then it will be implicitly closed, so you are not required to call | 233 * open, then it will be implicitly closed, so you are not required to call |
| 243 * Close(). | 234 * Close(). |
| 244 * | 235 * |
| 245 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file | 236 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file |
| 246 * FileIO. | 237 * FileIO. |
| 247 */ | 238 */ |
| 248 void (*Close)(PP_Resource file_io); | 239 void (*Close)(PP_Resource file_io); |
| 249 }; | 240 }; |
| 250 /** | 241 /** |
| 251 * @} | 242 * @} |
| 252 */ | 243 */ |
| 253 | 244 |
| 254 #endif /* PPAPI_C_PPB_FILE_IO_H_ */ | 245 #endif /* PPAPI_C_PPB_FILE_IO_H_ */ |
| 255 | 246 |
| OLD | NEW |