Moved JNI helper macros to a separate file
Also initialize a reference to the CharonVpnService class during JNI_OnLoad, which allows us later to call methods from C to Java.
This commit is contained in:
@@ -3,6 +3,7 @@ include $(CLEAR_VARS)
|
|||||||
|
|
||||||
# copy-n-paste from Makefile.am
|
# copy-n-paste from Makefile.am
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
|
android_jni.c android_jni.h \
|
||||||
charonservice.c
|
charonservice.c
|
||||||
|
|
||||||
# build libandroidbridge -------------------------------------------------------
|
# build libandroidbridge -------------------------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 Tobias Brunner
|
||||||
|
* Copyright (C) 2012 Giuliano Grassi
|
||||||
|
* Copyright (C) 2012 Ralf Sager
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "android_jni.h"
|
||||||
|
|
||||||
|
#include <library.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JVM
|
||||||
|
*/
|
||||||
|
static JavaVM *android_jvm;
|
||||||
|
|
||||||
|
jclass *android_charonvpnservice_class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when this library is loaded by the JVM
|
||||||
|
*/
|
||||||
|
jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||||
|
{
|
||||||
|
JNIEnv *env;
|
||||||
|
|
||||||
|
android_jvm = vm;
|
||||||
|
|
||||||
|
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
android_charonvpnservice_class =
|
||||||
|
(*env)->NewGlobalRef(env, (*env)->FindClass(env,
|
||||||
|
JNI_PACKAGE_STRING "/CharonVpnService"));
|
||||||
|
|
||||||
|
return JNI_VERSION_1_6;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 Tobias Brunner
|
||||||
|
* Copyright (C) 2012 Giuliano Grassi
|
||||||
|
* Copyright (C) 2012 Ralf Sager
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup android_jni android_jni
|
||||||
|
* @{ @ingroup libandroidbridge
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANDROID_JNI_H_
|
||||||
|
#define ANDROID_JNI_H_
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
#define JNI_PACKAGE org_strongswan_android
|
||||||
|
#define JNI_PACKAGE_STRING "org/strongswan/android"
|
||||||
|
|
||||||
|
#define JNI_METHOD_PP(pack, klass, name, ret, ...) \
|
||||||
|
ret Java_##pack##_##klass##_##name(JNIEnv *env, jobject this, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define JNI_METHOD_P(pack, klass, name, ret, ...) \
|
||||||
|
JNI_METHOD_PP(pack, klass, name, ret, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define JNI_METHOD(klass, name, ret, ...) \
|
||||||
|
JNI_METHOD_P(JNI_PACKAGE, klass, name, ret, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Java classes
|
||||||
|
* Initialized in JNI_OnLoad()
|
||||||
|
*/
|
||||||
|
extern jclass *android_charonvpnservice_class;
|
||||||
|
|
||||||
|
#endif /** ANDROID_JNI_H_ @}*/
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2012 Giuliano Grassi
|
||||||
|
* Copyright (C) 2012 Ralf Sager
|
||||||
* Copyright (C) 2012 Tobias Brunner
|
* Copyright (C) 2012 Tobias Brunner
|
||||||
* Hochschule fuer Technik Rapperswil
|
* Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
@@ -15,23 +17,14 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <jni.h>
|
|
||||||
|
|
||||||
|
#include "android_jni.h"
|
||||||
|
|
||||||
|
#include <daemon.h>
|
||||||
#include <hydra.h>
|
#include <hydra.h>
|
||||||
#include <ipsec.h>
|
#include <ipsec.h>
|
||||||
#include <daemon.h>
|
|
||||||
#include <library.h>
|
#include <library.h>
|
||||||
|
|
||||||
#define JNI_PACKAGE org_strongswan_android
|
|
||||||
|
|
||||||
#define JNI_METHOD_PP(pack, klass, name, ret, ...) \
|
|
||||||
ret Java_##pack##_##klass##_##name(JNIEnv *env, jobject this, ##__VA_ARGS__)
|
|
||||||
|
|
||||||
#define JNI_METHOD_P(pack, klass, name, ret, ...) \
|
|
||||||
JNI_METHOD_PP(pack, klass, name, ret, ##__VA_ARGS__)
|
|
||||||
|
|
||||||
#define JNI_METHOD(klass, name, ret, ...) \
|
|
||||||
JNI_METHOD_P(JNI_PACKAGE, klass, name, ret, ##__VA_ARGS__)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hook in library for debugging messages
|
* hook in library for debugging messages
|
||||||
|
|||||||
Reference in New Issue
Block a user