Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / things-manager / sdk / java / jni / jniutil / inc / jni_object.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 JObject class  declarations and its functions required
24   * for getting and setting basic data types in C++ and Java.
25   */
26
27 #ifndef JNI_OBJECT_H_
28 #define JNI_OBJECT_H_
29
30 #include <jni.h>
31 #include "JniOcResource.h"
32
33 /**
34  * This class provides a set of functions for JNI object.
35  */
36 class JObject
37 {
38     public:
39         /**
40          * constructor
41          */
42         JObject(JNIEnv *env);
43
44         /**
45          * constructor
46          */
47         JObject(JNIEnv *env, jobject obj);
48
49         /**
50          * constructor
51          */
52         JObject(JNIEnv *env, const char *classPath);
53
54         /**
55          * destructor
56          */
57         virtual ~JObject();
58
59         /**
60          * Function to get the jobject.
61          *
62          * @return jobject, returns a new JNI object or NULL otherwise.
63          */
64         virtual jobject getObject() const;
65
66         /**
67          * Function to detach the jobject.
68          */
69         void detachObject();
70
71     protected:
72         /**
73          *  JNI Environment Pointer
74          */
75         JNIEnv *m_pEnv;
76         /**
77          *  Java Object
78          */
79         jobject m_pObject;
80         /**
81          *  Java Class
82          */
83         jclass  m_pClazz;
84         /**
85          *  Boolean variable to check if an object is new.
86          */
87         bool m_fIsNewObject;
88 };
89 #endif //JNI_OBJECT_H_