Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / java / jni / simulator_common_jni.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 #ifndef SIMULATOR_COMMON_JNI_H_
22 #define SIMULATOR_COMMON_JNI_H_
23
24 #include <jni.h>
25
26 typedef struct
27 {
28     jclass classObject;
29     jclass classInteger;
30     jclass classDouble;
31     jclass classString;
32     jclass classHashMap;
33     jclass classVector;
34     jclass classMap;
35     jclass classMapEntry;
36     jclass classSet;
37     jclass classIterator;
38     jclass classLinkedList;
39
40     jclass classSimulatorResource;
41     jclass classSimulatorResourceModel;
42     jclass classResourceAttribute;
43     jclass classSimulatorRemoteResource;
44     jclass classSimulatorCallback;
45     jclass classObserverInfo;
46     jclass classDeviceInfo;
47     jclass classPlatformInfo;
48     jclass classSimulatorException;
49     jclass classInvalidArgsException;
50     jclass classNoSupportException;
51     jclass classOperationInProgressException;
52
53     jmethodID classIntegerCtor;
54     jmethodID classDoubleCtor;
55     jmethodID classHashMapCtor;
56     jmethodID classHashMapPut;
57     jmethodID classVectorCtor;
58     jmethodID classVectorAddElement;
59     jmethodID classMapEntrySet;
60     jmethodID classMapGetKey;
61     jmethodID classMapGetValue;
62     jmethodID classIteratorId;
63     jmethodID classHasNextId;
64     jmethodID classNextId;
65     jmethodID classLinkedListCtor;
66     jmethodID classLinkedListAddObject;
67
68     jmethodID classSimulatorResourceCtor;
69     jmethodID classSimulatorResourceModelCtor;
70     jmethodID classResourceAttributeCtor;
71     jmethodID classResourceAttributeSetRange;
72     jmethodID classSimulatorResourceModelId;
73     jmethodID classObserverInfoCtor;
74     jmethodID classSimulatorExceptionCtor;
75     jmethodID classInvalidArgsExceptionCtor;
76     jmethodID classNoSupportExceptionCtor;
77     jmethodID classOperationInProgressExceptionCtor;
78
79 } SimulatorClassRefs;
80
81 static jfieldID GetHandleField(JNIEnv *env, jobject jobj)
82 {
83     jclass cls = env->GetObjectClass(jobj);
84     return env->GetFieldID(cls, "nativeHandle", "J");
85 }
86
87 template <typename T>
88 static T *GetHandle(JNIEnv *env, jobject jobj)
89 {
90     jlong handle = env->GetLongField(jobj, GetHandleField(env, jobj));
91     return reinterpret_cast<T *>(handle);
92 }
93
94 template <typename T>
95 static void SetHandle(JNIEnv *env, jobject jobj, T *type)
96 {
97     jlong handle = reinterpret_cast<jlong>(type);
98
99     env->SetLongField(jobj, GetHandleField(env, jobj), handle);
100 }
101
102 JNIEnv *getEnv();
103 void releaseEnv();
104
105 #endif