From: doil.kwon Date: Thu, 2 Jul 2015 09:05:26 +0000 (+0900) Subject: Distributed Resource Hosting Sample App and ResourceHosting for JAVA API folder. X-Git-Tag: 1.2.0+RC1~1518 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ecd70e9f74875f50a75957d429b152749099102a;p=platform%2Fupstream%2Fiotivity.git Distributed Resource Hosting Sample App and ResourceHosting for JAVA API folder. - Added new folder in NotificationManager folder - "/NotificationManger/android/resource_hosting" Modified notification-manager's Sconscript - ~_JNI.cpp file is not included in Sconscript. Changed folder name : ResourceHostingSampleApp->SampleResourceHosting Deleted files : resourceCoordinator_JNI.cpp and resourceCoordinator_JNI.h in Notification/src folder. Modified about ResourceHosing_JNI.h path is relative path to absolute path in ResourceHosing_JNI.cpp Added "OCProcessFunc"'s return value : none -> return; Change-Id: I2c44c31f1399ca9722c4f2281ec2b8af1646ed21 Signed-off-by: doil.kwon Reviewed-on: https://gerrit.iotivity.org/gerrit/1487 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/.classpath b/service/notification-manager/NotificationManager/android/resource_hosting/.classpath old mode 100644 new mode 100755 similarity index 72% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/.classpath rename to service/notification-manager/NotificationManager/android/resource_hosting/.classpath index c2653d9..7bc01d9 --- a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/.classpath +++ b/service/notification-manager/NotificationManager/android/resource_hosting/.classpath @@ -1,10 +1,9 @@ + + - - - diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/.project b/service/notification-manager/NotificationManager/android/resource_hosting/.project old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/.project rename to service/notification-manager/NotificationManager/android/resource_hosting/.project diff --git a/service/notification-manager/NotificationManager/android/resource_hosting/AndroidManifest.xml b/service/notification-manager/NotificationManager/android/resource_hosting/AndroidManifest.xml new file mode 100755 index 0000000..bb17c60 --- /dev/null +++ b/service/notification-manager/NotificationManager/android/resource_hosting/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + + + + + + diff --git a/service/notification-manager/NotificationManager/android/resource_hosting/jni/Android.mk b/service/notification-manager/NotificationManager/android/resource_hosting/jni/Android.mk new file mode 100755 index 0000000..4bac6bd --- /dev/null +++ b/service/notification-manager/NotificationManager/android/resource_hosting/jni/Android.mk @@ -0,0 +1,65 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := ca +LOCAL_SRC_FILES := ../libs/libconnectivity_abstraction.so +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := ca_i +LOCAL_SRC_FILES := ../libs/libca-interface.so +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := oc_logger_core +LOCAL_SRC_FILES := ../libs/liboc_logger_core.so +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := oc_logger +LOCAL_SRC_FILES := ../libs/liboc_logger.so +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := octbstack +LOCAL_SRC_FILES := ../libs/liboctbstack.so +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := oc +LOCAL_SRC_FILES := ../libs/liboc.so +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := ocstack-jni +LOCAL_SRC_FILES := ../libs/libocstack-jni.so +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := NotificationManager +LOCAL_SRC_FILES := ../libs/libNotificationManager.so +include $(PREBUILT_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := ResourceHosing_JNI +LOCAL_CPPFLAGS := -std=c++0x -frtti -fexceptions + +LOCAL_STATIC_LIBRARIES = ca_i +LOCAL_STATIC_LIBRARIES += ca +LOCAL_STATIC_LIBRARIES += oc_logger_core +LOCAL_STATIC_LIBRARIES += oc_logger +LOCAL_STATIC_LIBRARIES += octbstack +LOCAL_STATIC_LIBRARIES += oc +LOCAL_STATIC_LIBRARIES += ocstack-jni +LOCAL_STATIC_LIBRARIES += NotificationManager + +LOCAL_C_INCLUDES := ../../../../../../resource/csdk/stack/include/ +LOCAL_C_INCLUDES += ../../../../../../resource/csdk/logger/include/ +LOCAL_C_INCLUDES += ../../../../../../resource/include/ +LOCAL_C_INCLUDES += ../../../../../../resource/oc_logger/include/ +LOCAL_C_INCLUDES += ../../../../../../extlibs/boost/boost_1_58_0/ +LOCAL_C_INCLUDES += ../../../../NotificationManager/include/ + + +LOCAL_SRC_FILES := ResourceHosing_JNI.cpp +include $(BUILD_SHARED_LIBRARY) diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/jni/Application.mk b/service/notification-manager/NotificationManager/android/resource_hosting/jni/Application.mk old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/jni/Application.mk rename to service/notification-manager/NotificationManager/android/resource_hosting/jni/Application.mk diff --git a/service/notification-manager/NotificationManager/src/resourceCoordinator_JNI.cpp b/service/notification-manager/NotificationManager/android/resource_hosting/jni/ResourceHosing_JNI.cpp old mode 100644 new mode 100755 similarity index 59% rename from service/notification-manager/NotificationManager/src/resourceCoordinator_JNI.cpp rename to service/notification-manager/NotificationManager/android/resource_hosting/jni/ResourceHosing_JNI.cpp index 4382ea8..2b7106b --- a/service/notification-manager/NotificationManager/src/resourceCoordinator_JNI.cpp +++ b/service/notification-manager/NotificationManager/android/resource_hosting/jni/ResourceHosing_JNI.cpp @@ -1,3 +1,4 @@ + //****************************************************************** // // Copyright 2015 Samsung Electronics All Rights Reserved. @@ -21,8 +22,8 @@ extern "C" { #include "hosting.h" } -#include "resourceCoordinator_JNI.h" -#include "android_cpp11_compat.h" +#include "ResourceHosing_JNI.h" +#include "OCAndroid.h" using namespace std; @@ -38,54 +39,38 @@ void ocProcessFunc() if (OCProcess() != OC_STACK_OK) { - //OCProcess ERROR + return ; } sleep(2); } } -/* - * To callback log message from C++ to Java for android - */ -void messageCallback(JNIEnv *env, jobject obj, const char *c_str) -{ - jstring jstr = (env)->NewStringUTF(c_str); - jclass cls = env->GetObjectClass(obj); - jmethodID cbMessage = env->GetMethodID(cls, "cbMessage", "(Ljava/lang/String;)V"); - env->CallVoidMethod(obj,cbMessage, jstr); -} + /* * for Hosting Device Side */ -JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_OICCoordinatorStart +JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_OICCoordinatorStart (JNIEnv *env, jobject obj) { jint result = 0; if(threadRun==true) { - - messageCallback(env,obj,"OICCoordinatorStart already executed"); result = (jint)HOSTING_THREAD_ERROR; return result; } else { - messageCallback(env,obj,"OICCoordinatorStart"); result = (jint)OICStartCoordinate(); - string str = "OICStartCoordinate result : "; - string result_str = std::to_string(result); - str += result_str; - messageCallback(env,obj,str.c_str()); + threadRun = true; ocProcessThread = thread(ocProcessFunc); return result; } } -JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_OICCoordinatorStop +JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_OICCoordinatorStop (JNIEnv *env, jobject obj) { - messageCallback(env,obj,"OICCoordinatorStop"); jint result = 0; //terminate Thread if (ocProcessThread.joinable()) @@ -95,22 +80,17 @@ JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting } else { - messageCallback(env,obj,"OICCoordinatorStop already terminated"); result = (jint)HOSTING_THREAD_ERROR; return result; } result = (jint)OICStopCoordinate(); - string str = "OICStopCoordinate result : "; - string result_str = std::to_string(result); - str += result_str; - messageCallback(env,obj,str.c_str()); + return result; } -JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_ResourceHostingInit +JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_ResourceHostingInit (JNIEnv *env, jobject obj,jstring j_addr) { - messageCallback(env,obj,"ResourceHostingInit"); const char* addr = env->GetStringUTFChars(j_addr,NULL); if (NULL == j_addr) @@ -118,7 +98,6 @@ JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting if(OCInit(addr,USE_RANDOM_PORT,OC_CLIENT_SERVER)!=OC_STACK_OK) { - messageCallback(env,obj,"OCStack init Error"); return (jint)OCSTACK_ERROR; } @@ -126,14 +105,11 @@ JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting return (jint)OCSTACK_OK; } -JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_ResourceHostingTerminate +JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_ResourceHostingTerminate (JNIEnv *env, jobject obj) { - messageCallback(env,obj,"ResourceHostingTerminate"); if (OCStop() != OC_STACK_OK) { - - messageCallback(env,obj,"OCStack stop error"); return (jint)OCSTACK_ERROR; } //terminate Thread @@ -144,7 +120,6 @@ JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting } else { - messageCallback(env,obj,"The thread may be not running."); return (jint)HOSTING_THREAD_ERROR; } diff --git a/service/notification-manager/NotificationManager/src/resourceCoordinator_JNI.h b/service/notification-manager/NotificationManager/android/resource_hosting/jni/ResourceHosing_JNI.h old mode 100644 new mode 100755 similarity index 64% rename from service/notification-manager/NotificationManager/src/resourceCoordinator_JNI.h rename to service/notification-manager/NotificationManager/android/resource_hosting/jni/ResourceHosing_JNI.h index cce1e35..fc62f94 --- a/service/notification-manager/NotificationManager/src/resourceCoordinator_JNI.h +++ b/service/notification-manager/NotificationManager/android/resource_hosting/jni/ResourceHosing_JNI.h @@ -19,8 +19,8 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#ifndef RESOURCECOORDINATOR_JNI_H_ -#define RESOURCECOORDINATOR_JNI_H_ +#ifndef RESOURCEHOSTING_JNI_H_ +#define RESOURCEHOSTING_JNI_H_ #include #include @@ -39,37 +39,37 @@ extern "C" { #endif /* - * Class: org_iotivity_service_resourcehostingsampleapp_ResourceHosting + * Class: org_iotivity_service_resourcehosting_ResourceHosting * Method: OICCoordinatorStart * Signature: ()V */ -JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_OICCoordinatorStart +JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_OICCoordinatorStart (JNIEnv *, jobject); /* - * @Class: org_iotivity_service_resourcehostingsampleapp_ResourceHosting + * @Class: org_iotivity_service_resourcehosting_ResourceHosting * @Method: OICCoordinatorStop * @Signature: ()V */ -JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_OICCoordinatorStop +JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_OICCoordinatorStop (JNIEnv *, jobject); /* - * Class: org_iotivity_service_resourcehostingsampleapp_ResourceHosting + * Class: org_iotivity_service_resourcehosting_ResourceHosting * Method: ResourceHostingInit * Signature: ()V */ -JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_ResourceHostingInit +JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_ResourceHostingInit (JNIEnv *env, jobject obj,jstring j_addr); /* - * Class: org_iotivity_service_resourcehostingsampleapp_ResourceHosting + * Class: org_iotivity_service_resourcehosting_ResourceHosting * Method: ResourceHostingTerminate * Signature: (Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_ResourceHostingTerminate +JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_ResourceHostingTerminate (JNIEnv *env, jobject obj); #ifdef __cplusplus } #endif -#endif /* RESOURCECOORDINATOR_JNI_H_ */ +#endif /* RESOURCEHOSTING_JNI_H_ */ diff --git a/service/notification-manager/NotificationManager/android/resource_hosting/project.properties b/service/notification-manager/NotificationManager/android/resource_hosting/project.properties new file mode 100755 index 0000000..00cf62b --- /dev/null +++ b/service/notification-manager/NotificationManager/android/resource_hosting/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-22 diff --git a/service/notification-manager/NotificationManager/android/resource_hosting/src/org/iotivity/ResourceHosting/ResourceHosting.java b/service/notification-manager/NotificationManager/android/resource_hosting/src/org/iotivity/ResourceHosting/ResourceHosting.java new file mode 100755 index 0000000..451b773 --- /dev/null +++ b/service/notification-manager/NotificationManager/android/resource_hosting/src/org/iotivity/ResourceHosting/ResourceHosting.java @@ -0,0 +1,88 @@ +//****************************************************************** +// +// Copyright 2015 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +package org.iotivity.ResourceHosting; +import java.lang.System; +import java.lang.String;; +/** + * To execute resource hosting function for android sample application . + * + * @author Copyright 2015 Samsung Electronics All Rights Reserved. + * @see className class : ResourceHosting
+ * + */ + +public class ResourceHosting { + + /** + * jni function - OicCorrdinatorstart() method. + * + * @see Class class : + * org_iotivity_resourcehosting_ResourceHosting
+ * @see Method method : OICCoordinatorStart
+ * @see Signature signature : ()V
+ */ + public native int OICCoordinatorStart(); + + /** + * jni function - OICCoordinatorStop() method. + * + * @see Class class : + * org_iotivity_resourcehosting_ResourceHosting
+ * @see Method method : OICCoordinatorStop
+ * @see signature signature : ()V
+ */ + public native int OICCoordinatorStop(); + + /** + * jni function - ResourceHostingInit() method in order to execute + * OICCoordinatorStart() method. + * + * @see Class class : + * org_iotivity_resourcehosting_ResourceHosting
+ * @see Method method : ResourceHostingInit
+ * @param addr + * ipAddress + * @see signature signature : (Ljava/lang/String;)V
+ */ + public native int ResourceHostingInit(String addr); + + /** + * jni function - ResourceHostingTerminate() method in order to terminate + * resource hosting + * + * @see Class class : + * org_iotivity_resourcehosting_ResourceHosting
+ * @see Method method : ResourceHostingTerminate
+ * @see signature signature : ()V
+ */ + public native int ResourceHostingTerminate(); + + static { + System.loadLibrary("connectivity_abstraction"); + System.loadLibrary("ca-interface"); + System.loadLibrary("oc_logger_core"); + System.loadLibrary("oc_logger"); + System.loadLibrary("octbstack"); + System.loadLibrary("oc"); + System.loadLibrary("ocstack-jni"); + System.loadLibrary("NotificationManager"); + System.loadLibrary("ResourceHosing_JNI"); + } +} diff --git a/service/notification-manager/SConscript b/service/notification-manager/SConscript index 7dc9128..94aa89e 100644 --- a/service/notification-manager/SConscript +++ b/service/notification-manager/SConscript @@ -68,9 +68,6 @@ notimgr_src = [ NOTI_SRC_DIR + 'requestHandler.c', NOTI_SRC_DIR + 'virtualResource.c'] -if target_os == 'android': - notimgr_src.append(NOTI_SRC_DIR + 'resourceCoordinator_JNI.cpp') - if target_os in ['tizen','android'] : notificationsdk = notimgr_env.SharedLibrary('NotificationManager', notimgr_src) else : diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/ic_launcher-web.png b/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/ic_launcher-web.png deleted file mode 100644 index a18cbb4..0000000 Binary files a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/ic_launcher-web.png and /dev/null differ diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/jni/Android.mk b/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/jni/Android.mk deleted file mode 100644 index f2f39d8..0000000 --- a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/jni/Android.mk +++ /dev/null @@ -1,31 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_MODULE := ca -LOCAL_SRC_FILES := ../libs/libconnectivity_abstraction.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := oc_logger_core -LOCAL_SRC_FILES := ../libs/liboc_logger_core.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := oc_logger -LOCAL_SRC_FILES := ../libs/liboc_logger.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := octbstack -LOCAL_SRC_FILES := ../libs/liboctbstack.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := oc -LOCAL_SRC_FILES := ../libs/liboc.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := libNotificationManager -LOCAL_SRC_FILES := ../libs/libNotificationManager.so -include $(PREBUILT_SHARED_LIBRARY) diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/jni/armeabi b/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/jni/armeabi deleted file mode 100644 index a2f1b66..0000000 Binary files a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/jni/armeabi and /dev/null differ diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/AndroidManifest.xml b/service/notification-manager/SampleApp/android/SampleResourceHosting/AndroidManifest.xml old mode 100644 new mode 100755 similarity index 98% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/AndroidManifest.xml rename to service/notification-manager/SampleApp/android/SampleResourceHosting/AndroidManifest.xml index 31ac554..275534b --- a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/AndroidManifest.xml +++ b/service/notification-manager/SampleApp/android/SampleResourceHosting/AndroidManifest.xml @@ -29,7 +29,7 @@ android:label="@string/app_name" android:theme="@style/AppTheme" > diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/project.properties b/service/notification-manager/SampleApp/android/SampleResourceHosting/project.properties old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/project.properties rename to service/notification-manager/SampleApp/android/SampleResourceHosting/project.properties diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/drawable-hdpi/ic_launcher.png b/service/notification-manager/SampleApp/android/SampleResourceHosting/res/drawable-hdpi/ic_launcher.png old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/drawable-hdpi/ic_launcher.png rename to service/notification-manager/SampleApp/android/SampleResourceHosting/res/drawable-hdpi/ic_launcher.png diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/drawable-mdpi/ic_launcher.png b/service/notification-manager/SampleApp/android/SampleResourceHosting/res/drawable-mdpi/ic_launcher.png old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/drawable-mdpi/ic_launcher.png rename to service/notification-manager/SampleApp/android/SampleResourceHosting/res/drawable-mdpi/ic_launcher.png diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/drawable-xhdpi/ic_launcher.png b/service/notification-manager/SampleApp/android/SampleResourceHosting/res/drawable-xhdpi/ic_launcher.png old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/drawable-xhdpi/ic_launcher.png rename to service/notification-manager/SampleApp/android/SampleResourceHosting/res/drawable-xhdpi/ic_launcher.png diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/drawable-xxhdpi/ic_launcher.png b/service/notification-manager/SampleApp/android/SampleResourceHosting/res/drawable-xxhdpi/ic_launcher.png old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/drawable-xxhdpi/ic_launcher.png rename to service/notification-manager/SampleApp/android/SampleResourceHosting/res/drawable-xxhdpi/ic_launcher.png diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/layout/activity_main.xml b/service/notification-manager/SampleApp/android/SampleResourceHosting/res/layout/activity_main.xml old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/layout/activity_main.xml rename to service/notification-manager/SampleApp/android/SampleResourceHosting/res/layout/activity_main.xml diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/values-v11/styles.xml b/service/notification-manager/SampleApp/android/SampleResourceHosting/res/values-v11/styles.xml old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/values-v11/styles.xml rename to service/notification-manager/SampleApp/android/SampleResourceHosting/res/values-v11/styles.xml diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/values-v14/styles.xml b/service/notification-manager/SampleApp/android/SampleResourceHosting/res/values-v14/styles.xml old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/values-v14/styles.xml rename to service/notification-manager/SampleApp/android/SampleResourceHosting/res/values-v14/styles.xml diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/values/strings.xml b/service/notification-manager/SampleApp/android/SampleResourceHosting/res/values/strings.xml old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/values/strings.xml rename to service/notification-manager/SampleApp/android/SampleResourceHosting/res/values/strings.xml diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/values/styles.xml b/service/notification-manager/SampleApp/android/SampleResourceHosting/res/values/styles.xml old mode 100644 new mode 100755 similarity index 100% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/res/values/styles.xml rename to service/notification-manager/SampleApp/android/SampleResourceHosting/res/values/styles.xml diff --git a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/src/com/example/resourcehostingsampleapp/ResourceHosting.java b/service/notification-manager/SampleApp/android/SampleResourceHosting/src/com/example/resourcehostingsampleapp/ResourceHostingSampleApp.java old mode 100644 new mode 100755 similarity index 65% rename from service/notification-manager/SampleApp/android/ResourceHostingSampleApp/src/com/example/resourcehostingsampleapp/ResourceHosting.java rename to service/notification-manager/SampleApp/android/SampleResourceHosting/src/com/example/resourcehostingsampleapp/ResourceHostingSampleApp.java index 219b622..602c9ac --- a/service/notification-manager/SampleApp/android/ResourceHostingSampleApp/src/com/example/resourcehostingsampleapp/ResourceHosting.java +++ b/service/notification-manager/SampleApp/android/SampleResourceHosting/src/com/example/resourcehostingsampleapp/ResourceHostingSampleApp.java @@ -19,12 +19,14 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= package com.example.resourcehostingsampleapp; +import java.lang.reflect.Method; import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; +import org.iotivity.ResourceHosting.ResourceHosting; import org.iotivity.base.ModeType; import org.iotivity.base.OcPlatform; import org.iotivity.base.OcResourceHandle; @@ -47,15 +49,18 @@ import android.widget.Toast; * */ -public class ResourceHosting extends Activity implements OnClickListener +public class ResourceHostingSampleApp extends Activity implements OnClickListener { private final int OCSTACK_OK = 0; private final int OCSTACK_ERROR = 255; private final int RESOURCEHOSTING_DO_NOT_THREADRUNNING = -2; - private final String TAG = "NMResourceHosting : " + this.getClass().getSimpleName(); + private String TAG = "ResourceHosting"; + private OcResourceHandle mResourceHandle; + private String mIpAddress; private TextView mLogTextView; private String mLog = ""; + private ResourceHosting resourceHosting; /** * To initialize UI Function Setting. * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting
@@ -71,7 +76,7 @@ public class ResourceHosting extends Activity implements OnClickListener findViewById(R.id.btLogClear).setOnClickListener(this); PlatformConfig platformConfigObj; - + resourceHosting = new ResourceHosting(); platformConfigObj = new PlatformConfig(this,ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0", 0, QualityOfService.LOW); @@ -89,6 +94,7 @@ public class ResourceHosting extends Activity implements OnClickListener protected void onStart() { super.onStart(); + initOICStack(); } /** @@ -100,6 +106,9 @@ public class ResourceHosting extends Activity implements OnClickListener protected void onStop() { super.onStop(); + int result; + result = resourceHosting.ResourceHostingTerminate(); + Log.d(TAG, "ResourceHostingTerminate : "+ result); } protected void onResume() @@ -116,6 +125,7 @@ public class ResourceHosting extends Activity implements OnClickListener protected void onRestart() { super.onRestart(); + initOICStack(); } /** @@ -125,9 +135,56 @@ public class ResourceHosting extends Activity implements OnClickListener protected void onDestroy() { super.onDestroy(); - int result; - result = OICCoordinatorStop(); - Log.d(TAG, "OICCoordinatorStop() : "+ result); + } + + /** + * get IpAddress and execute resourceHostingInit() method. + * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting
+ * @see Method method : initOICStack
+ */ + private void initOICStack() + { + try + { + mIpAddress = getIpAddress(); + int result = 0; + result = resourceHosting.ResourceHostingInit(mIpAddress); + Log.d(TAG, "ResourceHostingInit : " + result); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /** + * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting
+ * @see Method method : getIpAddress
+ */ + private String getIpAddress() + { + try + { + for (Enumeration en = NetworkInterface.getNetworkInterfaces(); + en.hasMoreElements();) + { + NetworkInterface intf = (NetworkInterface) en.nextElement(); + for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) + { + InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement(); + if (!inetAddress.isLoopbackAddress()) + { + if (inetAddress instanceof Inet4Address) + return inetAddress.getHostAddress().toString(); + } + } + } + } + catch (SocketException e) + { + e.printStackTrace(); + } + return null; } /** @@ -145,94 +202,23 @@ public class ResourceHosting extends Activity implements OnClickListener try { int result; - result = OICCoordinatorStart(); + result = resourceHosting.OICCoordinatorStart(); Log.d(TAG, "OICCoordinatorStart : " + result); } catch (Exception e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); - Log.d(TAG, e.getMessage() + result); } break; case R.id.btnStopHosting: int result; - result = OICCoordinatorStop(); + result = resourceHosting.OICCoordinatorStop(); Log.d(TAG, "OICCoordinatorStop : "+ result); break; case R.id.btLogClear: - clearLog(); default: break; } } - /** - * all clear log view - * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting
- * @see Method method : clearLog
- */ - private void clearLog() - { - mLog = ""; - mLogTextView.setText(mLog); - Log.i(TAG, "Log textbox is cleared"); - } - - /** - * recieve the callback log message. - * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting
- * @see Method method : cbMessage
- * @param msg callback log message - */ - public void cbMessage(String msg) - { - mLog += msg + "\n"; - mLogTextView.setText(mLog); - Log.i(TAG, msg); - } - - /** - * jni function - OicCorrdinatorstart() method. - * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting
- * @see Method method : OICCoordinatorStart
- * @see Signature signature : ()V
- */ - public native int OICCoordinatorStart(); - - /** - * jni function - OICCoordinatorStop() method. - * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting
- * @see Method method : OICCoordinatorStop
- * @see signature signature : ()V
- */ - public native int OICCoordinatorStop(); - - /** - * jni function - ResourceHostingInit() method in order to execute OICCoordinatorStart() method. - * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting
- * @see Method method : ResourceHostingInit
- * @param addr ipAddress - * @see signature signature : (Ljava/lang/String;)V
- */ - public native int ResourceHostingInit(String addr); - - /** - * jni function - ResourceHostingTerminate() method in order to terminate resource hosting - * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting
- * @see Method method : ResourceHostingTerminate
- * @see signature signature : ()V
- */ - public native int ResourceHostingTerminate(); - - static - { - System.loadLibrary("gnustl_shared"); - System.loadLibrary("oc_logger"); - System.loadLibrary("connectivity_abstraction"); - System.loadLibrary("ca-interface"); - System.loadLibrary("octbstack"); - System.loadLibrary("oc"); - System.loadLibrary("ocstack-jni"); - System.loadLibrary("NotificationManager"); - } }