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

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

Issue 7242002: Sang's initial CL for moving the file interface out of dev. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 6 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
OLDNEW
(Empty)
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
3 * found in the LICENSE file.
4 */
5 #ifndef PPAPI_C_PPB_FILE_IO_H_
6 #define PPAPI_C_PPB_FILE_IO_H_
7
8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/c/pp_macros.h"
11 #include "ppapi/c/pp_resource.h"
12 #include "ppapi/c/pp_stdint.h"
13 #include "ppapi/c/pp_time.h"
14
15 struct PP_CompletionCallback;
16 struct PP_FileInfo;
17
18 typedef enum {
19 // Requests read access to a file.
20 PP_FILEOPENFLAG_READ = 1 << 0,
21
22 // Requests write access to a file. May be combined with
23 // PP_FILEOPENFLAG_READ to request read and write access.
24 PP_FILEOPENFLAG_WRITE = 1 << 1,
25
26 // Requests that the file be created if it does not exist. If the file
27 // already exists, then this flag is ignored unless PP_FILEOPENFLAG_EXCLUSIVE
28 // was also specified, in which case FileIO::Open will fail.
29 PP_FILEOPENFLAG_CREATE = 1 << 2,
30
31 // Requests that the file be truncated to length 0 if it exists and is a
32 // regular file. PP_FILEOPENFLAG_WRITE must also be specified.
33 PP_FILEOPENFLAG_TRUNCATE = 1 << 3,
34
35 // Requests that the file is created when this flag is combined with
36 // PP_FILEOPENFLAG_CREATE. If this flag is specified, and the file already
37 // exists, then the FileIO::Open call will fail.
38 PP_FILEOPENFLAG_EXCLUSIVE = 1 << 4
39 } PP_FileOpenFlags;
40 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FileOpenFlags, 4);
41
42 #define PPB_FILEIO_INTERFACE_0_4 "PPB_FileIO;0.4"
43 #define PPB_FILEIO_INTERFACE PPB_FILEIO_INTERFACE_0_4
44
45 // Use this interface to operate on a regular file (PP_FileType_Regular).
46 struct PPB_FileIO {
47 // Creates a new FileIO object. Returns 0 if the module is invalid.
48 PP_Resource (*Create)(PP_Instance instance);
49
50 // Returns PP_TRUE if the given resource is a FileIO. Returns PP_FALSE if the
51 // resource is invalid or some type other than a FileIO.
52 PP_Bool (*IsFileIO)(PP_Resource resource);
53
54 // Open the specified regular file for I/O according to the given open flags,
55 // which is a bit-mask of the PP_FileOpenFlags values. Upon success, the
56 // corresponding file is classified as "in use" by this FileIO object until
57 // such time as the FileIO object is closed or destroyed.
58 int32_t (*Open)(PP_Resource file_io,
59 PP_Resource file_ref,
60 int32_t open_flags,
61 struct PP_CompletionCallback callback);
62
63 // Queries info about the file opened by this FileIO object. Fails if the
64 // FileIO object has not been opened.
65 int32_t (*Query)(PP_Resource file_io,
66 struct PP_FileInfo* info,
67 struct PP_CompletionCallback callback);
68
69 // Updates timestamps for the file opened by this FileIO object. Fails if
70 // the FileIO object has not been opened.
71 int32_t (*Touch)(PP_Resource file_io,
72 PP_Time last_access_time,
73 PP_Time last_modified_time,
74 struct PP_CompletionCallback callback);
75
76 // Read from an offset in the file. The size of the buffer must be large
77 // enough to hold the specified number of bytes to read. May perform a
78 // partial read. Returns the number of bytes read or an error code. If the
79 // return value is 0, then it indicates that end-of-file was reached. It is
80 // valid to call Read multiple times with a completion callback to queue up
81 // parallel reads from the file at different offsets.
82 int32_t (*Read)(PP_Resource file_io,
83 int64_t offset,
84 char* buffer,
85 int32_t bytes_to_read,
86 struct PP_CompletionCallback callback);
87
88 // Write to an offset in the file. May perform a partial write. Returns the
89 // number of bytes written or an error code. It is valid to call Write
90 // multiple times with a completion callback to queue up parallel writes to
91 // the file at different offsets. The FileIO object must have been opened
92 // with write access.
93 int32_t (*Write)(PP_Resource file_io,
94 int64_t offset,
95 const char* buffer,
96 int32_t bytes_to_write,
97 struct PP_CompletionCallback callback);
98
99 // Sets the length of the file. If the file size is extended, then the
100 // extended area of the file is zero-filled. The FileIO object must have
101 // been opened with write access.
102 int32_t (*SetLength)(PP_Resource file_io,
103 int64_t length,
104 struct PP_CompletionCallback callback);
105
106 // Flush changes to disk. This call can be very expensive!
107 int32_t (*Flush)(PP_Resource file_io,
108 struct PP_CompletionCallback callback);
109
110 // Cancels any IO that may be pending, and closes the FileIO object. Any
111 // pending callbacks will still run, reporting PP_Error_Aborted if pending IO
112 // was interrupted. It is NOT valid to call Open again after a call to this
113 // method. Note: If the FileIO object is destroyed, and it is still open,
114 // then it will be implicitly closed, so you are not required to call the
115 // Close method.
116 void (*Close)(PP_Resource file_io);
117 };
118
119 #endif /* PPAPI_C_PPB_FILE_IO_H_ */
OLDNEW
« no previous file with comments | « ppapi/c/pp_file_info.h ('k') | ppapi/c/ppb_file_ref.h » ('j') | ppapi/cpp/file_io.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698