Android SDK - Initial commit and build system updates
authorPatrick C Lankswert <patrick.lankswert@intel.com>
Sun, 28 Dec 2014 05:15:52 +0000 (00:15 -0500)
committerPatrick C Lankswert <patrick.lankswert@intel.com>
Tue, 30 Dec 2014 01:22:36 +0000 (20:22 -0500)
This commit add makes the auto_build process more complete by
adding the following:

1) Auto build now always performs the dependency check
2) Auto build now always attempts to build the Android stack artifacts.
3) Transitioned the Android build process to the v4.9 tool chain
4) Android build now depends on the internal boost dependencies
5) Add an Android compatibility layer for the code that is using
   the C++ 11 basic string functions with is not supported in the
   Android toolchain yet.
6) Added static libraries to many of the shared libraries for the
   Android SDK

NOTE:
a) This commit conflicts with the work that Caiwen was making in the
   C++11 basic_string function compatibility. I will close with him.
b) Expat is needed by the protocol plug in manager for Android.
   This still needs to be closed by release. The PPM build for
   Android under SCONS is currently disabled.

This is the Android SDK client API.
Validation has not been completed. However, this is all new
functionality and does not have any negative impact on any
existing features. Until validation is completed this
functionality should be considered experimental.

This code based currently uses gradle to build the SDK.
It does require that the Android libraries for IoTivity
be built previously using the appropriate SCONS scripts.

This additional patch attempts to transition the boost
build to using git instead of a download in hopes that
the build machine will be happier about it.

Final patch makes Android build optional in auto_build

Another patch to add support for 64-bit hosts

Another patch set to reduce parallel builds to 4

Another patch to add licensing header to two files that we missing
in gerrit review #72

