WPILibC++ 2024.3.2
jni_util.h File Reference
#include <jni.h>
#include <concepts>
#include <queue>
#include <span>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include <fmt/core.h>
#include "wpi/ConvertUTF.h"
#include "wpi/SafeThread.h"
#include "wpi/SmallString.h"
#include "wpi/SmallVector.h"
#include "wpi/StringExtras.h"
#include "wpi/mutex.h"
#include "wpi/raw_ostream.h"

Go to the source code of this file.

Classes

class  wpi::java::JClass
 Finds a class and keeps it as a global reference. More...
 
struct  wpi::java::JClassInit
 
class  wpi::java::JGlobal< T >
 
class  wpi::java::JLocal< T >
 Container class for cleaning up Java local references. More...
 
class  wpi::java::JStringRef
 Java string (jstring) reference. More...
 
struct  wpi::java::detail::ArrayHelper< T >
 
struct  wpi::java::detail::copy_cv< CvSrc, Dest >
 
class  wpi::java::detail::JSpanBase< T, IsCritical, Size >
 Helper class for working with JNI arrays. More...
 
struct  wpi::java::detail::ConvertIntArray< T >
 
class  wpi::java::JCallbackThread< T >
 Generic callback thread implementation. More...
 
class  wpi::java::JCallbackManager< T >
 
class  wpi::java::JSingletonCallbackManager< T >
 
class  wpi::java::JException
 Finds an exception class and keep it as a global reference. More...
 
struct  wpi::java::JExceptionInit
 

Namespaces

namespace  wpi
 
namespace  wpi::java
 Java Native Interface (JNI) utility functions.
 
namespace  wpi::java::detail
 

Concepts

concept  wpi::java::detail::JArrayType
 

Macros

#define WPI_JNI_ARRAYHELPER(T, F)
 
#define WPI_JNI_MAKEJARRAY(T, F)
 

Typedefs

template<typename CvSrc , typename Dest >
using wpi::java::detail::copy_cv_t = typename copy_cv< CvSrc, Dest >::type
 
template<typename T , size_t Extent = std::dynamic_extent>
using wpi::java::JSpan = detail::JSpanBase< T, false, Extent >
 
template<typename T , size_t Extent = std::dynamic_extent>
using wpi::java::CriticalJSpan = detail::JSpanBase< T, true, Extent >
 

Functions

std::string wpi::java::GetJavaStackTrace (JNIEnv *env, std::string *func=nullptr, std::string_view excludeFuncPrefix={})
 Gets a Java stack trace. More...
 
jstring wpi::java::MakeJString (JNIEnv *env, std::string_view str)
 Convert a UTF8 string into a jstring. More...
 
template<typename T >
jintArray wpi::java::MakeJIntArray (JNIEnv *env, std::span< const T > arr)
 Convert a span to a jintArray. More...
 
template<typename T >
jintArray wpi::java::MakeJIntArray (JNIEnv *env, const SmallVectorImpl< T > &arr)
 Convert a SmallVector to a jintArray. More...
 
template<typename T >
jintArray wpi::java::MakeJIntArray (JNIEnv *env, const std::vector< T > &arr)
 Convert a std::vector to a jintArray. More...
 
jbyteArray wpi::java::MakeJByteArray (JNIEnv *env, std::span< const uint8_t > str)
 Convert a span into a jbyteArray. More...
 
jbooleanArray wpi::java::MakeJBooleanArray (JNIEnv *env, std::span< const int > arr)
 Convert an array of integers into a jbooleanArray. More...
 
jbooleanArray wpi::java::MakeJBooleanArray (JNIEnv *env, std::span< const bool > arr)
 Convert an array of booleans into a jbooleanArray. More...
 
template<class T >
requires (sizeof(typename T::value_type) == sizeof(jlong) && std::integral<typename T::value_type>)
jlongArray wpi::java::MakeJLongArray (JNIEnv *env, const T &arr)
 
jobjectArray wpi::java::MakeJStringArray (JNIEnv *env, std::span< const std::string > arr)
 Convert an array of std::string into a jarray of jstring. More...
 
jobjectArray wpi::java::MakeJStringArray (JNIEnv *env, std::span< std::string_view > arr)
 Convert an array of std::string into a jarray of jstring. More...
 
std::string wpi::java::GetJavaStackTrace (JNIEnv *env, std::string_view skipPrefix)
 

Variables

template<typename From , typename To >
constexpr bool wpi::java::detail::is_qualification_convertible_v
 

Macro Definition Documentation

◆ WPI_JNI_ARRAYHELPER

#define WPI_JNI_ARRAYHELPER (   T,
 
)
Value:
template <> \
struct ArrayHelper<T> { \
using jarray_type = T##Array; \
static T* GetArrayElements(JNIEnv* env, jarray_type jarr) { \
return env->Get##F##ArrayElements(jarr, nullptr); \
} \
static void ReleaseArrayElements(JNIEnv* env, jarray_type jarr, T* elems, \
jint mode) { \
env->Release##F##ArrayElements(jarr, elems, mode); \
} \
};
static constexpr const unit_t< compound_unit< charge::coulomb, inverse< substance::mol > > > F(N_A *e)
Faraday constant.

◆ WPI_JNI_MAKEJARRAY

#define WPI_JNI_MAKEJARRAY (   T,
 
)
Value:
inline T##Array MakeJ##F##Array(JNIEnv* env, std::span<const T> arr) { \
T##Array jarr = env->New##F##Array(arr.size()); \
if (!jarr) { \
return nullptr; \
} \
env->Set##F##ArrayRegion(jarr, 0, arr.size(), arr.data()); \
return jarr; \
}