src/hidapi/android/hid.cpp
changeset 12308 4e3b4ddb8787
parent 12242 df7260f149f2
child 12346 b4c98c84a0b2
equal deleted inserted replaced
12307:461ef7221483 12308:4e3b4ddb8787
   694 	}
   694 	}
   695 }
   695 }
   696 
   696 
   697 
   697 
   698 extern "C"
   698 extern "C"
   699 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz, jobject callbackHandler);
   699 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz);
   700 
   700 
   701 extern "C"
   701 extern "C"
   702 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz);
   702 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz);
   703 
   703 
   704 extern "C"
   704 extern "C"
   719 extern "C"
   719 extern "C"
   720 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceFeatureReport)(JNIEnv *env, jobject thiz, int nDeviceID, jbyteArray value);
   720 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceFeatureReport)(JNIEnv *env, jobject thiz, int nDeviceID, jbyteArray value);
   721 
   721 
   722 
   722 
   723 extern "C"
   723 extern "C"
   724 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz, jobject callbackHandler)
   724 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz )
   725 {
   725 {
   726 	LOGV( "HIDDeviceRegisterCallback()");
   726 	LOGV( "HIDDeviceRegisterCallback()");
   727 
   727 
   728 	env->GetJavaVM( &g_JVM );
   728 	env->GetJavaVM( &g_JVM );
   729 
   729 
   733 	 */
   733 	 */
   734 	if (pthread_key_create(&g_ThreadKey, ThreadDestroyed) != 0) {
   734 	if (pthread_key_create(&g_ThreadKey, ThreadDestroyed) != 0) {
   735 		__android_log_print(ANDROID_LOG_ERROR, TAG, "Error initializing pthread key");
   735 		__android_log_print(ANDROID_LOG_ERROR, TAG, "Error initializing pthread key");
   736 	}
   736 	}
   737 
   737 
   738 	g_HIDDeviceManagerCallbackHandler = env->NewGlobalRef( callbackHandler );
   738 	if ( g_HIDDeviceManagerCallbackHandler != NULL )
   739 	jclass objClass = env->GetObjectClass( callbackHandler );
   739 	{
       
   740 		env->DeleteGlobalRef( g_HIDDeviceManagerCallbackClass );
       
   741 		g_HIDDeviceManagerCallbackClass = NULL;
       
   742 		env->DeleteGlobalRef( g_HIDDeviceManagerCallbackHandler );
       
   743 		g_HIDDeviceManagerCallbackHandler = NULL;
       
   744 	}
       
   745 
       
   746 	g_HIDDeviceManagerCallbackHandler = env->NewGlobalRef( thiz );
       
   747 	jclass objClass = env->GetObjectClass( thiz );
   740 	if ( objClass )
   748 	if ( objClass )
   741 	{
   749 	{
   742 		g_HIDDeviceManagerCallbackClass = reinterpret_cast< jclass >( env->NewGlobalRef(objClass) );
   750 		g_HIDDeviceManagerCallbackClass = reinterpret_cast< jclass >( env->NewGlobalRef( objClass ) );
   743 		g_midHIDDeviceManagerOpen = env->GetMethodID( g_HIDDeviceManagerCallbackClass, "openDevice", "(I)Z" );
   751 		g_midHIDDeviceManagerOpen = env->GetMethodID( g_HIDDeviceManagerCallbackClass, "openDevice", "(I)Z" );
   744 		if ( !g_midHIDDeviceManagerOpen )
   752 		if ( !g_midHIDDeviceManagerOpen )
   745 		{
   753 		{
   746 			__android_log_print(ANDROID_LOG_ERROR, TAG, "HIDDeviceRegisterCallback: callback class missing openDevice" );
   754 			__android_log_print(ANDROID_LOG_ERROR, TAG, "HIDDeviceRegisterCallback: callback class missing openDevice" );
   747 		}
   755 		}
   771 
   779 
   772 extern "C"
   780 extern "C"
   773 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz)
   781 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz)
   774 {
   782 {
   775 	LOGV("HIDDeviceReleaseCallback");
   783 	LOGV("HIDDeviceReleaseCallback");
   776 	env->DeleteGlobalRef( g_HIDDeviceManagerCallbackClass );
   784 	if ( env->IsSameObject( thiz, g_HIDDeviceManagerCallbackHandler ) )
   777 	env->DeleteGlobalRef( g_HIDDeviceManagerCallbackHandler );
   785 	{
       
   786 		env->DeleteGlobalRef( g_HIDDeviceManagerCallbackClass );
       
   787 		g_HIDDeviceManagerCallbackClass = NULL;
       
   788 		env->DeleteGlobalRef( g_HIDDeviceManagerCallbackHandler );
       
   789 		g_HIDDeviceManagerCallbackHandler = NULL;
       
   790 	}
   778 }
   791 }
   779 
   792 
   780 extern "C"
   793 extern "C"
   781 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface )
   794 JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface )
   782 {
   795 {