Change-Id: I9695ebf3ea271ec28b69a4fcec509a6c2b7c46a4
Signed-off-by: Patrick Lankswert <patrick.lankswert@intel.com>
88 files changed:
android/Base/app/build.gradle [new file with mode: 0644]
android/Base/app/jni/Android.mk [new file with mode: 0644]
android/Base/app/jni/Application.mk [new file with mode: 0644]
android/Base/app/jni/ocheaderoption-jni.cpp [new file with mode: 0644]
android/Base/app/jni/ocplatform-jni.cpp [new file with mode: 0644]
android/Base/app/jni/ocrepresentation-jni.cpp [new file with mode: 0644]
android/Base/app/jni/ocresource-jni.cpp [new file with mode: 0644]
android/Base/app/jni/ocstack-jni.cpp [new file with mode: 0644]
android/Base/app/jni/ocstack-jni.h [new file with mode: 0644]
android/Base/app/jni/platformcfg-jni.cpp [new file with mode: 0644]
android/Base/app/proguard-rules.pro [new file with mode: 0644]
android/Base/app/src/androidTest/java/org/iotivity/base/ApplicationTest.java [new file with mode: 0644]
android/Base/app/src/main/AndroidManifest.xml [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/AbstractDeleteCallback.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/AbstractFindCallback.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/AbstractGetCallback.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/AbstractObserveCallback.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/AbstractPostCallback.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/AbstractPutCallback.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/AbstractSubscriberCallback.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/EntityHandler.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/NativeInstance.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/OCHeaderOption.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/OCPlatform.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/OCRepresentation.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/OCResource.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/OCResourceRequest.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/OCResourceResponse.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/OCStackResult.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/ObserveType.java [new file with mode: 0644]
android/Base/app/src/main/java/org/iotivity/base/PlatformConfig.java [new file with mode: 0755]
android/Base/app/src/main/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
android/Base/app/src/main/res/drawable-mdpi/ic_launcher.png [new file with mode: 0644]
android/Base/app/src/main/res/drawable-xhdpi/ic_launcher.png [new file with mode: 0644]
android/Base/app/src/main/res/drawable-xxhdpi/ic_launcher.png [new file with mode: 0644]
android/Base/app/src/main/res/values/strings.xml [new file with mode: 0644]
android/Base/app/src/main/res/values/styles.xml [new file with mode: 0644]
android/Base/build.gradle [new file with mode: 0644]
android/Base/gradle.properties [new file with mode: 0644]
android/Base/gradlew [new file with mode: 0755]
android/Base/gradlew.bat [new file with mode: 0644]
android/Base/settings.gradle [new file with mode: 0644]
android/SimpleClient/app/build.gradle [new file with mode: 0644]
android/SimpleClient/app/proguard-rules.pro [new file with mode: 0644]
android/SimpleClient/app/src/androidTest/java/org/iotivity/simpleclient/ApplicationTest.java [new file with mode: 0644]
android/SimpleClient/app/src/main/AndroidManifest.xml [new file with mode: 0644]
android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/FoundResource.java [new file with mode: 0644]
android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnGet.java [new file with mode: 0644]
android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnObserve.java [new file with mode: 0644]
android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnPost.java [new file with mode: 0644]
android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnPost2.java [new file with mode: 0644]
android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnPut.java [new file with mode: 0644]
android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/SimpleClient.java [new file with mode: 0644]
android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/SimpleToast.java [new file with mode: 0644]
android/SimpleClient/app/src/main/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
android/SimpleClient/app/src/main/res/drawable-mdpi/ic_launcher.png [new file with mode: 0644]
android/SimpleClient/app/src/main/res/drawable-xhdpi/ic_launcher.png [new file with mode: 0644]
android/SimpleClient/app/src/main/res/drawable-xxhdpi/ic_launcher.png [new file with mode: 0644]
android/SimpleClient/app/src/main/res/layout/activity_simple_client.xml [new file with mode: 0644]
android/SimpleClient/app/src/main/res/menu/simple_client.xml [new file with mode: 0644]
android/SimpleClient/app/src/main/res/values-w820dp/dimens.xml [new file with mode: 0644]
android/SimpleClient/app/src/main/res/values/dimens.xml [new file with mode: 0644]
android/SimpleClient/app/src/main/res/values/strings.xml [new file with mode: 0644]
android/SimpleClient/app/src/main/res/values/styles.xml [new file with mode: 0644]
android/SimpleClient/build.gradle [new file with mode: 0644]
android/SimpleClient/gradle.properties [new file with mode: 0644]
android/SimpleClient/gradlew [new file with mode: 0755]
android/SimpleClient/gradlew.bat [new file with mode: 0644]
android/SimpleClient/settings.gradle [new file with mode: 0644]
auto_build.sh
build_common/android/SConscript
extlibs/buildDependencies.sh
resource/SConscript
resource/android/OCAndroid.cpp [new file with mode: 0644]
resource/android/SConscript [new file with mode: 0644]
resource/csdk/SConscript
resource/csdk/libcoap-4.1.1/SConscript
resource/examples/ocicuc/SConscript
resource/include/OCAndroid.h [new file with mode: 0644]
resource/include/OCRepresentation.h
resource/oc_logger/SConscript
resource/patches/boost/arm-linux-androideabi/user-config.jam [moved from resource/patches/user-config-arm-linux-androideabi.jam with 100% similarity]
resource/patches/boost/x86/user-config.jam [moved from resource/patches/user-config-x86.jam with 100% similarity]
resource/src/OCRepresentation.cpp
resource/src/SConscript
service/SConscript
service/soft-sensor-manager/SConscript
service/soft-sensor-manager/SoftSensorPlugin/DiscomfortIndexSensor/src/DiscomfortIndexSensor.cpp

diff --git a/android/Base/app/build.gradle b/android/Base/app/build.gradle
new file mode 100644 (file)
index 0000000..31d66bb
--- /dev/null
@@ -0,0 +1,60 @@
+apply plugin: 'com.android.library'
+
+android {
+    compileSdkVersion 19
+    buildToolsVersion "19.1.0"
+
+    defaultConfig {
+        applicationId "org.iotivity.base"
+        minSdkVersion 19
+        targetSdkVersion 19
+        versionCode 1
+        versionName "1.0"
+    }
+    buildTypes {
+        release {
+            runProguard false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+}
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+}
+
+
+//////////////
+// NDK Support
+//////////////
+// If using this, Android studio will fail run the following to set the environment variable for android studio:
+// launchctl setenv ANDROID_NDK_HOME /Users/boos_patrick/Development/Android/android-ndk-r8e
+// otherwise remove the dependsOn part and run ./gradlew buildNative from the command line
+task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
+    dependsOn 'buildNative'
+    from(new File('libs')) { include '**/*.so' }
+    into new File(buildDir, 'native-libs')
+}
+
+tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }
+
+clean.dependsOn 'cleanCopyNativeLibs'
+
+tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
+    pkgTask.jniFolders = new HashSet<File>()
+    pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
+}
+
+task buildNative(type: Exec) {
+    if (System.env.ANDROID_NDK_HOME != null) {
+        def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
+        commandLine ndkBuild
+    } else {
+        doLast {
+            println '##################'
+            println 'Skipping NDK build'
+            println 'Reason: ANDROID_NDK_HOME not set.'
+            println '##################'
+        }
+    }
+}
diff --git a/android/Base/app/jni/Android.mk b/android/Base/app/jni/Android.mk
new file mode 100644 (file)
index 0000000..58e9a36
--- /dev/null
@@ -0,0 +1,57 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := libandroid-oc_logger
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboc_logger.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := libandroid-octbstack
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboctbstack.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := libandroid-oc
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboc.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := libandroid-coap
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libcoap.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := libandroid-compatibility
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libcompatibility.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_SRC_PATH := ../../../resource
+OIC_OUT_PATH := ../../../out
+LOCAL_MODULE    := ocstack-jni
+LOCAL_SRC_FILES := ocstack-jni.cpp \
+                   ocheaderoption-jni.cpp \
+                   ocrepresentation-jni.cpp \
+                   ocresource-jni.cpp \
+                   ocplatform-jni.cpp \
+                   platformcfg-jni.cpp
+LOCAL_LDLIBS := -llog
+LOCAL_STATIC_LIBRARIES := android-oc
+LOCAL_STATIC_LIBRARIES += android-octbstack
+LOCAL_STATIC_LIBRARIES += android-coap
+LOCAL_STATIC_LIBRARIES += android-oc_logger
+LOCAL_STATIC_LIBRARIES += libandroid-compatibility
+LOCAL_CPPFLAGS += -std=c++0x -frtti -fexceptions
+LOCAL_C_INCLUDES := $(OIC_SRC_PATH)/include
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/stack/include
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/ocsocket/include
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/oc_logger/include
+LOCAL_C_INCLUDES += $(OIC_OUT_PATH)/android/include
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/dependencies/cereal/include
+include $(BUILD_SHARED_LIBRARY)
+
diff --git a/android/Base/app/jni/Application.mk b/android/Base/app/jni/Application.mk
new file mode 100644 (file)
index 0000000..4450fdf
--- /dev/null
@@ -0,0 +1,2 @@
+NDK_TOOLCHAIN_VERSION := 4.9
+APP_STL               := gnustl_static
diff --git a/android/Base/app/jni/ocheaderoption-jni.cpp b/android/Base/app/jni/ocheaderoption-jni.cpp
new file mode 100644 (file)
index 0000000..7dcd320
--- /dev/null
@@ -0,0 +1,44 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "ocstack-jni.h"
+
+static const char* TAG = "OCHEADEROPTION-JNI";
+
+JNIEXPORT jint JNICALL getOptionID(JNIEnv *env, jobject jobj)
+{
+    OC::HeaderOption::OCHeaderOption *option = getHandle<OC::HeaderOption::OCHeaderOption>(env, jobj);
+    return option->getOptionID();
+}
+
+JNIEXPORT jstring JNICALL getOptionData(JNIEnv *env, jobject jobj)
+{
+    OC::HeaderOption::OCHeaderOption *option = getHandle<OC::HeaderOption::OCHeaderOption>(env, jobj);
+    std::string data = option->getOptionData();
+    return env->NewStringUTF(data.c_str());
+}
+
+JNIEXPORT jlong JNICALL OCHeaderOptionConstructor(JNIEnv *env, jobject jobj, jint joption, jstring jdata)
+{
+    OC::HeaderOption::OCHeaderOption *option = new OC::HeaderOption::OCHeaderOption(joption, env->GetStringUTFChars(jdata, 0));
+    jlong instptr = reinterpret_cast<jlong>(option);
+    return instptr;
+}
+
diff --git a/android/Base/app/jni/ocplatform-jni.cpp b/android/Base/app/jni/ocplatform-jni.cpp
new file mode 100644 (file)
index 0000000..a69ac2d
--- /dev/null
@@ -0,0 +1,124 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "ocstack-jni.h"
+
+static const char* TAG = "OCPLATFORM-JNI";
+
+JNIEXPORT void JNICALL configure(JNIEnv *env, jobject obj, jobject jcfg)
+{
+    OC::PlatformConfig *cfg = getHandle<OC::PlatformConfig>(env, jcfg);
+
+    __android_log_print(ANDROID_LOG_INFO, TAG, "service : %d\n", (int) cfg->serviceType);
+    __android_log_print(ANDROID_LOG_INFO, TAG, "mode    : %d\n", (int) cfg->mode);
+    __android_log_print(ANDROID_LOG_INFO, TAG, "IP      : %s\n", (cfg->ipAddress).c_str());
+    __android_log_print(ANDROID_LOG_INFO, TAG, "port    : %d\n", cfg->port);
+    __android_log_print(ANDROID_LOG_INFO, TAG, "QOS     : %d\n", (int) cfg->QoS);
+
+    OC::OCPlatform::Configure(*cfg);
+}
+
+
+JNIEXPORT jint JNICALL findResource(JNIEnv* env, jobject obj, jstring jhost, jstring juri, jobject found)
+{
+       string host = env->GetStringUTFChars(jhost,0);
+       string uri = env->GetStringUTFChars(juri,0);
+
+    JNICallBackContext *callbackContext;
+    string key = uri + "/FIND";
+    std:map<std::string, JNICallBackContext*>::iterator iter = gJNICallBackContextList.find(key);
+    if(iter == gJNICallBackContextList.end()) {
+        gJNICallBackContextList[key] = new JNICallBackContext(env->NewGlobalRef(found));
+        callbackContext = gJNICallBackContextList[key];
+        __android_log_print(ANDROID_LOG_INFO, TAG, "Adding %s to gJNICallBackContextList", key.c_str());
+    }
+    else
+        callbackContext = iter->second;
+
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "Calling oic base findresource()\n");
+    try {
+        OC::OCPlatform::findResource(host, uri,
+            [callbackContext](std::shared_ptr<OC::OCResource> resource)
+            {
+                 JNIEnv * env;
+
+                // Attach to JavaVM
+                // double check it's all ok
+                int getEnvStat = g_JavaVM->GetEnv((void **)&env, JNI_VERSION_1_6);
+                if (getEnvStat == JNI_EDETACHED) {
+                    __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: not attached");
+                    if (g_JavaVM->AttachCurrentThread(&env, NULL) != 0) {
+                    __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to attach");
+                    }
+                    else
+                        __android_log_print(ANDROID_LOG_INFO, TAG, "Attached OK");
+                } else if (getEnvStat == JNI_OK) {
+                //
+                } else if (getEnvStat == JNI_EVERSION) {
+                    __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: version not supported");
+                }
+
+                // save the C++ resource ptr now
+                jmethodID resource_constructor = env->GetMethodID(g_ocresource_clazz, "<init>", "(J)V");
+
+                callbackContext->m_resource = resource;
+                jobject jresource = env->NewObject(g_ocresource_clazz, resource_constructor, \
+                                        (jlong) reinterpret_cast<jlong>(&callbackContext->m_resource));
+
+                if(jresource == NULL) {
+                    __android_log_print(ANDROID_LOG_ERROR, TAG, "cannot create OCResource class");
+                    return;
+                }
+
+                jclass clazz = env->GetObjectClass(callbackContext->m_callBackFunction);
+                if (clazz == NULL) {
+                    __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to find class");
+                }
+
+                // Find Callback function
+                jmethodID mid = env->GetMethodID(clazz, "Callback", \
+                        "(Lorg/iotivity/base/OCResource;)V");
+                if(mid == NULL) {
+                    __android_log_print(ANDROID_LOG_ERROR, TAG, "FoundResource.Callback() is not defined in JAVA");
+                    return;
+                }
+
+                __android_log_print(ANDROID_LOG_INFO, TAG, "calling JAVA FindCallback");
+                try {
+                    env->CallVoidMethod(callbackContext->m_callBackFunction, mid, jresource);
+                } catch(OC::OCException& e) {
+                    __android_log_print(ANDROID_LOG_ERROR, TAG, "callbackContext() exception : %s", e.reason(e).c_str());
+                }
+
+                __android_log_print(ANDROID_LOG_INFO, TAG, "fineResourceCB detach");
+                env->DeleteLocalRef(jresource);
+                g_JavaVM->DetachCurrentThread();
+
+            }
+        );
+    }
+    catch(OC::OCException& e) {
+        __android_log_print(ANDROID_LOG_ERROR, TAG, "FindCB() exception : %s", e.reason(e).c_str());
+    }
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "Called oic base findresource()\n");
+
+    return 0;
+}
+
diff --git a/android/Base/app/jni/ocrepresentation-jni.cpp b/android/Base/app/jni/ocrepresentation-jni.cpp
new file mode 100644 (file)
index 0000000..d7c894d
--- /dev/null
@@ -0,0 +1,101 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "ocstack-jni.h"
+
+static const char* TAG = "OCREPRESENTATION-JNI";
+
+JNIEXPORT jlong JNICALL OCRepresentationConstructor(JNIEnv *env, jobject jobj)
+{
+    OC::OCRepresentation *rep = new OC::OCRepresentation();
+    jlong instptr = reinterpret_cast<jlong>(rep);
+    return instptr;
+}
+
+JNIEXPORT jstring JNICALL getUri(JNIEnv *env, jobject jobj)
+{
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
+    string uri = rep->getUri();
+    __android_log_print(ANDROID_LOG_INFO, TAG, "getUri() URI : %s", uri.c_str());
+    return env->NewStringUTF(uri.c_str());
+}
+
+JNIEXPORT jint JNICALL getValueInt(JNIEnv *env, jobject jobj, jstring jstr)
+{
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
+       string str = env->GetStringUTFChars(jstr,0);
+       int val;
+    rep->getValue(str, val);
+    __android_log_print(ANDROID_LOG_INFO, TAG, "getValueInt() : %d", val);
+    return((jint) val);
+}
+
+
+JNIEXPORT jboolean JNICALL getValueBool(JNIEnv *env, jobject jobj, jstring jstr)
+{
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
+       string str = env->GetStringUTFChars(jstr,0);
+    bool val;
+    rep->getValue(str, val);
+    __android_log_print(ANDROID_LOG_INFO, TAG, "getValueBool() : %d", val);
+    return((jboolean) val);
+}
+
+JNIEXPORT jstring JNICALL getValueString(JNIEnv *env, jobject jobj, jstring jstr)
+{
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
+       string str = env->GetStringUTFChars(jstr,0);
+       string get_val;
+    rep->getValue(str, get_val);
+
+    __android_log_print(ANDROID_LOG_INFO, TAG, "getValueString() : %s", get_val.c_str());
+    return env->NewStringUTF(get_val.c_str());
+}
+
+JNIEXPORT void JNICALL setValueInt(JNIEnv *env, jobject jobj, jstring jstr, jint jval)
+{
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
+       string str = env->GetStringUTFChars(jstr,0);
+    rep->setValue(str, jval);
+}
+
+JNIEXPORT void JNICALL setValueBool(JNIEnv *env, jobject jobj, jstring jstr, jboolean jval)
+{
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
+       string str = env->GetStringUTFChars(jstr,0);
+    rep->setValue(str, (bool) jval);
+}
+
+JNIEXPORT void JNICALL setValueString(JNIEnv *env, jobject jobj, jstring jstr, jstring jval)
+{
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
+       string str = env->GetStringUTFChars(jstr,0);
+       string val = env->GetStringUTFChars(jval,0);
+
+    rep->setValue(str, val);
+}
+
+JNIEXPORT jboolean JNICALL hasAttribute(JNIEnv *env, jobject jobj, jstring jstr)
+{
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
+       string str = env->GetStringUTFChars(jstr,0);
+
+    return rep->hasAttribute(str);
+}
diff --git a/android/Base/app/jni/ocresource-jni.cpp b/android/Base/app/jni/ocresource-jni.cpp
new file mode 100644 (file)
index 0000000..95c2c39
--- /dev/null
@@ -0,0 +1,445 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "ocstack-jni.h"
+
+static const char* TAG = "OCRESOURCE-JNI";
+
+JNIEXPORT jobject JNICALL jniOicGet(JNIEnv *env, jobject jobj, jobject jattributeHandler)
+{
+
+    std::shared_ptr<OC::OCResource> *resource = getHandle<std::shared_ptr<OC::OCResource>>(env, jobj);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "get() resource = %p\n", resource);
+
+    JNICallBackContext *callbackContext;
+    string key = (*resource)->uri() + "/GET";
+    std:map<std::string, JNICallBackContext*>::iterator iter = gJNICallBackContextList.find(key);
+    if(iter == gJNICallBackContextList.end()) {
+        gJNICallBackContextList[key] = new JNICallBackContext(*resource, env->NewGlobalRef(jattributeHandler));
+        callbackContext = gJNICallBackContextList[key];
+        __android_log_print(ANDROID_LOG_INFO, TAG, "Adding %s to gJNICallBackContextList", key.c_str());
+    }
+    else {
+        iter->second->m_callBackFunction = env->NewGlobalRef(jattributeHandler);
+        callbackContext = iter->second;
+    }
+
+       OC::QueryParamsMap test;
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "calling oic base get()\n");
+
+    (*resource)->get(test,
+        [callbackContext](const OC::HeaderOptions& headerOptions, const OC::OCRepresentation& rep, const int eCode)
+        {
+             JNIEnv * env;
+
+            // Attach to JavaVM
+            // double check it's all ok
+            int getEnvStat = g_JavaVM->GetEnv((void **)&env, JNI_VERSION_1_6);
+            if (getEnvStat == JNI_EDETACHED) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: not attached");
+                if (g_JavaVM->AttachCurrentThread(&env, NULL) != 0) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to attach");
+                }
+                else
+                    __android_log_print(ANDROID_LOG_INFO, TAG, "Attached OK");
+            } else if (getEnvStat == JNI_OK) {
+            //
+            } else if (getEnvStat == JNI_EVERSION) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: version not supported");
+            }
+
+            // save C++ ocheaderoption ptr now
+            jmethodID option_constructor = env->GetMethodID(g_ocheaderoption_clazz, "<init>", "(J)V");
+            int size = headerOptions.size();
+            jobjectArray joptions = env->NewObjectArray(size, g_ocheaderoption_clazz, 0);
+            for (int n=0; n<size;n++) {
+                jobject jelem = env->NewObject(g_ocheaderoption_clazz, option_constructor, \
+                                            (jlong) reinterpret_cast<jlong>(&headerOptions[n]));
+
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "jelem : %llu",  (jlong) reinterpret_cast<jlong>(&headerOptions[n]));
+
+                env->SetObjectArrayElement(joptions, n, jelem);
+                env->DeleteLocalRef(jelem);
+            }
+
+            // save C++ ocrepresentation ptr now
+            jmethodID representation_constructor = env->GetMethodID(g_ocrepresentation_clazz, "<init>", "(J)V");
+            jobject jrepresentation = env->NewObject(g_ocrepresentation_clazz, representation_constructor, \
+                                    (jlong) reinterpret_cast<jlong>(&rep));
+            if(jrepresentation == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "cannot create OCRepresentation class");
+                return;
+            }
+
+            jclass cb_clazz = env->GetObjectClass(callbackContext->m_callBackFunction);
+            if (cb_clazz == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to find class");
+            }
+
+            // Find Callback function
+            jmethodID cb_mid = env->GetMethodID(cb_clazz, "Callback", \
+                    "([Lorg/iotivity/base/OCHeaderOption;Lorg/iotivity/base/OCRepresentation;I)V");
+            if(cb_mid == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "onGet.Callback() is not defined in JAVA");
+                return;
+            }
+
+            __android_log_print(ANDROID_LOG_INFO, TAG, "calling JAVA GetCallback");
+            env->CallVoidMethod(callbackContext->m_callBackFunction, cb_mid, joptions, jrepresentation, eCode);
+
+            __android_log_print(ANDROID_LOG_INFO, TAG, "getCB detach");
+            g_JavaVM->DetachCurrentThread();
+
+        }
+        );
+    return NULL;
+
+}
+
+JNIEXPORT jobject JNICALL jniOicPut(JNIEnv *env, jobject jobj, jobject jocrepresentation, jobject jattributeHandler)
+{
+    std::shared_ptr<OC::OCResource> *resource = getHandle<std::shared_ptr<OC::OCResource>>(env, jobj);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "put1() resource = %p\n", resource);
+
+    JNICallBackContext *callbackContext;
+    string key = (*resource)->uri() + "/PUT";
+    std:map<std::string, JNICallBackContext*>::iterator iter = gJNICallBackContextList.find(key);
+    if(iter == gJNICallBackContextList.end()) {
+        gJNICallBackContextList[key] = new JNICallBackContext(*resource, env->NewGlobalRef(jattributeHandler));
+        callbackContext = gJNICallBackContextList[key];
+        __android_log_print(ANDROID_LOG_INFO, TAG, "Adding %s to gJNICallBackContextList", key.c_str());
+    }
+    else {
+        iter->second->m_callBackFunction = env->NewGlobalRef(jattributeHandler);
+        callbackContext = iter->second;
+    }
+
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jocrepresentation);
+       OC::QueryParamsMap test;
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "calling oic base put()\n");
+
+    (*resource)->put(*rep, test,
+        [callbackContext](const OC::HeaderOptions& headerOptions, const OC::OCRepresentation& rep, const int eCode)
+        {
+             JNIEnv * env;
+
+            // Attach to JavaVM
+            // double check it's all ok
+            int getEnvStat = g_JavaVM->GetEnv((void **)&env, JNI_VERSION_1_6);
+            if (getEnvStat == JNI_EDETACHED) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: not attached");
+                if (g_JavaVM->AttachCurrentThread(&env, NULL) != 0) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to attach");
+                }
+                else
+                    __android_log_print(ANDROID_LOG_INFO, TAG, "Attached OK");
+            } else if (getEnvStat == JNI_OK) {
+            //
+            } else if (getEnvStat == JNI_EVERSION) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: version not supported");
+            }
+
+            // save C++ ocheaderoption ptr now
+            jmethodID option_constructor = env->GetMethodID(g_ocheaderoption_clazz, "<init>", "(J)V");
+            int size = headerOptions.size();
+            jobjectArray joptions = env->NewObjectArray(size, g_ocheaderoption_clazz, 0);
+            for (int n=0; n<size;n++) {
+                jobject jelem = env->NewObject(g_ocheaderoption_clazz, option_constructor, \
+                                            (jlong) reinterpret_cast<jlong>(&headerOptions[n]));
+
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "jelem : %llu",  (jlong) reinterpret_cast<jlong>(&headerOptions[n]));
+
+                env->SetObjectArrayElement(joptions, n, jelem);
+                env->DeleteLocalRef(jelem);
+            }
+
+            // save C++ ocrepresentation ptr now
+            jmethodID representation_constructor = env->GetMethodID(g_ocrepresentation_clazz, "<init>", "(J)V");
+            jobject jrepresentation = env->NewObject(g_ocrepresentation_clazz, representation_constructor, \
+                                    (jlong) reinterpret_cast<jlong>(&rep));
+            if(jrepresentation == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "cannot create OCRepresentation class");
+                return;
+            }
+
+            jclass cb_clazz = env->GetObjectClass(callbackContext->m_callBackFunction);
+            if (cb_clazz == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to find class");
+            }
+
+            // Find Callback function
+            jmethodID cb_mid = env->GetMethodID(cb_clazz, "Callback", \
+                    "([Lorg/iotivity/base/OCHeaderOption;Lorg/iotivity/base/OCRepresentation;I)V");
+            if(cb_mid == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "onPut.Callback() is not defined in JAVA");
+                return;
+            }
+
+            __android_log_print(ANDROID_LOG_INFO, TAG, "calling JAVA PutCallback");
+            env->CallVoidMethod(callbackContext->m_callBackFunction, cb_mid, joptions, jrepresentation, eCode);
+
+            __android_log_print(ANDROID_LOG_INFO, TAG, "putCB detach");
+            g_JavaVM->DetachCurrentThread();
+        }
+        );
+    return NULL;
+}
+
+JNIEXPORT jobject JNICALL jniOicPost(JNIEnv *env, jobject jobj, jobject jocrepresentation, jobject jattributeHandler)
+{
+    std::shared_ptr<OC::OCResource> *resource = getHandle<std::shared_ptr<OC::OCResource>>(env, jobj);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "post1() resource = %p\n", resource);
+
+    JNICallBackContext *callbackContext;
+    string key = (*resource)->uri() + "/POST";
+    std:map<std::string, JNICallBackContext*>::iterator iter = gJNICallBackContextList.find(key);
+    if(iter == gJNICallBackContextList.end()) {
+        gJNICallBackContextList[key] = new JNICallBackContext(*resource, env->NewGlobalRef(jattributeHandler));
+        callbackContext = gJNICallBackContextList[key];
+        __android_log_print(ANDROID_LOG_INFO, TAG, "Adding %s to gJNICallBackContextList", key.c_str());
+    }
+    else {
+        iter->second->m_callBackFunction = env->NewGlobalRef(jattributeHandler);
+        callbackContext = iter->second;
+    }
+
+    OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jocrepresentation);
+       OC::QueryParamsMap test;
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "calling oic base post()\n");
+
+    (*resource)->post(*rep, test,
+        [callbackContext](const OC::HeaderOptions& headerOptions, const OC::OCRepresentation& rep, const int eCode)
+        {
+             JNIEnv * env;
+
+            // Attach to JavaVM
+            // double check it's all ok
+            int getEnvStat = g_JavaVM->GetEnv((void **)&env, JNI_VERSION_1_6);
+            if (getEnvStat == JNI_EDETACHED) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: not attached");
+                if (g_JavaVM->AttachCurrentThread(&env, NULL) != 0) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to attach");
+                }
+                else
+                    __android_log_print(ANDROID_LOG_INFO, TAG, "Attached OK");
+            } else if (getEnvStat == JNI_OK) {
+            //
+            } else if (getEnvStat == JNI_EVERSION) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: version not supported");
+            }
+
+            // save C++ ocheaderoption ptr now
+            jmethodID option_constructor = env->GetMethodID(g_ocheaderoption_clazz, "<init>", "(J)V");
+            int size = headerOptions.size();
+            jobjectArray joptions = env->NewObjectArray(size, g_ocheaderoption_clazz, 0);
+            for (int n=0; n<size;n++) {
+                jobject jelem = env->NewObject(g_ocheaderoption_clazz, option_constructor, \
+                                            (jlong) reinterpret_cast<jlong>(&headerOptions[n]));
+
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "jelem : %llu",  (jlong) reinterpret_cast<jlong>(&headerOptions[n]));
+
+                env->SetObjectArrayElement(joptions, n, jelem);
+                env->DeleteLocalRef(jelem);
+            }
+
+            // save C++ ocrepresentation ptr now
+            jmethodID representation_constructor = env->GetMethodID(g_ocrepresentation_clazz, "<init>", "(J)V");
+            jobject jrepresentation = env->NewObject(g_ocrepresentation_clazz, representation_constructor, \
+                                    (jlong) reinterpret_cast<jlong>(&rep));
+            if(jrepresentation == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "cannot create OCRepresentation class");
+                return;
+            }
+
+            jclass cb_clazz = env->GetObjectClass(callbackContext->m_callBackFunction);
+            if (cb_clazz == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to find class");
+            }
+
+            // Find Callback function
+            jmethodID cb_mid = env->GetMethodID(cb_clazz, "Callback", \
+                    "([Lorg/iotivity/base/OCHeaderOption;Lorg/iotivity/base/OCRepresentation;I)V");
+            if(cb_mid == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "onPost.Callback() is not defined in JAVA");
+                return;
+            }
+
+            __android_log_print(ANDROID_LOG_INFO, TAG, "calling JAVA PostCallback");
+            env->CallVoidMethod(callbackContext->m_callBackFunction, cb_mid, joptions, jrepresentation, eCode);
+
+            __android_log_print(ANDROID_LOG_INFO, TAG, "postCB detach");
+            g_JavaVM->DetachCurrentThread();
+
+            }
+    );
+    return NULL;
+}
+
+JNIEXPORT jobject JNICALL jniOicObserve(JNIEnv *env, jobject jobj, jint jobservetype, jobject jattributeHandler)
+{
+    std::shared_ptr<OC::OCResource> *resource = getHandle<std::shared_ptr<OC::OCResource>>(env, jobj);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "observe1() resource = %p\n", resource);
+
+    JNICallBackContext *callbackContext;
+    string key = (*resource)->uri() + "/OBSERVE";
+    std:map<std::string, JNICallBackContext*>::iterator iter = gJNICallBackContextList.find(key);
+    if(iter == gJNICallBackContextList.end()) {
+        gJNICallBackContextList[key] = new JNICallBackContext(*resource, env->NewGlobalRef(jattributeHandler));
+        callbackContext = gJNICallBackContextList[key];
+        __android_log_print(ANDROID_LOG_INFO, TAG, "Adding %s to gJNICallBackContextList", key.c_str());
+    }
+    else {
+        iter->second->m_callBackFunction = env->NewGlobalRef(jattributeHandler);
+        callbackContext = iter->second;
+    }
+
+       OC::QueryParamsMap test;
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "calling oic base observe()\n");
+
+    (*resource)->observe((OC::ObserveType) jobservetype, test,
+        [callbackContext](const OC::HeaderOptions& headerOptions, const OC::OCRepresentation& rep, const int eCode, const int seqNum)
+        {
+             JNIEnv * env;
+
+            // Attach to JavaVM
+            // double check it's all ok
+            int getEnvStat = g_JavaVM->GetEnv((void **)&env, JNI_VERSION_1_6);
+            if (getEnvStat == JNI_EDETACHED) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: not attached");
+                if (g_JavaVM->AttachCurrentThread(&env, NULL) != 0) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to attach");
+                }
+                else
+                    __android_log_print(ANDROID_LOG_INFO, TAG, "Attached OK");
+            } else if (getEnvStat == JNI_OK) {
+            //
+            } else if (getEnvStat == JNI_EVERSION) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "GetEnv: version not supported");
+            }
+
+            // save C++ ocheaderoption ptr now
+            jmethodID option_constructor = env->GetMethodID(g_ocheaderoption_clazz, "<init>", "(J)V");
+            int size = headerOptions.size();
+            jobjectArray joptions = env->NewObjectArray(size, g_ocheaderoption_clazz, 0);
+            for (int n=0; n<size;n++) {
+                jobject jelem = env->NewObject(g_ocheaderoption_clazz, option_constructor, \
+                                            (jlong) reinterpret_cast<jlong>(&headerOptions[n]));
+
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "jelem : %llu",  (jlong) reinterpret_cast<jlong>(&headerOptions[n]));
+
+                env->SetObjectArrayElement(joptions, n, jelem);
+                env->DeleteLocalRef(jelem);
+            }
+
+            // save C++ ocrepresentation ptr now
+            jmethodID representation_constructor = env->GetMethodID(g_ocrepresentation_clazz, "<init>", "(J)V");
+            jobject jrepresentation = env->NewObject(g_ocrepresentation_clazz, representation_constructor, \
+                                    (jlong) reinterpret_cast<jlong>(&rep));
+            if(jrepresentation == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "cannot create OCRepresentation class");
+                return;
+            }
+
+            jclass cb_clazz = env->GetObjectClass(callbackContext->m_callBackFunction);
+            if (cb_clazz == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "Failed to find class");
+            }
+
+            // Find Callback function
+            jmethodID cb_mid = env->GetMethodID(cb_clazz, "Callback", \
+                    "([Lorg/iotivity/base/OCHeaderOption;Lorg/iotivity/base/OCRepresentation;II)V");
+            if(cb_mid == NULL) {
+                __android_log_print(ANDROID_LOG_ERROR, TAG, "onObserve.Callback() is not defined in JAVA");
+                return;
+            }
+
+            __android_log_print(ANDROID_LOG_INFO, TAG, "calling JAVA ObserveCallback");
+            env->CallVoidMethod(callbackContext->m_callBackFunction, cb_mid, joptions, jrepresentation, eCode, seqNum);
+
+            __android_log_print(ANDROID_LOG_INFO, TAG, "observeCB detach");
+            g_JavaVM->DetachCurrentThread();
+
+        }
+    );
+    return NULL;
+}
+
+JNIEXPORT jobject JNICALL jniOicCancelObserve(JNIEnv *env, jobject jobj)
+{
+    std::shared_ptr<OC::OCResource> *resource = getHandle<std::shared_ptr<OC::OCResource>>(env, jobj);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "cancelObserve1() resource = %p\n", resource);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "calling oic base cancelObserve()\n");
+
+    (*resource)->cancelObserve();
+    return NULL;
+}
+
+JNIEXPORT jstring JNICALL uri(JNIEnv *env, jobject jobj)
+{
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "uri()");
+    std::shared_ptr<OC::OCResource> *resource = getHandle<std::shared_ptr<OC::OCResource>>(env, jobj);
+    return env->NewStringUTF((*resource)->uri().c_str());
+}
+
+JNIEXPORT jstring JNICALL host(JNIEnv *env, jobject jobj)
+{
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "host()");
+    std::shared_ptr<OC::OCResource> *resource = getHandle<std::shared_ptr<OC::OCResource>>(env, jobj);
+    return env->NewStringUTF((*resource)->host().c_str());
+}
+
+JNIEXPORT jobjectArray JNICALL getResourceTypes(JNIEnv *env, jobject jobj)
+{
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "getResourceTypes()");
+    std::shared_ptr<OC::OCResource> *resource = getHandle<std::shared_ptr<OC::OCResource>>(env, jobj);
+
+    std::vector<std::string> resourceTypes = (*resource)->getResourceTypes();
+
+    int size = resourceTypes.size();
+    jclass clazz = env->FindClass("java/lang/String");
+    jobjectArray jresourceTypes = env->NewObjectArray(size, clazz, 0);
+
+    for (int n=0; n<size;n++) {
+        jstring jstr = env->NewStringUTF(resourceTypes[n].c_str());
+        env->SetObjectArrayElement(jresourceTypes, n, jstr);
+    }
+
+    return jresourceTypes;
+}
+
+JNIEXPORT jobjectArray JNICALL getResourceInterfaces(JNIEnv *env, jobject jobj)
+{
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "getResourceInterfaces()");
+    std::shared_ptr<OC::OCResource> *resource = getHandle<std::shared_ptr<OC::OCResource>>(env, jobj);
+
+    std::vector<std::string> resourceInterfaces = (*resource)->getResourceInterfaces();
+
+    int size = resourceInterfaces.size();
+    jclass clazz = env->FindClass("java/lang/String");
+    jobjectArray jresourceInterfaces = env->NewObjectArray(size, clazz, 0);
+
+    for (int n=0; n<size;n++) {
+        jstring jstr = env->NewStringUTF(resourceInterfaces[n].c_str());
+        env->SetObjectArrayElement(jresourceInterfaces, n, jstr);
+    }
+
+    return jresourceInterfaces;
+}
+
diff --git a/android/Base/app/jni/ocstack-jni.cpp b/android/Base/app/jni/ocstack-jni.cpp
new file mode 100644 (file)
index 0000000..d9ae850
--- /dev/null
@@ -0,0 +1,134 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "ocstack-jni.h"
+
+// Global map to maintain callback functions and ocresource
+// with key = URL + callback operation
+// e.g. key = /a/light/GET
+std::map<string, JNICallBackContext*> gJNICallBackContextList;
+
+JavaVM* g_JavaVM = NULL;
+
+jclass g_ocplatform_clazz;
+jclass g_ocresource_clazz;
+jclass g_ocheaderoption_clazz;
+jclass g_ocrepresentation_clazz;
+jclass g_platformcfg_clazz;
+
+static const char* TAG = "OCSTACK-JNI";
+
+static JNINativeMethod ocplatform_method_table[] = {
+  { "configure", "(Lorg/iotivity/base/PlatformConfig;)V", (void *) configure},
+  { "findResource", "(Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/AbstractFindCallback;)I", (void *) findResource }
+};
+
+static int ocplatform_method_table_size = sizeof(ocplatform_method_table) / sizeof(ocplatform_method_table[0]);
+
+static JNINativeMethod platformconfig_method_table[] = {
+  { "createNativeInstance", "(IILjava/lang/String;II)J", (void *) createNativeInstance },
+};
+
+static int platformconfig_method_table_size = sizeof(platformconfig_method_table) / sizeof(platformconfig_method_table[0]);
+
+static JNINativeMethod ocresource_method_table[] = {
+  { "get", "(Lorg/iotivity/base/AbstractGetCallback;)Lorg/iotivity/base/OCStackResult;", (void *) jniOicGet},
+
+  { "put", "(Lorg/iotivity/base/OCRepresentation;Lorg/iotivity/base/AbstractPutCallback;)Lorg/iotivity/base/OCStackResult;", (void *) jniOicPut},
+  { "post", "(Lorg/iotivity/base/OCRepresentation;Lorg/iotivity/base/AbstractPostCallback;)Lorg/iotivity/base/OCStackResult;", (void *) jniOicPost},
+  { "observe", "(ILorg/iotivity/base/AbstractObserveCallback;)Lorg/iotivity/base/OCStackResult;", (void *) jniOicObserve},
+  { "cancelObserve", "()Lorg/iotivity/base/OCStackResult;", (void *) jniOicCancelObserve},
+  { "uri", "()Ljava/lang/String;", (void *) uri},
+  { "host", "()Ljava/lang/String;", (void *) host},
+  { "getResourceTypes", "()[Ljava/lang/String;", (void *) getResourceTypes},
+  { "getResourceInterfaces", "()[Ljava/lang/String;", (void *) getResourceInterfaces},
+};
+
+static int ocresource_method_table_size = sizeof(ocresource_method_table) / sizeof(ocresource_method_table[0]);
+
+static JNINativeMethod ocheaderoption_method_table[] = {
+  { "getOptionID", "()I", (void *) getOptionID},
+  { "getOptionData", "()Ljava/lang/String;", (void *) getOptionData},
+  { "OCHeaderOptionConstructor", "(ILjava/lang/String;)J", (void *) OCHeaderOptionConstructor},
+};
+
+static int ocheaderoption_method_table_size = sizeof(ocheaderoption_method_table) / sizeof(ocheaderoption_method_table[0]);
+
+static JNINativeMethod ocrepresentation_method_table[] = {
+  { "OCRepresentationConstructor", "()J", (void *) OCRepresentationConstructor},
+  { "getUri", "()Ljava/lang/String;", (void *) getUri},
+  { "getValueInt", "(Ljava/lang/String;)I", (void *) getValueInt},
+  { "getValueBool", "(Ljava/lang/String;)Z", (void *) getValueBool},
+  { "getValueString", "(Ljava/lang/String;)Ljava/lang/String;", (void *) getValueString},
+  { "setValueInt", "(Ljava/lang/String;I)V", (void *) setValueInt},
+  { "setValueBool", "(Ljava/lang/String;Z)V", (void *) setValueBool},
+  { "setValueString", "(Ljava/lang/String;Ljava/lang/String;)V", (void *) setValueString},
+  { "hasAttribute", "(Ljava/lang/String;)Z", (void *) hasAttribute},
+};
+
+static int ocrepresentation_method_table_size = sizeof(ocrepresentation_method_table) / sizeof(ocrepresentation_method_table[0]);
+
+// JNI OnLoad
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
+{
+  JNIEnv* env;
+
+  g_JavaVM = vm;
+  __android_log_print(ANDROID_LOG_ERROR, TAG, "g_JavaVM = %p\n", g_JavaVM);
+
+  if (vm->GetEnv((void **) &env, JNI_VERSION_1_6) != JNI_OK) {
+    return JNI_ERR;
+  } else {
+    jint ret;
+    jclass clazz;
+
+    clazz = env->FindClass("org/iotivity/base/OCPlatform");
+    g_ocplatform_clazz = (jclass) env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+    ret = env->RegisterNatives(g_ocplatform_clazz, ocplatform_method_table, ocplatform_method_table_size);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "load ocplatform = %d\n", ret);
+
+    clazz = env->FindClass("org/iotivity/base/OCResource");
+    g_ocresource_clazz = (jclass) env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+    ret = env->RegisterNatives(g_ocresource_clazz, ocresource_method_table, ocresource_method_table_size);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "load ocresource = %d\n", ret);
+
+    clazz = env->FindClass("org/iotivity/base/PlatformConfig");
+    g_platformcfg_clazz = (jclass) env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+    ret = env->RegisterNatives(g_platformcfg_clazz, platformconfig_method_table, platformconfig_method_table_size);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "load platformconfig = %d\n", ret);
+
+    clazz = env->FindClass("org/iotivity/base/OCHeaderOption");
+    g_ocheaderoption_clazz = (jclass) env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+    ret = env->RegisterNatives(g_ocheaderoption_clazz, ocheaderoption_method_table, ocheaderoption_method_table_size);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "load ocheaderoption = %d\n", ret);
+
+    clazz = env->FindClass("org/iotivity/base/OCRepresentation");
+    g_ocrepresentation_clazz = (jclass) env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+    ret = env->RegisterNatives(g_ocrepresentation_clazz, ocrepresentation_method_table, ocrepresentation_method_table_size);
+    __android_log_print(ANDROID_LOG_ERROR, TAG, "load ocrepresentation = %d\n", ret);
+
+    return JNI_VERSION_1_6;
+  }
+}
diff --git a/android/Base/app/jni/ocstack-jni.h b/android/Base/app/jni/ocstack-jni.h
new file mode 100644 (file)
index 0000000..dd55aa4
--- /dev/null
@@ -0,0 +1,101 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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 _Included_org_iotivity_base_ocstack
+#define _Included_org_iotivity_base_ocstack
+
+#include <jni.h>
+#include <android/log.h>
+#include "OCApi.h"
+#include "OCPlatform.h"
+
+class JNICallBackContext {
+    public:
+
+    std::shared_ptr<OC::OCResource> m_resource;
+    jobject m_callBackFunction;
+
+    JNICallBackContext(jobject callback) {
+        m_resource = NULL;
+        m_callBackFunction = callback;
+    }
+
+    JNICallBackContext(std::shared_ptr<OC::OCResource> rsrc,
+        jobject callback) {
+        m_resource = rsrc;
+        m_callBackFunction = callback;
+    }
+};
+
+extern std::map<string, JNICallBackContext*> gJNICallBackContextList;
+
+extern JavaVM* g_JavaVM;
+
+extern jclass g_ocplatform_clazz;
+extern jclass g_ocresource_clazz;
+extern jclass g_ocheaderoption_clazz;
+extern jclass g_ocrepresentation_clazz;
+extern jclass g_platformcfg_clazz;
+
+template <typename T>
+T *getHandle(JNIEnv *env, jobject obj)
+{
+    jclass cls = env->GetObjectClass(obj);
+    jfieldID fid = env->GetFieldID(cls, "nativeHandle", "J");
+    jlong handle = env->GetLongField(obj, fid);
+    return reinterpret_cast<T *>(handle);
+}
+
+// ocplatform-jni
+extern JNIEXPORT void JNICALL configure(JNIEnv *env, jobject obj, jobject jcfg);
+extern JNIEXPORT jint JNICALL findResource(JNIEnv* env, jobject obj, jstring jhost, jstring juri, jobject found);
+
+// platformcfg-jni
+extern JNIEXPORT jlong JNICALL createNativeInstance
+  (JNIEnv *env, jobject obj, jint jServiceType, jint jModeType, jstring jIpAddress, jint port, jint jQOS);
+
+// ocheaderoption-jni
+extern JNIEXPORT jint JNICALL getOptionID(JNIEnv *env, jobject jobj);
+extern JNIEXPORT jstring JNICALL getOptionData(JNIEnv *env, jobject jobj);
+extern JNIEXPORT jlong JNICALL OCHeaderOptionConstructor(JNIEnv *env, jobject jobj, jint joption, jstring jdata);
+
+// ocrepresentation-jni
+extern JNIEXPORT jlong JNICALL OCRepresentationConstructor(JNIEnv *env, jobject jobj);
+extern JNIEXPORT jstring JNICALL getUri(JNIEnv *env, jobject jobj);
+extern JNIEXPORT jint JNICALL getValueInt(JNIEnv *env, jobject jobj, jstring jstr);
+extern JNIEXPORT jboolean JNICALL getValueBool(JNIEnv *env, jobject jobj, jstring jstr);
+extern JNIEXPORT jstring JNICALL getValueString(JNIEnv *env, jobject jobj, jstring jstr);
+extern JNIEXPORT void JNICALL setValueInt(JNIEnv *env, jobject jobj, jstring jstr, jint jval);
+extern JNIEXPORT void JNICALL setValueBool(JNIEnv *env, jobject jobj, jstring jstr, jboolean jval);
+extern JNIEXPORT void JNICALL setValueString(JNIEnv *env, jobject jobj, jstring jstr, jstring jval);
+extern JNIEXPORT jboolean JNICALL hasAttribute(JNIEnv *env, jobject jobj, jstring jstr);
+
+// ocresource-jni
+extern JNIEXPORT jobject JNICALL jniOicGet(JNIEnv *env, jobject jobj, jobject jattributeHandler);
+extern JNIEXPORT jobject JNICALL jniOicPut(JNIEnv *env, jobject jobj, jobject jocrepresentation, jobject jattributeHandler);
+extern JNIEXPORT jobject JNICALL jniOicPost(JNIEnv *env, jobject jobj, jobject jocrepresentation, jobject jattributeHandler);
+extern JNIEXPORT jobject JNICALL jniOicObserve(JNIEnv *env, jobject jobj, jint jobservetype, jobject jattributeHandler);
+extern JNIEXPORT jobject JNICALL jniOicCancelObserve(JNIEnv *env, jobject jobj);
+extern JNIEXPORT jstring JNICALL uri(JNIEnv *env, jobject jobj);
+extern JNIEXPORT jstring JNICALL host(JNIEnv *env, jobject jobj);
+extern JNIEXPORT jobjectArray JNICALL getResourceTypes(JNIEnv *env, jobject jobj);
+extern JNIEXPORT jobjectArray JNICALL getResourceInterfaces(JNIEnv *env, jobject jobj);
+
+#endif
diff --git a/android/Base/app/jni/platformcfg-jni.cpp b/android/Base/app/jni/platformcfg-jni.cpp
new file mode 100644 (file)
index 0000000..73d40f9
--- /dev/null
@@ -0,0 +1,80 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "ocstack-jni.h"
+
+static const char* TAG = "PLATFORMCFG-JNI";
+
+OC::ServiceType getServiceType(int type)
+{
+    switch (type) {
+        case 0:
+            return OC::ServiceType::InProc;
+        case 1:
+        default:
+            return OC::ServiceType::OutOfProc;
+    };
+}
+
+OC::ModeType getModeType(int type)
+{
+    switch (type) {
+        case 0:
+            return OC::ModeType::Server;
+        case 1:
+            return OC::ModeType::Client;
+        case 2:
+        default:
+            return OC::ModeType::Both;
+    };
+}
+
+OC::QualityOfService getQOS(int type)
+{
+    switch (type) {
+        case 0:
+            return OC::QualityOfService::LowQos;
+        case 1:
+            return OC::QualityOfService::MidQos;
+        case 2:
+            return OC::QualityOfService::HighQos;
+        case 3:
+        default:
+            return OC::QualityOfService::NaQos;
+    };
+}
+
+OC::PlatformConfig *g_cfg;
+
+JNIEXPORT jlong JNICALL createNativeInstance
+  (JNIEnv *env, jobject obj, jint jServiceType, jint jModeType, jstring jIpAddress, jint port, jint jQOS)
+{
+
+    g_cfg = new OC::PlatformConfig{getServiceType(jServiceType),
+                            getModeType(jModeType),
+                            env->GetStringUTFChars(jIpAddress, 0),
+                            (uint16_t) port,
+                            getQOS(jQOS)
+    };
+
+
+    jlong instptr = reinterpret_cast<jlong>(g_cfg);
+    return instptr;
+}
diff --git a/android/Base/app/proguard-rules.pro b/android/Base/app/proguard-rules.pro
new file mode 100644 (file)
index 0000000..0e559b0
--- /dev/null
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/vchen/ubuntu_sw/adt-bundle-linux-x86_64/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/android/Base/app/src/androidTest/java/org/iotivity/base/ApplicationTest.java b/android/Base/app/src/androidTest/java/org/iotivity/base/ApplicationTest.java
new file mode 100644 (file)
index 0000000..ac4bdc3
--- /dev/null
@@ -0,0 +1,33 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+import android.app.Application;
+import android.test.ApplicationTestCase;
+
+/**
+ * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
+ */
+public class ApplicationTest extends ApplicationTestCase<Application> {
+    public ApplicationTest() {
+        super(Application.class);
+    }
+}
diff --git a/android/Base/app/src/main/AndroidManifest.xml b/android/Base/app/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..32cf1c1
--- /dev/null
@@ -0,0 +1,11 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.base">
+
+    <application android:allowBackup="true"
+        android:label="@string/app_name"
+        android:icon="@drawable/ic_launcher"
+        android:theme="@style/AppTheme">
+
+    </application>
+
+</manifest>
diff --git a/android/Base/app/src/main/java/org/iotivity/base/AbstractDeleteCallback.java b/android/Base/app/src/main/java/org/iotivity/base/AbstractDeleteCallback.java
new file mode 100644 (file)
index 0000000..d1c26b4
--- /dev/null
@@ -0,0 +1,25 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public abstract class AbstractDeleteCallback {
+    public abstract void Callback(OCHeaderOption options, int a);
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/AbstractFindCallback.java b/android/Base/app/src/main/java/org/iotivity/base/AbstractFindCallback.java
new file mode 100644 (file)
index 0000000..132b1a8
--- /dev/null
@@ -0,0 +1,26 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public abstract class AbstractFindCallback {
+    public abstract void Callback(OCResource resource);
+//    public OCResource ocresource = new OCResource();
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/AbstractGetCallback.java b/android/Base/app/src/main/java/org/iotivity/base/AbstractGetCallback.java
new file mode 100644 (file)
index 0000000..6ba339b
--- /dev/null
@@ -0,0 +1,27 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public abstract class AbstractGetCallback {
+    public abstract void Callback(OCHeaderOption[] options, OCRepresentation rep, int a);
+//    public OCHeaderOption[] ocoptions;
+//    public OCRepresentation ocrep = new OCRepresentation();
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/AbstractObserveCallback.java b/android/Base/app/src/main/java/org/iotivity/base/AbstractObserveCallback.java
new file mode 100644 (file)
index 0000000..6c90561
--- /dev/null
@@ -0,0 +1,27 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public abstract class AbstractObserveCallback {
+    public abstract void Callback(OCHeaderOption[] options, OCRepresentation rep, int a, int b);
+//    public OCHeaderOption[] ocoptions;
+//    public OCRepresentation ocrep = new OCRepresentation();
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/AbstractPostCallback.java b/android/Base/app/src/main/java/org/iotivity/base/AbstractPostCallback.java
new file mode 100644 (file)
index 0000000..20acbea
--- /dev/null
@@ -0,0 +1,27 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public abstract class AbstractPostCallback {
+    public abstract void Callback(OCHeaderOption[] options, OCRepresentation rep, int a);
+//    public OCHeaderOption[] ocoptions;
+//    public OCRepresentation ocrep = new OCRepresentation();
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/AbstractPutCallback.java b/android/Base/app/src/main/java/org/iotivity/base/AbstractPutCallback.java
new file mode 100644 (file)
index 0000000..46f2a19
--- /dev/null
@@ -0,0 +1,7 @@
+package org.iotivity.base;
+
+public abstract class AbstractPutCallback {
+    public abstract void Callback(OCHeaderOption[] options, OCRepresentation rep, int a);
+//    public OCHeaderOption[] ocoptions;
+//    public OCRepresentation ocrep = new OCRepresentation();
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/AbstractSubscriberCallback.java b/android/Base/app/src/main/java/org/iotivity/base/AbstractSubscriberCallback.java
new file mode 100644 (file)
index 0000000..1f996cb
--- /dev/null
@@ -0,0 +1,25 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public abstract class AbstractSubscriberCallback {
+    public abstract void Callback(OCStackResult result, int a);
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/EntityHandler.java b/android/Base/app/src/main/java/org/iotivity/base/EntityHandler.java
new file mode 100644 (file)
index 0000000..779543c
--- /dev/null
@@ -0,0 +1,25 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public interface EntityHandler {
+    public abstract void Callback(OCResourceRequest request, OCResourceResponse response);
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/NativeInstance.java b/android/Base/app/src/main/java/org/iotivity/base/NativeInstance.java
new file mode 100644 (file)
index 0000000..f6d02bb
--- /dev/null
@@ -0,0 +1,33 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public abstract class NativeInstance
+{
+    protected long nativeHandle = 0;
+
+    public NativeInstance()
+    {
+    }
+
+    public long getHandle() { return nativeHandle;}
+
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/OCHeaderOption.java b/android/Base/app/src/main/java/org/iotivity/base/OCHeaderOption.java
new file mode 100644 (file)
index 0000000..c169870
--- /dev/null
@@ -0,0 +1,36 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public class OCHeaderOption extends NativeInstance {
+    final private static String TAG = "OCHeaderOption";
+    static {
+        System.loadLibrary("ocstack-jni");
+    }
+
+    public OCHeaderOption(long instPtr) {
+        super.nativeHandle = instPtr;
+    }
+
+    public native int getOptionID();
+    public native String getOptionData();
+    public native long OCHeaderOptionConstructor(int optionID, String optionData);
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/OCPlatform.java b/android/Base/app/src/main/java/org/iotivity/base/OCPlatform.java
new file mode 100644 (file)
index 0000000..e4424a6
--- /dev/null
@@ -0,0 +1,32 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public class OCPlatform {
+    final private static String TAG = "OCPlatform";
+    static {
+        System.loadLibrary("ocstack-jni");
+    }
+
+    public static native void configure(PlatformConfig cfg);
+    public static native int findResource(String host, String Uri, AbstractFindCallback found);
+
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/OCRepresentation.java b/android/Base/app/src/main/java/org/iotivity/base/OCRepresentation.java
new file mode 100644 (file)
index 0000000..06a2156
--- /dev/null
@@ -0,0 +1,49 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public class OCRepresentation extends NativeInstance {
+    final private static String TAG = "OCRepresentation";
+    static {
+        System.loadLibrary("ocstack-jni");
+    }
+
+    public OCRepresentation(long instPtr) {
+        super.nativeHandle = instPtr;
+    }
+    public OCRepresentation() {
+        super.nativeHandle = OCRepresentationConstructor();
+    }
+
+    public native long OCRepresentationConstructor();
+
+    public native int getValueInt(String str);
+    public native boolean getValueBool(String str);
+    public native String getValueString(String str);
+
+    public native void setValueInt (String str, int val);
+    public native void setValueBool (String str, boolean val);
+    public native void setValueString (String str, String val);
+
+    public native String getUri();
+
+    public native boolean hasAttribute(String str);
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/OCResource.java b/android/Base/app/src/main/java/org/iotivity/base/OCResource.java
new file mode 100644 (file)
index 0000000..7a7f6c8
--- /dev/null
@@ -0,0 +1,60 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public class OCResource extends NativeInstance {
+    final private static String TAG = "OCResource";
+    static {
+        System.loadLibrary("ocstack-jni");
+    }
+
+    public native OCStackResult get(AbstractGetCallback attributeHandler);
+//    public native OCStackResult get(AbstractGetCallback attributeHandler, PlatformConfig.QualityOfService QoS);
+
+    public native OCStackResult get(String resourceType, String resourceInterface, AbstractGetCallback attributeHandler);
+//    public native OCStackResult get(String resourceType, String resourceInterface, AbstractGetCallback attributeHandler, PlatformConfig.QualityOfService QoS);
+
+    public native OCStackResult put(OCRepresentation rep, AbstractPutCallback attributeHandler);
+//    public native OCStackResult put(OCRepresentation rep, AbstractPutCallback attributeHandler, PlatformConfig.QualityOfService QoS);
+//    public native OCStackResult put(String resourceType, String resourceInterface, OCRepresentation rep, AbstractPutCallback attributeHandler);
+//    public native OCStackResult put(String resourceType, String resourceInterface, OCRepresentation rep, AbstractPutCallback attributeHandler, PlatformConfig.QualityOfService QoS);
+
+    public native OCStackResult post(OCRepresentation rep, AbstractPostCallback attributeHandler);
+//    public native OCStackResult post(OCRepresentation rep, AbstractPostCallback attributeHandler, PlatformConfig.QualityOfService QoS);
+//    public native OCStackResult post(String resourceType, String resourceInterface, OCRepresentation rep, AbstractPostCallback attributeHandler);
+//    public native OCStackResult post(String resourceType, String resourceInterface, OCRepresentation rep, AbstractPostCallback attributeHandler, PlatformConfig.QualityOfService QoS);
+
+    public native OCStackResult observe(int observeType, AbstractObserveCallback observerHandler);
+//    public native OCStackResult observe(int observeType, AbstractObserveCallback observerHandler, PlatformConfig.QualityOfService QoS);
+
+    public native OCStackResult cancelObserve();
+//    public native OCStackResult cancelObserve(PlatformConfig.QualityOfService QoS);
+
+    public native String uri();
+    public native String host();
+
+    public native String[] getResourceInterfaces();
+    public native String[] getResourceTypes();
+
+    public OCResource(long instPtr) {
+        super.nativeHandle = instPtr;
+    }
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/OCResourceRequest.java b/android/Base/app/src/main/java/org/iotivity/base/OCResourceRequest.java
new file mode 100644 (file)
index 0000000..87c406e
--- /dev/null
@@ -0,0 +1,24 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public class OCResourceRequest {
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/OCResourceResponse.java b/android/Base/app/src/main/java/org/iotivity/base/OCResourceResponse.java
new file mode 100644 (file)
index 0000000..283d8de
--- /dev/null
@@ -0,0 +1,24 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public class OCResourceResponse {
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/OCStackResult.java b/android/Base/app/src/main/java/org/iotivity/base/OCStackResult.java
new file mode 100644 (file)
index 0000000..10440b6
--- /dev/null
@@ -0,0 +1,54 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public class OCStackResult {
+    /* Success status code - START HERE */
+    static final public int  OC_STACK_OK                    = 0;
+    static final public int  OC_STACK_RESOURCE_CREATED      = 1;
+    static final public int  OC_STACK_RESOURCE_DELETED      = 2;
+    /* Success status code - END HERE */
+    /* Error status code - START HERE */
+    static final public int  OC_STACK_INVALID_URI           = 3;
+    static final public int  OC_STACK_INVALID_QUERY         = 4;
+    static final public int  OC_STACK_INVALID_IP            = 5;
+    static final public int  OC_STACK_INVALID_PORT          = 6;
+    static final public int  OC_STACK_INVALID_CALLBACK      = 7;
+    static final public int  OC_STACK_INVALID_METHOD        = 8;
+    static final public int  OC_STACK_INVALID_PARAM         = 9;
+    static final public int  OC_STACK_INVALID_OBSERVE_PARAM = 10;
+    static final public int  OC_STACK_NO_MEMORY             = 11;
+    static final public int  OC_STACK_COMM_ERROR            = 12;
+    static final public int  OC_STACK_NOTIMPL               = 13;
+    static final public int  OC_STACK_NO_RESOURCE           = 14;               /* resource not found */
+    static final public int  OC_STACK_RESOURCE_ERROR        = 15;            /* ex: not supported method or interface */
+    static final public int  OC_STACK_SLOW_RESOURCE         = 16;
+    static final public int  OC_STACK_NO_OBSERVERS          = 17;              /* resource has no registered observers */
+    static final public int  OC_STACK_OBSERVER_NOT_FOUND    = 18;
+    static final public int  OC_STACK_OBSERVER_NOT_ADDED    = 19;
+    static final public int  OC_STACK_OBSERVER_NOT_REMOVED  = 20;
+    static final public int  OC_STACK_PRESENCE_STOPPED      = 21;
+    static final public int  OC_STACK_PRESENCE_DO_NOT_HANDLE = 22;
+    static final public int  OC_STACK_INVALID_OPTION        = 23;
+    static final public int  OC_STACK_MALFORMED_RESPONSE    = 24;        /* the remote reply contained malformed data */
+    static final public int  OC_STACK_ERROR                 = 25;
+    /* Error status code - END HERE */
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/ObserveType.java b/android/Base/app/src/main/java/org/iotivity/base/ObserveType.java
new file mode 100644 (file)
index 0000000..f61c5d8
--- /dev/null
@@ -0,0 +1,26 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public class ObserveType {
+    static final public int Observe    = 0;
+    static final public int ObserveAll = 1;
+}
diff --git a/android/Base/app/src/main/java/org/iotivity/base/PlatformConfig.java b/android/Base/app/src/main/java/org/iotivity/base/PlatformConfig.java
new file mode 100755 (executable)
index 0000000..301cdde
--- /dev/null
@@ -0,0 +1,68 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.base;
+
+public class PlatformConfig extends NativeInstance
+{
+    final private static String TAG = "PlatformConfig";
+    static {
+        System.loadLibrary("ocstack-jni");
+    }
+
+    // ENUM definition. Need to match with OCApi.h
+    public class ServiceType
+    {
+        static final public int INPROC  = 0;
+        static final public int OUTPROC = 1;
+    };
+
+    public class ModeType
+    {
+        static final public int SERVER = 0;
+        static final public int CLIENT = 1;
+        static final public int BOTH   = 2;
+
+    };
+
+    public class QualityOfService
+    {
+        static final public int LO_QOS  = 0;
+        static final public int ME_QOS  = 1;
+        static final public int HI_QOS  = 2;
+        static final public int NA_QOS  = 3;
+    }
+
+    public PlatformConfig(int serviceType,
+                          int mode,
+                          String ipAddress,
+                          int port,
+                          int QoS)
+    {
+        super.nativeHandle = createNativeInstance(serviceType, mode, ipAddress, port, QoS);
+    }
+   
+
+    protected native long createNativeInstance(int serviceType,
+             int mode,
+             String ipAddress,
+             int port,
+             int QoS);
+}
diff --git a/android/Base/app/src/main/res/drawable-hdpi/ic_launcher.png b/android/Base/app/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..96a442e
Binary files /dev/null and b/android/Base/app/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/android/Base/app/src/main/res/drawable-mdpi/ic_launcher.png b/android/Base/app/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..359047d
Binary files /dev/null and b/android/Base/app/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/android/Base/app/src/main/res/drawable-xhdpi/ic_launcher.png b/android/Base/app/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..71c6d76
Binary files /dev/null and b/android/Base/app/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/android/Base/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/android/Base/app/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..4df1894
Binary files /dev/null and b/android/Base/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/android/Base/app/src/main/res/values/strings.xml b/android/Base/app/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..73ef225
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+    <string name="app_name">Base</string>
+</resources>
diff --git a/android/Base/app/src/main/res/values/styles.xml b/android/Base/app/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..ff6c9d2
--- /dev/null
@@ -0,0 +1,8 @@
+<resources>
+
+    <!-- Base application theme. -->
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- Customize your theme here. -->
+    </style>
+
+</resources>
diff --git a/android/Base/build.gradle b/android/Base/build.gradle
new file mode 100644 (file)
index 0000000..9b8abe4
--- /dev/null
@@ -0,0 +1,19 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+    repositories {
+        jcenter()
+    }
+    dependencies {
+        classpath 'com.android.tools.build:gradle:0.12.2'
+
+        // NOTE: Do not place your application dependencies here; they belong
+        // in the individual module build.gradle files
+    }
+}
+
+allprojects {
+    repositories {
+        jcenter()
+    }
+}
diff --git a/android/Base/gradle.properties b/android/Base/gradle.properties
new file mode 100644 (file)
index 0000000..5d08ba7
--- /dev/null
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/android/Base/gradlew b/android/Base/gradlew
new file mode 100755 (executable)
index 0000000..91a7e26
--- /dev/null
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/android/Base/gradlew.bat b/android/Base/gradlew.bat
new file mode 100644 (file)
index 0000000..aec9973
--- /dev/null
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off\r
+@rem ##########################################################################\r
+@rem\r
+@rem  Gradle startup script for Windows\r
+@rem\r
+@rem ##########################################################################\r
+\r
+@rem Set local scope for the variables with windows NT shell\r
+if "%OS%"=="Windows_NT" setlocal\r
+\r
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r
+set DEFAULT_JVM_OPTS=\r
+\r
+set DIRNAME=%~dp0\r
+if "%DIRNAME%" == "" set DIRNAME=.\r
+set APP_BASE_NAME=%~n0\r
+set APP_HOME=%DIRNAME%\r
+\r
+@rem Find java.exe\r
+if defined JAVA_HOME goto findJavaFromJavaHome\r
+\r
+set JAVA_EXE=java.exe\r
+%JAVA_EXE% -version >NUL 2>&1\r
+if "%ERRORLEVEL%" == "0" goto init\r
+\r
+echo.\r
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r
+echo.\r
+echo Please set the JAVA_HOME variable in your environment to match the\r
+echo location of your Java installation.\r
+\r
+goto fail\r
+\r
+:findJavaFromJavaHome\r
+set JAVA_HOME=%JAVA_HOME:"=%\r
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe\r
+\r
+if exist "%JAVA_EXE%" goto init\r
+\r
+echo.\r
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r
+echo.\r
+echo Please set the JAVA_HOME variable in your environment to match the\r
+echo location of your Java installation.\r
+\r
+goto fail\r
+\r
+:init\r
+@rem Get command-line arguments, handling Windowz variants\r
+\r
+if not "%OS%" == "Windows_NT" goto win9xME_args\r
+if "%@eval[2+2]" == "4" goto 4NT_args\r
+\r
+:win9xME_args\r
+@rem Slurp the command line arguments.\r
+set CMD_LINE_ARGS=\r
+set _SKIP=2\r
+\r
+:win9xME_args_slurp\r
+if "x%~1" == "x" goto execute\r
+\r
+set CMD_LINE_ARGS=%*\r
+goto execute\r
+\r
+:4NT_args\r
+@rem Get arguments from the 4NT Shell from JP Software\r
+set CMD_LINE_ARGS=%$\r
+\r
+:execute\r
+@rem Setup the command line\r
+\r
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar\r
+\r
+@rem Execute Gradle\r
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\r
+\r
+:end\r
+@rem End local scope for the variables with windows NT shell\r
+if "%ERRORLEVEL%"=="0" goto mainEnd\r
+\r
+:fail\r
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r
+rem the _cmd.exe /c_ return code!\r
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1\r
+exit /b 1\r
+\r
+:mainEnd\r
+if "%OS%"=="Windows_NT" endlocal\r
+\r
+:omega\r
diff --git a/android/Base/settings.gradle b/android/Base/settings.gradle
new file mode 100644 (file)
index 0000000..e7b4def
--- /dev/null
@@ -0,0 +1 @@
+include ':app'
diff --git a/android/SimpleClient/app/build.gradle b/android/SimpleClient/app/build.gradle
new file mode 100644 (file)
index 0000000..bf753bf
--- /dev/null
@@ -0,0 +1,40 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 20
+    buildToolsVersion "19.1.0"
+
+    defaultConfig {
+        applicationId "org.iotivity.simpleclient"
+        minSdkVersion 19
+        targetSdkVersion 20
+        versionCode 1
+        versionName "1.0"
+    }
+    buildTypes {
+        release {
+            runProguard false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+}
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+}
+
+repositories {
+    mavenCentral()
+    flatDir {
+        dirs 'libs'
+    }
+}
+
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+    compile fileTree(dir: 'libs', include: ['*.so'])
+    compile fileTree(dir: 'libs', include: ['**/*.so'])
+//    compile(name: 'OicLib', ext:'aar')
+    compile 'org.iotivity.Base:app:1.0@aar'
+}
\ No newline at end of file
diff --git a/android/SimpleClient/app/proguard-rules.pro b/android/SimpleClient/app/proguard-rules.pro
new file mode 100644 (file)
index 0000000..0e559b0
--- /dev/null
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/vchen/ubuntu_sw/adt-bundle-linux-x86_64/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/android/SimpleClient/app/src/androidTest/java/org/iotivity/simpleclient/ApplicationTest.java b/android/SimpleClient/app/src/androidTest/java/org/iotivity/simpleclient/ApplicationTest.java
new file mode 100644 (file)
index 0000000..a2b6778
--- /dev/null
@@ -0,0 +1,33 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.simpleclient;
+
+import android.app.Application;
+import android.test.ApplicationTestCase;
+
+/**
+ * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
+ */
+public class ApplicationTest extends ApplicationTestCase<Application> {
+    public ApplicationTest() {
+        super(Application.class);
+    }
+}
diff --git a/android/SimpleClient/app/src/main/AndroidManifest.xml b/android/SimpleClient/app/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..08329da
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.simpleclient" >
+
+    <uses-permission android:name="android.permission.INTERNET" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name=".SimpleClient"
+            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>
diff --git a/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/FoundResource.java b/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/FoundResource.java
new file mode 100644 (file)
index 0000000..cd558f4
--- /dev/null
@@ -0,0 +1,72 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.simpleclient;
+
+import android.util.Log;
+
+import org.iotivity.base.AbstractFindCallback;
+import org.iotivity.base.OCResource;
+
+public class FoundResource extends AbstractFindCallback {
+    final private static String TAG = "FoundResource";
+
+
+    public void Callback(OCResource resource) {
+
+        if(SimpleClient.curResource != null) {
+            Log.e(TAG, "Found another resource, ignoring");
+        }
+
+        String resourceURI;
+        String hostAddress;
+
+        if(resource != null) {
+            Log.i(TAG, "DISCOVERED Resource");
+
+            resourceURI = resource.uri();
+            Log.i(TAG, "URI of the resource: " + resourceURI);
+
+            hostAddress = resource.host();
+            Log.i(TAG, "Host address of the resource: " + hostAddress);
+
+            new SimpleToast().execute("URI of the resource: " + resourceURI + "\nHost address of the resource: " + hostAddress);
+
+            String[] resourceTypes = resource.getResourceTypes();
+            for(int i=0; i<resourceTypes.length; i++) {
+                Log.i(TAG, "[" + i + "] : " + resourceTypes[i]);
+            }
+
+            String[] resourceInterfaces = resource.getResourceInterfaces();
+            for(int i=0; i<resourceInterfaces.length; i++) {
+                Log.i(TAG, "[" + i + "] : " + resourceInterfaces[i]);
+            }
+
+            if(resourceURI.equals("/a/light")) {
+                SimpleClient.curResource = resource;
+                SimpleClient.getLightRepresentation(resource);
+            }
+        }
+        else {
+            Log.e(TAG, "Resource is invalid");
+        }
+    }
+
+}
diff --git a/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnGet.java b/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnGet.java
new file mode 100644 (file)
index 0000000..428c65b
--- /dev/null
@@ -0,0 +1,58 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.simpleclient;
+
+import android.util.Log;
+
+import org.iotivity.base.AbstractGetCallback;
+import org.iotivity.base.OCHeaderOption;
+import org.iotivity.base.OCRepresentation;
+import org.iotivity.base.OCStackResult;
+
+public class OnGet extends AbstractGetCallback {
+    final private static String TAG = "OnGet";
+    public void Callback(OCHeaderOption[] options, OCRepresentation rep, int eCode) {
+        if(eCode == OCStackResult.OC_STACK_OK) {
+
+            Log.i(TAG, "GET request was successful");
+            Log.i(TAG, "Resource URI : " + rep.getUri());
+
+            SimpleClient.mylight.m_state = rep.getValueBool("state");
+            Log.i(TAG, "state : " + SimpleClient.mylight.m_state);
+            SimpleClient.mylight.m_power = rep.getValueInt("power");
+            Log.i(TAG, "power : " + SimpleClient.mylight.m_power);
+            SimpleClient.mylight.m_name = rep.getValueString("name");
+            Log.i(TAG, "name  : " + SimpleClient.mylight.m_name);
+
+            new SimpleToast().execute(
+                    "state : " + SimpleClient.mylight.m_state +
+                            "\npower : " + SimpleClient.mylight.m_power +
+                            "\nname  : " + SimpleClient.mylight.m_name
+            );
+
+            SimpleClient.putLightRepresentation(SimpleClient.curResource);
+        }
+        else {
+           Log.e(TAG, "onGet Response error : " + eCode);
+        }
+    }
+
+}
diff --git a/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnObserve.java b/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnObserve.java
new file mode 100644 (file)
index 0000000..5a06cbc
--- /dev/null
@@ -0,0 +1,75 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.simpleclient;
+
+import android.util.Log;
+
+import org.iotivity.base.AbstractObserveCallback;
+import org.iotivity.base.OCHeaderOption;
+import org.iotivity.base.OCRepresentation;
+import org.iotivity.base.OCStackResult;
+
+public class OnObserve extends AbstractObserveCallback {
+    final private static String TAG = "OnObserve";
+
+    public void Callback(OCHeaderOption[] options, OCRepresentation rep, int eCode, int seqNum) {
+        if(eCode == OCStackResult.OC_STACK_OK) {
+            {
+                Log.i(TAG, "OBSERVE RESULT :");
+                Log.i(TAG, "SequenceNumber : " + seqNum);
+
+                SimpleClient.mylight.m_state = rep.getValueBool("state");
+                Log.i(TAG, "state : " + SimpleClient.mylight.m_state);
+                SimpleClient.mylight.m_power = rep.getValueInt("power");
+                Log.i(TAG, "power : " + SimpleClient.mylight.m_power);
+                SimpleClient.mylight.m_name = rep.getValueString("name");
+                Log.i(TAG, "name  : " + SimpleClient.mylight.m_name);
+
+                new SimpleToast().execute(
+                        "state : " + SimpleClient.mylight.m_state +
+                                "\npower : " + SimpleClient.mylight.m_power +
+                                "\nname  : " + SimpleClient.mylight.m_name
+                );
+
+                if(SimpleClient.observe_count() > 5) {
+                    Log.i(TAG, "Cancelling Observe ...");
+                    OCStackResult result = SimpleClient.curResource.cancelObserve();
+                    Log.i(TAG, "Cancel result : " + result);
+                    try {
+                        Thread.sleep(10000); // 10 sec
+                    } catch (InterruptedException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                    Log.i(TAG, "DONE");
+                    new SimpleToast().execute(
+                            "DONE"
+                    );
+                }
+
+            }
+        }
+        else {
+            Log.e(TAG, "onPut Response error : " + eCode);
+        }
+
+    }
+}
diff --git a/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnPost.java b/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnPost.java
new file mode 100644 (file)
index 0000000..ca7e1ae
--- /dev/null
@@ -0,0 +1,77 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.simpleclient;
+
+import android.util.Log;
+
+import org.iotivity.base.AbstractPostCallback;
+import org.iotivity.base.OCHeaderOption;
+import org.iotivity.base.OCRepresentation;
+
+public class OnPost extends AbstractPostCallback {
+
+    final private static String TAG = "OnPost";
+
+    public void Callback(OCHeaderOption[] options, OCRepresentation rep, int eCode) {
+//FIXME : Need to check why ocstack is returning error code 28 to us after 12/6/14 rebase
+//        if(eCode == OCStackResult.OC_STACK_OK || eCode == OCStackResult.OC_STACK_RESOURCE_CREATED) {
+        if(true) {
+                Log.i(TAG, "POST request was successful");
+
+            if(rep.hasAttribute("createduri")) {
+                Log.i(TAG, "Uri of the created resource : " + rep.getValueString("createduri"));
+            }
+            else {
+                SimpleClient.mylight.m_state = rep.getValueBool("state");
+                Log.i(TAG, "state : " + SimpleClient.mylight.m_state);
+                SimpleClient.mylight.m_power = rep.getValueInt("power");
+                Log.i(TAG, "power : " + SimpleClient.mylight.m_power);
+                SimpleClient.mylight.m_name = rep.getValueString("name");
+                Log.i(TAG, "name  : " + SimpleClient.mylight.m_name);
+
+                new SimpleToast().execute(
+                        "state : " + SimpleClient.mylight.m_state +
+                                "\npower : " + SimpleClient.mylight.m_power +
+                                "\nname  : " + SimpleClient.mylight.m_name
+                );
+            }
+
+            OCRepresentation rep2 = new OCRepresentation();
+
+            Log.e(TAG, "Posting Light Representation ...");
+
+            SimpleClient.mylight.m_state = true;
+            SimpleClient.mylight.m_power = 55;
+
+            Log.i(TAG, "setValueBool : " + SimpleClient.mylight.m_state);
+            Log.i(TAG, "setValueInt  : " + SimpleClient.mylight.m_power);
+            rep2.setValueBool("state", SimpleClient.mylight.m_state);
+            rep2.setValueInt("power", SimpleClient.mylight.m_power);
+
+            OnPost2 onPost2 = new OnPost2();
+            SimpleClient.curResource.post(rep2, onPost2);
+        }
+        else {
+            Log.e(TAG, "onPost Response error : " + eCode);
+        }
+
+    }
+}
diff --git a/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnPost2.java b/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnPost2.java
new file mode 100644 (file)
index 0000000..cfc6ae6
--- /dev/null
@@ -0,0 +1,75 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.simpleclient;
+
+import android.util.Log;
+
+import org.iotivity.base.AbstractPostCallback;
+import org.iotivity.base.OCHeaderOption;
+import org.iotivity.base.OCRepresentation;
+import org.iotivity.base.OCStackResult;
+import org.iotivity.base.ObserveType;
+
+public class OnPost2 extends AbstractPostCallback {
+
+    final private static String TAG = "OnPost2";
+
+    public void Callback(OCHeaderOption[] options, OCRepresentation rep, int eCode) {
+//FIXME : Need to check why ocstack is returning error code 28 to us after 12/6/14 rebase
+//        if(eCode == OCStackResult.OC_STACK_OK || eCode == OCStackResult.OC_STACK_RESOURCE_CREATED) {
+        if(true) {
+
+            Log.i(TAG, "POST2 request was successful");
+
+            if(rep.hasAttribute("createduri")) {
+                String createdUri =  rep.getValueString("createduri");
+                Log.i(TAG, "Uri of the created resource : " + createdUri); // FIXME
+                new SimpleToast().execute(
+                        "Uri of the created resource : " + createdUri
+                );
+            }
+            else {
+                SimpleClient.mylight.m_state = rep.getValueBool("state");
+                Log.i(TAG, "state : " + SimpleClient.mylight.m_state);
+                SimpleClient.mylight.m_power = rep.getValueInt("power");
+                Log.i(TAG, "power : " + SimpleClient.mylight.m_power);
+                SimpleClient.mylight.m_name = rep.getValueString("name");
+                Log.i(TAG, "name  : " + SimpleClient.mylight.m_name);
+                new SimpleToast().execute(
+                        "state : " + SimpleClient.mylight.m_state +
+                                "\npower : " + SimpleClient.mylight.m_power +
+                                "\nname  : " + SimpleClient.mylight.m_name
+                );
+            }
+
+            if(SimpleClient.OBSERVE_TYPE_TO_USE == ObserveType.Observe)
+                Log.i(TAG, "Observe is used");
+            else if(SimpleClient.OBSERVE_TYPE_TO_USE == ObserveType.ObserveAll)
+                Log.i(TAG, "ObserveAll is used");
+
+            OnObserve onObserve = new OnObserve();
+            SimpleClient.curResource.observe(SimpleClient.OBSERVE_TYPE_TO_USE, onObserve);
+        }
+        else {
+            Log.e(TAG, "onPost Response error : " + eCode);
+        }
+    }
+}
diff --git a/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnPut.java b/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/OnPut.java
new file mode 100644 (file)
index 0000000..fa8410c
--- /dev/null
@@ -0,0 +1,59 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.simpleclient;
+
+import android.util.Log;
+
+import org.iotivity.base.AbstractPutCallback;
+import org.iotivity.base.OCHeaderOption;
+import org.iotivity.base.OCRepresentation;
+import org.iotivity.base.OCStackResult;
+
+public class OnPut extends AbstractPutCallback {
+
+    final private static String TAG = "OnGet";
+
+    public void Callback(OCHeaderOption[] options, OCRepresentation rep, int eCode) {
+        if(eCode == OCStackResult.OC_STACK_OK) {
+            {
+                Log.i(TAG, "PUT request was successful");
+
+                SimpleClient.mylight.m_state = rep.getValueBool("state");
+                Log.i(TAG, "state : " + SimpleClient.mylight.m_state);
+                SimpleClient.mylight.m_power = rep.getValueInt("power");
+                Log.i(TAG, "power : " + SimpleClient.mylight.m_power);
+                SimpleClient.mylight.m_name = rep.getValueString("name");
+                Log.i(TAG, "name  : " + SimpleClient.mylight.m_name);
+                new SimpleToast().execute(
+                        "state : " + SimpleClient.mylight.m_state +
+                        "\npower : " + SimpleClient.mylight.m_power +
+                        "\nname  : " + SimpleClient.mylight.m_name
+                );
+
+                SimpleClient.postLightRepresentation(SimpleClient.curResource);
+            }
+        }
+        else {
+            Log.e(TAG, "onPut Response error : " + eCode);
+        }
+
+    }
+}
diff --git a/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/SimpleClient.java b/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/SimpleClient.java
new file mode 100644 (file)
index 0000000..7413ca2
--- /dev/null
@@ -0,0 +1,151 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.simpleclient;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import org.iotivity.base.OCPlatform;
+import org.iotivity.base.OCRepresentation;
+import org.iotivity.base.OCResource;
+import org.iotivity.base.ObserveType;
+import org.iotivity.base.PlatformConfig;
+
+
+public class SimpleClient extends Activity {
+    final private static String TAG = "SimpleClient";
+
+    class Light {
+        public boolean m_state;
+        public int m_power;
+        public String m_name;
+
+        public Light() {
+            m_state = false;
+            m_power = 0;
+            m_name = "vincent";
+        }
+    }
+
+    static int OBSERVE_TYPE_TO_USE = ObserveType.Observe;
+
+    public static Light mylight;
+    public static OCResource curResource;
+    static int oc = 0;
+    static Activity mActivity;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mActivity = this;
+
+        mylight = new Light();
+
+               PlatformConfig cfg = new PlatformConfig(PlatformConfig.ServiceType.INPROC,
+                                                               PlatformConfig.ModeType.CLIENT,
+                                                               "0.0.0.0",
+                                                               0,
+                                                               PlatformConfig.QualityOfService.LO_QOS);
+
+        OCPlatform.configure(cfg);
+        FoundResource foundResource = new FoundResource();
+        OCPlatform.findResource("", "coap://224.0.1.187/oc/core?rt=core.light", foundResource);
+
+        setContentView(R.layout.activity_simple_client);
+    }
+
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        // Inflate the menu; this adds items to the action bar if it is present.
+        getMenuInflater().inflate(R.menu.simple_client, menu);
+        return true;
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        // Handle action bar item clicks here. The action bar will
+        // automatically handle clicks on the Home/Up button, so long
+        // as you specify a parent activity in AndroidManifest.xml.
+        int id = item.getItemId();
+        if (id == R.id.action_settings) {
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
+    protected static void getLightRepresentation(OCResource resource) {
+        if(resource != null) {
+            Log.e(TAG, "Getting Light Representation ...");
+
+            OnGet onGet = new OnGet();
+            resource.get(onGet);
+        }
+    }
+
+    protected static void putLightRepresentation(OCResource resource) {
+        if(resource != null) {
+
+            OCRepresentation rep = new OCRepresentation();
+
+            Log.e(TAG, "Putting Light Representation ...");
+
+            mylight.m_state = true;
+            mylight.m_power = 15;
+
+            Log.i(TAG, "setValueBool : " + SimpleClient.mylight.m_state);
+            Log.i(TAG, "setValueInt  : " + SimpleClient.mylight.m_power);
+            rep.setValueBool("state", mylight.m_state);
+            rep.setValueInt("power", mylight.m_power);
+
+            OnPut onPut = new OnPut();
+            resource.put(rep, onPut);
+        }
+    }
+
+    protected static void postLightRepresentation(OCResource resource) {
+        if(resource != null) {
+
+            OCRepresentation rep = new OCRepresentation();
+
+            Log.e(TAG, "Posting Light Representation ...");
+
+            mylight.m_state = false;
+            mylight.m_power = 105;
+
+            Log.i(TAG, "setValueBool : " + SimpleClient.mylight.m_state);
+            Log.i(TAG, "setValueInt  : " + SimpleClient.mylight.m_power);
+            rep.setValueBool("state", mylight.m_state);
+            rep.setValueInt("power", mylight.m_power);
+
+            OnPost onPost = new OnPost();
+            resource.post(rep, onPost);
+        }
+    }
+
+    protected static int observe_count() {
+        return ++oc;
+    }
+
+}
diff --git a/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/SimpleToast.java b/android/SimpleClient/app/src/main/java/org/iotivity/simpleclient/SimpleToast.java
new file mode 100644 (file)
index 0000000..8f7d672
--- /dev/null
@@ -0,0 +1,44 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.simpleclient;
+
+import android.os.AsyncTask;
+import android.widget.Toast;
+
+public class SimpleToast extends AsyncTask<String, String, String> {
+    String toastMessage;
+
+    @Override
+    protected String doInBackground(String... params) {
+        toastMessage = params[0];
+        return toastMessage;
+    }
+
+    protected void OnProgressUpdate(String... values) {
+        super.onProgressUpdate(values);
+    }
+   // This is executed in the context of the main GUI thread
+    protected void onPostExecute(String result){
+           Toast toast = Toast.makeText(SimpleClient.mActivity, result, Toast.LENGTH_SHORT);
+           toast.show();
+    }
+
+}
diff --git a/android/SimpleClient/app/src/main/res/drawable-hdpi/ic_launcher.png b/android/SimpleClient/app/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..96a442e
Binary files /dev/null and b/android/SimpleClient/app/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/android/SimpleClient/app/src/main/res/drawable-mdpi/ic_launcher.png b/android/SimpleClient/app/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..359047d
Binary files /dev/null and b/android/SimpleClient/app/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/android/SimpleClient/app/src/main/res/drawable-xhdpi/ic_launcher.png b/android/SimpleClient/app/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..71c6d76
Binary files /dev/null and b/android/SimpleClient/app/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/android/SimpleClient/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/android/SimpleClient/app/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..4df1894
Binary files /dev/null and b/android/SimpleClient/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/android/SimpleClient/app/src/main/res/layout/activity_simple_client.xml b/android/SimpleClient/app/src/main/res/layout/activity_simple_client.xml
new file mode 100644 (file)
index 0000000..f347f6c
--- /dev/null
@@ -0,0 +1,16 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    tools:context=".SimpleClient">
+
+    <TextView
+        android:text="@string/hello_world"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+
+</RelativeLayout>
diff --git a/android/SimpleClient/app/src/main/res/menu/simple_client.xml b/android/SimpleClient/app/src/main/res/menu/simple_client.xml
new file mode 100644 (file)
index 0000000..1a65997
--- /dev/null
@@ -0,0 +1,8 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:context=".SimpleClient" >
+    <item android:id="@+id/action_settings"
+        android:title="@string/action_settings"
+        android:orderInCategory="100"
+        android:showAsAction="never" />
+</menu>
diff --git a/android/SimpleClient/app/src/main/res/values-w820dp/dimens.xml b/android/SimpleClient/app/src/main/res/values-w820dp/dimens.xml
new file mode 100644 (file)
index 0000000..63fc816
--- /dev/null
@@ -0,0 +1,6 @@
+<resources>
+    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
+         (such as screen margins) for screens with more than 820dp of available width. This
+         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
+    <dimen name="activity_horizontal_margin">64dp</dimen>
+</resources>
diff --git a/android/SimpleClient/app/src/main/res/values/dimens.xml b/android/SimpleClient/app/src/main/res/values/dimens.xml
new file mode 100644 (file)
index 0000000..47c8224
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
diff --git a/android/SimpleClient/app/src/main/res/values/strings.xml b/android/SimpleClient/app/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..532e40d
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">SimpleClient</string>
+    <string name="hello_world">Hello world!</string>
+    <string name="action_settings">Settings</string>
+
+</resources>
diff --git a/android/SimpleClient/app/src/main/res/values/styles.xml b/android/SimpleClient/app/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..ff6c9d2
--- /dev/null
@@ -0,0 +1,8 @@
+<resources>
+
+    <!-- Base application theme. -->
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- Customize your theme here. -->
+    </style>
+
+</resources>
diff --git a/android/SimpleClient/build.gradle b/android/SimpleClient/build.gradle
new file mode 100644 (file)
index 0000000..9b8abe4
--- /dev/null
@@ -0,0 +1,19 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+    repositories {
+        jcenter()
+    }
+    dependencies {
+        classpath 'com.android.tools.build:gradle:0.12.2'
+
+        // NOTE: Do not place your application dependencies here; they belong
+        // in the individual module build.gradle files
+    }
+}
+
+allprojects {
+    repositories {
+        jcenter()
+    }
+}
diff --git a/android/SimpleClient/gradle.properties b/android/SimpleClient/gradle.properties
new file mode 100644 (file)
index 0000000..5d08ba7
--- /dev/null
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/android/SimpleClient/gradlew b/android/SimpleClient/gradlew
new file mode 100755 (executable)
index 0000000..91a7e26
--- /dev/null
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/android/SimpleClient/gradlew.bat b/android/SimpleClient/gradlew.bat
new file mode 100644 (file)
index 0000000..aec9973
--- /dev/null
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off\r
+@rem ##########################################################################\r
+@rem\r
+@rem  Gradle startup script for Windows\r
+@rem\r
+@rem ##########################################################################\r
+\r
+@rem Set local scope for the variables with windows NT shell\r
+if "%OS%"=="Windows_NT" setlocal\r
+\r
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r
+set DEFAULT_JVM_OPTS=\r
+\r
+set DIRNAME=%~dp0\r
+if "%DIRNAME%" == "" set DIRNAME=.\r
+set APP_BASE_NAME=%~n0\r
+set APP_HOME=%DIRNAME%\r
+\r
+@rem Find java.exe\r
+if defined JAVA_HOME goto findJavaFromJavaHome\r
+\r
+set JAVA_EXE=java.exe\r
+%JAVA_EXE% -version >NUL 2>&1\r
+if "%ERRORLEVEL%" == "0" goto init\r
+\r
+echo.\r
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r
+echo.\r
+echo Please set the JAVA_HOME variable in your environment to match the\r
+echo location of your Java installation.\r
+\r
+goto fail\r
+\r
+:findJavaFromJavaHome\r
+set JAVA_HOME=%JAVA_HOME:"=%\r
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe\r
+\r
+if exist "%JAVA_EXE%" goto init\r
+\r
+echo.\r
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r
+echo.\r
+echo Please set the JAVA_HOME variable in your environment to match the\r
+echo location of your Java installation.\r
+\r
+goto fail\r
+\r
+:init\r
+@rem Get command-line arguments, handling Windowz variants\r
+\r
+if not "%OS%" == "Windows_NT" goto win9xME_args\r
+if "%@eval[2+2]" == "4" goto 4NT_args\r
+\r
+:win9xME_args\r
+@rem Slurp the command line arguments.\r
+set CMD_LINE_ARGS=\r
+set _SKIP=2\r
+\r
+:win9xME_args_slurp\r
+if "x%~1" == "x" goto execute\r
+\r
+set CMD_LINE_ARGS=%*\r
+goto execute\r
+\r
+:4NT_args\r
+@rem Get arguments from the 4NT Shell from JP Software\r
+set CMD_LINE_ARGS=%$\r
+\r
+:execute\r
+@rem Setup the command line\r
+\r
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar\r
+\r
+@rem Execute Gradle\r
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\r
+\r
+:end\r
+@rem End local scope for the variables with windows NT shell\r
+if "%ERRORLEVEL%"=="0" goto mainEnd\r
+\r
+:fail\r
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r
+rem the _cmd.exe /c_ return code!\r
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1\r
+exit /b 1\r
+\r
+:mainEnd\r
+if "%OS%"=="Windows_NT" endlocal\r
+\r
+:omega\r
diff --git a/android/SimpleClient/settings.gradle b/android/SimpleClient/settings.gradle
new file mode 100644 (file)
index 0000000..e7b4def
--- /dev/null
@@ -0,0 +1 @@
+include ':app'
index 12761e6..536331c 100755 (executable)
@@ -22,12 +22,12 @@ function build()
        # Note: for android, as oic-resource uses C++11 feature stoi and to_string,
        # it requires gcc-4.9, currently only android-ndk-r10(for linux)
        # and windows android-ndk-r10(64bit target version) support these features.
-
        if [ "$BUILD_FOR_ANDROID" = "true" ]
                then
+
                echo "*********** Build Boost for android ***********"
                pushd extlibs
-               .//buildDependencies.sh
+               ./buildDependencies.sh
                popd
 
                echo "*********** Build for android x86 *************"
@@ -42,7 +42,7 @@ function build()
                echo "*********** Build for android armeabi-v7a-hard *************"
                scons TARGET_OS=android TARGET_ARCH=armeabi-v7a-hard ANDROID_NDK=$1 RELEASE=$3
        fi
-
+       
        echo "*********** Build for arduino avr *************"
        scons TARGET_OS=arduino TARGET_ARCH=avr ARDUINO_HOME=$2 RELEASE=$3
 
@@ -97,7 +97,7 @@ then
 fi
 
 # Suppress "Reading ..." message and enable parallel build
-export SCONSFLAGS="-Q -j 8"
+export SCONSFLAGS="-Q -j 4"
 build $1 $2 true
 build $1 $2 false
 echo "===================== done ====================="
index be49aee..4ae0fe4 100644 (file)
@@ -81,7 +81,7 @@ target_arch = env.get('TARGET_ARCH')
 
 # Android ndk early version doesn't support C++11. Detect the toolchain version
 # to make sure proper toolchain is used
-for tc_ver in ['4.7', '4.8', '4.9', '']:
+for tc_ver in ['4.9', '4.8', '4.7', '']:
        if os.path.exists(android_ndk + '/toolchains/x86-' + tc_ver):
                break
 
@@ -141,6 +141,13 @@ for flags in p.stdout.readlines():
                if not platform_ver.isdigit():
                        platform_ver = ''
 
+# Add external libraries including boost
+env.AppendUnique(CPPPATH = [env.get('SRC_DIR') + '/out/android/include' ])
+if target_arch == 'x86':
+       env.AppendUnique(LIBPATH = [env.get('SRC_DIR') + '/out/android/lib/x86'])
+else:
+       env.AppendUnique(LIBPATH = [env.get('SRC_DIR') + '/out/android/lib/arm-linux-androideabi'])
+
 ######################################################################
 # Set release/debug flags
 ######################################################################
@@ -159,7 +166,7 @@ env.Replace(CXXCOM = '$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM -fPIE $SO
 env.Replace(LINKCOM = '$LINK -o $TARGET -pie $LINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS')
 
 # Fix android-ndk compatibility issue, make applications build on new NDK can run on old platform
-if platform_ver == '' or int(platform_ver) > 20:
-       SConscript('compatibility/c_compat.scons')
-
-SConscript('compatibility/cpp11_compat.scons')
+#if platform_ver == '' or int(platform_ver) > 20:
+#      SConscript('compatibility/c_compat.scons')
+#
+#SConscript('compatibility/cpp11_compat.scons')
index 9b919d2..4ebe318 100755 (executable)
@@ -5,6 +5,8 @@ set -e
 # Change to extlibs directory
 cd "$(dirname "$0")"
 
+EXTDIR=$(pwd)
+
 # Check for cereal existence
 if [ ! -d "cereal" ]; then
     git clone https://github.com/USCiLab/cereal.git cereal
@@ -14,64 +16,84 @@ if [ ! -d "cereal" ]; then
     popd
 fi
 
+# Pick the preferred version of boost to use
 BOOST_MAJOR=1
-BOOST_MINOR=55
+BOOST_MINOR=57
 BOOST_REVISION=0
 
 BOOST_VERSION="${BOOST_MAJOR}.${BOOST_MINOR}.${BOOST_REVISION}"
-BOOST_NAME="boost_${BOOST_MAJOR}_${BOOST_MINOR}_${BOOST_REVISION}"
-BOOST_FILE="${BOOST_NAME}.zip"
 
-function downloadBoost {
-    echo "Downloading boost v${BOOST_VERSION}"
-    wget --progress=bar --continue --output-document=${BOOST_FILE} http://downloads.sourceforge.net/project/boost/boost/${BOOST_VERSION}/${BOOST_FILE}?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F${BOOST_VERSION}%2F\&ts=1419450713\&use_mirror=iweb
-}
+# Determine the architecture
+HOST_ARCH=$(arch)
 
-function unpackBoost {
-    if [ ! -f "${BOOST_FILE}" ]; then
-        downloadBoost
-    fi
+if [ "${HOST_ARCH}" != "x86_64" ];
+then
+    HOST_ARCH="x86"
+fi
 
-    echo "Unpacking boost v${BOOST_VERSION}"
-    unzip ${BOOST_FILE} >> build.log
-    pushd ${BOOST_NAME}
-    ./bootstrap.sh
-    popd
+HOST_ARCH="linux-${HOST_ARCH}"
+
+function cloneBoost {
+    echo "Removing old boost repo..."
+    rm -rf boost
+    echo "Cloning boost from GIT HUB..."
+    git clone --recursive https://github.com/boostorg/boost.git boost
 }
 
 function buildBoost {
-    if [ ! -d "${BOOST_NAME}" ]; then
-        unpackBoost
+    if [ ! -d "boost" ]; then
+        cloneBoost
     fi
     
-    TOOLCHAIN=${ANDROID_NDK}/toolchains/${TOOLSET}-${VERSION}/prebuilt/linux-x86/bin
-    echo "Copying user configs to boost"
-    cp ../resource/patches/user-config-${TOOLSET}.jam ${BOOST_NAME}/tools/build/v2/user-config.jam
+    # Determine the 
+    TOOLCHAIN=${ANDROID_NDK}/toolchains/${TOOLSET}-${VERSION}/prebuilt/${HOST_ARCH}/bin
 
     OLDPATH=$PATH
     PATH=$TOOLCHAIN:$PATH
 
-    pushd ${BOOST_NAME}
-    ./b2 clean
+    rm -f boost.log
+
+    pushd boost
+    echo "Checking out boost v${BOOST_VERSION}..."
+    git checkout --force -B boost-${BOOST_VERSION} tags/boost-${BOOST_VERSION}                                   &>> ../boost.log
+    git submodule foreach --recursive git checkout --force -B boost-${BOOST_VERSION} tags/boost-${BOOST_VERSION} &>> ../boost.log
+    echo "Reset and clean all modular repositories..."
+    git reset --hard HEAD                                     >> ../boost.log
+    git clean -d --force                                      >> ../boost.log
+    git clean -d --force -x                                   >> ../boost.log
+    git submodule foreach --recursive git reset --hard HEAD   >> ../boost.log
+    git submodule foreach --recursive git clean --force -d    >> ../boost.log
+    git submodule foreach --recursive git clean --force -d -x >> ../boost.log
+    echo "Copying user configs to boost..."
+    cp ${EXTDIR}/../resource/patches/boost/${TOOLSET}/user-config.jam tools/build/src/user-config.jam
+    echo "Boostrapping boost..."
+    ./bootstrap.sh
+    echo "Building..."
     ./b2 -q \
         target-os=linux \
         link=static \
         threading=multi \
         --layout=system \
-        --prefix="./../../out/boost" \
-        -s PLATFORM=android-${PLATFORM} \
+        --build-type=minimal \
+        -s PLATFORM=${PLATFORM} \
         -s VERSION=${VERSION} \
+        --prefix="${EXTDIR}/../out/boost" \
+        --includedir="${INCPATH}" \
+        --libdir="${LIBPATH}" \
+        --build-dir="$(pwd)/build" \
         --with-thread \
         --with-program_options \
-        install
+        headers install
     popd
 
-    PATH=$OLDPATH
+    if [ ! -d "${INCPATH}" ];
+    then
+        echo "Copying headers to android include directory..."
+        mkdir -p ${INCPATH}
+        cp --recursive --dereference boost/boost ${INCPATH}
+    fi
 
-    mkdir -p ${INCPATH}
-    cp -R ../out/boost/include/* ${INCPATH}
-    mkdir -p ${LIBPATH}
-    cp -R ../out/boost/lib/*     ${LIBPATH}
+    PATH=$OLDPATH
 }
 
 function checkBoost {
@@ -79,18 +101,14 @@ function checkBoost {
     TOOLSET=$2
     VERSION=$3
 
-    INCPATH="$(dirname "$0")/../out/android/include"
-    LIBPATH="$(dirname "$0")/../out/android/lib/${TOOLSET}"
+    INCPATH="${EXTDIR}/../out/android/include"
+    LIBPATH="${EXTDIR}/../out/android/lib/${TOOLSET}"
 
-    if [ ! -d "${INCPATH}" ];
-    then
-        buildBoost
-    fi
     if [ ! -d "${LIBPATH}" ];
     then
         buildBoost
     fi
 }
 
-checkBoost 19 arm-linux-androideabi 4.9
-checkBoost 19 x86 4.9
+checkBoost android-19 arm-linux-androideabi 4.9
+checkBoost android-19 x86 4.9
index fc82826..e1ad14e 100644 (file)
@@ -13,6 +13,9 @@ SConscript('csdk/libcoap/SConscript')
 # Build liboctbstack
 SConscript('csdk/SConscript')
 
+if target_os == 'android':
+       SConscript('android/SConscript')
+
 if target_os != 'arduino':
        # Build liboc_logger
        SConscript('oc_logger/SConscript')
diff --git a/resource/android/OCAndroid.cpp b/resource/android/OCAndroid.cpp
new file mode 100644 (file)
index 0000000..a43d578
--- /dev/null
@@ -0,0 +1,104 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <sstream>
+#include "OCAndroid.h"
+
+namespace OC {
+       template <typename T>
+       void from_string(const std::string& s, T& result) {
+               std::stringstream ss(s);
+               ss >> result;    // TODO handle errors
+       }
+
+       /*
+       template <typename T>
+       std::string to_string(T value)
+       {
+       std::ostringstream os ;
+       os << value ;
+       return os.str() ;
+       }
+       */
+
+}
+
+namespace std {
+
+       int stoi(const string& s)
+       {
+               int ret;
+               int &ref = ret;
+               OC::from_string(s, ref);
+               return ret;
+       }
+
+       double stod(const std::string& s)
+       {
+               double ret;
+               double &ref = ret;
+               OC::from_string(s, ref);
+               return ret;
+       }
+
+       long long stoll(const std::string& s)
+       {
+               long long ret;
+               long long int &ref = ret;
+               OC::from_string(s, ref);
+               return ret;
+       }
+
+       unsigned long long stoull(const std::string& s)
+       {
+               unsigned long long ret;
+               unsigned long long  &ref = ret;
+               OC::from_string(s, ref);
+               return ret;
+       }
+
+       long double stold(const string& s)
+       {
+               long double ret;
+               long double &ref = ret;
+               OC::from_string(s, ref);
+               return ret;
+       }
+
+       std::string to_string(int t) {
+               std::ostringstream os;
+                       os << t;
+               return os.str();
+       }
+
+       std::string to_string(double t) {
+               std::ostringstream os;
+                       os << t;
+               return os.str();
+       }
+
+       std::string to_string(uint32_t t)
+       {
+               std::ostringstream os;
+                       os << t;
+               return os.str();
+       }
+
+} // std
diff --git a/resource/android/SConscript b/resource/android/SConscript
new file mode 100644 (file)
index 0000000..35e3616
--- /dev/null
@@ -0,0 +1,30 @@
+##
+# Android Compatibility (static library) build script
+##
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+#SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
+
+compatibilitylib_env = lib_env.Clone()
+######################################################################
+# Build flags
+######################################################################
+compatibilitylib_env.AppendUnique(CPPPATH = ['../include/'])
+
+target_os = env.get('TARGET_OS')
+
+if target_os == 'android':
+       compatibilitylib_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+       #oclib_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+       compatibilitylib_env.AppendUnique(LIBS = ['gnustl_static'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+compatibilitylib_src = ['OCAndroid.cpp']
+
+if target_os == 'android':
+       static_compatibilitylib = compatibilitylib_env.StaticLibrary('compatibility', compatibilitylib_src)
+       compatibilitylib_env.InstallTarget(static_compatibilitylib, 'libcompatibility')
index 6de4c2d..65d02a1 100644 (file)
@@ -74,8 +74,11 @@ liboctbstack_src = [
     OCTBSTACK_SRC + 'oicgroup.c'
        ]
 if target_os == 'arduino':
-       liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
+       static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
+       liboctbstack_env.InstallTarget(static_liboctbstack, 'liboctbstack')
 else:
-       liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
+       static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
+       shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
+       liboctbstack_env.InstallTarget([static_liboctbstack, shared_liboctbstack], 'liboctbstack')
+
 
-liboctbstack_env.InstallTarget(liboctbstack, 'liboctbstack')
index 7e1bdf1..d10bba0 100644 (file)
@@ -78,8 +78,9 @@ else:
        libcoap_src.append(['../ocsocket/src/ocsocket.c'])
 
 if target_os == 'arduino':
-       libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+       static_libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+       libcoap_env.InstallTarget(static_libcoap, 'libcoap')
 else:
-       libcoap = libcoap_env.SharedLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
-
-libcoap_env.InstallTarget(libcoap, 'libcoap')
+       static_libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+       shared_libcoap = libcoap_env.SharedLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+       libcoap_env.InstallTarget([static_libcoap, shared_libcoap], 'libcoap')
index f4d8bb9..434efd7 100644 (file)
@@ -28,7 +28,7 @@ if target_os not in ['windows', 'winrt']:
 
 if target_os == 'android':
        ocicuc_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
-       ocicuc_env.AppendUnique(LIBS = ['boost_program_options-gcc-mt-1_49', 'boost_thread-gcc-mt-1_49', 'gnustl_static'])
+       ocicuc_env.AppendUnique(LIBS = ['boost_program_options', 'boost_thread', 'gnustl_static'])
 
        if not env.get('RELEASE'):
                ocicuc_env.AppendUnique(LIBS = ['log'])
diff --git a/resource/include/OCAndroid.h b/resource/include/OCAndroid.h
new file mode 100644 (file)
index 0000000..ec015ee
--- /dev/null
@@ -0,0 +1,44 @@
+//******************************************************************
+//
+// Copyright 2014 MediaTek 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 _OCANDROID_H_
+#define _OCANDROID_H_
+
+#ifdef __ANDROID__
+#include <string>
+
+// FIXME : ugly hack
+// Android missing functions
+namespace std {
+       int stoi(const std::string& s);
+       double stod(const std::string& s);
+       long long stoll(const std::string& s);
+       unsigned long long stoull(const std::string& s);
+       long double stold(const string& s);
+
+       std::string to_string(int i);
+       std::string to_string(uint32_t i);
+       std::string to_string(double d);
+}
+
+#endif
+
+
+#endif
index 3a1746b..2e64fcd 100644 (file)
 #include <AttributeValue.h>
 #include <StringConstants.h>
 
-#include <OCException.h>
-
 #ifdef __ANDROID__
-#include "android_cpp11_compat.h"
+#include "OCAndroid.h"
 #endif
 
+#include <OCException.h>
+
 namespace cereal
 {
     class access;
index 52e665e..5cb21cb 100644 (file)
@@ -25,11 +25,11 @@ if target_os not in ['arduino', 'windows', 'winrt']:
 ######################################################################
 # Source files and Targets
 ######################################################################
-liboc_logger_core = liboc_logger_env.SharedLibrary('oc_logger_core', 'c/oc_logger.c',  OBJPREFIX='core_')
-liboc_logger = liboc_logger_env.SharedLibrary('oc_logger',
-               ['c/oc_logger.c', 'c/oc_console_logger.c', 'cpp/oc_ostream_logger.cpp'])
+shared_liboc_logger_core = liboc_logger_env.SharedLibrary('oc_logger_core', 'c/oc_logger.c',  OBJPREFIX='core_')
+shared_liboc_logger      = liboc_logger_env.SharedLibrary('oc_logger', ['c/oc_logger.c', 'c/oc_console_logger.c', 'cpp/oc_ostream_logger.cpp'])
+static_liboc_logger      = liboc_logger_env.StaticLibrary('oc_logger', ['c/oc_logger.c', 'c/oc_console_logger.c', 'cpp/oc_ostream_logger.cpp'])
 
-liboc_logger_env.InstallTarget([liboc_logger_core, liboc_logger], 'liboc_logger')
+liboc_logger_env.InstallTarget([shared_liboc_logger_core, shared_liboc_logger, static_liboc_logger ], 'liboc_logger')
 
 if target_os not in ['ios']:
        SConscript('examples/SConscript')
index 71487cd..99b3e65 100644 (file)
@@ -23,6 +23,9 @@
 /// @brief  This file contains the implementation of classes and its members
 ///         related to OCRepresentation
 
+#ifdef __ANDROID__
+#include "OCAndroid.h"
+#endif
 
 #include <OCRepresentation.h>
 
index 4dc2570..3a50c87 100644 (file)
@@ -28,7 +28,7 @@ if target_os not in ['windows', 'winrt']:
 if target_os == 'android':
        oclib_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
        oclib_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-       oclib_env.AppendUnique(LIBS = ['octbstack', 'coap', 'oc_logger', 'boost_thread-gcc-mt-1_49', 'gnustl_static', 'log'])
+       oclib_env.AppendUnique(LIBS = ['octbstack', 'coap', 'oc_logger', 'boost_thread', 'gnustl_static', 'log', 'compatibility'])
 
 if target_os in ['darwin', 'ios']:
        oclib_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
@@ -48,5 +48,6 @@ oclib_src = [
                'InProcClientWrapper.cpp'
        ]
 
-oclib = oclib_env.SharedLibrary('oc', oclib_src)
-oclib_env.InstallTarget(oclib, 'liboc')
+shared_oclib = oclib_env.SharedLibrary('oc', oclib_src)
+static_oclib = oclib_env.StaticLibrary('oc', oclib_src)
+oclib_env.InstallTarget([shared_oclib, static_oclib], 'liboc')
index 1ea7f78..e8d873e 100644 (file)
@@ -15,7 +15,7 @@ if target_os != 'arduino':
 
        # Build protocol plugin project
        # protocol-plugin use 'inotify', this feature isn't support by MAC OSX
-       if target_os not in ['darwin', 'ios']:
+       if target_os not in ['darwin', 'ios', 'android']:
                SConscript('protocol-plugin/SConscript')
 
        # Build notification manager project
index eb64e7e..8dceeeb 100644 (file)
@@ -26,7 +26,7 @@ if target_os not in ['windows', 'winrt']:
 
 if target_os == 'android':
        soft_sensor_manager_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
-       soft_sensor_manager_env.AppendUnique(LIBS = ['gnustl_static'])
+       soft_sensor_manager_env.AppendUnique(LIBS = ['gnustl_static', 'compatibility'])
 
        if not env.get('RELEASE'):
                soft_sensor_manager_env.AppendUnique(LIBS = ['log'])