Home | History | Annotate | Download | only in android
      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  * Close the asset, freeing all associated resources.
     98  */
     99 void AAsset_close(AAsset* asset);
    100 
    101 /**
    102  * Get a pointer to a buffer holding the entire contents of the assset.
    103  *
    104  * Returns NULL on failure.
    105  */
    106 const void* AAsset_getBuffer(AAsset* asset);
    107 
    108 /**
    109  * Report the total size of the asset data.
    110  */
    111 off_t AAsset_getLength(AAsset* asset);
    112 
    113 /**
    114  * Report the total amount of asset data that can be read from the current position.
    115  */
    116 off_t AAsset_getRemainingLength(AAsset* asset);
    117 
    118 /**
    119  * Open a new file descriptor that can be used to read the asset data.
    120  *
    121  * Returns < 0 if direct fd access is not possible (for example, if the asset is
    122  * compressed).
    123  */
    124 int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength);
    125 
    126 /**
    127  * Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not
    128  * mmapped).
    129  */
    130 int AAsset_isAllocated(AAsset* asset);
    131 
    132 
    133 
    134 #ifdef __cplusplus
    135 };
    136 #endif
    137 
    138 #endif      // ANDROID_ASSET_MANAGER_H
    139