3 Copyright (C) 2013 Belledonne Communications, Grenoble, France
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "linphonecore_utils.h"
27 #define defCallMethod(Type) \
28 template <typename ReturnType> \
29 static ReturnType call##Type##Method(JNIEnv *env, jobject obj, const char *className, const char *methodName, \
30 const char *methodSignature, ...) { \
31 jclass my_class = env->GetObjectClass(obj); \
33 ms_error("Can't get %s JNI class", className); \
36 jmethodID my_method = env->GetMethodID(my_class, methodName, methodSignature); \
37 if(my_method == 0) { \
38 ms_error("Can't get %s %s %s method", className, methodSignature); \
42 va_start(vl, methodSignature); \
43 ReturnType ret = env->Call##Type##MethodV(obj, my_method, vl); \
48 #define defGetterTypeField(Type, JavaType, JavaStringType) \
49 template <typename ValueType> \
50 static ValueType get##Type##Field(JNIEnv *env, jobject obj, const char *className, const char *fieldName) { \
51 jclass my_class = env->GetObjectClass(obj); \
53 ms_error("Can't get %s JNI class", className); \
56 jfieldID my_field = env->GetFieldID(my_class, fieldName, JavaStringType); \
58 ms_error("Can't get %s %s field", className, fieldName); \
61 return (ValueType) env->Get##Type##Field(obj, my_field); \
64 #define defSetterTypeField(Type, JavaType, JavaStringType) \
65 template <typename ValueType> \
66 static bool set##Type##Field(JNIEnv *env, jobject obj, const char *className, const char *fieldName, ValueType val) { \
67 jclass my_class = env->GetObjectClass(obj); \
69 ms_error("Can't get %s JNI class", className); \
72 jfieldID my_field = env->GetFieldID(my_class, fieldName, JavaStringType); \
74 ms_error("Can't get %s %s field", className, fieldName); \
77 env->Set##Type##Field(obj, my_field, (JavaType) val); \
81 #define defGetterAndSetterTypeField(Type, JavaType, JavaStringType) \
82 defGetterTypeField(Type, JavaType, JavaStringType) \
83 defSetterTypeField(Type, JavaType, JavaStringType) \
86 template <typename ReturnType>
87 static void callVoidMethod(JNIEnv *env, jobject obj, const char *className, const char *methodName,
88 const char *methodSignature, ...) {
89 jclass my_class = env->GetObjectClass(obj);
91 ms_error("Can't get %s JNI class", className);
94 jmethodID my_method = env->GetMethodID(my_class, methodName, methodSignature);
96 ms_error("Can't get %s %s %s method", className, methodName, methodSignature);
100 va_start(vl, methodSignature);
101 env->CallVoidMethodV(obj, my_method, vl);
104 defCallMethod(Object)
105 defGetterAndSetterTypeField(Long, jlong, "J")