Files
yoga/java/jni/common.h
Nick Gerleman 660edcec20 C++ 17 style nested namespaces (#1326)
Summary:
X-link: https://github.com/facebook/react-native/pull/38304

Pull Request resolved: https://github.com/facebook/yoga/pull/1326

For better readability

Reviewed By: christophpurrer

Differential Revision: D47384926

fbshipit-source-id: 2f60d50a185331b3624d45d1fc45f98d504b3034
2023-07-12 09:38:40 -07:00

77 lines
2.1 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include "ScopedGlobalRef.h"
#include "ScopedLocalRef.h"
namespace facebook::yoga::vanillajni {
/**
* Registers a set of methods for a JNI class. Aborts if registration fails.
*/
void registerNatives(
JNIEnv* env,
const char* className,
const JNINativeMethod methods[],
size_t numMethods);
/**
* Returns a jmethodID for a class static method. Aborts if any error happens.
*/
jmethodID getStaticMethodId(
JNIEnv* env,
jclass clazz,
const char* methodName,
const char* methodDescriptor);
/**
* Returns a jmethodID for a class non-static method. Aborts if any error
* happens.
*/
jmethodID getMethodId(
JNIEnv* env,
jclass clazz,
const char* methodName,
const char* methodDescriptor);
/**
* Returns a class non-static field ID. Aborts if any error happens.
*/
jfieldID getFieldId(
JNIEnv* env,
jclass clazz,
const char* fieldName,
const char* fieldSignature);
// Helper methods to call a non-static method on an object depending on the
// return type. Each method will abort the execution if an error
// (such as a Java pending exception) is detected after invoking the
// Java method.
#define DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jnitype, readableType) \
jnitype call##readableType##Method( \
JNIEnv* env, jobject obj, jmethodID methodId, ...)
DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(void, Void);
DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jlong, Long);
DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jfloat, Float);
ScopedLocalRef<jobject> callStaticObjectMethod(
JNIEnv* env,
jclass clazz,
jmethodID methodId,
...);
/**
* Given a local or a global reference, this method creates a new global
* reference out of it. If any error happens, aborts the process.
*/
ScopedGlobalRef<jobject> newGlobalRef(JNIEnv* env, jobject obj);
ScopedGlobalRef<jthrowable> newGlobalRef(JNIEnv* env, jthrowable obj);
} // namespace facebook::yoga::vanillajni