Imported Upstream version 1.0.1
[platform/upstream/iotivity.git] / service / easy-setup / sdk / mediator / android / jni / jniutil / inc / jni_easy_setup_jvm.h
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 /**
22  * @file   jni_easy_setup_jvm.h
23  *
24  * @brief  This file contains the essential declarations and functions required
25  *            for JNI implementation
26  */
27
28 #ifndef __JNI_EASY_SETUP_JVM_H_
29 #define __JNI_EASY_SETUP_JVM_H_
30
31 #include <jni.h>
32 #include <thread>
33 #include <mutex>
34
35 #define EASY_SETUP_SERVICE_NATIVE_API_CLASS_PATH    "org/iotivity/service/easysetup/core/EasySetupManager"
36 #define EASY_SETUP_SERVICE_NATIVE_API_CLASS_TYPE    "Lorg/iotivity/service/easysetup/core/EasySetupManager;"
37 #define EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH    "org/iotivity/service/easysetup/core/EasySetupCallbackHandler"
38 #define EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_TYPE    "Lorg/iotivity/service/easysetup/core/EasySetupCallbackHandler;"
39
40 #define EASY_SETUP_JAVA_STRING_TYPE "Ljava/lang/String;"
41 #define EASY_SETUP_JAVA_INTEGER_TYPE "I"
42
43 /**
44  * @class   EasySetupJVM
45  * @brief   This class provides functions related to JNI Environment.
46  *
47  */
48 class EasySetupJVM {
49 public:
50     /**
51      * @brief destructor
52      */
53     ~EasySetupJVM() {
54     }
55     ;
56
57     /**
58      * @brief  Get JVM instance
59      */
60     static JNIEnv *getEnv();
61
62     /**
63      * @brief  Release aquired JVM instance
64      */
65     static void releaseEnv();
66
67 public:
68     /**
69      *  Java VM pointer
70      */
71     static JavaVM *m_jvm;
72
73 private:
74     /**
75      * @brief constructor
76      */
77     EasySetupJVM();
78
79     /**
80      *  Mutex for thread synchronization
81      */
82     static std::mutex m_currentThreadMutex;
83 };
84
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88 jclass GetJClass(const char *szClassPath);
89 jobject GetJObjectInstance(const char *szClassPath);
90 #ifdef __cplusplus
91 }
92 #endif
93 #endif //__JNI_EASY_SETUP_JVM_H_
94