Flutter Engine
The Flutter Engine
jni_weak_ref.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_FML_PLATFORM_ANDROID_JNI_WEAK_REF_H_
6#define FLUTTER_FML_PLATFORM_ANDROID_JNI_WEAK_REF_H_
7
8#include <jni.h>
9
10#include "flutter/fml/platform/android/scoped_java_ref.h"
11
12namespace fml {
13namespace jni {
14
15// Manages WeakGlobalRef lifecycle.
16// This class is not thread-safe w.r.t. get() and reset(). Multiple threads may
17// safely use get() concurrently, but if the user calls reset() (or of course,
18// calls the destructor) they'll need to provide their own synchronization.
20 public:
22
24
25 JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj);
26
28
29 void operator=(const JavaObjectWeakGlobalRef& rhs);
30
31 ScopedJavaLocalRef<jobject> get(JNIEnv* env) const;
32
33 bool is_empty() const { return obj_ == NULL; }
34
35 void reset();
36
37 private:
38 void Assign(const JavaObjectWeakGlobalRef& rhs);
39
40 jweak obj_;
41};
42
43// Get the real object stored in the weak reference returned as a
44// ScopedJavaLocalRef.
45ScopedJavaLocalRef<jobject> GetRealObject(JNIEnv* env, jweak obj);
46
47} // namespace jni
48} // namespace fml
49
50#endif // FLUTTER_FML_PLATFORM_ANDROID_JNI_WEAK_REF_H_
void operator=(const JavaObjectWeakGlobalRef &rhs)
Definition: jni_weak_ref.cc:30
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
Definition: __init__.py:1
ScopedJavaLocalRef< jobject > GetRealObject(JNIEnv *env, jweak obj)
Definition: jni_weak_ref.cc:45
Definition: ascii_trie.cc:9