blob: 93d8b405e4d48c85d14c74b90c424f2c33722ee6 [file] [log] [blame]
Dongwon Kang0d7042d2018-10-12 16:52:14 -07001/*
2 * Copyright 2018, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef JOBJECT_HOLDER_H_
18
19#define JOBJECT_HOLDER_H_
20
21#include "jni.h"
22#include <mediaplayer2/JavaVMHelper.h>
23#include <utils/RefBase.h>
24
25namespace android {
26
27// Helper class for managing global reference of jobject.
28struct JObjectHolder : public RefBase {
29 JObjectHolder(jobject obj) {
30 JNIEnv *env = JavaVMHelper::getJNIEnv();
31 mJObject = reinterpret_cast<jobject>(env->NewGlobalRef(obj));
32 }
33
34 virtual ~JObjectHolder() {
35 JNIEnv *env = JavaVMHelper::getJNIEnv();
36 env->DeleteGlobalRef(mJObject);
37 }
38
39 jobject getJObject() { return mJObject; }
40
41private:
42 jobject mJObject;
43};
44
45} //" android
46
47#endif // JOBJECT_HOLDER_H_