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