Index: content/browser/android/gamepad_reader_impl.h |
diff --git a/content/browser/android/gamepad_reader_impl.h b/content/browser/android/gamepad_reader_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1c51a7f16b965ceece086657003900c796606672 |
--- /dev/null |
+++ b/content/browser/android/gamepad_reader_impl.h |
@@ -0,0 +1,94 @@ |
+/* |
+ * 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. |
+*/ |
+ |
+#ifndef CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_ |
+#define CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_ |
+ |
+#include <jni.h> |
+#include <vector> |
+ |
+#include "base/android/jni_array.h" |
+#include "base/android/jni_helper.h" |
+#include "base/android/scoped_java_ref.h" |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/singleton.h" |
+ |
+namespace content { |
+using std::string; |
+// Interacts with JNI and calls GamepadList. |
+// This class creates a GamepadsReader java object and pings GamepadList for |
+// updates. |
+// The simplified flow is: |
+// GamepadDataFetcher runs on a Polling Thread and it tries to fetch data from |
+// the framework for android platform. |
+// GamepadPlatformDataFetcherAndroid access a singleton GamepadsReader |
+// GamepadsReader calls via JNI and uses the singleton GamepadList |
+// in the java side to get the updated gamepad state. We then bounce these |
+// updates to the GamepadProvider which writes to GamepadHardwareBuffer. |
+// GamepadHardwareBuffer structure is stored in shared memory that's shared |
+// between a writer that does hardware polling, and the various consumers of |
+// the gamepad. |
+ |
+// Note that GamepadsReader is a singleton and there's at most only |
+// one GamepadsReader that has called updateGamepadList(). |
+ |
+class GamepadsReader{ |
scottmg
2014/01/13 19:42:43
There's a lot of code that doesn't follow the styl
SaurabhK
2014/01/15 16:57:08
WIll update in next patchset.
|
+public: |
+ |
+ // Registers the JNI methods for GamepadsReader. |
+ static bool RegisterGamepadsReader(JNIEnv* env); |
+ |
+ // Returns our singleton. |
+ static GamepadsReader* GetInstance(); |
+ |
+ // Methods called to update GamepadList for Gamepad access and release by |
+ // navigator object. |
+ void notifyForGamepadsAccess(bool); |
+ // Methods called on the Polling thread. |
+ int updateGamepadsCount(); |
+ bool isDeviceConnected(int); |
+ std::string getDeviceName(int); |
+ long getDeviceTimestamp(int); |
+ std::vector<float> getDeviceAxes(int); |
+ std::vector<float> getDeviceButtons(int); |
+ bool isGamepadLayoutKnown(int); |
+ |
+private: |
+ friend struct DefaultSingletonTraits<GamepadsReader>; |
+ GamepadsReader(); |
+ ~GamepadsReader(); |
+ |
+ void CreateJavaObject(JNIEnv* env); |
+ |
+ base::android::ScopedJavaGlobalRef<jobject> |
+ java_gamepadList_object_; |
+}; |
+ |
+} // namespace content |
+#endif // CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_ |