2 * //******************************************************************
4 * // Copyright 2016 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
12 * // http://www.apache.org/licenses/LICENSE-2.0
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.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "JniOcDirectPairDevice.h"
24 #include "OCDirectPairing.h"
25 #include "OCDirectPairing.h"
27 namespace PH = std::placeholders;
29 JniOcDirectPairDevice::JniOcDirectPairDevice(std::shared_ptr<OC::OCDirectPairing> directPairingDevice)
30 : m_sharedDirectPairDevice(directPairingDevice)
33 JniOcDirectPairDevice::~JniOcDirectPairDevice()
35 LOGD("~JniOcDirectPairDevice()");
36 m_sharedDirectPairDevice = nullptr;
39 std::string JniOcDirectPairDevice::getHost()
41 return m_sharedDirectPairDevice->getHost();
44 std::vector<OCPrm_t> JniOcDirectPairDevice::getPairingMethods()
47 return m_sharedDirectPairDevice->getPairingMethods();
50 OCConnectivityType JniOcDirectPairDevice::connectivityType()
52 return m_sharedDirectPairDevice->getConnType();
55 JniOcDirectPairDevice* JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(JNIEnv *env, jobject thiz)
57 JniOcDirectPairDevice *dpDev = GetHandle<JniOcDirectPairDevice>(env, thiz);
58 if (env->ExceptionCheck())
60 LOGE("Failed to get native handle from OcDirectPairingDevice");
64 ThrowOcException(JNI_NO_NATIVE_POINTER, "");
68 std::shared_ptr<OC::OCDirectPairing> JniOcDirectPairDevice::getPtr()
70 return m_sharedDirectPairDevice;
73 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcDirectPairDevice_getHost
74 (JNIEnv *env, jobject thiz)
77 LOGD("OcDirectPairing_getHost");
79 JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz);
80 if (!device) return nullptr;
82 std::string dev = device->getHost();
83 return env->NewStringUTF(dev.c_str());
86 JNIEXPORT jintArray JNICALL Java_org_iotivity_base_OcDirectPairDevice_getPairingMethods
87 (JNIEnv *env, jobject thiz)
90 LOGD("OcDirectPairing_getPairingMethods");
92 std::vector<jint> pairingMethodList;
93 JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz);
94 if (!device) return nullptr;
96 std::vector<OCPrm_t> pairingMethods = device->getPairingMethods();
97 return JniOcDirectPairDevice::JconvertIntVectorToJavaList(env,pairingMethods);
101 jintArray JniOcDirectPairDevice::JconvertIntVectorToJavaList(JNIEnv *env, std::vector<OCPrm_t> &vector)
104 jsize len = static_cast<jsize>(vector.size());
106 jintArray intArray = env->NewIntArray(len);
107 if (!intArray) return nullptr;
109 env->SetIntArrayRegion(intArray, (jsize)0, len, (const jint*)&vector[0]);
111 if (env->ExceptionCheck())
113 LOGE("ArrayIndexOutOfBoundsException in JconvertIntVectorToJavaList");
119 * Class: org_iotivity_base_OcDirectPairDevice
120 * Method: getConnectivityTypeN
123 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcDirectPairDevice_getConnectivityTypeN
124 (JNIEnv *env, jobject thiz)
126 LOGD("OcDirectPairDevice_getConnectivityType");
127 JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz);
128 if (!device) return -1;
130 OCConnectivityType connectivityType = device->connectivityType();
131 return static_cast<jint>(connectivityType);