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