FreeStick  0.3
Cross Platform Open Sorce Joystick Lib
FSJNI_Wrapper.h
Go to the documentation of this file.
1 /**************************************************************************
2 Created by Alan Uthoff on 10/8/2013
3 Copyright (C) 2013.
4 
5 This Code is free software; you can redistribute it and/or
6 modify it under the terms of the zlib/libpng License as published
7 by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 This software is provided 'as-is', without any express or implied warranty.
10 
11 In no event will the authors be held liable for any damages arising from the use of this software.
12 
13 Permission is granted to anyone to use this software for any purpose,
14 including commercial applications, and to alter it and redistribute
15 it freely, subject to the following restrictions:
16 
17 1. The origin of this software must not be misrepresented;
18 you must not claim that you wrote the original software.
19 If you use this software in a product, an acknowledgment
20 in the product documentation would be appreciated but is not required.
21 
22 2. Altered source versions must be plainly marked as such,
23 and must not be misrepresented as being the original software.
24 
25 3. This notice may not be removed or altered from any source distribution.
26 **************************************************************************/
27 
28 #pragma once
29 
30 #include <jni.h>
31 #include <android/log.h>
32 #define FS_LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__))
33 #define FS_LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__))
34 
35 typedef enum
36 {
39  KeyEvent = 2,
42 
43 enum class UpdateType:int
44 {
45  addedDevice = 0,
46  removedDevice = 1
47 };
48 
49 #ifdef __cplusplus
50 #include <vector>
51 extern "C" {
52 #endif
53  JNIEXPORT void JNICALL Java_org_freestick_FreestickDeviceManager_gamepadWasAdded(JNIEnv *env, jobject thisObj,jint HID_ID);
54  JNIEXPORT void JNICALL Java_org_freestick_FreestickDeviceManager_gamepadWasRemoved(JNIEnv *env, jobject thisObj,jint HID_ID);
55  JNIEXPORT bool JNICALL Java_org_freestick_FreestickDeviceManager_gamepadDeviceUpdate(JNIEnv *env, jobject thisObj,jint deviceid,jint code,jint type,jfloat value,jint min,jint max);
56  JNIEXPORT void JNICALL Java_org_freestick_FreestickDeviceManager_updateJoystickConnectedStatus(JNIEnv *env, jobject thisObj );
57 #ifdef __cplusplus
58 }
59 class IJNICallBack
60 {
61 public:
62  virtual void gamepadWasAddedFromJINBridge(int hid_id,JavaVM * jvm) = 0;
63  virtual void gamepadWasRemovedFromJINBridge(int hid_id) = 0;
64  virtual bool gamepadWasUpdatedFromJINBridge(int deviceid,int code,JNICallBackType type,float value,int min,int max) = 0;
65 };
66 
67 class JNIBridge
68 {
69  public:
70  //TODO use flag to make this all the register call backs two functions
71  static void registerDeviceWasAdded(IJNICallBack * listener);
72  static void registerDeviceWasRemoved(IJNICallBack * listener);
73  static void registerDeviceWasUpdated(IJNICallBack * listener);
74  static void deregisterDeviceWasAdded(IJNICallBack * listener){}
75  static void deregisterDeviceWasRemoved(IJNICallBack * listener){}
76  static void update(int hidDeviceID, UpdateType type);
77  static void update(int hidDeviceID, UpdateType type,JavaVM * jvm);
78  static bool updateValue(int deviceid,int code,JNICallBackType type,float value,int min,int max);
79  static void updateJoysticks(JavaVM * jvm);
80  private:
81  static std::vector<IJNICallBack*> _deviceAddedCallback;
82  static std::vector<IJNICallBack*> _deviceRemovedCallback;
83  static std::vector<IJNICallBack*> _deviceUpdateCallback;
84 };
85 #endif
JNIEXPORT void JNICALL Java_org_freestick_FreestickDeviceManager_gamepadWasAdded(JNIEnv *env, jobject thisObj, jint HID_ID)
Definition: FSJNI_Wrapper.cpp:56
Definition: FSJNI_Wrapper.h:38
JNIEXPORT void JNICALL Java_org_freestick_FreestickDeviceManager_updateJoystickConnectedStatus(JNIEnv *env, jobject thisObj)
Definition: FSJNI_Wrapper.cpp:41
Definition: FSJNI_Wrapper.h:37
JNICallBackType
Definition: FSJNI_Wrapper.h:35
JNIEXPORT bool JNICALL Java_org_freestick_FreestickDeviceManager_gamepadDeviceUpdate(JNIEnv *env, jobject thisObj, jint deviceid, jint code, jint type, jfloat value, jint min, jint max)
Definition: FSJNI_Wrapper.cpp:48
JNIEXPORT void JNICALL Java_org_freestick_FreestickDeviceManager_gamepadWasRemoved(JNIEnv *env, jobject thisObj, jint HID_ID)
Definition: FSJNI_Wrapper.cpp:65
Definition: FSJNI_Wrapper.h:39
Definition: FSJNI_Wrapper.h:40
UpdateType
Definition: FSJNI_Wrapper.h:43