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

Side by Side Diff: ppapi/c/ppb_file_io.h

Issue 7314007: All new file i/o documentation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 | « no previous file | ppapi/c/ppb_file_ref.h » ('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) 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 <code>PP_FileOpenFlags</code>
57 // such time as the FileIO object is closed or destroyed. 102 * values. Upon success, the corresponding file is classified as "in use"
103 * by this FileIO object until such time as the FileIO object is closed
104 * or destroyed.
105 *
106 * @param[in] file_io A <code>PP_Resource</code> corresponding to a
107 * FileIO.
108 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
109 * reference.
110 * @param[in] open_flags A bit-mask of the <code>PP_FileOpenFlags</code>
111 * values.
112 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
113 * completion of Open().
114 *
115 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
116 */
58 int32_t (*Open)(PP_Resource file_io, 117 int32_t (*Open)(PP_Resource file_io,
59 PP_Resource file_ref, 118 PP_Resource file_ref,
60 int32_t open_flags, 119 int32_t open_flags,
61 struct PP_CompletionCallback callback); 120 struct PP_CompletionCallback callback);
62 121
63 // Queries info about the file opened by this FileIO object. Fails if the 122 /**
64 // FileIO object has not been opened. 123 * Query() queries info about the file opened by this FileIO object. This
124 * function will fail if the FileIO object has not been opened.
125 *
126 * @param[in] file_io A <code>PP_Resource</code> corresponding to a
127 * FileIO.
128 * @param[in] info The <code>PP_FileInfo</code> structure representing all
129 * information about the file.
130 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
131 * completion of Query().
132 *
133 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
134 */
65 int32_t (*Query)(PP_Resource file_io, 135 int32_t (*Query)(PP_Resource file_io,
66 struct PP_FileInfo* info, 136 struct PP_FileInfo* info,
67 struct PP_CompletionCallback callback); 137 struct PP_CompletionCallback callback);
68 138
69 // Updates timestamps for the file opened by this FileIO object. Fails if 139 /**
70 // the FileIO object has not been opened. 140 * Touch() Updates time stamps for the file opened by this FileIO object.
141 * This function will fail if the FileIO object has not been opened.
142 *
143 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
144 * FileIO.
145 * @param[in] last_access_time The last time the FileIO was accessed.
146 * @param[in] last_modified_time The last time the FileIO was modified.
147 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
148 * completion of Touch().
149 *
150 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
151 */
71 int32_t (*Touch)(PP_Resource file_io, 152 int32_t (*Touch)(PP_Resource file_io,
72 PP_Time last_access_time, 153 PP_Time last_access_time,
73 PP_Time last_modified_time, 154 PP_Time last_modified_time,
74 struct PP_CompletionCallback callback); 155 struct PP_CompletionCallback callback);
75 156
76 // Read from an offset in the file. The size of the buffer must be large 157 /**
77 // enough to hold the specified number of bytes to read. May perform a 158 * 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 159 * 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 160 * might perform a partial read.
80 // valid to call Read multiple times with a completion callback to queue up 161 *
81 // parallel reads from the file at different offsets. 162 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
163 * FileIO.
164 * @param[in] offset The offset into the file.
165 * @param[in] buffer The buffer to hold the specified number of bytes read.
166 * @param[in] bytes_to_read The number of bytes to read from
167 * <code>offset</code>.
168 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
169 * completion of Read().
170 *
171 * @return An The number of bytes read an error code from
172 * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was
173 * reached. It is valid to call Read() multiple times with a completion
174 * callback to queue up parallel reads from the file at different offsets.
175 */
82 int32_t (*Read)(PP_Resource file_io, 176 int32_t (*Read)(PP_Resource file_io,
83 int64_t offset, 177 int64_t offset,
84 char* buffer, 178 char* buffer,
85 int32_t bytes_to_read, 179 int32_t bytes_to_read,
86 struct PP_CompletionCallback callback); 180 struct PP_CompletionCallback callback);
87 181
88 // Write to an offset in the file. May perform a partial write. Returns the 182 /**
89 // number of bytes written or an error code. It is valid to call Write 183 * 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 184 * 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 185 *
92 // with write access. 186 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
187 * FileIO.
188 * @param[in] offset The offset into the file.
189 * @param[in] buffer The buffer to hold the specified number of bytes read.
190 * @param[in] bytes_to_write The number of bytes to write to
191 * <code>offset</code>.
192 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
193 * completion of Write().
194 *
195 * @return An The number of bytes written or an error code from
196 * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was
197 * reached. It is valid to call Write() multiple times with a completion
198 * callback to queue up parallel writes to the file at different offsets.
199 */
93 int32_t (*Write)(PP_Resource file_io, 200 int32_t (*Write)(PP_Resource file_io,
94 int64_t offset, 201 int64_t offset,
95 const char* buffer, 202 const char* buffer,
96 int32_t bytes_to_write, 203 int32_t bytes_to_write,
97 struct PP_CompletionCallback callback); 204 struct PP_CompletionCallback callback);
98 205 /**
99 // Sets the length of the file. If the file size is extended, then the 206 * 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 207 * then the extended area of the file is zero-filled. The FileIO object must
101 // been opened with write access. 208 * have been opened with write access.
209 *
210 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
211 * FileIO.
212 * @param[in] length The length of the file to be set.
213 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
214 * completion of SetLength().
215 *
216 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
217 */
102 int32_t (*SetLength)(PP_Resource file_io, 218 int32_t (*SetLength)(PP_Resource file_io,
103 int64_t length, 219 int64_t length,
104 struct PP_CompletionCallback callback); 220 struct PP_CompletionCallback callback);
105 221
106 // Flush changes to disk. This call can be very expensive! 222 /**
223 * Flush() flushes changes to disk. This call can be very expensive!
224 *
225 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
226 * FileIO.
227 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
228 * completion of Flush().
229 *
230 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
231 */
107 int32_t (*Flush)(PP_Resource file_io, 232 int32_t (*Flush)(PP_Resource file_io,
108 struct PP_CompletionCallback callback); 233 struct PP_CompletionCallback callback);
109 234
110 // Cancels any IO that may be pending, and closes the FileIO object. Any 235 /**
111 // pending callbacks will still run, reporting PP_Error_Aborted if pending IO 236 * 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 237 * Any pending callbacks will still run, reporting
113 // method. Note: If the FileIO object is destroyed, and it is still open, 238 * <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 239 * valid to call Open() again after a call to this method.
115 // Close method. 240 * <strong>Note:</strong> If the FileIO object is destroyed, and it is still
241 * open, then it will be implicitly closed, so you are not required to call
242 * Close().
243 *
244 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
245 * FileIO.
246 */
116 void (*Close)(PP_Resource file_io); 247 void (*Close)(PP_Resource file_io);
117 }; 248 };
249 /**
250 * @}
251 */
118 252
119 #endif /* PPAPI_C_PPB_FILE_IO_H_ */ 253 #endif /* PPAPI_C_PPB_FILE_IO_H_ */
120 254
OLDNEW
« no previous file with comments | « no previous file | ppapi/c/ppb_file_ref.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698