2 //******************************************************************
4 // Copyright 2015 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
25 #include "ResourceHosing_JNI.h"
26 #include "OCAndroid.h"
30 atomic_bool threadRun;
31 thread ocProcessThread;
33 * To execute OCProcess when threadRun value is only true
40 if (OCProcess() != OC_STACK_OK)
50 * for Hosting Device Side
52 JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_OICCoordinatorStart
53 (JNIEnv *env, jobject obj)
58 result = (jint)HOSTING_THREAD_ERROR;
63 result = (jint)OICStartCoordinate();
66 ocProcessThread = thread(ocProcessFunc);
71 JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_OICCoordinatorStop
72 (JNIEnv *env, jobject obj)
76 if (ocProcessThread.joinable())
79 ocProcessThread.join();
83 result = (jint)HOSTING_THREAD_ERROR;
86 result = (jint)OICStopCoordinate();
91 JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_ResourceHostingInit
92 (JNIEnv *env, jobject obj,jstring j_addr)
94 const char* addr = env->GetStringUTFChars(j_addr,NULL);
97 return (jint)OCSTACK_ERROR;
99 if(OCInit(addr,USE_RANDOM_PORT,OC_CLIENT_SERVER)!=OC_STACK_OK)
101 return (jint)OCSTACK_ERROR;
104 env->ReleaseStringUTFChars(j_addr,addr);
105 return (jint)OCSTACK_OK;
108 JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_ResourceHostingTerminate
109 (JNIEnv *env, jobject obj)
111 if (OCStop() != OC_STACK_OK)
113 return (jint)OCSTACK_ERROR;
116 if (ocProcessThread.joinable())
119 ocProcessThread.join();
123 return (jint)HOSTING_THREAD_ERROR;
126 return (jint)OCSTACK_OK;