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 ******************************************************************/
23 #include "OCPlatform.h"
24 #include "OCResource.h"
26 #include "ESRichCommon.h"
28 #include "JniOcResource.h"
29 #include "JniEasySetup.h"
32 using namespace OIC::Service;
37 JNIEXPORT jobject JNICALL
38 Java_org_iotivity_service_easysetup_mediator_EasySetup_nativeCreateRemoteEnrollee
39 (JNIEnv *env, jobject thiz, jobject jResource)
41 ES_LOGI("JniEasySetup::nativeCreateRemoteEnrollee enter");
43 std::shared_ptr<RemoteEnrollee> nativeRemoteEnrollee;
44 jobject jRemoteEnrollee;
48 ES_LOGE("JniEasySetup::nativeCreateRemoteEnrollee Invalid param.");
52 JniOcResource* jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource);
56 ES_LOGE("JniEasySetup::nativeCreateRemoteEnrollee getJniOcResourcePtr returns nullptr.");
62 nativeRemoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(jniOcResource->getOCResource());
63 if (!nativeRemoteEnrollee)
65 ES_LOGE("Failed to create RemoteEnrollee object.");
69 //create the java object
70 jRemoteEnrollee = env->NewObject(g_cls_RemoteEnrollee, g_mid_RemoteEnrollee_ctor);
73 ES_LOGE("JniEasySetup::nativeCreateRemoteEnrollee Unable to create the java object");
76 JniRemoteEnrollee *jniRemoteEnrollee = new JniRemoteEnrollee(nativeRemoteEnrollee);
77 ESSetHandle<JniRemoteEnrollee>(env, jRemoteEnrollee, jniRemoteEnrollee);
79 catch (ESBadRequestException exception)
81 ES_LOGE("JniEasySetup::nativeCreateRemoteEnrollee Unable to create the Native EnrolleeDevice");
82 //throw the exception to java layer
83 throwESException( env, exception.what());
86 ES_LOGI("JniEasySetup::nativeCreateRemoteEnrollee exit");
88 return jRemoteEnrollee;