Chromium Code Reviews| 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 |
| 11 /// @file | |
| 12 /// This file defines the API to create a file i/o object. | |
| 13 | |
| 11 struct PP_FileInfo; | 14 struct PP_FileInfo; |
| 12 | 15 |
| 13 namespace pp { | 16 namespace pp { |
| 14 | 17 |
| 15 class CompletionCallback; | 18 class CompletionCallback; |
| 16 class FileRef; | 19 class FileRef; |
| 17 class Instance; | 20 class Instance; |
| 18 | 21 |
| 22 /// The <code>FileIO</code> class represents a regular file. | |
| 19 class FileIO : public Resource { | 23 class FileIO : public Resource { |
| 20 public: | 24 public: |
| 21 // Constructs an is_null resource. | 25 /// Default constructor for creating an is_null() <code>FileIO</code> |
| 26 /// object. | |
| 22 FileIO(); | 27 FileIO(); |
| 23 | 28 |
| 29 /// A constructor used when an <code>Instance</code> is provided as a | |
| 30 /// return value whose reference count we need to increment. | |
|
sanga
2011/07/08 00:54:49
return value?
jond
2011/07/08 15:22:35
Right, I believe you use this constructor and pass
dmichael (off chromium)
2011/07/08 15:29:00
The current woding doesn't make sense to me. It's
jond
2011/07/08 15:35:53
Done.
| |
| 31 /// | |
| 32 /// @param[in] instance An <code>Instance</code>. | |
| 24 FileIO(Instance* instance); | 33 FileIO(Instance* instance); |
| 34 | |
| 35 /// The copy constructor for <code>FileIO</code>. | |
| 36 /// | |
| 37 /// @param[in] other A pointer to a <code>FileIO</code>. | |
| 25 FileIO(const FileIO& other); | 38 FileIO(const FileIO& other); |
| 26 | 39 |
| 27 // PPB_FileIO methods: | 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 | |
| 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. | |
| 44 /// | |
| 45 /// @param[in] file_ref A <code>PP_Resource</code> corresponding to a file | |
| 46 /// reference. | |
| 47 /// @param[in] open_flags A bit-mask of the <code>PP_FileOpenFlags</code> | |
| 48 /// values. | |
| 49 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
| 50 /// completion of Open(). | |
| 51 /// | |
| 52 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
| 28 int32_t Open(const FileRef& file_ref, | 53 int32_t Open(const FileRef& file_ref, |
| 29 int32_t open_flags, | 54 int32_t open_flags, |
| 30 const CompletionCallback& cc); | 55 const CompletionCallback& cc); |
| 56 | |
| 57 /// 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 /// | |
| 60 /// @param[in] info The <code>PP_FileInfo</code> structure representing all | |
| 61 /// information about the file. | |
| 62 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
| 63 /// completion of Query(). | |
| 64 /// | |
| 65 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
| 31 int32_t Query(PP_FileInfo* result_buf, | 66 int32_t Query(PP_FileInfo* result_buf, |
| 32 const CompletionCallback& cc); | 67 const CompletionCallback& cc); |
| 68 | |
| 69 /// 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. | |
| 71 /// | |
| 72 /// @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. | |
| 74 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
| 75 /// completion of Touch(). | |
| 76 /// | |
| 77 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
| 33 int32_t Touch(PP_Time last_access_time, | 78 int32_t Touch(PP_Time last_access_time, |
| 34 PP_Time last_modified_time, | 79 PP_Time last_modified_time, |
| 35 const CompletionCallback& cc); | 80 const CompletionCallback& cc); |
| 81 | |
| 82 /// 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 | |
| 84 /// might perform a partial read. | |
| 85 /// | |
| 86 /// @param[in] offset The offset into the file. | |
| 87 /// @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 | |
| 89 /// <code>offset</code>. | |
| 90 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
| 91 /// completion of Read(). | |
| 92 /// | |
| 93 /// @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 | |
| 95 /// 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. | |
| 36 int32_t Read(int64_t offset, | 97 int32_t Read(int64_t offset, |
| 37 char* buffer, | 98 char* buffer, |
| 38 int32_t bytes_to_read, | 99 int32_t bytes_to_read, |
| 39 const CompletionCallback& cc); | 100 const CompletionCallback& cc); |
| 101 | |
| 102 /// 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. | |
| 104 /// | |
| 105 /// @param[in] offset The offset into the file. | |
| 106 /// @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 | |
| 108 /// <code>offset</code>. | |
| 109 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
| 110 /// completion of Write(). | |
| 111 /// | |
| 112 /// @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 | |
| 114 /// 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. | |
| 40 int32_t Write(int64_t offset, | 116 int32_t Write(int64_t offset, |
| 41 const char* buffer, | 117 const char* buffer, |
| 42 int32_t bytes_to_write, | 118 int32_t bytes_to_write, |
| 43 const CompletionCallback& cc); | 119 const CompletionCallback& cc); |
| 120 | |
| 121 /// 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 | |
| 123 /// have been opened with write access. | |
| 124 /// | |
| 125 /// @param[in] length The length of the file to be set. | |
| 126 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
| 127 /// completion of SetLength(). | |
| 128 /// | |
| 129 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
| 44 int32_t SetLength(int64_t length, | 130 int32_t SetLength(int64_t length, |
| 45 const CompletionCallback& cc); | 131 const CompletionCallback& cc); |
| 132 | |
| 133 /// Flush() flushes changes to disk. This call can be very expensive! | |
| 134 /// | |
| 135 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
| 136 /// completion of Flush(). | |
| 137 /// | |
| 138 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
| 46 int32_t Flush(const CompletionCallback& cc); | 139 int32_t Flush(const CompletionCallback& cc); |
| 140 | |
| 141 /// Close() cancels any IO that may be pending, and closes the FileIO object. | |
| 142 /// Any pending callbacks will still run, reporting | |
| 143 /// <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. | |
| 145 /// <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 | |
| 147 /// Close(). | |
| 47 void Close(); | 148 void Close(); |
| 48 }; | 149 }; |
| 49 | 150 |
| 50 } // namespace pp | 151 } // namespace pp |
| 51 | 152 |
| 52 #endif // PPAPI_CPP_FILE_IO_H_ | 153 #endif // PPAPI_CPP_FILE_IO_H_ |
| OLD | NEW |