proxygen
fizz::jni Namespace Reference

Functions

void setVM (JavaVM *jvm)
 
JNIEnv * getEnv (bool *shouldDetach)
 
void releaseEnv (bool shouldDetach)
 
jclass getClass (JNIEnv *env, const std::string &name)
 
jmethodID getMethodID (JNIEnv *env, jclass clazz, const std::string &name, const std::string &signature)
 
void maybeThrowException (JNIEnv *env, bool shouldDetach)
 
jbyteArray createByteArray (JNIEnv *env, folly::ByteRange byteRange)
 
jbyteArray createByteArray (JNIEnv *env, Buf buf)
 

Function Documentation

jbyteArray fizz::jni::createByteArray ( JNIEnv *  env,
folly::ByteRange  byteRange 
)

Definition at line 72 of file JniUtils.cpp.

References folly::Range< Iter >::data(), and folly::Range< Iter >::size().

Referenced by createByteArray(), fizz::JavaCryptoPeerCert::JavaCryptoPeerCert(), and fizz::JavaCryptoPeerCert::verify().

72  {
73  auto byteArray = env->NewByteArray(byteRange.size());
74  env->SetByteArrayRegion(
75  byteArray,
76  0 /*start*/,
77  byteRange.size(),
78  reinterpret_cast<const jbyte*>(byteRange.data()));
79  return byteArray;
80 }
constexpr size_type size() const
Definition: Range.h:431
constexpr Iter data() const
Definition: Range.h:446
jbyteArray fizz::jni::createByteArray ( JNIEnv *  env,
Buf  buf 
)

Definition at line 82 of file JniUtils.cpp.

References createByteArray().

82  {
83  return createByteArray(env, buf->coalesce());
84 }
jbyteArray createByteArray(JNIEnv *env, Buf buf)
Definition: JniUtils.cpp:82
jclass fizz::jni::getClass ( JNIEnv *  env,
const std::string name 
)

Definition at line 46 of file JniUtils.cpp.

Referenced by fizz::JavaCryptoPeerCert::onLoad().

46  {
47  auto clazz =
48  reinterpret_cast<jclass>(env->NewGlobalRef(env->FindClass(name.c_str())));
49  CHECK(clazz);
50  return clazz;
51 }
const char * name
Definition: http_parser.c:437
JNIEnv * fizz::jni::getEnv ( bool *  shouldDetach)

Definition at line 23 of file JniUtils.cpp.

Referenced by fizz::JavaCryptoPeerCert::getIdentity(), fizz::JavaCryptoPeerCert::JavaCryptoPeerCert(), and fizz::JavaCryptoPeerCert::verify().

23  {
24  *shouldDetach = false;
25 
26  JNIEnv* env;
27  auto status = vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
28  CHECK(status == JNI_OK || status == JNI_EDETACHED);
29 
30  if (status == JNI_EDETACHED) {
31  status = vm->AttachCurrentThread(
32  reinterpret_cast<void**>(&env), nullptr /*args*/);
33  CHECK_EQ(status, JNI_OK);
34  *shouldDetach = true;
35  }
36 
37  return env;
38 }
jmethodID fizz::jni::getMethodID ( JNIEnv *  env,
jclass  clazz,
const std::string name,
const std::string signature 
)

Definition at line 53 of file JniUtils.cpp.

Referenced by fizz::JavaCryptoPeerCert::onLoad().

57  {
58  auto methodId = env->GetMethodID(clazz, name.c_str(), signature.c_str());
59  CHECK(methodId);
60  return methodId;
61 }
const char * name
Definition: http_parser.c:437
void fizz::jni::maybeThrowException ( JNIEnv *  env,
bool  shouldDetach 
)

Definition at line 63 of file JniUtils.cpp.

References releaseEnv().

Referenced by fizz::JavaCryptoPeerCert::getIdentity(), fizz::JavaCryptoPeerCert::JavaCryptoPeerCert(), and fizz::JavaCryptoPeerCert::verify().

63  {
64  if (!env->ExceptionCheck()) {
65  return;
66  }
67  env->ExceptionDescribe();
68  releaseEnv(shouldDetach);
69  throw std::runtime_error("JNI exception");
70 }
void releaseEnv(bool shouldDetach)
Definition: JniUtils.cpp:40
void fizz::jni::releaseEnv ( bool  shouldDetach)

Definition at line 40 of file JniUtils.cpp.

Referenced by fizz::JavaCryptoPeerCert::getIdentity(), fizz::JavaCryptoPeerCert::JavaCryptoPeerCert(), maybeThrowException(), and fizz::JavaCryptoPeerCert::verify().

40  {
41  if (shouldDetach) {
42  vm->DetachCurrentThread();
43  }
44 }
void fizz::jni::setVM ( JavaVM *  jvm)

Definition at line 19 of file JniUtils.cpp.

Referenced by JNI_OnLoad().

19  {
20  vm = jvm;
21 }