1 /* |
|
2 * Copyright (c) 2002-2007 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: JNI file for OrientationControl |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //#include <jutils.h> |
|
20 |
|
21 #include "com_nokia_amms_control_audio3d_OrientationControl.h" |
|
22 #include <mmafunctionserver.h> |
|
23 #include "cammsorientationcontrolgroup.h" |
|
24 |
|
25 /** |
|
26 * wrapper for CAMMSOrientationControlGroup::OrientationVectors() |
|
27 */ |
|
28 static void GetOrientationVectorsL( |
|
29 CAMMSOrientationControlGroup* control, |
|
30 TInt aOrientation[ KAMMSTwoVectorComponents ]) |
|
31 { |
|
32 control->OrientationVectorsL(aOrientation); |
|
33 } |
|
34 |
|
35 /** |
|
36 * wrapper for CAMMSOrientationControlGroup::SetOrientationVectorsL() |
|
37 */ |
|
38 static void SetOrientationVectorsL( |
|
39 CAMMSOrientationControlGroup* control, |
|
40 TInt aFrontVector[ KAMMSVectorComponents ], |
|
41 TInt aAboveVector[ KAMMSVectorComponents ]) |
|
42 { |
|
43 control->SetOrientationVectorsL(aFrontVector, aAboveVector); |
|
44 } |
|
45 |
|
46 /** |
|
47 * wrapper for CAMMSOrientationControlGroup::SetOrientationL() |
|
48 */ |
|
49 static void SetOrientationL( |
|
50 CAMMSOrientationControlGroup* control, |
|
51 TInt aHeading, |
|
52 TInt aPitch, |
|
53 TInt aRoll) |
|
54 { |
|
55 control->SetOrientationL(aHeading, aPitch, aRoll); |
|
56 } |
|
57 |
|
58 /* |
|
59 * Class: com_nokia_amms_control_audio3d_OrientationControl |
|
60 * Method: _setOrientation |
|
61 * Signature: |
|
62 */ |
|
63 JNIEXPORT jint JNICALL |
|
64 Java_com_nokia_amms_control_audio3d_OrientationControl__1setOrientation( |
|
65 JNIEnv*, |
|
66 jclass, |
|
67 jint aEventSource, |
|
68 jint aControl, |
|
69 jint aHeading, |
|
70 jint aPitch, |
|
71 jint aRoll) |
|
72 { |
|
73 MMAFunctionServer* eventSource = |
|
74 reinterpret_cast< MMAFunctionServer* >(aEventSource); |
|
75 |
|
76 CAMMSOrientationControlGroup* control = |
|
77 static_cast< CAMMSOrientationControlGroup* >( |
|
78 reinterpret_cast< CAMMSControlGroup* >(aControl)); |
|
79 |
|
80 TInt error; |
|
81 error = eventSource->ExecuteTrap(SetOrientationL, control, |
|
82 aHeading, aPitch, aRoll); |
|
83 |
|
84 return error; |
|
85 } |
|
86 |
|
87 /* |
|
88 * Class: com_nokia_amms_control_audio3d_OrientationControl |
|
89 * Method: _getOrientationVectros |
|
90 * Signature: |
|
91 */ |
|
92 JNIEXPORT jintArray JNICALL |
|
93 Java_com_nokia_amms_control_audio3d_OrientationControl__1getOrientationVectors( |
|
94 JNIEnv* aJni, |
|
95 jclass, |
|
96 jint aEventSource, |
|
97 jint aControl, |
|
98 jintArray aError) |
|
99 { |
|
100 MMAFunctionServer* eventSource = |
|
101 reinterpret_cast< MMAFunctionServer* >(aEventSource); |
|
102 |
|
103 CAMMSOrientationControlGroup* control = |
|
104 static_cast< CAMMSOrientationControlGroup* >( |
|
105 reinterpret_cast< CAMMSControlGroup* >(aControl)); |
|
106 |
|
107 TInt orientation[ KAMMSTwoVectorComponents ]; |
|
108 TInt error; |
|
109 error = eventSource->ExecuteTrap( |
|
110 GetOrientationVectorsL, |
|
111 control, |
|
112 orientation); |
|
113 |
|
114 // Java side method can not throw exception, store possible error here |
|
115 // aError is an array of 1 element allocated at the java side |
|
116 aJni->SetIntArrayRegion( |
|
117 /*destination*/ aError, |
|
118 /*first*/ 0, |
|
119 /*count*/ 1, |
|
120 /*source*/ &error); |
|
121 |
|
122 // allocate new array |
|
123 jintArray javaArray = aJni->NewIntArray(KAMMSTwoVectorComponents); |
|
124 |
|
125 if (javaArray) |
|
126 { |
|
127 aJni->SetIntArrayRegion( |
|
128 /*destination*/ javaArray, |
|
129 /*first*/0, |
|
130 /*count*/KAMMSTwoVectorComponents, |
|
131 /*source*/ &orientation[ 0 ]); |
|
132 } |
|
133 |
|
134 return javaArray; |
|
135 } |
|
136 |
|
137 /* |
|
138 * Class: com_nokia_amms_control_audio3d_OrientationControl |
|
139 * Method: _setOrientation |
|
140 * Signature: |
|
141 */ |
|
142 JNIEXPORT jint JNICALL |
|
143 Java_com_nokia_amms_control_audio3d_OrientationControl__1setOrientationVectors( |
|
144 JNIEnv* aJni, |
|
145 jclass, |
|
146 jint aEventSource, |
|
147 jint aControl, |
|
148 jintArray aFrontVector, |
|
149 jintArray aAboveVector) |
|
150 { |
|
151 MMAFunctionServer* eventSource = |
|
152 reinterpret_cast< MMAFunctionServer *>(aEventSource); |
|
153 |
|
154 CAMMSOrientationControlGroup* control = |
|
155 static_cast< CAMMSOrientationControlGroup* >( |
|
156 reinterpret_cast< CAMMSControlGroup *>(aControl)); |
|
157 |
|
158 TInt i; |
|
159 |
|
160 // copy java front vector array to native front vector array |
|
161 TInt frontVector[ KAMMSVectorComponents ]; |
|
162 TInt count = aJni->GetArrayLength(aFrontVector); |
|
163 jint* elements = aJni->GetIntArrayElements(aFrontVector, NULL); |
|
164 for (i = 0; i < count; i++) |
|
165 { |
|
166 frontVector[ i ] = elements[ i ]; |
|
167 } |
|
168 aJni->ReleaseIntArrayElements(aFrontVector, elements, 0); |
|
169 |
|
170 // copy java above vector array to native above vector array |
|
171 TInt aboveVector[ KAMMSVectorComponents ]; |
|
172 count = aJni->GetArrayLength(aAboveVector); |
|
173 elements = aJni->GetIntArrayElements(aAboveVector, NULL); |
|
174 for (i = 0; i < count; i++) |
|
175 { |
|
176 aboveVector[ i ] = elements[ i ]; |
|
177 } |
|
178 aJni->ReleaseIntArrayElements(aAboveVector, elements, 0); |
|
179 |
|
180 TInt error; |
|
181 error = eventSource->ExecuteTrap( |
|
182 SetOrientationVectorsL, |
|
183 control, |
|
184 frontVector, |
|
185 aboveVector); |
|
186 |
|
187 return error; |
|
188 } |
|
189 |
|
190 |
|
191 // End of File |
|