Global charonservice_t object added to libandroidbridge
[strongswan.git] / src / frontends / android / jni / libandroidbridge / android_jni.h
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup android_jni android_jni
20 * @{ @ingroup libandroidbridge
21 */
22
23 #ifndef ANDROID_JNI_H_
24 #define ANDROID_JNI_H_
25
26 #include <jni.h>
27
28 #define JNI_PACKAGE org_strongswan_android
29 #define JNI_PACKAGE_STRING "org/strongswan/android"
30
31 #define JNI_METHOD_PP(pack, klass, name, ret, ...) \
32 ret Java_##pack##_##klass##_##name(JNIEnv *env, jobject this, ##__VA_ARGS__)
33
34 #define JNI_METHOD_P(pack, klass, name, ret, ...) \
35 JNI_METHOD_PP(pack, klass, name, ret, ##__VA_ARGS__)
36
37 #define JNI_METHOD(klass, name, ret, ...) \
38 JNI_METHOD_P(JNI_PACKAGE, klass, name, ret, ##__VA_ARGS__)
39
40 /**
41 * Java classes
42 * Initialized in JNI_OnLoad()
43 */
44 extern jclass *android_charonvpnservice_class;
45
46 /**
47 * Attach the current thread to the JVM
48 *
49 * As local JNI references are not freed until the thread detaches
50 * androidjni_detach_thread() should be called as soon as possible.
51 * If it is not called a thread-local destructor ensures that the
52 * thread is at least detached as soon as it terminates.
53 *
54 * @param env JNIEnv
55 */
56 void androidjni_attach_thread(JNIEnv **env);
57
58 /**
59 * Detach the current thread from the JVM
60 *
61 * Call this as soon as possible to ensure that local JNI references are freed.
62 */
63 void androidjni_detach_thread();
64
65 #endif /** ANDROID_JNI_H_ @}*/