<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry exported="true" kind="lib" path="C:/Users/jay.sharma/Desktop/master_19_may/iotivity/android/android_api/base/build/intermediates/bundles/release/classes.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
--- /dev/null
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.iotivity.ResourceHosting"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="21" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ </application>
+
+</manifest>
--- /dev/null
+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)
+
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
extern "C" {
#include "hosting.h"
}
-#include "resourceCoordinator_JNI.h"
-#include "android_cpp11_compat.h"
+#include "ResourceHosing_JNI.h"
+#include "OCAndroid.h"
using namespace std;
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())
}
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)
if(OCInit(addr,USE_RANDOM_PORT,OC_CLIENT_SERVER)!=OC_STACK_OK)
{
- messageCallback(env,obj,"OCStack init Error");
return (jint)OCSTACK_ERROR;
}
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
}
else
{
- messageCallback(env,obj,"The thread may be not running.");
return (jint)HOSTING_THREAD_ERROR;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#ifndef RESOURCECOORDINATOR_JNI_H_
-#define RESOURCECOORDINATOR_JNI_H_
+#ifndef RESOURCEHOSTING_JNI_H_
+#define RESOURCEHOSTING_JNI_H_
#include <jni.h>
#include <thread>
#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_ */
--- /dev/null
+# 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
--- /dev/null
+//******************************************************************
+//
+// 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</br>
+ *
+ */
+
+public class ResourceHosting {
+
+ /**
+ * jni function - OicCorrdinatorstart() method.
+ *
+ * @see Class class :
+ * org_iotivity_resourcehosting_ResourceHosting</br>
+ * @see Method method : OICCoordinatorStart</br>
+ * @see Signature signature : ()V</br>
+ */
+ public native int OICCoordinatorStart();
+
+ /**
+ * jni function - OICCoordinatorStop() method.
+ *
+ * @see Class class :
+ * org_iotivity_resourcehosting_ResourceHosting</br>
+ * @see Method method : OICCoordinatorStop</br>
+ * @see signature signature : ()V</br>
+ */
+ public native int OICCoordinatorStop();
+
+ /**
+ * jni function - ResourceHostingInit() method in order to execute
+ * OICCoordinatorStart() method.
+ *
+ * @see Class class :
+ * org_iotivity_resourcehosting_ResourceHosting</br>
+ * @see Method method : ResourceHostingInit</br>
+ * @param addr
+ * ipAddress
+ * @see signature signature : (Ljava/lang/String;)V</br>
+ */
+ public native int ResourceHostingInit(String addr);
+
+ /**
+ * jni function - ResourceHostingTerminate() method in order to terminate
+ * resource hosting
+ *
+ * @see Class class :
+ * org_iotivity_resourcehosting_ResourceHosting</br>
+ * @see Method method : ResourceHostingTerminate</br>
+ * @see signature signature : ()V</br>
+ */
+ 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");
+ }
+}
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 :
+++ /dev/null
-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)
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
- android:name="com.example.resourcehostingsampleapp.ResourceHosting"
+ android:name="com.example.resourcehostingsampleapp.ResourceHostingSampleApp"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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;
*
*/
-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</br>
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);
protected void onStart()
{
super.onStart();
+ initOICStack();
}
/**
protected void onStop()
{
super.onStop();
+ int result;
+ result = resourceHosting.ResourceHostingTerminate();
+ Log.d(TAG, "ResourceHostingTerminate : "+ result);
}
protected void onResume()
protected void onRestart()
{
super.onRestart();
+ initOICStack();
}
/**
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</br>
+ * @see Method method : initOICStack</br>
+ */
+ 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</br>
+ * @see Method method : getIpAddress</br>
+ */
+ private String getIpAddress()
+ {
+ try
+ {
+ for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
+ en.hasMoreElements();)
+ {
+ NetworkInterface intf = (NetworkInterface) en.nextElement();
+ for (Enumeration<InetAddress> 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;
}
/**
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</br>
- * @see Method method : clearLog</br>
- */
- 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</br>
- * @see Method method : cbMessage</br>
- * @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</br>
- * @see Method method : OICCoordinatorStart</br>
- * @see Signature signature : ()V</br>
- */
- public native int OICCoordinatorStart();
-
- /**
- * jni function - OICCoordinatorStop() method.
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : OICCoordinatorStop</br>
- * @see signature signature : ()V</br>
- */
- public native int OICCoordinatorStop();
-
- /**
- * jni function - ResourceHostingInit() method in order to execute OICCoordinatorStart() method.
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : ResourceHostingInit</br>
- * @param addr ipAddress
- * @see signature signature : (Ljava/lang/String;)V</br>
- */
- public native int ResourceHostingInit(String addr);
-
- /**
- * jni function - ResourceHostingTerminate() method in order to terminate resource hosting
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : ResourceHostingTerminate</br>
- * @see signature signature : ()V</br>
- */
- 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");
- }
}