| 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 |
{ @exclude Internal for the engine. } |
| 18 |
unit CastleAndroidInternalAssetManager; |
| 19 |
|
| 20 |
{$I castleconf.inc} |
| 21 |
|
| 22 |
interface |
| 23 |
|
| 24 |
uses ctypes; |
| 25 |
|
| 26 |
type |
| 27 |
PAAssetManager = ^AAssetManager; |
| 28 |
AAssetManager = record end; |
| 29 |
|
| 30 |
AAssetDir = record end; |
| 31 |
|
| 32 |
AAsset = record end; |
| 33 |
|
| 34 |
PAAssetDir = ^AAssetDir; |
| 35 |
PAAsset = ^AAsset; |
| 36 |
Poff_t = ^coff_t; |
| 37 |
|
| 38 |
(* Available modes for opening assets *) |
| 39 |
const |
| 40 |
AASSET_MODE_UNKNOWN = 0; |
| 41 |
AASSET_MODE_RANDOM = 1; |
| 42 |
AASSET_MODE_STREAMING = 2; |
| 43 |
AASSET_MODE_BUFFER = 3; |
| 44 |
|
| 45 |
|
| 46 |
(** |
| 47 |
* Open the named directory within the asset hierarchy. The directory can then |
| 48 |
* be inspected with the AAssetDir functions. To open the top-level directory, |
| 49 |
* pass in "" as the dirName. |
| 50 |
* |
| 51 |
* The object returned here should be freed by calling AAssetDir_close(). |
| 52 |
*) |
| 53 |
function AAssetManager_openDir(mgr: PAAssetManager; dirName: Pchar): PAAssetDir; cdecl; external; |
| 54 |
|
| 55 |
(** |
| 56 |
* Open an asset. |
| 57 |
* |
| 58 |
* The object returned here should be freed by calling AAsset_close(). |
| 59 |
*) |
| 60 |
function AAssetManager_open(mgr: PAAssetManager; filename: Pchar; mode: cint): PAAsset; cdecl; external; |
| 61 |
|
| 62 |
(** |
| 63 |
* Iterate over the files in an asset directory. A NULL string is returned |
| 64 |
* when all the file names have been returned. |
| 65 |
* |
| 66 |
* The returned file name is suitable for passing to AAssetManager_open(). |
| 67 |
* |
| 68 |
* The string returned here is owned by the AssetDir implementation and is not |
| 69 |
* guaranteed to remain valid if any other calls are made on this AAssetDir |
| 70 |
* instance. |
| 71 |
*) |
| 72 |
function AAssetDir_getNextFileName(assetDir: PAAssetDir): Pchar; cdecl; external; |
| 73 |
|
| 74 |
(** |
| 75 |
* Reset the iteration state of AAssetDir_getNextFileName() to the beginning. |
| 76 |
*) |
| 77 |
procedure AAssetDir_rewind(assetDir: PAAssetDir); cdecl; external; |
| 78 |
|
| 79 |
(** |
| 80 |
* Close an opened AAssetDir, freeing any related resources. |
| 81 |
*) |
| 82 |
procedure AAssetDir_close(assetDir: PAAssetDir); cdecl; external; |
| 83 |
|
| 84 |
(** |
| 85 |
* Attempt to read 'count' bytes of data from the current offset. |
| 86 |
* |
| 87 |
* Returns the number of bytes read, zero on EOF, or < 0 on error. |
| 88 |
*) |
| 89 |
function AAsset_read(asset: PAAsset; buf: Pointer; count: csize_t): cint; cdecl; external; |
| 90 |
|
| 91 |
(** |
| 92 |
* Seek to the specified offset within the asset data. 'whence' uses the |
| 93 |
* same constants as lseek()/fseek(). |
| 94 |
* |
| 95 |
* Returns the new position on success, or (off_t) -1 on error. |
| 96 |
*) |
| 97 |
function AAsset_seek(asset: PAAsset; offset: coff_t; whence: cint): coff_t; cdecl; external; |
| 98 |
|
| 99 |
(** |
| 100 |
* Close the asset, freeing all associated resources. |
| 101 |
*) |
| 102 |
procedure AAsset_close(asset: PAAsset); cdecl; external; |
| 103 |
|
| 104 |
(** |
| 105 |
* Get a pointer to a buffer holding the entire contents of the assset. |
| 106 |
* |
| 107 |
* Returns NULL on failure. |
| 108 |
*) |
| 109 |
function AAsset_getBuffer(asset: PAAsset): Pointer; cdecl; external; |
| 110 |
|
| 111 |
(** |
| 112 |
* Report the total size of the asset data. |
| 113 |
*) |
| 114 |
function AAsset_getLength(asset: PAAsset): coff_t; cdecl; external; |
| 115 |
|
| 116 |
(** |
| 117 |
* Report the total amount of asset data that can be read from the current position. |
| 118 |
*) |
| 119 |
function AAsset_getRemainingLength(asset: PAAsset): coff_t; cdecl; external; |
| 120 |
|
| 121 |
(** |
| 122 |
* Open a new file descriptor that can be used to read the asset data. |
| 123 |
* |
| 124 |
* Returns < 0 if direct fd access is not possible (for example, if the asset is |
| 125 |
* compressed). |
| 126 |
*) |
| 127 |
function AAsset_openFileDescriptor(asset: PAAsset; outStart, outLength: Poff_t): cint; cdecl; external; |
| 128 |
|
| 129 |
(** |
| 130 |
* Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not |
| 131 |
* mmapped). |
| 132 |
*) |
| 133 |
function AAsset_isAllocated(asset: PAAsset): cint; cdecl; external; |
| 134 |
|
| 135 |
implementation |
| 136 |
|
| 137 |
end. |