blob: b628bf7b8546c12d73005d428a9e36051f430d09 [file] [log] [blame]
Igor Murashkin31927e42017-02-17 15:50:15 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * JNI helper macros.
19 *
20 * Only intended to be used in the platform.
21 */
22
23#ifndef NATIVEHELPER_JNI_MACROS_H
24#define NATIVEHELPER_JNI_MACROS_H
25
26
27// Intended to construct a JNINativeMethod.
28// (Assumes the C name is the ClassName_JavaMethodName).
29#ifndef NATIVE_METHOD
30#define NATIVE_METHOD(className, functionName, signature) \
31 { #functionName, \
32 signature, \
33 _NATIVEHELPER_JNI_MACRO_CAST(void*) (className ## _ ## functionName) \
34 }
35#endif
36
37// Intended to construct a JNINativeMethod (when the C name doesn't match the Java name).
38// (Assumes the C name is the ClassName_Identifier).
39#ifndef OVERLOADED_NATIVE_METHOD
40#define OVERLOADED_NATIVE_METHOD(className, functionName, signature, identifier) \
41 { #functionName, \
42 signature, \
43 _NATIVEHELPER_JNI_MACRO_CAST(void*) (className ## _ ## identifier) \
44 }
45#endif
46
47// Used for methods that are annotated with @FastNative on the managed side.
48// See NATIVE_METHOD for usage.
49#ifndef FAST_NATIVE_METHOD
50#define FAST_NATIVE_METHOD(className, functionName, signature) \
51 { #functionName, \
52 signature, \
53 _NATIVEHELPER_JNI_MACRO_CAST(void*) (className ## _ ## functionName) \
54 }
55#endif
56
57// Used for methods that are annotated with @FastNative on the managed side,
58// and when the C-name doesn't match the Java-name.
59//
60// See OVERLOADED_NATIVE_METHOD for usage.
61#ifndef OVERLOADED_FAST_NATIVE_METHOD
62#define OVERLOADED_FAST_NATIVE_METHOD(className, functionName, signature, identifier) \
63 { #functionName, \
64 signature, \
65 _NATIVEHELPER_JNI_MACRO_CAST(void*) (className ## _ ## identifier) \
66 }
67#endif
68
69////////////////////////////////////////////////////////
70// IMPLEMENTATION ONLY.
71// DO NOT USE DIRECTLY.
72////////////////////////////////////////////////////////
73
74
75// C-style cast for C, C++-style cast for C++ to avoid warnings/errors.
76#if defined(__cplusplus)
77#define _NATIVEHELPER_JNI_MACRO_CAST(to) \
78 reinterpret_cast<to>
79#else
80#define _NATIVEHELPER_JNI_MACRO_CAST(to) \
81 (to)
82#endif
83
84#endif