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