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