Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / android / android_api / base / jni / JniOcPresenceHandle.cpp
1 /*
2 * //******************************************************************
3 * //
4 * // Copyright 2015 Intel Corporation.
5 * //
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 * //
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
11 * //
12 * //      http://www.apache.org/licenses/LICENSE-2.0
13 * //
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
19 * //
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 */
22 #include "JniOcPresenceHandle.h"
23 #include "OCPlatform.h"
24
25 JniOcPresenceHandle::JniOcPresenceHandle(JniOnPresenceListener* jniListener, OCPresenceHandle presenceHandle)
26     : m_jniListener(jniListener), m_presenceHandle(presenceHandle)
27 {}
28
29 JniOcPresenceHandle::~JniOcPresenceHandle()
30 {
31     LOGD("~JniOcPresenceHandle()");
32
33     //delete m_jniListener;
34     m_presenceHandle = nullptr;
35 }
36
37 JniOcPresenceHandle* JniOcPresenceHandle::getJniOcPresenceHandlePtr
38 (JNIEnv *env, jobject thiz)
39 {
40     JniOcPresenceHandle *handle = GetHandle<JniOcPresenceHandle>(env, thiz);
41     if (env->ExceptionCheck())
42     {
43         LOGE("Failed to get native handle from OcPresenceHandle");
44     }
45     if (!handle)
46     {
47         ThrowOcException(JNI_NO_NATIVE_POINTER, "");
48     }
49     return handle;
50 }
51
52 OCPresenceHandle JniOcPresenceHandle::getOCPresenceHandle()
53 {
54     return this->m_presenceHandle;
55 }
56
57 JniOnPresenceListener* JniOcPresenceHandle::getJniOnPresenceListener()
58 {
59     return this->m_jniListener;
60 }
61
62 /*
63 * Class:     org_iotivity_base_OcPresenceHandle
64 * Method:    dispose
65 * Signature: ()V
66 */
67 JNIEXPORT void JNICALL Java_org_iotivity_base_OcPresenceHandle_dispose
68 (JNIEnv *env, jobject thiz)
69 {
70     LOGD("OcPresenceHandle_dispose");
71     JniOcPresenceHandle *presenceHandle = JniOcPresenceHandle::getJniOcPresenceHandlePtr(env, thiz);
72     delete presenceHandle;
73 }