|
1 /* |
|
2 * Copyright (c) 2002 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: This class has ManagerImpl JNI functions |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <jdebug.h> |
|
19 #include <JniEnvWrapper.h> |
|
20 |
|
21 #include "com_nokia_microedition_media_ManagerImpl.h" |
|
22 #include "cmmamanager.h" |
|
23 #include "cmmaplayer.h" |
|
24 |
|
25 const TInt KMMADefaultArrayGranularity = 8; |
|
26 |
|
27 JNIEXPORT void JNICALL Java_com_nokia_microedition_media_ManagerImpl__1dispose |
|
28 (JNIEnv* aJni, jobject, jint aEventSourceHandle) |
|
29 { |
|
30 DEBUG("MMA::ManagerImpl dispose"); |
|
31 CMMAEventSource* eventSource = |
|
32 JavaUnhand< CMMAEventSource >(aEventSourceHandle); |
|
33 |
|
34 eventSource->Dispose(*aJni); |
|
35 } |
|
36 |
|
37 LOCAL_C void ReleaseEventSource(CMMAEventSource* aEventSource) |
|
38 { |
|
39 aEventSource->Release(); |
|
40 } |
|
41 |
|
42 JNIEXPORT void JNICALL Java_com_nokia_microedition_media_ManagerImpl__1release |
|
43 (JNIEnv*, jobject, jint aEventSourceHandle) |
|
44 { |
|
45 DEBUG("MMA::ManagerImpl release"); |
|
46 CMMAEventSource* eventSource = |
|
47 JavaUnhand< CMMAEventSource >(aEventSourceHandle); |
|
48 eventSource->ExecuteV(&ReleaseEventSource, |
|
49 eventSource); |
|
50 } |
|
51 |
|
52 /* |
|
53 * Class: javax_microedition_media_Manager |
|
54 * Method: _createManager |
|
55 * Signature: (II)I |
|
56 */ |
|
57 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_ManagerImpl__1createManager |
|
58 (JNIEnv*, jobject, jint aEventSourceHandle, jint aMIDletSuiteID) |
|
59 { |
|
60 CMMAEventSource* eventSource = |
|
61 JavaUnhand< CMMAEventSource >(aEventSourceHandle); |
|
62 |
|
63 CMMAManager* manager = NULL; |
|
64 TInt error = eventSource->ExecuteTrap(&CMMAManager::StaticCreateManagerL, |
|
65 &manager, |
|
66 aMIDletSuiteID); |
|
67 DEBUG_INT("MMA::ManagerImpl createManager StaticCreateManagerL %d", |
|
68 error); |
|
69 if (error != KErrNone) |
|
70 { |
|
71 return error; |
|
72 } |
|
73 |
|
74 TInt managerHandle(JavaMakeHandle(manager)); |
|
75 |
|
76 error = eventSource->ExecuteTrap(CMMAEventSource::StaticAddObjectFromHandleL, |
|
77 eventSource, |
|
78 managerHandle); |
|
79 |
|
80 DEBUG_INT("MMA::ManagerImpl createManager StaticAddObjectFromHandleL %d", |
|
81 error); |
|
82 |
|
83 if (error != KErrNone) |
|
84 { |
|
85 // Adding manager to event source failed. |
|
86 delete manager; |
|
87 |
|
88 // Error code will be returned to java |
|
89 managerHandle = error; |
|
90 } |
|
91 DEBUG_INT("MMA::ManagerImpl createManager %d", |
|
92 managerHandle); |
|
93 return managerHandle; |
|
94 } |
|
95 |
|
96 |
|
97 LOCAL_C void InvokeConstructSvrL(CMMAEventSource* aEventSource) |
|
98 { |
|
99 aEventSource->ConstructSvrL(); |
|
100 } |
|
101 |
|
102 /* |
|
103 * Class: javax_microedition_media_Manager |
|
104 * Method: _getEventSource |
|
105 */ |
|
106 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_ManagerImpl__1createEventSource |
|
107 (JNIEnv* aJni, jobject aPeer , jint aEventServerHandle) |
|
108 { |
|
109 TInt eventSourceHandle = CMMAEventSource::New(*aJni, aPeer, aEventServerHandle); |
|
110 if (eventSourceHandle > KErrNone) |
|
111 { |
|
112 CMMAEventSource* eventSource = |
|
113 JavaUnhand< CMMAEventSource >(eventSourceHandle); |
|
114 |
|
115 // third phase construction |
|
116 TInt error = eventSource->ExecuteTrap(&InvokeConstructSvrL, |
|
117 eventSource); |
|
118 if (error != KErrNone) |
|
119 { |
|
120 eventSourceHandle = error; |
|
121 } |
|
122 } |
|
123 DEBUG_INT("MMA::ManagerImpl createEventSource %d", |
|
124 eventSourceHandle); |
|
125 return eventSourceHandle; |
|
126 } |
|
127 |
|
128 /** |
|
129 * Local function which can be used to call CMMAManager class methods. |
|
130 * Type of of the function pointer must be |
|
131 * void CMMAManager::aFuncL( RPointerArray< HBufC >&, const TDesC& ) |
|
132 * Java String array will be created and set to aArray variable. |
|
133 * |
|
134 * @param aManager CMMAManager instance. |
|
135 * @param aFuncL Pointer to the CMMAManager method. |
|
136 * @param aJni Used to create an array. |
|
137 * @param aArray Values got from aFuncL will be copied to this array. |
|
138 * @param aParam Parameter that will be passed to aFuncL method. |
|
139 */ |
|
140 LOCAL_C void GetObjectArrayL( |
|
141 CMMAManager* aManager, |
|
142 void (CMMAManager::*aFuncL)(const TDesC&, |
|
143 CDesC16Array&), |
|
144 JNIEnv* aJni, |
|
145 jobjectArray* aArray, |
|
146 const TDesC* aParam) |
|
147 { |
|
148 // Temporary descriptor array to be copied to Java array. |
|
149 CDesC16ArrayFlat* values = new(ELeave) CDesC16ArrayFlat( |
|
150 KMMADefaultArrayGranularity); |
|
151 CleanupStack::PushL(values); |
|
152 |
|
153 // Call void CMMAManager::aFuncL( const TDesC&, RPointerArray< HBufC >& ) |
|
154 // method. Method can leave. |
|
155 // Elements of the array will be owned by this method. |
|
156 (aManager->*aFuncL)(*aParam, *values); |
|
157 |
|
158 // JNI interface pointer can't be passed to different thread, so |
|
159 // it is needed to get valid JNI interface pointer for Event Server thread |
|
160 aJni = JniEnvWrapper::GetValidJniRef(); |
|
161 |
|
162 // Create new java String array and copy values from the values array |
|
163 *aArray = CopyToNewJavaStringArrayL(*aJni, *values); |
|
164 CleanupStack::PopAndDestroy(values); |
|
165 } |
|
166 |
|
167 |
|
168 /* |
|
169 * Class: javax_microedition_media_Manager |
|
170 * Method: _getSupportedContentTypes |
|
171 * Signature: (II)[[B |
|
172 */ |
|
173 JNIEXPORT jobjectArray JNICALL Java_com_nokia_microedition_media_ManagerImpl__1getSupportedContentTypes |
|
174 (JNIEnv* aJni, |
|
175 jclass, |
|
176 jint aEventSourceHandle, |
|
177 jint aManagerHandle, |
|
178 jstring aProtocol) |
|
179 { |
|
180 CMMAEventSource* eventSource = |
|
181 JavaUnhand< CMMAEventSource >(aEventSourceHandle); |
|
182 CMMAManager* manager = JavaUnhand< CMMAManager >(aManagerHandle); |
|
183 |
|
184 jobjectArray contentTypes = NULL; |
|
185 |
|
186 // Create descritor from Java String. |
|
187 // RJString is derived from TPtrC16 and is save to cast to TDesC |
|
188 RJString tmp(*aJni, aProtocol); |
|
189 const TDesC* protocol = &tmp; |
|
190 if (aProtocol == NULL) |
|
191 { |
|
192 protocol = &KNullDesC; |
|
193 } |
|
194 |
|
195 // Call manager->GetSupportedContentTypesL and create Java array. |
|
196 TInt err = eventSource->ExecuteTrap(&GetObjectArrayL, |
|
197 manager, |
|
198 &CMMAManager::GetSupportedContentTypesL, |
|
199 aJni, |
|
200 &contentTypes, |
|
201 protocol); |
|
202 |
|
203 if (err != KErrNone) |
|
204 { |
|
205 // Something failed. Returning NULL, because contentTypes array may not |
|
206 // be complete. contentTypes array is left for carbage collertor, |
|
207 // because it can't be released. |
|
208 return NULL; |
|
209 } |
|
210 return contentTypes; |
|
211 } |
|
212 |
|
213 /* |
|
214 * Class: javax_microedition_media_Manager |
|
215 * Method: _getSupportedProtocols |
|
216 * Signature: (II)[[B |
|
217 */ |
|
218 JNIEXPORT jobjectArray JNICALL Java_com_nokia_microedition_media_ManagerImpl__1getSupportedProtocols |
|
219 (JNIEnv* aJni, |
|
220 jclass, |
|
221 jint aEventSourceHandle, |
|
222 jint aManagerHandle, |
|
223 jstring aContentType) |
|
224 { |
|
225 CMMAEventSource* eventSource = |
|
226 JavaUnhand< CMMAEventSource >(aEventSourceHandle); |
|
227 CMMAManager* manager = JavaUnhand< CMMAManager >(aManagerHandle); |
|
228 |
|
229 jobjectArray protocols = NULL; |
|
230 |
|
231 // Create descritor from Java String. |
|
232 // RJString is derived from TPtrC16 and is save to cast to TDesC |
|
233 RJString tmp(*aJni, aContentType); |
|
234 const TDesC* contentType = &tmp; |
|
235 if (aContentType == NULL) |
|
236 { |
|
237 contentType = &KNullDesC; |
|
238 } |
|
239 |
|
240 // Call manager->GetSupportedProtocolsL and create Java array. |
|
241 TInt err = eventSource->ExecuteTrap(&GetObjectArrayL, |
|
242 manager, |
|
243 &CMMAManager::GetSupportedProtocolsL, |
|
244 aJni, |
|
245 &protocols, |
|
246 contentType); |
|
247 if (err != KErrNone) |
|
248 { |
|
249 // Something failed. Returning NULL, because contentTypes array may not |
|
250 // be complete. contentTypes array is left for carbage collertor, |
|
251 // because it can't be released. |
|
252 return NULL; |
|
253 } |
|
254 return protocols; |
|
255 } |
|
256 |
|
257 // END OF FILE |