Flutter Engine
fml::jni::JavaRef< jobject > Class Template Reference

#include <scoped_java_ref.h>

Inheritance diagram for fml::jni::JavaRef< jobject >:
fml::jni::ScopedJavaGlobalRef< jobject >

Public Member Functions

jobject obj () const
 
bool is_null () const
 

Protected Member Functions

 JavaRef ()
 
 JavaRef (JNIEnv *env, jobject obj)
 
 ~JavaRef ()
 
JNIEnv * SetNewLocalRef (JNIEnv *env, jobject obj)
 
void SetNewGlobalRef (JNIEnv *env, jobject obj)
 
void ResetLocalRef (JNIEnv *env)
 
void ResetGlobalRef ()
 
jobject ReleaseInternal ()
 

Detailed Description

template<>
class fml::jni::JavaRef< jobject >

Definition at line 42 of file scoped_java_ref.h.

Constructor & Destructor Documentation

◆ JavaRef() [1/2]

fml::jni::JavaRef< jobject >::JavaRef ( )
protected

Definition at line 30 of file scoped_java_ref.cc.

30 : obj_(NULL) {}

◆ JavaRef() [2/2]

fml::jni::JavaRef< jobject >::JavaRef ( JNIEnv *  env,
jobject  obj 
)
protected

Definition at line 32 of file scoped_java_ref.cc.

References FML_DCHECK, and fml::jni::JavaRef< T >::~JavaRef().

32  : obj_(obj) {
33  if (obj) {
34  FML_DCHECK(env && env->GetObjectRefType(obj) == JNILocalRefType);
35  }
36 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ ~JavaRef()

fml::jni::JavaRef< jobject >::~JavaRef ( )
protecteddefault

Member Function Documentation

◆ is_null()

bool fml::jni::JavaRef< jobject >::is_null ( ) const
inline

Definition at line 46 of file scoped_java_ref.h.

References FML_DISALLOW_COPY_AND_ASSIGN.

46 { return obj_ == NULL; }

◆ obj()

jobject fml::jni::JavaRef< jobject >::obj ( ) const
inline

Definition at line 44 of file scoped_java_ref.h.

44 { return obj_; }

◆ ReleaseInternal()

jobject fml::jni::JavaRef< jobject >::ReleaseInternal ( )
protected

Definition at line 82 of file scoped_java_ref.cc.

References fml::jni::JavaRef< T >::obj().

82  {
83  jobject obj = obj_;
84  obj_ = NULL;
85  return obj;
86 }

◆ ResetGlobalRef()

void fml::jni::JavaRef< jobject >::ResetGlobalRef ( )
protected

Definition at line 75 of file scoped_java_ref.cc.

References fml::jni::AttachCurrentThread().

75  {
76  if (obj_) {
77  AttachCurrentThread()->DeleteGlobalRef(obj_);
78  obj_ = NULL;
79  }
80 }
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:26

◆ ResetLocalRef()

void fml::jni::JavaRef< jobject >::ResetLocalRef ( JNIEnv *  env)
protected

Definition at line 67 of file scoped_java_ref.cc.

References fml::jni::AttachCurrentThread(), and FML_DCHECK.

67  {
68  if (obj_) {
69  FML_DCHECK(env == AttachCurrentThread()); // Is |env| on correct thread.
70  env->DeleteLocalRef(obj_);
71  obj_ = NULL;
72  }
73 }
#define FML_DCHECK(condition)
Definition: logging.h:86
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:26

◆ SetNewGlobalRef()

void fml::jni::JavaRef< jobject >::SetNewGlobalRef ( JNIEnv *  env,
jobject  obj 
)
protected

Definition at line 54 of file scoped_java_ref.cc.

References fml::jni::AttachCurrentThread(), FML_DCHECK, and fml::jni::JavaRef< T >::obj().

54  {
55  if (!env) {
56  env = AttachCurrentThread();
57  } else {
58  FML_DCHECK(env == AttachCurrentThread()); // Is |env| on correct thread.
59  }
60  if (obj)
61  obj = env->NewGlobalRef(obj);
62  if (obj_)
63  env->DeleteGlobalRef(obj_);
64  obj_ = obj;
65 }
#define FML_DCHECK(condition)
Definition: logging.h:86
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:26

◆ SetNewLocalRef()

JNIEnv * fml::jni::JavaRef< jobject >::SetNewLocalRef ( JNIEnv *  env,
jobject  obj 
)
protected

Definition at line 40 of file scoped_java_ref.cc.

References fml::jni::AttachCurrentThread(), FML_DCHECK, and fml::jni::JavaRef< T >::obj().

40  {
41  if (!env) {
42  env = AttachCurrentThread();
43  } else {
44  FML_DCHECK(env == AttachCurrentThread()); // Is |env| on correct thread.
45  }
46  if (obj)
47  obj = env->NewLocalRef(obj);
48  if (obj_)
49  env->DeleteLocalRef(obj_);
50  obj_ = obj;
51  return env;
52 }
#define FML_DCHECK(condition)
Definition: logging.h:86
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:26

The documentation for this class was generated from the following files: