2019-10-08 17:48:32 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2019-10-08 17:48:32 -07:00
|
|
|
*/
|
2019-10-15 10:30:08 -07:00
|
|
|
|
2019-10-08 17:48:32 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace yoga {
|
|
|
|
namespace vanillajni {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method has to be called before using the vanillajni library. This method
|
|
|
|
* is typically called when doing initialization in the "on load" JNI hook of a
|
|
|
|
* particular library.
|
|
|
|
*
|
|
|
|
* This method is thread safe, and after the first time it's called it has no
|
|
|
|
* initialization effect.
|
|
|
|
*
|
|
|
|
* @param env use this output parameter to get a JNIEnv to use for things such
|
|
|
|
* as registering native methods and such.
|
|
|
|
* @param vm the VM instance passed by JNI. This is usually the VM instance
|
|
|
|
* that is passed to the "on load" JNI hook.
|
|
|
|
* @return an integer value to return from the "on load" hook.
|
|
|
|
*/
|
|
|
|
jint ensureInitialized(JNIEnv** env, JavaVM* vm);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a JNIEnv* suitable for the current thread. If the current thread is
|
|
|
|
* not attached to the Java VM, this method aborts execution.
|
|
|
|
*/
|
|
|
|
JNIEnv* getCurrentEnv();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs an error message and aborts the current process.
|
|
|
|
*/
|
|
|
|
void logErrorMessageAndDie(const char* message);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether there is a pending JNI exception. If so, it logs an error
|
|
|
|
* message and aborts the current process. Otherwise it does nothing.
|
|
|
|
*/
|
|
|
|
void assertNoPendingJniException(JNIEnv* env);
|
|
|
|
|
2019-12-02 05:21:56 -08:00
|
|
|
void assertNoPendingJniExceptionIf(JNIEnv* env, bool condition);
|
|
|
|
|
2019-10-08 17:48:32 -07:00
|
|
|
} // namespace vanillajni
|
|
|
|
} // namespace yoga
|
|
|
|
} // namespace facebook
|