|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "javax_microedition_m3g_Loader.h" |
|
18 |
|
19 #include <ezlib.h> |
|
20 |
|
21 /*! |
|
22 * \brief Symbian implementation of the block inflation function for |
|
23 * the Loader class |
|
24 */ |
|
25 static M3Gsizei m3gSymbianInflateBlock1(M3Gsizei srcLength, |
|
26 const M3Gubyte *src, |
|
27 M3Gsizei dstLength, |
|
28 M3Gubyte *dst) |
|
29 { |
|
30 unsigned long len = (unsigned long) dstLength; |
|
31 if (uncompress((Bytef *) dst, &len, |
|
32 (const Bytef *) src, (uLong) srcLength) != Z_OK) |
|
33 { |
|
34 return 0; |
|
35 } |
|
36 return (M3Gsizei) len; |
|
37 } |
|
38 |
|
39 JNIEXPORT jboolean JNICALL Java_javax_microedition_m3g_Loader__1inflate |
|
40 (JNIEnv* aEnv, jclass, jbyteArray aCompressed, jbyteArray aInflated) |
|
41 { |
|
42 M3Guint result; |
|
43 |
|
44 M3Gubyte *compressedData = (M3Gubyte *)aEnv->GetByteArrayElements(aCompressed, NULL); |
|
45 if (compressedData == NULL) |
|
46 { |
|
47 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
48 return 0; |
|
49 } |
|
50 M3Gint compressedLength = aEnv->GetArrayLength(aCompressed); |
|
51 M3Gubyte *inflatedData = (M3Gubyte *)aEnv->GetByteArrayElements(aInflated, NULL); |
|
52 if (inflatedData == NULL) |
|
53 { |
|
54 if (compressedData) |
|
55 aEnv->ReleaseByteArrayElements(aCompressed, (jbyte*)compressedData, JNI_ABORT); |
|
56 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
57 return 0; |
|
58 } |
|
59 M3Gint inflatedLength = aEnv->GetArrayLength(aInflated); |
|
60 |
|
61 M3G_DO_LOCK |
|
62 if (m3gSymbianInflateBlock1(compressedLength, compressedData, |
|
63 inflatedLength, inflatedData)) |
|
64 { |
|
65 result = TRUE; |
|
66 } |
|
67 else |
|
68 { |
|
69 result = FALSE; |
|
70 } |
|
71 M3G_DO_UNLOCK(aEnv) |
|
72 |
|
73 if (aCompressed) |
|
74 { |
|
75 aEnv->ReleaseByteArrayElements(aCompressed, (jbyte*)compressedData, JNI_ABORT); |
|
76 } |
|
77 |
|
78 if (aInflated) |
|
79 { |
|
80 aEnv->ReleaseByteArrayElements(aInflated, (jbyte*)inflatedData, 0); |
|
81 } |
|
82 |
|
83 return result; |
|
84 } |
|
85 |
|
86 |
|
87 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Loader__1ctor |
|
88 (JNIEnv* aEnv, jclass, jint aM3g) |
|
89 { |
|
90 M3G_DO_LOCK |
|
91 M3GLoader loader = (M3GLoader)m3gCreateLoader((M3GInterface)aM3g); |
|
92 M3G_DO_UNLOCK(aEnv) |
|
93 return (M3Guint)loader; |
|
94 } |
|
95 |
|
96 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Loader__1decodeData |
|
97 (JNIEnv* aEnv, jclass, jint aLoader, jint aOffset, jbyteArray aDataArray) |
|
98 { |
|
99 /* null array is never passed */ |
|
100 M3Gubyte *data = (M3Gubyte *)aEnv->GetByteArrayElements(aDataArray, NULL); |
|
101 if (data == NULL) |
|
102 { |
|
103 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
104 return 0; |
|
105 } |
|
106 |
|
107 M3Gint bytes = aEnv->GetArrayLength(aDataArray); |
|
108 M3GLoader loader = (M3GLoader)aLoader; |
|
109 |
|
110 M3G_DO_LOCK |
|
111 jint retVal = m3gDecodeData(loader, bytes, data + aOffset); |
|
112 M3G_DO_UNLOCK(aEnv) |
|
113 |
|
114 if (aDataArray) |
|
115 { |
|
116 aEnv->ReleaseByteArrayElements(aDataArray, (jbyte*)data, JNI_ABORT); |
|
117 } |
|
118 |
|
119 return retVal; |
|
120 } |
|
121 |
|
122 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Loader__1getLoadedObjects |
|
123 (JNIEnv* aEnv, jclass, jint aLoader, jintArray aObjectArray) |
|
124 { |
|
125 M3GObject *objects = NULL; |
|
126 if (aObjectArray) |
|
127 { |
|
128 objects = (M3GObject *)aEnv->GetIntArrayElements(aObjectArray, NULL); |
|
129 if (objects == NULL) |
|
130 { |
|
131 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
132 return 0; |
|
133 } |
|
134 } |
|
135 |
|
136 M3GLoader loader = (M3GLoader)aLoader; |
|
137 |
|
138 M3G_DO_LOCK |
|
139 jint retVal = m3gGetLoadedObjects(loader, objects); |
|
140 M3G_DO_UNLOCK(aEnv) |
|
141 |
|
142 if (aObjectArray) |
|
143 { |
|
144 aEnv->ReleaseIntArrayElements(aObjectArray, (jint*)objects, 0); |
|
145 } |
|
146 |
|
147 return retVal; |
|
148 } |
|
149 |
|
150 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Loader__1setExternalReferences |
|
151 (JNIEnv* aEnv, jclass, jint aLoader, jintArray aObjectArray) |
|
152 { |
|
153 /* null array is never passed */ |
|
154 M3GObject *xRefs = (M3GObject *)aEnv->GetIntArrayElements(aObjectArray, NULL); |
|
155 if (xRefs == NULL) |
|
156 { |
|
157 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
158 return; |
|
159 } |
|
160 |
|
161 M3Gint numXRefs = aEnv->GetArrayLength(aObjectArray); |
|
162 M3GLoader loader = (M3GLoader)aLoader; |
|
163 |
|
164 M3G_DO_LOCK |
|
165 m3gImportObjects(loader, numXRefs, xRefs); |
|
166 M3G_DO_UNLOCK(aEnv) |
|
167 |
|
168 aEnv->ReleaseIntArrayElements(aObjectArray, (jint*)xRefs, JNI_ABORT); |
|
169 } |
|
170 |
|
171 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Loader__1getObjectsWithUserParameters |
|
172 (JNIEnv* aEnv, jclass, jint aLoader, jintArray aObjectArray) |
|
173 { |
|
174 M3GObject *objects = NULL; |
|
175 if (aObjectArray) |
|
176 { |
|
177 objects = (M3GObject *)aEnv->GetIntArrayElements(aObjectArray, NULL); |
|
178 if (objects == NULL) |
|
179 { |
|
180 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
181 return 0; |
|
182 } |
|
183 } |
|
184 |
|
185 M3GLoader loader = (M3GLoader)aLoader; |
|
186 |
|
187 M3G_DO_LOCK |
|
188 jint retVal = m3gGetObjectsWithUserParameters(loader, objects); |
|
189 M3G_DO_UNLOCK(aEnv) |
|
190 |
|
191 if (objects) |
|
192 { |
|
193 aEnv->ReleaseIntArrayElements(aObjectArray, (jint*)objects, 0); |
|
194 } |
|
195 |
|
196 return retVal; |
|
197 } |
|
198 |
|
199 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Loader__1getNumUserParameters |
|
200 (JNIEnv* aEnv, jclass, jint aLoader, jint aObj) |
|
201 { |
|
202 M3GLoader loader = (M3GLoader)aLoader; |
|
203 M3G_DO_LOCK |
|
204 jint numParams = (jint)m3gGetNumUserParameters(loader, aObj); |
|
205 M3G_DO_UNLOCK(aEnv) |
|
206 return numParams; |
|
207 } |
|
208 |
|
209 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Loader__1getUserParameter |
|
210 (JNIEnv* aEnv, jclass, jint aLoader, jint aObj, jint aIndex, jbyteArray aDataArray) |
|
211 { |
|
212 M3Gbyte *data = NULL; |
|
213 if (aDataArray) |
|
214 { |
|
215 data = (M3Gbyte *)aEnv->GetByteArrayElements(aDataArray, NULL); |
|
216 if (data == NULL) |
|
217 { |
|
218 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
219 return 0; |
|
220 } |
|
221 } |
|
222 |
|
223 M3GLoader loader = (M3GLoader)aLoader; |
|
224 M3G_DO_LOCK |
|
225 jint retVal = m3gGetUserParameter(loader, aObj, aIndex, data); |
|
226 M3G_DO_UNLOCK(aEnv) |
|
227 |
|
228 if (data) |
|
229 { |
|
230 aEnv->ReleaseByteArrayElements(aDataArray, (jbyte*)data, 0); |
|
231 } |
|
232 |
|
233 return retVal; |
|
234 } |