Index: content/browser/android/gamepad_reader_impl.cc |
diff --git a/content/browser/android/gamepad_reader_impl.cc b/content/browser/android/gamepad_reader_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c630ee8f5612ef28beb5b14e3ba27594b9c869a3 |
--- /dev/null |
+++ b/content/browser/android/gamepad_reader_impl.cc |
@@ -0,0 +1,187 @@ |
+/* |
+ * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions |
+ * are met: |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above copyright |
+ * notice, this list of conditions and the following disclaimer in the |
+ * documentation and/or other materials provided with the distribution. |
+ * * Neither the name of NVIDIA CORPORATION nor the names of its |
+ * contributors may be used to endorse or promote products derived |
+ * from this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+*/ |
+ |
+#include "base/android/jni_android.h" |
+#include "base/android/jni_string.h" |
+#include "content/browser/android/gamepad_reader_impl.h" |
+ |
+#include "jni/GamepadList_jni.h" |
+ |
+using base::android::AttachCurrentThread; |
+using base::android::CheckException; |
+using base::android::ClearException; |
+using base::android::ConvertJavaStringToUTF8; |
+using base::android::ScopedJavaLocalRef; |
+ |
+namespace content { |
+ |
+bool GamepadsReader::RegisterGamepadsReader(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+GamepadsReader::GamepadsReader() |
+{ |
+ JNIEnv* env = AttachCurrentThread(); |
+ CreateJavaObject(env); |
+} |
+ |
+GamepadsReader::~GamepadsReader() { |
+ CHECK(java_gamepadList_object_.is_null()); |
+} |
+ |
+GamepadsReader* GamepadsReader::GetInstance() { |
+ return Singleton<GamepadsReader>::get(); |
+} |
+ |
+void GamepadsReader::notifyForGamepadsAccess(bool isaccesspaused) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ if(!env) |
+ return; |
+ |
+ CHECK(!java_gamepadList_object_.is_null()); |
+ Java_GamepadList_notifyForGamepadsAccess(env, |
+ java_gamepadList_object_.obj(), |
+ isaccesspaused); |
+} |
+ |
+int GamepadsReader::updateGamepadsCount() { |
+ JNIEnv* env = AttachCurrentThread(); |
+ if(!env) |
+ return 0; |
+ |
+ CHECK(!java_gamepadList_object_.is_null()); |
+ ScopedJavaLocalRef<jobject> javaGamepadListObject = |
+ Java_GamepadList_getGamepadList(env, |
+ java_gamepadList_object_.obj()); |
+ |
+ if (javaGamepadListObject.is_null()) |
+ 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
|
+ |
+ return (int)Java_GamepadList_getDeviceCount(env, |
+ java_gamepadList_object_.obj()); |
+} |
+ |
+bool GamepadsReader::isDeviceConnected(int Index) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ if(!env) |
+ return false; |
+ |
+ CHECK(!java_gamepadList_object_.is_null()); |
+ return Java_GamepadList_isDeviceConnected(env, |
+ java_gamepadList_object_.obj(), |
+ Index); |
+} |
+ |
+std::string GamepadsReader::getDeviceName(int Index) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ if(!env) |
+ return (std::string)0; |
+ |
+ CHECK(!java_gamepadList_object_.is_null()); |
+ |
+ ScopedJavaLocalRef<jstring> str = |
+ Java_GamepadList_getDeviceName(env, |
+ java_gamepadList_object_.obj(), |
+ Index); |
+ |
+ bool ua_overidden = str.obj() != NULL; |
+ std::string override; |
+ |
+ if (override.empty()) |
+ override += " "; |
+ |
+ if (ua_overidden) { |
+ override = base::android::ConvertJavaStringToUTF8(str); |
+ } |
+ |
+ return override; |
+} |
+ |
+long GamepadsReader::getDeviceTimestamp(int Index) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ if(!env) |
+ return 0; |
+ |
+ CHECK(!java_gamepadList_object_.is_null()); |
+ return Java_GamepadList_getDeviceTimestamp(env, |
+ java_gamepadList_object_.obj(), |
+ Index); |
+} |
+ |
+std::vector<float> GamepadsReader::getDeviceAxes(int Index) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ if(!env) |
+ return (std::vector<float>)0; |
+ |
+ CHECK(!java_gamepadList_object_.is_null()); |
+ std::vector<float> axes; |
+ base::android::JavaFloatArrayToFloatVector( |
+ env, |
+ Java_GamepadList_getDeviceAxes(env, |
+ java_gamepadList_object_.obj(), |
+ Index).obj(), |
+ &axes); |
+ return axes; |
+} |
+ |
+std::vector<float> GamepadsReader::getDeviceButtons(int Index) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ if(!env) |
+ return (std::vector<float>)0; |
+ |
+ CHECK(!java_gamepadList_object_.is_null()); |
+ std::vector<float> buttons; |
+ base::android::JavaFloatArrayToFloatVector( |
+ env, |
+ Java_GamepadList_getDeviceButtons(env, |
+ java_gamepadList_object_.obj(), |
+ Index).obj(), |
+ &buttons); |
+ |
+ return buttons; |
+} |
+ |
+bool GamepadsReader::isGamepadLayoutKnown(int Index) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ if(!env) |
+ return 0; |
+ |
+ CHECK(!java_gamepadList_object_.is_null()); |
+ return Java_GamepadList_isKnownGamepadLayout(env, |
+ java_gamepadList_object_.obj(), |
+ Index); |
+} |
+ |
+void GamepadsReader::CreateJavaObject(JNIEnv* env) { |
+ // Create the Java GamepadsReader object. |
+ java_gamepadList_object_.Reset( |
+ Java_GamepadList_getInstance(env)); |
+ CHECK(!java_gamepadList_object_.is_null()); |
+} |
+ |
+} // namespace content |