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.
6 /* From ppb_file_ref.idl modified Thu Aug 15 10:50:43 2013. */
8 #ifndef PPAPI_C_PPB_FILE_REF_H_
9 #define PPAPI_C_PPB_FILE_REF_H_
11 #include "ppapi/c/pp_array_output.h"
12 #include "ppapi/c/pp_bool.h"
13 #include "ppapi/c/pp_completion_callback.h"
14 #include "ppapi/c/pp_file_info.h"
15 #include "ppapi/c/pp_macros.h"
16 #include "ppapi/c/pp_resource.h"
17 #include "ppapi/c/pp_stdint.h"
18 #include "ppapi/c/pp_time.h"
19 #include "ppapi/c/pp_var.h"
21 #define PPB_FILEREF_INTERFACE_1_0 "PPB_FileRef;1.0"
22 #define PPB_FILEREF_INTERFACE_1_1 "PPB_FileRef;1.1"
23 #define PPB_FILEREF_INTERFACE PPB_FILEREF_INTERFACE_1_1
27 * This file defines the API to create a file reference or "weak pointer" to a
28 * file in a file system.
33 * @addtogroup Interfaces
37 * The <code>PPB_FileRef</code> struct represents a "weak pointer" to a file in
38 * a file system. This struct contains a <code>PP_FileSystemType</code>
39 * identifier and a file path string.
41 struct PPB_FileRef_1_1
{
43 * Create() creates a weak pointer to a file in the given file system. File
44 * paths are POSIX style.
46 * @param[in] resource A <code>PP_Resource</code> corresponding to a file
48 * @param[in] path A path to the file. Must begin with a '/' character.
50 * @return A <code>PP_Resource</code> corresponding to a file reference if
51 * successful or 0 if the path is malformed.
53 PP_Resource (*Create
)(PP_Resource file_system
, const char* path
);
55 * IsFileRef() determines if the provided resource is a file reference.
57 * @param[in] resource A <code>PP_Resource</code> corresponding to a file
60 * @return <code>PP_TRUE</code> if the resource is a
61 * <code>PPB_FileRef</code>, <code>PP_FALSE</code> if the resource is
62 * invalid or some type other than <code>PPB_FileRef</code>.
64 PP_Bool (*IsFileRef
)(PP_Resource resource
);
66 * GetFileSystemType() returns the type of the file system.
68 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
71 * @return A <code>PP_FileSystemType</code> with the file system type if
72 * valid or <code>PP_FILESYSTEMTYPE_INVALID</code> if the provided resource
73 * is not a valid file reference.
75 PP_FileSystemType (*GetFileSystemType
)(PP_Resource file_ref
);
77 * GetName() returns the name of the file.
79 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
82 * @return A <code>PP_Var</code> containing the name of the file. The value
83 * returned by this function does not include any path components (such as
84 * the name of the parent directory, for example). It is just the name of the
85 * file. Use GetPath() to get the full file path.
87 struct PP_Var (*GetName
)(PP_Resource file_ref
);
89 * GetPath() returns the absolute path of the file.
91 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
94 * @return A <code>PP_Var</code> containing the absolute path of the file.
95 * This function fails if the file system type is
96 * <code>PP_FileSystemType_External</code>.
98 struct PP_Var (*GetPath
)(PP_Resource file_ref
);
100 * GetParent() returns the parent directory of this file. If
101 * <code>file_ref</code> points to the root of the filesystem, then the root
104 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
107 * @return A <code>PP_Resource</code> containing the parent directory of the
108 * file. This function fails if the file system type is
109 * <code>PP_FileSystemType_External</code>.
111 PP_Resource (*GetParent
)(PP_Resource file_ref
);
113 * MakeDirectory() makes a new directory in the file system as well as any
114 * parent directories if the <code>make_ancestors</code> argument is
115 * <code>PP_TRUE</code>. It is not valid to make a directory in the external
118 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
120 * @param[in] make_ancestors A <code>PP_Bool</code> set to
121 * <code>PP_TRUE</code> to make ancestor directories or <code>PP_FALSE</code>
122 * if ancestor directories are not needed.
124 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
125 * Succeeds if the directory already exists. Fails if ancestor directories
126 * do not exist and <code>make_ancestors</code> was passed as
127 * <code>PP_FALSE</code>.
129 int32_t (*MakeDirectory
)(PP_Resource directory_ref
,
130 PP_Bool make_ancestors
,
131 struct PP_CompletionCallback callback
);
133 * Touch() Updates time stamps for a file. You must have write access to the
134 * file if it exists in the external filesystem.
136 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
138 * @param[in] last_access_time The last time the file was accessed.
139 * @param[in] last_modified_time The last time the file was modified.
140 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
141 * completion of Touch().
143 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
145 int32_t (*Touch
)(PP_Resource file_ref
,
146 PP_Time last_access_time
,
147 PP_Time last_modified_time
,
148 struct PP_CompletionCallback callback
);
150 * Delete() deletes a file or directory. If <code>file_ref</code> refers to
151 * a directory, then the directory must be empty. It is an error to delete a
152 * file or directory that is in use. It is not valid to delete a file in
153 * the external file system.
155 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
157 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
158 * completion of Delete().
160 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
162 int32_t (*Delete
)(PP_Resource file_ref
,
163 struct PP_CompletionCallback callback
);
165 * Rename() renames a file or directory. Arguments <code>file_ref</code> and
166 * <code>new_file_ref</code> must both refer to files in the same file
167 * system. It is an error to rename a file or directory that is in use. It
168 * is not valid to rename a file in the external file system.
170 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
172 * @param[in] new_file_ref A <code>PP_Resource</code> corresponding to a new
174 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
175 * completion of Rename().
177 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
179 int32_t (*Rename
)(PP_Resource file_ref
,
180 PP_Resource new_file_ref
,
181 struct PP_CompletionCallback callback
);
183 * Query() queries info about a file or directory. You must have access to
184 * read this file or directory if it exists in the external filesystem.
186 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
188 * @param[out] info A pointer to a <code>PP_FileInfo</code> which will be
189 * populated with information about the file or directory.
190 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
191 * completion of Query().
193 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
195 int32_t (*Query
)(PP_Resource file_ref
,
196 struct PP_FileInfo
* info
,
197 struct PP_CompletionCallback callback
);
199 * ReadDirectoryEntries() reads all entries in a directory.
201 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a directory
203 * @param[in] output An output array which will receive
204 * <code>PP_DirectoryEntry</code> objects on success.
205 * @param[in] callback A <code>PP_CompletionCallback</code> to run on
208 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
210 int32_t (*ReadDirectoryEntries
)(PP_Resource file_ref
,
211 struct PP_ArrayOutput output
,
212 struct PP_CompletionCallback callback
);
215 typedef struct PPB_FileRef_1_1 PPB_FileRef
;
217 struct PPB_FileRef_1_0
{
218 PP_Resource (*Create
)(PP_Resource file_system
, const char* path
);
219 PP_Bool (*IsFileRef
)(PP_Resource resource
);
220 PP_FileSystemType (*GetFileSystemType
)(PP_Resource file_ref
);
221 struct PP_Var (*GetName
)(PP_Resource file_ref
);
222 struct PP_Var (*GetPath
)(PP_Resource file_ref
);
223 PP_Resource (*GetParent
)(PP_Resource file_ref
);
224 int32_t (*MakeDirectory
)(PP_Resource directory_ref
,
225 PP_Bool make_ancestors
,
226 struct PP_CompletionCallback callback
);
227 int32_t (*Touch
)(PP_Resource file_ref
,
228 PP_Time last_access_time
,
229 PP_Time last_modified_time
,
230 struct PP_CompletionCallback callback
);
231 int32_t (*Delete
)(PP_Resource file_ref
,
232 struct PP_CompletionCallback callback
);
233 int32_t (*Rename
)(PP_Resource file_ref
,
234 PP_Resource new_file_ref
,
235 struct PP_CompletionCallback callback
);
241 #endif /* PPAPI_C_PPB_FILE_REF_H_ */