Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef ANDROID_ASSET_MANAGER_H |
| 19 | #define ANDROID_ASSET_MANAGER_H |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | struct AAssetManager; |
| 26 | typedef struct AAssetManager AAssetManager; |
| 27 | |
| 28 | struct AAssetDir; |
| 29 | typedef struct AAssetDir AAssetDir; |
| 30 | |
| 31 | struct AAsset; |
| 32 | typedef struct AAsset AAsset; |
| 33 | |
| 34 | /* Available modes for opening assets */ |
| 35 | enum { |
| 36 | AASSET_MODE_UNKNOWN = 0, |
| 37 | AASSET_MODE_RANDOM = 1, |
| 38 | AASSET_MODE_STREAMING = 2, |
| 39 | AASSET_MODE_BUFFER = 3 |
| 40 | }; |
| 41 | |
| 42 | |
| 43 | /** |
| 44 | * Open the named directory within the asset hierarchy. The directory can then |
| 45 | * be inspected with the AAssetDir functions. To open the top-level directory, |
| 46 | * pass in "" as the dirName. |
| 47 | * |
| 48 | * The object returned here should be freed by calling AAssetDir_close(). |
| 49 | */ |
| 50 | AAssetDir* AAssetManager_openDir(AAssetManager* mgr, const char* dirName); |
| 51 | |
| 52 | /** |
| 53 | * Open an asset. |
| 54 | * |
| 55 | * The object returned here should be freed by calling AAsset_close(). |
| 56 | */ |
| 57 | AAsset* AAssetManager_open(AAssetManager* mgr, const char* filename, int mode); |
| 58 | |
| 59 | /** |
| 60 | * Iterate over the files in an asset directory. A NULL string is returned |
| 61 | * when all the file names have been returned. |
| 62 | * |
| 63 | * The returned file name is suitable for passing to AAssetManager_open(). |
| 64 | * |
| 65 | * The string returned here is owned by the AssetDir implementation and is not |
| 66 | * guaranteed to remain valid if any other calls are made on this AAssetDir |
| 67 | * instance. |
| 68 | */ |
| 69 | const char* AAssetDir_getNextFileName(AAssetDir* assetDir); |
| 70 | |
| 71 | /** |
| 72 | * Reset the iteration state of AAssetDir_getNextFileName() to the beginning. |
| 73 | */ |
| 74 | void AAssetDir_rewind(AAssetDir* assetDir); |
| 75 | |
| 76 | /** |
| 77 | * Close an opened AAssetDir, freeing any related resources. |
| 78 | */ |
| 79 | void AAssetDir_close(AAssetDir* assetDir); |
| 80 | |
| 81 | /** |
| 82 | * Attempt to read 'count' bytes of data from the current offset. |
| 83 | * |
| 84 | * Returns the number of bytes read, zero on EOF, or < 0 on error. |
| 85 | */ |
| 86 | int AAsset_read(AAsset* asset, void* buf, size_t count); |
| 87 | |
| 88 | /** |
| 89 | * Seek to the specified offset within the asset data. 'whence' uses the |
| 90 | * same constants as lseek()/fseek(). |
| 91 | * |
| 92 | * Returns the new position on success, or (off_t) -1 on error. |
| 93 | */ |
| 94 | off_t AAsset_seek(AAsset* asset, off_t offset, int whence); |
| 95 | |
| 96 | /** |
| 97 | * Seek to the specified offset within the asset data. 'whence' uses the |
| 98 | * same constants as lseek()/fseek(). |
| 99 | * |
| 100 | * Uses 64-bit data type for large files as opposed to the 32-bit type used |
| 101 | * by AAsset_seek. |
| 102 | * |
| 103 | * Returns the new position on success, or (off64_t) -1 on error. |
| 104 | */ |
| 105 | off64_t AAsset_seek64(AAsset* asset, off64_t offset, int whence); |
| 106 | |
| 107 | /** |
| 108 | * Close the asset, freeing all associated resources. |
| 109 | */ |
| 110 | void AAsset_close(AAsset* asset); |
| 111 | |
| 112 | /** |
| 113 | * Get a pointer to a buffer holding the entire contents of the assset. |
| 114 | * |
| 115 | * Returns NULL on failure. |
| 116 | */ |
| 117 | const void* AAsset_getBuffer(AAsset* asset); |
| 118 | |
| 119 | /** |
| 120 | * Report the total size of the asset data. |
| 121 | */ |
| 122 | off_t AAsset_getLength(AAsset* asset); |
| 123 | |
| 124 | /** |
| 125 | * Report the total size of the asset data. Reports the size using a 64-bit |
| 126 | * number insted of 32-bit as AAsset_getLength. |
| 127 | */ |
| 128 | off64_t AAsset_getLength64(AAsset* asset); |
| 129 | |
| 130 | /** |
| 131 | * Report the total amount of asset data that can be read from the current position. |
| 132 | */ |
| 133 | off_t AAsset_getRemainingLength(AAsset* asset); |
| 134 | |
| 135 | /** |
| 136 | * Report the total amount of asset data that can be read from the current position. |
| 137 | * |
| 138 | * Uses a 64-bit number instead of a 32-bit number as AAsset_getRemainingLength does. |
| 139 | */ |
| 140 | off64_t AAsset_getRemainingLength64(AAsset* asset); |
| 141 | |
| 142 | /** |
| 143 | * Open a new file descriptor that can be used to read the asset data. If the |
| 144 | * start or length cannot be represented by a 32-bit number, it will be |
| 145 | * truncated. If the file is large, use AAsset_openFileDescriptor64 instead. |
| 146 | * |
| 147 | * Returns < 0 if direct fd access is not possible (for example, if the asset is |
| 148 | * compressed). |
| 149 | */ |
| 150 | int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength); |
| 151 | |
| 152 | /** |
| 153 | * Open a new file descriptor that can be used to read the asset data. |
| 154 | * |
| 155 | * Uses a 64-bit number for the offset and length instead of 32-bit instead of |
| 156 | * as AAsset_openFileDescriptor does. |
| 157 | * |
| 158 | * Returns < 0 if direct fd access is not possible (for example, if the asset is |
| 159 | * compressed). |
| 160 | */ |
| 161 | int AAsset_openFileDescriptor64(AAsset* asset, off64_t* outStart, off64_t* outLength); |
| 162 | |
| 163 | /** |
| 164 | * Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not |
| 165 | * mmapped). |
| 166 | */ |
| 167 | int AAsset_isAllocated(AAsset* asset); |
| 168 | |
| 169 | |
| 170 | |
| 171 | #ifdef __cplusplus |
| 172 | }; |
| 173 | #endif |
| 174 | |
| 175 | #endif // ANDROID_ASSET_MANAGER_H |