Commit c9f704c8 authored by Jay Sharma's avatar Jay Sharma Committed by Uze Choi

Merging primitive services(TM, SSM and NM) from android-api branch.

Change-Id: Ic94647509c50a44265dca63509f0883e99173f59
Signed-off-by: default avatarJay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1036Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
Tested-by: default avatarUze Choi <uzchoi@samsung.com>
parent a16e6faa
......@@ -55,7 +55,6 @@ if target_os not in ['arduino','darwin','ios', 'android']:
SConscript(build_dir + 'examples/OICMiddle/SConscript')
# Build 'service' sub-project
# if target_os != 'android':
SConscript(build_dir + 'service/SConscript')
# Append targets information to the help information, to see help info, execute command line:
......
......@@ -174,8 +174,10 @@ def __install(ienv, targets, name):
Alias(name, i_n)
env.AppendUnique(TS = [name])
def __append_target(ienv, target):
env.AppendUnique(TS = [target])
def __append_target(ienv, name, targets = None):
if targets:
env.Alias(name, targets)
env.AppendUnique(TS = [name])
def __print_targets(env):
Help('''
......
......@@ -57,6 +57,12 @@ namespace std {
return os.str();
}
std::string to_string(long t) {
std::ostringstream os;
os << t;
return os.str();
}
std::string to_string(double t) {
std::ostringstream os;
os << t;
......
......@@ -15,6 +15,7 @@ namespace std {
long double stold(const string& s);
std::string to_string(int i);
std::string to_string(long t);
std::string to_string(uint32_t i);
std::string to_string(double d);
}
......
......@@ -113,11 +113,11 @@ def __download(ienv, target, url) :
# Install header file(s) to <src_dir>/deps/<target_os>/include
def __install_head_file(ienv, file):
return ienv.Install(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'include'), file)
return ienv.Install(os.path.join(env.get('SRC_DIR'), 'dep', target_os, target_arch, 'usr', 'include'), file)
# Install library binaries to <src_dir>/deps/<target_os>/lib/<arch>
def __install_lib(ienv, lib):
return ienv.Install(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'lib', target_arch), lib)
return ienv.Install(os.path.join(env.get('SRC_DIR'), 'dep', target_os, target_arch, 'usr', 'lib'), lib)
SConscript('tools/UnpackAll.py')
......
......@@ -28,6 +28,7 @@
extern "C" {
#endif // __cplusplus
#define WITH_PRESENCE
#define USE_RANDOM_PORT (0)
//-----------------------------------------------------------------------------
// Function prototypes
......
......@@ -28,8 +28,7 @@ target_os = env.get('TARGET_OS')
if target_os not in ['arduino','darwin']:
# Build things manager project
if target_os != 'android':
SConscript('things-manager/SConscript')
SConscript('things-manager/SConscript')
# Build soft sensor manager project
SConscript('soft-sensor-manager/SConscript')
......
//******************************************************************
//
// 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.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
extern "C" {
#include "hosting.h"
}
#include "resourceCoordinator_JNI.h"
#include "android_cpp11_compat.h"
using namespace std;
atomic_bool threadRun;
thread ocProcessThread;
/*
* To execute OCProcess when threadRun value is only true
*/
void ocProcessFunc()
{
while (threadRun)
{
if (OCProcess() != OC_STACK_OK)
{
//OCProcess ERROR
}
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
(JNIEnv *env, jobject obj)
{
jint result = 0;
if(threadRun==true)
{
messageCallback(env,obj,"already execute OICCoordinatorStart");
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
(JNIEnv *env, jobject obj)
{
messageCallback(env,obj,"OICCoordinatorStop");
jint result = 0;
//terminate Thread
if (ocProcessThread.joinable())
{
threadRun = false;
ocProcessThread.join();
}
else
{
messageCallback(env,obj,"The thread may be not running.");
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
(JNIEnv *env, jobject obj,jstring j_addr)
{
messageCallback(env,obj,"ResourceHostingInit");
const char* addr = env->GetStringUTFChars(j_addr,NULL);
if (NULL == j_addr)
return (jint)OCSTACK_ERROR;
if(OCInit(addr,USE_RANDOM_PORT,OC_CLIENT_SERVER)!=OC_STACK_OK)
{
messageCallback(env,obj,"OCStack init Error");
return (jint)OCSTACK_ERROR;
}
env->ReleaseStringUTFChars(j_addr,addr);
return (jint)OCSTACK_OK;
}
JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_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
if (ocProcessThread.joinable())
{
threadRun = false;
ocProcessThread.join();
}
else
{
messageCallback(env,obj,"The thread may be not running.");
return (jint)HOSTING_THREAD_ERROR;
}
return (jint)OCSTACK_OK;
}
//******************************************************************
//
// 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.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifndef RESOURCECOORDINATOR_JNI_H_
#define RESOURCECOORDINATOR_JNI_H_
#include <jni.h>
#include <thread>
#include <atomic>
#include <unistd.h>
#define TAG "OIC-JNI"
#define JNI_CURRENT_VERSION JNI_VERSION_1_6
#define OCSTACK_OK 0
#define OCSTACK_ERROR 255
#define HOSTING_THREAD_ERROR -2
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_iotivity_service_resourcehostingsampleapp_ResourceHosting
* Method: OICCoordinatorStart
* Signature: ()V
*/
JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_OICCoordinatorStart
(JNIEnv *, jobject);
/*
* @Class: org_iotivity_service_resourcehostingsampleapp_ResourceHosting
* @Method: OICCoordinatorStop
* @Signature: ()V
*/
JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_OICCoordinatorStop
(JNIEnv *, jobject);
/*
* Class: org_iotivity_service_resourcehostingsampleapp_ResourceHosting
* Method: ResourceHostingInit
* Signature: ()V
*/
JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_ResourceHostingInit
(JNIEnv *env, jobject obj,jstring j_addr);
/*
* Class: org_iotivity_service_resourcehostingsampleapp_ResourceHosting
* Method: ResourceHostingTerminate
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting_ResourceHostingTerminate
(JNIEnv *env, jobject obj);
#ifdef __cplusplus
}
#endif
#endif /* RESOURCECOORDINATOR_JNI_H_ */
......@@ -47,14 +47,14 @@ notimgr_env.AppendUnique(CPPPATH = ['../../resource/csdk/logger/include'])
notimgr_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap'])
if target_os not in ['windows', 'winrt']:
notimgr_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0'])
notimgr_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
if target_os == 'linux':
notimgr_env.AppendUnique(LIBS = ['pthread'])
if target_os == 'android':
notimgr_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
notimgr_env.AppendUnique(LIBS = ['gnustl_static'])
notimgr_env.AppendUnique(LIBS = ['gnustl_shared','log'])
if not env.get('RELEASE'):
notimgr_env.AppendUnique(LIBS = ['log'])
......@@ -68,12 +68,15 @@ notimgr_src = [
NOTI_SRC_DIR + 'requestHandler.c',
NOTI_SRC_DIR + 'virtualResource.c']
if target_os in ['tizen'] :
notificationsdk = notimgr_env.SharedLibrary('NOTISDKLibrary', notimgr_src)
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 :
notificationsdk = notimgr_env.StaticLibrary('NOTISDKLibrary', notimgr_src)
notificationsdk = notimgr_env.StaticLibrary('NotificationManager', notimgr_src)
notimgr_env.InstallTarget(notificationsdk, 'libNMSDK')
notimgr_env.InstallTarget(notificationsdk, 'libResouceHosting')
# Go to build sample apps
SConscript('SampleApp/SConscript')
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<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>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ResourceHosting</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.resourcehostingsampleapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET_ACCESS" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="com.samsung.wmanager.ENABLE_NOTIFICATION"/>
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.resourcehostingsampleapp.ResourceHosting"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := coap
LOCAL_SRC_FILES := ../libs/libcoap.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)
# 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-19
//******************************************************************
//
// 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 com.example.resourcehostingsampleapp;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import org.iotivity.base.OcResourceHandle;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
/**
* 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 extends Activity implements OnClickListener
{
private final int OCSTACK_OK = 0;