OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * * Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * * Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * * Neither the name of NVIDIA CORPORATION nor the names of its | |
13 * contributors may be used to endorse or promote products derived | |
14 * from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 */ | |
28 | |
29 #include "base/android/jni_android.h" | |
30 #include "base/android/jni_string.h" | |
31 #include "content/browser/android/gamepad_reader_impl.h" | |
32 | |
33 #include "jni/GamepadList_jni.h" | |
34 | |
35 using base::android::AttachCurrentThread; | |
36 using base::android::CheckException; | |
37 using base::android::ClearException; | |
38 using base::android::ConvertJavaStringToUTF8; | |
39 using base::android::ScopedJavaLocalRef; | |
40 | |
41 namespace content { | |
42 | |
43 bool GamepadsReader::RegisterGamepadsReader(JNIEnv* env) { | |
44 return RegisterNativesImpl(env); | |
45 } | |
46 | |
47 GamepadsReader::GamepadsReader() | |
48 { | |
49 JNIEnv* env = AttachCurrentThread(); | |
50 CreateJavaObject(env); | |
51 } | |
52 | |
53 GamepadsReader::~GamepadsReader() { | |
54 CHECK(java_gamepadList_object_.is_null()); | |
55 } | |
56 | |
57 GamepadsReader* GamepadsReader::GetInstance() { | |
58 return Singleton<GamepadsReader>::get(); | |
59 } | |
60 | |
61 void GamepadsReader::notifyForGamepadsAccess(bool isaccesspaused) { | |
62 JNIEnv* env = AttachCurrentThread(); | |
63 if(!env) | |
64 return; | |
65 | |
66 CHECK(!java_gamepadList_object_.is_null()); | |
67 Java_GamepadList_notifyForGamepadsAccess(env, | |
68 java_gamepadList_object_.obj(), | |
69 isaccesspaused); | |
70 } | |
71 | |
72 int GamepadsReader::updateGamepadsCount() { | |
73 JNIEnv* env = AttachCurrentThread(); | |
74 if(!env) | |
75 return 0; | |
76 | |
77 CHECK(!java_gamepadList_object_.is_null()); | |
78 ScopedJavaLocalRef<jobject> javaGamepadListObject = | |
79 Java_GamepadList_getGamepadList(env, | |
80 java_gamepadList_object_.obj()); | |
81 | |
82 if (javaGamepadListObject.is_null()) | |
83 return 0; | |
xwang
2014/01/14 03:03:22
What is javaGamepadListObject for? Is that to chec
SaurabhK
2014/01/15 16:57:08
Yes, it is to check if gamepad device has been int
xwang
2014/01/16 02:36:42
Why not directly call haveDevicesBeenInteractedWit
SaurabhK
2014/01/28 13:23:09
Now i am directly calling haveDevicesBeenInteracte
| |
84 | |
85 return (int)Java_GamepadList_getDeviceCount(env, | |
86 java_gamepadList_object_.obj()); | |
87 } | |
88 | |
89 bool GamepadsReader::isDeviceConnected(int Index) { | |
90 JNIEnv* env = AttachCurrentThread(); | |
91 if(!env) | |
92 return false; | |
93 | |
94 CHECK(!java_gamepadList_object_.is_null()); | |
95 return Java_GamepadList_isDeviceConnected(env, | |
96 java_gamepadList_object_.obj(), | |
97 Index); | |
98 } | |
99 | |
100 std::string GamepadsReader::getDeviceName(int Index) { | |
101 JNIEnv* env = AttachCurrentThread(); | |
102 if(!env) | |
103 return (std::string)0; | |
104 | |
105 CHECK(!java_gamepadList_object_.is_null()); | |
106 | |
107 ScopedJavaLocalRef<jstring> str = | |
108 Java_GamepadList_getDeviceName(env, | |
109 java_gamepadList_object_.obj(), | |
110 Index); | |
111 | |
112 bool ua_overidden = str.obj() != NULL; | |
113 std::string override; | |
114 | |
115 if (override.empty()) | |
116 override += " "; | |
117 | |
118 if (ua_overidden) { | |
119 override = base::android::ConvertJavaStringToUTF8(str); | |
120 } | |
121 | |
122 return override; | |
123 } | |
124 | |
125 long GamepadsReader::getDeviceTimestamp(int Index) { | |
126 JNIEnv* env = AttachCurrentThread(); | |
127 if(!env) | |
128 return 0; | |
129 | |
130 CHECK(!java_gamepadList_object_.is_null()); | |
131 return Java_GamepadList_getDeviceTimestamp(env, | |
132 java_gamepadList_object_.obj(), | |
133 Index); | |
134 } | |
135 | |
136 std::vector<float> GamepadsReader::getDeviceAxes(int Index) { | |
137 JNIEnv* env = AttachCurrentThread(); | |
138 if(!env) | |
139 return (std::vector<float>)0; | |
140 | |
141 CHECK(!java_gamepadList_object_.is_null()); | |
142 std::vector<float> axes; | |
143 base::android::JavaFloatArrayToFloatVector( | |
144 env, | |
145 Java_GamepadList_getDeviceAxes(env, | |
146 java_gamepadList_object_.obj(), | |
147 Index).obj(), | |
148 &axes); | |
149 return axes; | |
150 } | |
151 | |
152 std::vector<float> GamepadsReader::getDeviceButtons(int Index) { | |
153 JNIEnv* env = AttachCurrentThread(); | |
154 if(!env) | |
155 return (std::vector<float>)0; | |
156 | |
157 CHECK(!java_gamepadList_object_.is_null()); | |
158 std::vector<float> buttons; | |
159 base::android::JavaFloatArrayToFloatVector( | |
160 env, | |
161 Java_GamepadList_getDeviceButtons(env, | |
162 java_gamepadList_object_.obj(), | |
163 Index).obj(), | |
164 &buttons); | |
165 | |
166 return buttons; | |
167 } | |
168 | |
169 bool GamepadsReader::isGamepadLayoutKnown(int Index) { | |
170 JNIEnv* env = AttachCurrentThread(); | |
171 if(!env) | |
172 return 0; | |
173 | |
174 CHECK(!java_gamepadList_object_.is_null()); | |
175 return Java_GamepadList_isKnownGamepadLayout(env, | |
176 java_gamepadList_object_.obj(), | |
177 Index); | |
178 } | |
179 | |
180 void GamepadsReader::CreateJavaObject(JNIEnv* env) { | |
181 // Create the Java GamepadsReader object. | |
182 java_gamepadList_object_.Reset( | |
183 Java_GamepadList_getInstance(env)); | |
184 CHECK(!java_gamepadList_object_.is_null()); | |
185 } | |
186 | |
187 } // namespace content | |
OLD | NEW |