1 /******************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
21 #include "JniEasySetup.h"
23 using namespace OIC::Service;
28 JNIEXPORT jobject JNICALL
29 Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateEnrolleeDevice
30 (JNIEnv *env, jobject interfaceClass, jstring ip, jstring ssid, jstring password,
31 jint connectivityType, jboolean needSecuredEasysetup)
34 LOGI("JniEasySetup::nativeCreateEnrolleeDevice enter");
36 std::shared_ptr<RemoteEnrollee> nativeRemoteEnrollee;
37 jobject jRemoteEnrollee;
38 EnrolleeNWProvInfo netInfo;
40 const char *cIp = (env)->GetStringUTFChars(ip, NULL);
41 const char *cSssid = (env)->GetStringUTFChars(ssid, NULL);
42 const char *cPassword = (env)->GetStringUTFChars(password, NULL);
45 std::string sSssid(cSssid);
46 std::string sPassword(cPassword);
48 netInfo.connType = getOCConnectivityTypeFromInt(connectivityType);
49 netInfo.isSecured = bool(
50 needSecuredEasysetup); // may be need to remove, if removed from c++ layer
51 netInfo.needSecuredEasysetup = bool(needSecuredEasysetup);
53 OICStrcpy(netInfo.netAddressInfo.WIFI.ipAddress, IPV4_ADDR_SIZE - 1, sIp.c_str());
54 OICStrcpy(netInfo.netAddressInfo.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, sSssid.c_str());
55 OICStrcpy(netInfo.netAddressInfo.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, sPassword.c_str());
59 nativeRemoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo);
60 //create the java object
61 jRemoteEnrollee = env->NewObject(g_cls_RemoteEnrollee, g_mid_RemoteEnrollee_ctor);
64 LOGE("JniEasySetup::nativeCreateEnrolleeDevice Unable to create the java object");
68 JniRemoteEnrollee *jniRemoteEnrollee = new JniRemoteEnrollee(nativeRemoteEnrollee);
69 ESSetHandle<JniRemoteEnrollee>(env, jRemoteEnrollee, jniRemoteEnrollee);
71 catch (ESBadRequestException exception)
73 LOGE("JniEasySetup::nativeCreateEnrolleeDevice Unable to create the Native EnrolleeDevice");
74 //throw the exception to java layer
75 throwESException( env, exception.what());
78 LOGI("JniEasySetup::nativeCreateEnrolleeDevice exit");
80 return jRemoteEnrollee;