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 JNI wrappers for CMMAMIDIControl |
|
15 * |
|
16 */ |
|
17 |
|
18 //#include <jutils.h> |
|
19 //#include "mmapiutils.h" |
|
20 |
|
21 #include "com_nokia_microedition_media_control_MIDIControl.h" |
|
22 #include "mmafunctionserver.h" |
|
23 #include "cmmamidicontrol.h" |
|
24 #include <logger.h> |
|
25 |
|
26 /** |
|
27 * Local function which is used to call CMMAMIDIControl class method. |
|
28 * Type of of the function pointer must be |
|
29 * void CMMAMIDIControl::aFunc( TInt, TInt, TInt ) |
|
30 * |
|
31 * @param aMIDIControl CMMAMIDIControl pointer. |
|
32 * @param aFunc Pointer to the CMMAMIDIControl method. |
|
33 * @param aParam1 Parameter passed to the aFunc. |
|
34 * @param aParam2 Parameter passed to the aFunc. |
|
35 * @param aParam3 Parameter passed to the aFunc. |
|
36 */ |
|
37 LOCAL_C void ReturnVoidParam3IntFuncL( |
|
38 CMMAMIDIControl* aMIDIControl, |
|
39 void (CMMAMIDIControl::*aFuncL)(TInt, TInt, TInt), |
|
40 TInt aParam1, |
|
41 TInt aParam2, |
|
42 TInt aParam3) |
|
43 { |
|
44 // call TInt CMMAMIDIControl::aFunc( TInt, TInt, TInt ) method. |
|
45 (aMIDIControl->*aFuncL)(aParam1, aParam2, aParam3); |
|
46 } |
|
47 |
|
48 /** |
|
49 * Implements generated JNI function prototype. |
|
50 */ |
|
51 JNIEXPORT jint JNICALL |
|
52 Java_com_nokia_microedition_media_control_MIDIControl__1setProgram |
|
53 ( |
|
54 JNIEnv*, |
|
55 jobject, |
|
56 jint aControlHandle, |
|
57 jint aEventSourceHandle, |
|
58 jint aChannel, |
|
59 jint aBank, |
|
60 jint aProgram) |
|
61 { |
|
62 MMAFunctionServer* eventSource = |
|
63 reinterpret_cast< MMAFunctionServer* >(aEventSourceHandle); |
|
64 |
|
65 CMMAMIDIControl* midiControl = |
|
66 reinterpret_cast< CMMAMIDIControl *>(aControlHandle); |
|
67 |
|
68 TInt error; |
|
69 error = eventSource->ExecuteTrap(&ReturnVoidParam3IntFuncL, |
|
70 midiControl, |
|
71 &CMMAMIDIControl::SetProgramL, |
|
72 aChannel, |
|
73 aBank, |
|
74 aProgram); |
|
75 |
|
76 return error; |
|
77 } |
|
78 |
|
79 /** |
|
80 * Local function which is used to call CMMAMIDIControl class method. |
|
81 * Type of of the function pointer must be |
|
82 * TInt CMMAMIDIControl::aFunc( TInt ) |
|
83 * |
|
84 * @param aMIDIControl CMMAMIDIControl pointer. |
|
85 * @param aFunc Pointer to the CMMAMIDIControl method. |
|
86 * @param aData Parameter passed to the aFunc. |
|
87 * @param aReturnValue The return value of the aFunc will |
|
88 * be assigned to this parameter. |
|
89 */ |
|
90 LOCAL_C void ReturnIntParamIntFuncL( |
|
91 CMMAMIDIControl* aMIDIControl, |
|
92 TInt(CMMAMIDIControl::*aFuncL)(TInt aData), |
|
93 TInt aData, |
|
94 TInt* aReturnValue) |
|
95 { |
|
96 // call TInt CMMAMIDIControl::aFunc( TDesC* aData ) method. |
|
97 *aReturnValue = (aMIDIControl->*aFuncL)(aData); |
|
98 } |
|
99 |
|
100 /** |
|
101 * Implements generated JNI function prototype. |
|
102 */ |
|
103 JNIEXPORT jint JNICALL |
|
104 Java_com_nokia_microedition_media_control_MIDIControl__1getChannelVolume |
|
105 (JNIEnv*, |
|
106 jobject, |
|
107 jint aControlHandle, |
|
108 jint aEventSourceHandle, |
|
109 jint aChannel) |
|
110 { |
|
111 // Get pointer to native event source. |
|
112 MMAFunctionServer* eventSource = |
|
113 reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle); |
|
114 CMMAMIDIControl* midiControl = |
|
115 reinterpret_cast< CMMAMIDIControl *>(aControlHandle); |
|
116 |
|
117 |
|
118 TInt returnValue = 0; |
|
119 TInt error; |
|
120 |
|
121 error = eventSource->ExecuteTrap(&ReturnIntParamIntFuncL, |
|
122 midiControl, |
|
123 &CMMAMIDIControl::ChannelVolumeL, |
|
124 aChannel, |
|
125 &returnValue); |
|
126 |
|
127 return (error == KErrNone) ? returnValue : error; |
|
128 } |
|
129 |
|
130 /** |
|
131 * Local function which is used to call CMMAMIDIControl class method. |
|
132 * Type of of the function pointer must be |
|
133 * void CMMAMIDIControl::aFunc( TInt, TInt ) |
|
134 * |
|
135 * @param aMIDIControl CMMAMIDIControl pointer. |
|
136 * @param aFunc Pointer to the CMMAMIDIControl method. |
|
137 * @param aParam1 Parameter passed to the aFunc. |
|
138 * @param aParam2 Parameter passed to the aFunc. |
|
139 */ |
|
140 LOCAL_C void ReturnVoidParamIntIntFuncL( |
|
141 CMMAMIDIControl* aMIDIControl, |
|
142 void (CMMAMIDIControl::*aFuncL)(TInt, TInt), |
|
143 TInt aParam1, |
|
144 TInt aParam2) |
|
145 { |
|
146 // call TInt CMMAMIDIControl::aFunc( TInt, TInt ) method. |
|
147 (aMIDIControl->*aFuncL)(aParam1, aParam2); |
|
148 } |
|
149 |
|
150 /** |
|
151 * Implements generated JNI function prototype. |
|
152 */ |
|
153 JNIEXPORT jint JNICALL |
|
154 Java_com_nokia_microedition_media_control_MIDIControl__1setChannelVolume |
|
155 (JNIEnv*, |
|
156 jobject, |
|
157 jint aControlHandle, |
|
158 jint aEventSourceHandle, |
|
159 jint aChannel, |
|
160 jint aVolume) |
|
161 { |
|
162 // Get pointer to native event source. |
|
163 MMAFunctionServer* eventSource = |
|
164 reinterpret_cast< MMAFunctionServer* >(aEventSourceHandle); |
|
165 |
|
166 CMMAMIDIControl* midiControl = |
|
167 reinterpret_cast< CMMAMIDIControl *>(aControlHandle); |
|
168 |
|
169 TInt error = eventSource->ExecuteTrap(&ReturnVoidParamIntIntFuncL, |
|
170 midiControl, |
|
171 &CMMAMIDIControl::SetChannelVolumeL, |
|
172 aChannel, |
|
173 aVolume); |
|
174 |
|
175 return error; |
|
176 } |
|
177 |
|
178 /** |
|
179 * Local function which can be used to call CMMAMIDIControl class methods. |
|
180 * Type of of the function pointer must be |
|
181 * TInt CMMAMIDIControl::aFunc( TDesC* aData ) |
|
182 * |
|
183 * @param aMIDIControl CMMAMIDIControl pointer. |
|
184 * @param aFunc Pointer to the CMMAMIDIControl method. |
|
185 * @param aData Parameter passed to the aFunc. |
|
186 * @param aReturnValue The return value of the aFunc will |
|
187 * be assigned to this parameter. |
|
188 */ |
|
189 LOCAL_C void SendMIDIEventFuncL( |
|
190 CMMAMIDIControl* aMIDIControl, |
|
191 TInt(CMMAMIDIControl::*aFuncL)(const TDesC8* aData), |
|
192 const TDesC8* aData, |
|
193 TInt* aReturnValue) |
|
194 { |
|
195 // call TInt CMMAMIDIControl::aFunc( TDesC* aData ) method. |
|
196 *aReturnValue = (aMIDIControl->*aFuncL)(aData); |
|
197 } |
|
198 |
|
199 /** |
|
200 * Implements generated JNI function prototype. |
|
201 */ |
|
202 JNIEXPORT jint JNICALL |
|
203 Java_com_nokia_microedition_media_control_MIDIControl__1sendMidiEvent |
|
204 (JNIEnv* aJni, |
|
205 jobject, |
|
206 jint aControlHandle, |
|
207 jint aEventSourceHandle, |
|
208 jbyteArray aData, |
|
209 jint aOffset, |
|
210 jint aLength) |
|
211 { |
|
212 // Get pointer to native event source. |
|
213 MMAFunctionServer* eventSource = |
|
214 reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle); |
|
215 |
|
216 CMMAMIDIControl* midiControl = |
|
217 reinterpret_cast< CMMAMIDIControl* >(aControlHandle); |
|
218 |
|
219 // Get pointer to Java data |
|
220 jbyte* data = aJni->GetByteArrayElements(aData, NULL); |
|
221 |
|
222 // Assert only in debug builds, array size must be checked in Java. |
|
223 __ASSERT_DEBUG(aJni->GetArrayLength(aData) >= aOffset + aLength && |
|
224 aOffset >= 0 && |
|
225 aLength > 0, |
|
226 User::Invariant()); |
|
227 |
|
228 // Create descriptor from Java data starting from offset |
|
229 jbyte* tempJbyte = &data[ aOffset ]; |
|
230 TUint8* tempPtr = (TUint8*) tempJbyte; |
|
231 TPtrC8 dataPtr(tempPtr, aLength); |
|
232 |
|
233 TInt returnValue = 0; |
|
234 |
|
235 TInt err = eventSource->ExecuteTrap(&SendMIDIEventFuncL, |
|
236 midiControl, |
|
237 &CMMAMIDIControl::SendMIDIEventL, |
|
238 (const TDesC8*)(&dataPtr), |
|
239 &returnValue); |
|
240 |
|
241 // Java bytes are not needed anymore |
|
242 aJni->ReleaseByteArrayElements(aData, data, 0); |
|
243 |
|
244 if (err != KErrNone) |
|
245 { |
|
246 // return error code to Java |
|
247 returnValue = err; |
|
248 } |
|
249 |
|
250 return returnValue; |
|
251 } |
|
252 |
|
253 JNIEXPORT jint JNICALL |
|
254 Java_com_nokia_microedition_media_control_MIDIControl__1reInitializeMidi |
|
255 (JNIEnv* aJni, |
|
256 jobject, |
|
257 jint aControlHandle, |
|
258 jint aEventSourceHandle, |
|
259 jbyteArray aMidiSequence, |
|
260 jint aOffset, |
|
261 jint aLength) |
|
262 { |
|
263 // Get pointer to native event source. |
|
264 MMAFunctionServer* eventSource = |
|
265 reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle); |
|
266 |
|
267 CMMAMIDIControl* midiControl = |
|
268 reinterpret_cast< CMMAMIDIControl* >(aControlHandle); |
|
269 |
|
270 // Assert only in debug builds, array size must be checked in Java. |
|
271 __ASSERT_DEBUG(aJni->GetArrayLength(aMidiSequence) >= aOffset + aLength && |
|
272 aOffset >= 0 && |
|
273 aLength > 0, |
|
274 User::Invariant()); |
|
275 |
|
276 // Get pointer to Java data |
|
277 jbyte* data = aJni->GetByteArrayElements(aMidiSequence, NULL); |
|
278 |
|
279 // Create descriptor from Java data starting from offset |
|
280 jbyte* tempJbyte = &data[ aOffset ]; |
|
281 TUint8* tempPtr = (TUint8*) tempJbyte; |
|
282 TPtrC8 dataPtr(tempPtr, aLength); |
|
283 |
|
284 // SendMIDIEventFuncL has suitable enough footprint for this call too. |
|
285 // Return value is not used but needs to be there for method footprint. |
|
286 |
|
287 TInt returnValue = 0; |
|
288 TInt err = eventSource->ExecuteTrap(&SendMIDIEventFuncL, |
|
289 midiControl, |
|
290 &CMMAMIDIControl::ReInitializeMidiL, |
|
291 (const TDesC8*)(&dataPtr), |
|
292 &returnValue); |
|
293 |
|
294 // Release Java bytes |
|
295 aJni->ReleaseByteArrayElements(aMidiSequence, data, 0); |
|
296 return err; |
|
297 } |
|
298 |
|
299 |
|
300 |
|
301 // END OF FILE |
|