1 /* 2 __ 3 / _| 4 __ _ _ _ _ __ ___ _ __ __ _ | |_ ___ ___ ___ 5 / _` | | | | '__/ _ \| '__/ _` | | _/ _ \/ __/ __| 6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \ 7 \__,_|\__,_|_| \___/|_| \__,_| |_| \___/|___/___/ 8 9 Copyright (C) 2010 The Android Open Source Project. 10 Copyright (C) 2018-2019 Aurora Free Open Source Software. 11 12 This file is part of the Aurora Free Open Source Software. This 13 organization promote free and open source software that you can 14 redistribute and/or modify under the terms of the GNU Lesser General 15 Public License Version 3 as published by the Free Software Foundation or 16 (at your option) any later version approved by the Aurora Free Open Source 17 Software Organization. The license is available in the package root path 18 as 'LICENSE' file. Please review the following information to ensure the 19 GNU Lesser General Public License version 3 requirements will be met: 20 https://www.gnu.org/licenses/lgpl.html . 21 22 Alternatively, this file may be used under the terms of the GNU General 23 Public License version 3 or later as published by the Free Software 24 Foundation. Please review the following information to ensure the GNU 25 General Public License requirements will be met: 26 https://www.gnu.org/licenses/gpl-3.0.html. 27 28 NOTE: All products, services or anything associated to trademarks and 29 service marks used or referenced on this file are the property of their 30 respective companies/owners or its subsidiaries. Other names and brands 31 may be claimed as the property of others. 32 33 For more info about intellectual property visit: aurorafoss.org or 34 directly send an email to: contact (at) aurorafoss.org . 35 36 This file has bindings for an existing code, part of The Android Open Source 37 Project implementation. Check it out at android.googlesource.com . 38 */ 39 40 module aurorafw.android.platform.asset_manager; 41 42 import core.sys.posix.sys.types; 43 44 version (Android): 45 extern (C): 46 @system: 47 nothrow: 48 @nogc: 49 50 /** 51 * @addtogroup Android Asset Manager 52 * @{ 53 */ 54 55 /** Android Asset Manager 56 * @file aurorafw/android/platform/asset_manager.d 57 * @brief This file contains interfacing with android ndk 58 * android/asset_manager.h . 59 * 60 * @authors Luís Ferreira <luis@aurorafoss.org> 61 * @authors Dan Albert <danalbert@google.com> 62 * @authors Johan Euphrosine <proppy@google.com> 63 * @authors Mathias Agopian <mathias@google.com> 64 */ 65 66 /** 67 * {@link AAssetManager} provides access to an application's raw assets by 68 * creating {@link AAsset} objects. 69 * 70 * AAssetManager is a wrapper to the low-level native implementation 71 * of the java {@link AAssetManager}, a pointer can be obtained using 72 * AAssetManager_fromJava(). 73 * 74 * The asset hierarchy may be examined like a filesystem, using 75 * {@link AAssetDir} objects to peruse a single directory. 76 * 77 * A native {@link AAssetManager} pointer may be shared across multiple threads. 78 */ 79 struct AAssetManager; 80 81 /** 82 * {@link AAssetDir} provides access to a chunk of the asset hierarchy as if 83 * it were a single directory. The contents are populated by the 84 * {@link AAssetManager}. 85 * 86 * The list of files will be sorted in ascending order by ASCII value. 87 */ 88 struct AAssetDir; 89 90 /** 91 * {@link AAsset} provides access to a read-only asset. 92 * 93 * {@link AAsset} objects are NOT thread-safe, and should not be shared across 94 * threads. 95 */ 96 struct AAsset; 97 98 /** Available access modes for opening assets with {@link AAssetManager_open} */ 99 enum 100 { 101 AASSET_MODE_UNKNOWN, /** No specific information about how data will be accessed. **/ 102 AASSET_MODE_RANDOM, /** Read chunks, and seek forward and backward. */ 103 AASSET_MODE_STREAMING, /** Read sequentially, with an occasional forward seek. */ 104 AASSET_MODE_BUFFER /** Caller plans to ask for a read-only buffer with all data. */ 105 } 106 107 108 /** 109 * Open the named directory within the asset hierarchy. The directory can then 110 * be inspected with the AAssetDir functions. To open the top-level directory, 111 * pass in "" as the dirName. 112 * 113 * The object returned here should be freed by calling AAssetDir_close(). 114 */ 115 AAssetDir* AAssetManager_openDir(AAssetManager* mgr, const(char)* dirName); 116 117 /** 118 * Open an asset. 119 * 120 * The object returned here should be freed by calling AAsset_close(). 121 */ 122 AAsset* AAssetManager_open(AAssetManager* mgr, const(char)* filename, int mode); 123 124 /** 125 * Iterate over the files in an asset directory. A NULL string is returned 126 * when all the file names have been returned. 127 * 128 * The returned file name is suitable for passing to AAssetManager_open(). 129 * 130 * The string returned here is owned by the AssetDir implementation and is not 131 * guaranteed to remain valid if any other calls are made on this AAssetDir 132 * instance. 133 */ 134 const(char)* AAssetDir_getNextFileName(AAssetDir* assetDir); 135 136 /** 137 * Reset the iteration state of AAssetDir_getNextFileName() to the beginning. 138 */ 139 void AAssetDir_rewind(AAssetDir* assetDir); 140 141 /** 142 * Close an opened AAssetDir, freeing any related resources. 143 */ 144 void AAssetDir_close(AAssetDir* assetDir); 145 146 /** 147 * Attempt to read 'count' bytes of data from the current offset. 148 * 149 * Returns the number of bytes read, zero on EOF, or < 0 on error. 150 */ 151 int AAsset_read(AAsset* asset, void* buf, size_t count); 152 153 /** 154 * Seek to the specified offset within the asset data. 'whence' uses the 155 * same constants as lseek()/fseek(). 156 * 157 * Returns the new position on success, or (off_t) -1 on error. 158 */ 159 off_t AAsset_seek(AAsset* asset, off_t offset, int whence); 160 161 /** 162 * Seek to the specified offset within the asset data. 'whence' uses the 163 * same constants as lseek()/fseek(). 164 * 165 * Uses 64-bit data type for large files as opposed to the 32-bit type used 166 * by AAsset_seek. 167 * 168 * Returns the new position on success, or (off64_t) -1 on error. 169 */ 170 off64_t AAsset_seek64(AAsset* asset, off64_t offset, int whence); 171 172 /** 173 * Close the asset, freeing all associated resources. 174 */ 175 void AAsset_close(AAsset* asset); 176 177 /** 178 * Get a pointer to a buffer holding the entire contents of the assset. 179 * 180 * Returns NULL on failure. 181 */ 182 const(void)* AAsset_getBuffer(AAsset* asset); 183 184 /** 185 * Report the total size of the asset data. 186 */ 187 off_t AAsset_getLength(AAsset* asset); 188 189 /** 190 * Report the total size of the asset data. Reports the size using a 64-bit 191 * number insted of 32-bit as AAsset_getLength. 192 */ 193 off64_t AAsset_getLength64(AAsset* asset); 194 195 /** 196 * Report the total amount of asset data that can be read from the current position. 197 */ 198 off_t AAsset_getRemainingLength(AAsset* asset); 199 200 /** 201 * Report the total amount of asset data that can be read from the current position. 202 * 203 * Uses a 64-bit number instead of a 32-bit number as AAsset_getRemainingLength does. 204 */ 205 off64_t AAsset_getRemainingLength64(AAsset* asset); 206 207 /** 208 * Open a new file descriptor that can be used to read the asset data. If the 209 * start or length cannot be represented by a 32-bit number, it will be 210 * truncated. If the file is large, use AAsset_openFileDescriptor64 instead. 211 * 212 * Returns < 0 if direct fd access is not possible (for example, if the asset is 213 * compressed). 214 */ 215 int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength); 216 217 /** 218 * Open a new file descriptor that can be used to read the asset data. 219 * 220 * Uses a 64-bit number for the offset and length instead of 32-bit instead of 221 * as AAsset_openFileDescriptor does. 222 * 223 * Returns < 0 if direct fd access is not possible (for example, if the asset is 224 * compressed). 225 */ 226 int AAsset_openFileDescriptor64(AAsset* asset, off64_t* outStart, off64_t* outLength); 227 228 /** 229 * Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not 230 * mmapped). 231 */ 232 int AAsset_isAllocated(AAsset* asset); 233 234 /** @} */