Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / things-manager / sdk / java / jni / jniutil / inc / jni_getter.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
23   * This file contains the JGetter class  declarations and its functions required
24   * for getting and setting basic data types in C++ and Java.
25   */
26
27 #ifndef JNI_GETTER_H_
28 #define JNI_GETTER_H_
29
30 #include <string>
31 #include <jni.h>
32
33 /**
34  * This class provide utility for get/set basic data types in C++ and Java.
35  */
36 class JGetter
37 {
38     public:
39         /**
40          * This function is called to get String field from the C++ object.
41          *
42          * @param env
43          *           JNI Environment reference
44          * @param object
45          *           JObject from which string field is expected
46          * @param fieldName
47          *           Name of the field to be extracted from JObject
48          * @param value
49          *         reference to string value mentioned in fieldName
50          *
51          * @return returns true on success and false on failer.
52          */
53         static bool getJStringField(JNIEnv *env, jobject &object, const char *fieldName,
54                                     std::string &value);
55
56         /**
57          * This function is called to get Boolean field from the C++ object.
58          *
59          * @param env
60          *           JNI Environment reference
61          * @param object
62          *           JObject from which boolean field is expected
63          * @param fieldName
64          *           Name of the field to be extracted from JObject
65          * @param value
66          *         reference to boolean value mentioned in fieldName
67          *
68          * @return returns true on success and false on failer.
69          */
70         static bool getJBoolField(JNIEnv *env, jobject &object, const char *fieldName,
71                                   bool &value);
72
73         /**
74          * This function is called to get Integer field from the C++ object.
75          *
76          * @param env
77          *           JNI Environment reference
78          * @param object
79          *           JObject from which integer field is expected
80          * @param fieldName
81          *           Name of the field to be extracted from JObject
82          * @param value
83          *         reference to integer value mentioned in fieldName
84          *
85          * @return returns true on success and false on failer.
86          */
87         static bool getJIntField(JNIEnv *env, jobject &object, const char *fieldName, int &value);
88
89         /**
90          * This function is called to get Object reference from the C++ object.
91          *
92          * @param env
93          *           JNI Environment reference
94          * @param object
95          *           JObject from which Object reference is expected
96          * @param fieldName
97          *           Name of the field to be extracted from JObject
98          * @param fieldType
99          *           Type of the field to be extracted from JObject
100          * @param value
101          *         reference to Object reference mentioned in fieldName
102          *
103          * @return returns true on success and false on failure
104          */
105         static bool getJObjectField(JNIEnv *env, jobject &object, const char *fieldName,
106                                     const char *fieldType, jobject &value);
107 };
108 #endif //JNI_GETTER_H_