Pepper_47_C_interfaces
ppb_file_io.h
Go to the documentation of this file.
1 /* Copyright (c) 2012 The Chromium 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 
6 /* From ppb_file_io.idl modified Wed Mar 15 15:22:36 2017. */
7 
8 #ifndef PPAPI_C_PPB_FILE_IO_H_
9 #define PPAPI_C_PPB_FILE_IO_H_
10 
12 #include "ppapi/c/pp_bool.h"
14 #include "ppapi/c/pp_file_info.h"
15 #include "ppapi/c/pp_instance.h"
16 #include "ppapi/c/pp_macros.h"
17 #include "ppapi/c/pp_resource.h"
18 #include "ppapi/c/pp_stdint.h"
19 #include "ppapi/c/pp_time.h"
20 
21 #define PPB_FILEIO_INTERFACE_1_0 "PPB_FileIO;1.0"
22 #define PPB_FILEIO_INTERFACE_1_1 "PPB_FileIO;1.1"
23 #define PPB_FILEIO_INTERFACE PPB_FILEIO_INTERFACE_1_1
24 
25 /**
26  * @file
27  * This file defines the API to create a file i/o object.
28  */
29 
30 
31 /**
32  * @addtogroup Enums
33  * @{
34  */
35 /**
36  * The PP_FileOpenFlags enum contains file open constants.
37  */
38 typedef enum {
39  /** Requests read access to a file. */
41  /**
42  * Requests write access to a file. May be combined with
43  * <code>PP_FILEOPENFLAG_READ</code> to request read and write access.
44  */
46  /**
47  * Requests that the file be created if it does not exist. If the file
48  * already exists, then this flag is ignored unless
49  * <code>PP_FILEOPENFLAG_EXCLUSIVE</code> was also specified, in which case
50  * FileIO::Open() will fail.
51  */
53  /**
54  * Requests that the file be truncated to length 0 if it exists and is a
55  * regular file. <code>PP_FILEOPENFLAG_WRITE</code> must also be specified.
56  */
58  /**
59  * Requests that the file is created when this flag is combined with
60  * <code>PP_FILEOPENFLAG_CREATE</code>. If this flag is specified, and the
61  * file already exists, then the FileIO::Open() call will fail.
62  */
64  /**
65  * Requests write access to a file, but writes will always occur at the end of
66  * the file. Mututally exclusive with <code>PP_FILEOPENFLAG_WRITE</code>.
67  *
68  * This is only supported in version 1.2 (Chrome 29) and later.
69  */
73 /**
74  * @}
75  */
76 
77 /**
78  * @addtogroup Interfaces
79  * @{
80  */
81 /**
82  * The <code>PPB_FileIO</code> struct is used to operate on a regular file
83  * (PP_FileType_Regular).
84  */
86  /**
87  * Create() creates a new FileIO object.
88  *
89  * @param[in] instance A <code>PP_Instance</code> identifying the instance
90  * with the file.
91  *
92  * @return A <code>PP_Resource</code> corresponding to a FileIO if
93  * successful or 0 if the module is invalid.
94  */
96  /**
97  * IsFileIO() determines if the provided resource is a FileIO.
98  *
99  * @param[in] resource A <code>PP_Resource</code> corresponding to a FileIO.
100  *
101  * @return <code>PP_TRUE</code> if the resource is a
102  * <code>PPB_FileIO</code>, <code>PP_FALSE</code> if the resource is
103  * invalid or some type other than <code>PPB_FileIO</code>.
104  */
106  /**
107  * Open() opens the specified regular file for I/O according to the given
108  * open flags, which is a bit-mask of the <code>PP_FileOpenFlags</code>
109  * values. Upon success, the corresponding file is classified as "in use"
110  * by this FileIO object until such time as the FileIO object is closed
111  * or destroyed.
112  *
113  * @param[in] file_io A <code>PP_Resource</code> corresponding to a
114  * FileIO.
115  * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
116  * reference.
117  * @param[in] open_flags A bit-mask of the <code>PP_FileOpenFlags</code>
118  * values.
119  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
120  * completion of Open().
121  *
122  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
123  */
124  int32_t (*Open)(PP_Resource file_io,
125  PP_Resource file_ref,
126  int32_t open_flags,
127  struct PP_CompletionCallback callback);
128  /**
129  * Query() queries info about the file opened by this FileIO object. The
130  * FileIO object must be opened, and there must be no other operations
131  * pending.
132  *
133  * @param[in] file_io A <code>PP_Resource</code> corresponding to a
134  * FileIO.
135  * @param[out] info The <code>PP_FileInfo</code> structure representing all
136  * information about the file.
137  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
138  * completion of Query(). <code>info</code> must remain valid until after the
139  * callback runs. If you pass a blocking callback, <code>info</code> must
140  * remain valid until after Query() returns.
141  *
142  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
143  * PP_ERROR_FAILED will be returned if the file isn't opened, and
144  * PP_ERROR_INPROGRESS will be returned if there is another operation pending.
145  */
146  int32_t (*Query)(PP_Resource file_io,
147  struct PP_FileInfo* info,
148  struct PP_CompletionCallback callback);
149  /**
150  * Touch() Updates time stamps for the file opened by this FileIO object.
151  * This function will fail if the FileIO object has not been opened. The
152  * FileIO object must be opened, and there must be no other operations
153  * pending.
154  *
155  * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
156  * FileIO.
157  * @param[in] last_access_time The last time the FileIO was accessed.
158  * @param[in] last_modified_time The last time the FileIO was modified.
159  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
160  * completion of Touch().
161  *
162  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
163  * PP_ERROR_FAILED will be returned if the file isn't opened, and
164  * PP_ERROR_INPROGRESS will be returned if there is another operation pending.
165  */
166  int32_t (*Touch)(PP_Resource file_io,
167  PP_Time last_access_time,
168  PP_Time last_modified_time,
169  struct PP_CompletionCallback callback);
170  /**
171  * Read() reads from an offset in the file. The size of the buffer must be
172  * large enough to hold the specified number of bytes to read. This function
173  * might perform a partial read, meaning all the requested bytes
174  * might not be returned, even if the end of the file has not been reached.
175  * The FileIO object must have been opened with read access.
176  *
177  * ReadToArray() is preferred to Read() when doing asynchronous operations.
178  *
179  * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
180  * FileIO.
181  * @param[in] offset The offset into the file.
182  * @param[out] buffer The buffer to hold the specified number of bytes read.
183  * @param[in] bytes_to_read The number of bytes to read from
184  * <code>offset</code>.
185  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
186  * completion of Read(). <code>buffer</code> must remain valid until after
187  * the callback runs. If you pass a blocking callback, <code>buffer</code>
188  * must remain valid until after Read() returns.
189  *
190  * @return The number of bytes read or an error code from
191  * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was
192  * reached. It is valid to call Read() multiple times with a completion
193  * callback to queue up parallel reads from the file, but pending reads
194  * cannot be interleaved with other operations.
195  */
196  int32_t (*Read)(PP_Resource file_io,
197  int64_t offset,
198  char* buffer,
199  int32_t bytes_to_read,
200  struct PP_CompletionCallback callback);
201  /**
202  * Write() writes to an offset in the file. This function might perform a
203  * partial write. The FileIO object must have been opened with write access.
204  *
205  * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
206  * FileIO.
207  * @param[in] offset The offset into the file.
208  * @param[in] buffer The buffer to hold the specified number of bytes to
209  * write.
210  * @param[in] bytes_to_write The number of bytes to write to
211  * <code>offset</code>.
212  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
213  * completion of Write().
214  *
215  * @return The number of bytes written or an error code from
216  * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was
217  * reached. It is valid to call Write() multiple times with a completion
218  * callback to queue up parallel writes to the file, but pending writes
219  * cannot be interleaved with other operations.
220  */
221  int32_t (*Write)(PP_Resource file_io,
222  int64_t offset,
223  const char* buffer,
224  int32_t bytes_to_write,
225  struct PP_CompletionCallback callback);
226  /**
227  * SetLength() sets the length of the file. If the file size is extended,
228  * then the extended area of the file is zero-filled. The FileIO object must
229  * have been opened with write access and there must be no other operations
230  * pending.
231  *
232  * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
233  * FileIO.
234  * @param[in] length The length of the file to be set.
235  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
236  * completion of SetLength().
237  *
238  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
239  * PP_ERROR_FAILED will be returned if the file isn't opened, and
240  * PP_ERROR_INPROGRESS will be returned if there is another operation pending.
241  */
242  int32_t (*SetLength)(PP_Resource file_io,
243  int64_t length,
244  struct PP_CompletionCallback callback);
245  /**
246  * Flush() flushes changes to disk. This call can be very expensive! The
247  * FileIO object must have been opened with write access and there must be no
248  * other operations pending.
249  *
250  * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
251  * FileIO.
252  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
253  * completion of Flush().
254  *
255  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
256  * PP_ERROR_FAILED will be returned if the file isn't opened, and
257  * PP_ERROR_INPROGRESS will be returned if there is another operation pending.
258  */
259  int32_t (*Flush)(PP_Resource file_io, struct PP_CompletionCallback callback);
260  /**
261  * Close() cancels any IO that may be pending, and closes the FileIO object.
262  * Any pending callbacks will still run, reporting
263  * <code>PP_ERROR_ABORTED</code> if pending IO was interrupted. It is not
264  * valid to call Open() again after a call to this method.
265  * <strong>Note:</strong> If the FileIO object is destroyed, and it is still
266  * open, then it will be implicitly closed, so you are not required to call
267  * Close().
268  *
269  * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
270  * FileIO.
271  */
272  void (*Close)(PP_Resource file_io);
273  /**
274  * ReadToArray() reads from an offset in the file. A PP_ArrayOutput must be
275  * provided so that output will be stored in its allocated buffer. This
276  * function might perform a partial read. The FileIO object must have been
277  * opened with read access.
278  *
279  * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
280  * FileIO.
281  * @param[in] offset The offset into the file.
282  * @param[in] max_read_length The maximum number of bytes to read from
283  * <code>offset</code>.
284  * @param[in] output A <code>PP_ArrayOutput</code> to hold the output data.
285  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
286  * completion of ReadToArray().
287  *
288  * @return The number of bytes read or an error code from
289  * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was
290  * reached. It is valid to call ReadToArray() multiple times with a completion
291  * callback to queue up parallel reads from the file, but pending reads
292  * cannot be interleaved with other operations.
293  */
294  int32_t (*ReadToArray)(PP_Resource file_io,
295  int64_t offset,
296  int32_t max_read_length,
297  struct PP_ArrayOutput* output,
298  struct PP_CompletionCallback callback);
299 };
300 
301 typedef struct PPB_FileIO_1_1 PPB_FileIO;
302 
306  int32_t (*Open)(PP_Resource file_io,
307  PP_Resource file_ref,
308  int32_t open_flags,
309  struct PP_CompletionCallback callback);
310  int32_t (*Query)(PP_Resource file_io,
311  struct PP_FileInfo* info,
312  struct PP_CompletionCallback callback);
313  int32_t (*Touch)(PP_Resource file_io,
314  PP_Time last_access_time,
315  PP_Time last_modified_time,
316  struct PP_CompletionCallback callback);
317  int32_t (*Read)(PP_Resource file_io,
318  int64_t offset,
319  char* buffer,
320  int32_t bytes_to_read,
321  struct PP_CompletionCallback callback);
322  int32_t (*Write)(PP_Resource file_io,
323  int64_t offset,
324  const char* buffer,
325  int32_t bytes_to_write,
326  struct PP_CompletionCallback callback);
327  int32_t (*SetLength)(PP_Resource file_io,
328  int64_t length,
329  struct PP_CompletionCallback callback);
330  int32_t (*Flush)(PP_Resource file_io, struct PP_CompletionCallback callback);
331  void (*Close)(PP_Resource file_io);
332 };
333 /**
334  * @}
335  */
336 
337 #endif /* PPAPI_C_PPB_FILE_IO_H_ */
338 
int32_t(* Write)(PP_Resource file_io, int64_t offset, const char *buffer, int32_t bytes_to_write, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:221
int32_t(* Query)(PP_Resource file_io, struct PP_FileInfo *info, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:310
double PP_Time
Definition: pp_time.h:29
int32_t(* SetLength)(PP_Resource file_io, int64_t length, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:327
PP_Bool(* IsFileIO)(PP_Resource resource)
Definition: ppb_file_io.h:105
void(* Close)(PP_Resource file_io)
Definition: ppb_file_io.h:272
int32_t(* Flush)(PP_Resource file_io, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:259
int32_t(* ReadToArray)(PP_Resource file_io, int64_t offset, int32_t max_read_length, struct PP_ArrayOutput *output, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:294
int32_t PP_Resource
Definition: pp_resource.h:40
int32_t(* SetLength)(PP_Resource file_io, int64_t length, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:242
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FileOpenFlags, 4)
int32_t(* Open)(PP_Resource file_io, PP_Resource file_ref, int32_t open_flags, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:306
PP_Resource(* Create)(PP_Instance instance)
Definition: ppb_file_io.h:95
int32_t(* Query)(PP_Resource file_io, struct PP_FileInfo *info, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:146
PP_FileOpenFlags
Definition: ppb_file_io.h:38
int32_t(* Write)(PP_Resource file_io, int64_t offset, const char *buffer, int32_t bytes_to_write, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:322
void(* Close)(PP_Resource file_io)
Definition: ppb_file_io.h:331
int32_t(* Touch)(PP_Resource file_io, PP_Time last_access_time, PP_Time last_modified_time, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:313
int32_t(* Touch)(PP_Resource file_io, PP_Time last_access_time, PP_Time last_modified_time, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:166
int32_t PP_Instance
Definition: pp_instance.h:34
int32_t(* Read)(PP_Resource file_io, int64_t offset, char *buffer, int32_t bytes_to_read, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:196
PP_Bool(* IsFileIO)(PP_Resource resource)
Definition: ppb_file_io.h:305
PP_Resource(* Create)(PP_Instance instance)
Definition: ppb_file_io.h:304
PP_Bool
Definition: pp_bool.h:30
int32_t(* Open)(PP_Resource file_io, PP_Resource file_ref, int32_t open_flags, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:124
int32_t(* Read)(PP_Resource file_io, int64_t offset, char *buffer, int32_t bytes_to_read, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:317
int32_t(* Flush)(PP_Resource file_io, struct PP_CompletionCallback callback)
Definition: ppb_file_io.h:330