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_CPP_FILE_IO_H_ | 5 #ifndef PPAPI_CPP_FILE_IO_H_ |
6 #define PPAPI_CPP_FILE_IO_H_ | 6 #define PPAPI_CPP_FILE_IO_H_ |
7 | 7 |
8 #include "ppapi/c/pp_time.h" | 8 #include "ppapi/c/pp_time.h" |
9 #include "ppapi/cpp/resource.h" | 9 #include "ppapi/cpp/resource.h" |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 /// Open() opens the specified regular file for I/O according to the given | 40 /// Open() opens the specified regular file for I/O according to the given |
41 /// open flags, which is a bit-mask of the PP_FileOpenFlags values. Upon | 41 /// open flags, which is a bit-mask of the PP_FileOpenFlags values. Upon |
42 /// success, the corresponding file is classified as "in use" by this FileIO | 42 /// success, the corresponding file is classified as "in use" by this FileIO |
43 /// object until such time as the FileIO object is closed or destroyed. | 43 /// object until such time as the FileIO object is closed or destroyed. |
44 /// | 44 /// |
45 /// @param[in] file_ref A <code>PP_Resource</code> corresponding to a file | 45 /// @param[in] file_ref A <code>PP_Resource</code> corresponding to a file |
46 /// reference. | 46 /// reference. |
47 /// @param[in] open_flags A bit-mask of the <code>PP_FileOpenFlags</code> | 47 /// @param[in] open_flags A bit-mask of the <code>PP_FileOpenFlags</code> |
48 /// values. | 48 /// values. |
49 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 49 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
50 /// completion of Open(). | 50 /// completion of Open(). |
51 /// | 51 /// |
52 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 52 /// @return An int32_t containing an error code from |
| 53 /// <code>pp_errors.h</code>. |
53 int32_t Open(const FileRef& file_ref, | 54 int32_t Open(const FileRef& file_ref, |
54 int32_t open_flags, | 55 int32_t open_flags, |
55 const CompletionCallback& cc); | 56 const CompletionCallback& cc); |
56 | 57 |
57 /// Query() queries info about the file opened by this FileIO object. This | 58 /// Query() queries info about the file opened by this FileIO object. This |
58 /// function will fail if the FileIO object has not been opened. | 59 /// function will fail if the FileIO object has not been opened. |
59 /// | 60 /// |
60 /// @param[in] info The <code>PP_FileInfo</code> structure representing all | 61 /// @param[in] result_buf The <code>PP_FileInfo</code> structure representing |
61 /// information about the file. | 62 /// all information about the file. |
62 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 63 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
63 /// completion of Query(). | 64 /// completion of Query(). |
64 /// | 65 /// |
65 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 66 /// @return An int32_t containing an error code from |
| 67 /// <code>pp_errors.h</code>. |
66 int32_t Query(PP_FileInfo* result_buf, | 68 int32_t Query(PP_FileInfo* result_buf, |
67 const CompletionCallback& cc); | 69 const CompletionCallback& cc); |
68 | 70 |
69 /// Touch() Updates time stamps for the file opened by this FileIO object. | 71 /// Touch() Updates time stamps for the file opened by this FileIO object. |
70 /// This function will fail if the FileIO object has not been opened. | 72 /// This function will fail if the FileIO object has not been opened. |
71 /// | 73 /// |
72 /// @param[in] last_access_time The last time the FileIO was accessed. | 74 /// @param[in] last_access_time The last time the FileIO was accessed. |
73 /// @param[in] last_modified_time The last time the FileIO was modified. | 75 /// @param[in] last_modified_time The last time the FileIO was modified. |
74 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 76 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
75 /// completion of Touch(). | 77 /// completion of Touch(). |
76 /// | 78 /// |
77 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 79 /// @return An int32_t containing an error code from |
| 80 /// <code>pp_errors.h</code>. |
78 int32_t Touch(PP_Time last_access_time, | 81 int32_t Touch(PP_Time last_access_time, |
79 PP_Time last_modified_time, | 82 PP_Time last_modified_time, |
80 const CompletionCallback& cc); | 83 const CompletionCallback& cc); |
81 | 84 |
82 /// Read() reads from an offset in the file. The size of the buffer must be | 85 /// Read() reads from an offset in the file. The size of the buffer must be |
83 /// large enough to hold the specified number of bytes to read. This function | 86 /// large enough to hold the specified number of bytes to read. This |
84 /// might perform a partial read. | 87 /// function might perform a partial read. |
85 /// | 88 /// |
86 /// @param[in] offset The offset into the file. | 89 /// @param[in] offset The offset into the file. |
87 /// @param[in] buffer The buffer to hold the specified number of bytes read. | 90 /// @param[in] buffer The buffer to hold the specified number of bytes read. |
88 /// @param[in] bytes_to_read The number of bytes to read from | 91 /// @param[in] bytes_to_read The number of bytes to read from |
89 /// <code>offset</code>. | 92 /// <code>offset</code>. |
90 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 93 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
91 /// completion of Read(). | 94 /// completion of Read(). |
92 /// | 95 /// |
93 /// @return An The number of bytes read an error code from | 96 /// @return An The number of bytes read an error code from |
94 /// <code>pp_errors.h</code>. If the return value is 0, then end-of-file was | 97 /// <code>pp_errors.h</code>. If the return value is 0, then end-of-file was |
95 /// reached. It is valid to call Read() multiple times with a completion | 98 /// reached. It is valid to call Read() multiple times with a completion |
96 /// callback to queue up parallel reads from the file at different offsets. | 99 /// callback to queue up parallel reads from the file at different offsets. |
97 int32_t Read(int64_t offset, | 100 int32_t Read(int64_t offset, |
98 char* buffer, | 101 char* buffer, |
99 int32_t bytes_to_read, | 102 int32_t bytes_to_read, |
100 const CompletionCallback& cc); | 103 const CompletionCallback& cc); |
101 | 104 |
102 /// Write() writes to an offset in the file. This function might perform a | 105 /// Write() writes to an offset in the file. This function might perform a |
103 /// partial write. The FileIO object must have been opened with write access. | 106 /// partial write. The FileIO object must have been opened with write access. |
104 /// | 107 /// |
105 /// @param[in] offset The offset into the file. | 108 /// @param[in] offset The offset into the file. |
106 /// @param[in] buffer The buffer to hold the specified number of bytes read. | 109 /// @param[in] buffer The buffer to hold the specified number of bytes read. |
107 /// @param[in] bytes_to_write The number of bytes to write to | 110 /// @param[in] bytes_to_write The number of bytes to write to |
108 /// <code>offset</code>. | 111 /// <code>offset</code>. |
109 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 112 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
110 /// completion of Write(). | 113 /// completion of Write(). |
111 /// | 114 /// |
112 /// @return An The number of bytes written or an error code from | 115 /// @return An The number of bytes written or an error code from |
113 /// <code>pp_errors.h</code>. If the return value is 0, then end-of-file was | 116 /// <code>pp_errors.h</code>. If the return value is 0, then end-of-file was |
114 /// reached. It is valid to call Write() multiple times with a completion | 117 /// reached. It is valid to call Write() multiple times with a completion |
115 /// callback to queue up parallel writes to the file at different offsets. | 118 /// callback to queue up parallel writes to the file at different offsets. |
116 int32_t Write(int64_t offset, | 119 int32_t Write(int64_t offset, |
117 const char* buffer, | 120 const char* buffer, |
118 int32_t bytes_to_write, | 121 int32_t bytes_to_write, |
119 const CompletionCallback& cc); | 122 const CompletionCallback& cc); |
120 | 123 |
121 /// SetLength() sets the length of the file. If the file size is extended, | 124 /// SetLength() sets the length of the file. If the file size is extended, |
122 /// then the extended area of the file is zero-filled. The FileIO object must | 125 /// then the extended area of the file is zero-filled. The FileIO object must |
123 /// have been opened with write access. | 126 /// have been opened with write access. |
124 /// | 127 /// |
125 /// @param[in] length The length of the file to be set. | 128 /// @param[in] length The length of the file to be set. |
126 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 129 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
127 /// completion of SetLength(). | 130 /// completion of SetLength(). |
128 /// | 131 /// |
129 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 132 /// @return An int32_t containing an error code from |
| 133 /// <code>pp_errors.h</code>. |
130 int32_t SetLength(int64_t length, | 134 int32_t SetLength(int64_t length, |
131 const CompletionCallback& cc); | 135 const CompletionCallback& cc); |
132 | 136 |
133 /// Flush() flushes changes to disk. This call can be very expensive! | 137 /// Flush() flushes changes to disk. This call can be very expensive! |
134 /// | 138 /// |
135 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 139 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
136 /// completion of Flush(). | 140 /// completion of Flush(). |
137 /// | 141 /// |
138 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 142 /// @return An int32_t containing an error code from |
| 143 /// <code>pp_errors.h</code>. |
139 int32_t Flush(const CompletionCallback& cc); | 144 int32_t Flush(const CompletionCallback& cc); |
140 | 145 |
141 /// Close() cancels any IO that may be pending, and closes the FileIO object. | 146 /// Close() cancels any IO that may be pending, and closes the FileIO object. |
142 /// Any pending callbacks will still run, reporting | 147 /// Any pending callbacks will still run, reporting |
143 /// <code>PP_Error_Aborted</code> if pending IO was interrupted. It is not | 148 /// <code>PP_Error_Aborted</code> if pending IO was interrupted. It is not |
144 /// valid to call Open() again after a call to this method. | 149 /// valid to call Open() again after a call to this method. |
| 150 /// |
145 /// <strong>Note:</strong> If the FileIO object is destroyed, and it is still | 151 /// <strong>Note:</strong> If the FileIO object is destroyed, and it is still |
146 /// open, then it will be implicitly closed, so you are not required to call | 152 /// open, then it will be implicitly closed, so you are not required to call |
147 /// Close(). | 153 /// Close(). |
148 void Close(); | 154 void Close(); |
149 }; | 155 }; |
150 | 156 |
151 } // namespace pp | 157 } // namespace pp |
152 | 158 |
153 #endif // PPAPI_CPP_FILE_IO_H_ | 159 #endif // PPAPI_CPP_FILE_IO_H_ |
OLD | NEW |