VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
SelfDetachingJNIEnv.h
1 /*
2  * Copyright (C) 2014 Google Inc.
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 SELFDETACHINGJNIENV_H
18 #define SELFDETACHINGJNIENV_H
19 
20 #include <QObject>
21 
22 #if defined(Q_OS_ANDROID)
23 
24 #include <jni.h>
25 
34 public:
50  SelfDetachingJNIEnv(const SelfDetachingJNIEnv& value) = delete;
51 
52  virtual ~SelfDetachingJNIEnv();
53 
57  JNIEnv* getJNIEnv() const;
62  JNIEnv& operator*();
67  const JNIEnv& operator*() const;
71  JNIEnv* operator->();
75  const JNIEnv* operator->() const;
93  SelfDetachingJNIEnv& operator=(const SelfDetachingJNIEnv& value) = delete;
97  operator bool() const { return mJNI; }
98 
107  static SelfDetachingJNIEnv fromJVM(JavaVM* vm);
108 
109 private:
110  SelfDetachingJNIEnv() { }
111  SelfDetachingJNIEnv(JavaVM* vm, JNIEnv* jni, bool attached);
112 
113  JavaVM* mVM = nullptr;
114  JNIEnv* mJNI = nullptr;
115  bool mAttached = false;
116 };
117 
118 #endif // Q_OS_ANDROID
119 #endif // SELFDETACHINGJNIENV_H
JNIEnv * getJNIEnv() const
Returns underlying JNIEnv pointer.
Smart wrapper around JNIEnv which retains information of how the environment was loaded.
Definition: SelfDetachingJNIEnv.h:33
static SelfDetachingJNIEnv fromJVM(JavaVM *vm)
Returns a SelfDetachingJNIEnv wrapper around the current JNIEnv.
JNIEnv * operator->()
Returns the underlying JNIEnv pointer to provide access to its members.
SelfDetachingJNIEnv & operator=(SelfDetachingJNIEnv &&value)
Move assigns value to this SelfDetachingJNIEnv instance.
JNIEnv & operator*()
Returns the dereferenced JNIEnv pointer.