|
Packit |
5e46da |
/*
|
|
Packit |
5e46da |
* This file is part of libbluray
|
|
Packit |
5e46da |
* Copyright (C) 2012 Petri Hintukainen <phintuka@users.sourceforge.net>
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is free software; you can redistribute it and/or
|
|
Packit |
5e46da |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License as published by the Free Software Foundation; either
|
|
Packit |
5e46da |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
5e46da |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
5e46da |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
5e46da |
* Lesser General Public License for more details.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License along with this library. If not, see
|
|
Packit |
5e46da |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#if HAVE_CONFIG_H
|
|
Packit |
5e46da |
#include "config.h"
|
|
Packit |
5e46da |
#endif
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#include "register_native.h"
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#include "util/logging.h"
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
#include <jni.h>
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
static int _register_methods(JNIEnv *env, const char *class_name,
|
|
Packit |
5e46da |
const JNINativeMethod *methods, int methods_count)
|
|
Packit |
5e46da |
{
|
|
Packit |
5e46da |
jclass cls;
|
|
Packit |
5e46da |
int error;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
(*env)->ExceptionClear(env);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
cls = (*env)->FindClass(env, class_name);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
if (!cls) {
|
|
Packit |
5e46da |
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to locate class %s\n", class_name);
|
|
Packit |
5e46da |
(*env)->ExceptionDescribe(env);
|
|
Packit |
5e46da |
(*env)->ExceptionClear(env);
|
|
Packit |
5e46da |
return 0;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
error = (*env)->RegisterNatives(env, cls, methods, methods_count);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
if ((*env)->ExceptionOccurred(env)) {
|
|
Packit |
5e46da |
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to register native methods for class %s\n", class_name);
|
|
Packit |
5e46da |
(*env)->ExceptionDescribe(env);
|
|
Packit |
5e46da |
(*env)->ExceptionClear(env);
|
|
Packit |
5e46da |
return 0;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
if (error) {
|
|
Packit |
5e46da |
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to register native methods for class %s\n", class_name);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
return !error;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
static int _unregister_methods(JNIEnv *env, const char *class_name)
|
|
Packit |
5e46da |
{
|
|
Packit |
5e46da |
jclass cls;
|
|
Packit |
5e46da |
int error;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
(*env)->ExceptionClear(env);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
cls = (*env)->FindClass(env, class_name);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
if (!cls) {
|
|
Packit |
5e46da |
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to locate class %s\n", class_name);
|
|
Packit |
5e46da |
(*env)->ExceptionDescribe(env);
|
|
Packit |
5e46da |
(*env)->ExceptionClear(env);
|
|
Packit |
5e46da |
return 0;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
error = (*env)->UnregisterNatives(env, cls);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
if ((*env)->ExceptionOccurred(env)) {
|
|
Packit |
5e46da |
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to unregister native methods for class %s\n", class_name);
|
|
Packit |
5e46da |
(*env)->ExceptionDescribe(env);
|
|
Packit |
5e46da |
(*env)->ExceptionClear(env);
|
|
Packit |
5e46da |
return 0;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
if (error) {
|
|
Packit |
5e46da |
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to unegister native methods for class %s\n", class_name);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
return !error;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
int bdj_register_native_methods(JNIEnv *env)
|
|
Packit |
5e46da |
{
|
|
Packit |
5e46da |
extern const JNINativeMethod Java_org_videolan_Logger_methods[];
|
|
Packit |
5e46da |
extern const JNINativeMethod Java_org_videolan_Libbluray_methods[];
|
|
Packit |
5e46da |
extern const JNINativeMethod Java_java_awt_BDGraphics_methods[];
|
|
Packit |
5e46da |
extern const JNINativeMethod Java_java_awt_BDFontMetrics_methods[];
|
|
Packit |
5e46da |
extern const int Java_org_videolan_Logger_methods_count;
|
|
Packit |
5e46da |
extern const int Java_org_videolan_Libbluray_methods_count;
|
|
Packit |
5e46da |
extern const int Java_java_awt_BDGraphics_methods_count;
|
|
Packit |
5e46da |
extern const int Java_java_awt_BDFontMetrics_methods_count;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
int result = _register_methods(env, "org/videolan/Logger",
|
|
Packit |
5e46da |
Java_org_videolan_Logger_methods,
|
|
Packit |
5e46da |
Java_org_videolan_Logger_methods_count);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
result *= _register_methods(env, "org/videolan/Libbluray",
|
|
Packit |
5e46da |
Java_org_videolan_Libbluray_methods,
|
|
Packit |
5e46da |
Java_org_videolan_Libbluray_methods_count);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
/* BDFontMetrics must be registered before BDGraphics */
|
|
Packit |
5e46da |
result *= _register_methods(env, "java/awt/BDFontMetrics",
|
|
Packit |
5e46da |
Java_java_awt_BDFontMetrics_methods,
|
|
Packit |
5e46da |
Java_java_awt_BDFontMetrics_methods_count);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
result *= _register_methods(env, "java/awt/BDGraphicsBase",
|
|
Packit |
5e46da |
Java_java_awt_BDGraphics_methods,
|
|
Packit |
5e46da |
Java_java_awt_BDGraphics_methods_count);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
return result;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
void bdj_unregister_native_methods(JNIEnv *env)
|
|
Packit |
5e46da |
{
|
|
Packit |
5e46da |
_unregister_methods(env, "java/awt/BDGraphicsBase");
|
|
Packit |
5e46da |
_unregister_methods(env, "java/awt/BDFontMetrics");
|
|
Packit |
5e46da |
_unregister_methods(env, "org/videolan/Libbluray");
|
|
Packit |
5e46da |
_unregister_methods(env, "org/videolan/Logger");
|
|
Packit |
5e46da |
}
|