# Make sure that boost for android is available
SConscript(env.get('SRC_DIR') + '/extlibs/boost/SConscript')
+SConscript(env.get('SRC_DIR') + '/extlibs/expat/SConscript')
Import('env')
expat_env = env.Clone()
-
+SConscript(env.get('SRC_DIR') + '/build_common/tools/UnpackAll.py')
######################################################################
# Build flags
######################################################################
expat_src = env.UnpackAll(src_dir + '/Makefile', 'expat.tar.gz')
env.Configure(src_dir, './configure')
-expat_env.AppendUnique(CPPPATH = [src_dir, src_dir + 'lib'])
+expat_env.AppendUnique(CPPPATH = [src_dir, src_dir + 'lib', src_dir + 'vms'])
target_os = env.get('TARGET_OS')
if target_os not in ['windows', 'winrt']:
# The code include pthread_cancel method, can't build on android
# MQTT requires openssl, forbid cross compile as it isn't ready
-#if env.get('TARGET_OS') != 'android' and env.get('TARGET_ARCH') == platform.machine():
if env.get('TARGET_OS') != 'android':
SConscript('plugins/SConscript')
pmimpl = pmimpl_env.SharedLibrary('pmimpl', pmimpl_src)
plugin_manager_env.InstallTarget([ppm, pmimpl], 'libppm')
+
+# Build JNI library for android
+if env.get('TARGET_OS') == 'android':
+ SConscript('src/Android/jni/SConscript')
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry exported="true" kind="lib" path="/home/minji/JUDO/out/felix.jar"/>
+ <classpathentry exported="true" kind="lib" path="/home/minji/JUDO/150520/iotivity/android/android_api/base/build/intermediates/bundles/release/classes.jar"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>MainActivity</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.iotivity.service.ppm"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+ <uses-permission android:name="android.permission.GET_TASKS"/>
+ <uses-permission android:name="com.samsung.wmanager.ENABLE_NOTIFICATION"/>
+ <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
+ <uses-permission android:name="android.permission.CALL_PHONE" />
+ <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
+ <uses-permission android:name="android.permission.READ_CONTACTS"/>
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
+ <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
+ <uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY"/>
+
+ <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme"
+ android:largeHeap="true" >
+ <activity
+ android:name="org.iotivity.service.ppm.MainActivity"
+ 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>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<pluginManager>
+ <pluginInfo
+ pluginPath="/data/data/org.iotivity.service.ppm/files"
+ maxMEM="64M"
+ maxPlugin=""
+ version="1.0"
+ name="pluginmanager">
+ </pluginInfo>
+ <specailpluginInfo>
+ </specailpluginInfo>
+</pluginManager>
--- /dev/null
+LOCAL_PATH:=$(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libexpat
+LOCAL_SRC_FILES := ../../../../../../deps/android/lib/armeabi/libexpat.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libboost_thread
+LOCAL_SRC_FILES := ../../../../../../deps/android/lib/armeabi/libboost_thread.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libboost_system
+LOCAL_SRC_FILES := ../../../../../../deps/android/lib/armeabi/libboost_system.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libcpluff
+LOCAL_SRC_FILES := ../../../../../../out/android/armeabi/release/libcpluff.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libpmimpl
+LOCAL_SRC_FILES := ../../../../../../out/android/armeabi/release/libpmimpl.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+
+include $(CLEAR_VARS)
+LOCAL_DEFAULT_CPP_EXTENSION := cpp
+LOCAL_MODULE := PluginManager
+LOCAL_SRC_FILES := PluginManager.cpp
+LOCAL_CPPFLAGS := -std=c++0x -frtti -fexceptions
+LOCAL_LDLIBS := -llog -ldl -lz
+
+LOCAL_STATIC_LIBRARIES := libcpluff
+LOCAL_STATIC_LIBRARIES += libpmimpl
+LOCAL_STATIC_LIBRARIES += libboost_thread
+LOCAL_STATIC_LIBRARIES += libboost_system
+LOCAL_STATIC_LIBRARIES += libexpat
+
+LOCAL_C_INCLUDES := ../../../../../../extlibs/boost/boost_1_57_0
+LOCAL_C_INCLUDES += ../../../../lib/cpluff/libcpluff
+LOCAL_C_INCLUDES += ../../../src
+LOCAL_C_INCLUDES += ../../../../../../extlibs/rapidxml
+
+include $(BUILD_SHARED_LIBRARY)
--- /dev/null
+NDK_TOOLCHAIN_VERSION := 4.9
+APP_STL := gnustl_shared
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file PluginManager.cpp
+
+/// @brief
+
+#include <stdio.h>
+#include <string>
+
+#include "PluginManager.h"
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: startPlugins
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ppm_PluginManager_jniStartPlugins(JNIEnv *env, jobject jobj,
+ jstring jkey, jstring jvalue)
+{
+ LOGD("jniStartPlugins() Called.");
+
+ if((!jkey)||(!jvalue))
+ return 0;
+ std::string ckey = env->GetStringUTFChars(jkey, 0);
+ std::string cvalue = env->GetStringUTFChars(jvalue, 0);
+
+ return (jint)pluginManagerImpl->startPlugins(ckey, cvalue);
+}
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: stopPlugins
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ppm_PluginManager_jniStopPlugins(JNIEnv *env, jobject jobj,
+ jstring jkey, jstring jvalue)
+{
+ LOGD("jniStopPlugins() Called.");
+
+ if((!jkey)||(!jvalue))
+ return 0;
+ std::string ckey = env->GetStringUTFChars(jkey, 0);
+ std::string cvalue = env->GetStringUTFChars(jvalue, 0);
+
+ return (jint)pluginManagerImpl->stopPlugins(ckey, cvalue);
+}
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: jniRescanPlugin
+ * Signature: (V)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ppm_PluginManager_jniRescanPlugin(JNIEnv *env, jobject jobj)
+{
+ LOGD("jniRescanPlugin() Called.");
+
+ return (jint)pluginManagerImpl->rescanPlugin();
+}
+
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: getPlugins
+ * Signature: (V)[Lorg/iotivity/service/ppm/Plugin;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_service_ppm_PluginManager_jniGetPlugins(JNIEnv *env,
+ jobject jobj)
+{
+ LOGD("jniGetPlugins() Called.");
+
+ std::vector<OIC::Plugin> result = pluginManagerImpl->getAllPlugins();
+
+ jclass cls = env->FindClass("org/iotivity/service/ppm/Plugin");
+ jmethodID mid = env->GetMethodID(cls, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
+ jobjectArray resultArray = (jobjectArray)env->NewObjectArray(result.size(), cls, NULL);
+
+ for (int i = 0; i < result.size(); i++)
+ {
+ jstring jname = env->NewStringUTF(result[i].getName().c_str());
+ LOGD("jniGetPlugins() [%d] Name: %s", i + 1, result[i].getName().c_str());
+ jstring jplugID = env->NewStringUTF(result[i].getID().c_str());
+ LOGD("jniGetPlugins() [%d] Version: %s", i + 1, result[i].getID().c_str());
+ env->SetObjectArrayElement(resultArray, i, env->NewObject(cls, mid, jname, jplugID));
+ }
+
+ return resultArray;
+}
+
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: getState
+ * Signature: (Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_iotivity_service_ppm_PluginManager_jniGetState(JNIEnv *env, jobject jobj,
+ jstring jplugID)
+{
+ LOGD("jniGetState() Called.");
+
+ if (!jplugID)
+ return env->NewStringUTF("NULL_INPUT");
+ std::string cplugID = env->GetStringUTFChars(jplugID, 0);
+ std::string result = pluginManagerImpl->getState(cplugID);
+
+ return env->NewStringUTF(result.c_str());
+}
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: JNI_OnLoad
+ */
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jjvm, void *reserved)
+{
+ LOGD("JNI_OnLoad() Called.");
+
+ JNIEnv *env;
+
+ if (jjvm->GetEnv((void **) &env, JNI_VERSION_1_6) != JNI_OK)
+ return JNI_ERR;
+
+ jvm = jjvm;
+ pluginManagerImpl = new OIC::PluginManagerImpl((void *)jvm);
+
+ return JNI_VERSION_1_6;
+}
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: JNI_OnUnload
+ */
+JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jjvm, void *reserved)
+{
+ LOGD("JNI_OnUnload() Called.");
+
+ JNIEnv *env;
+
+ if (jjvm->GetEnv((void **) &env, JNI_VERSION_1_6) != JNI_OK)
+ return ;
+
+ jvm = NULL;
+
+ if (pluginManagerImpl)
+ delete pluginManagerImpl;
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file PluginManager.h
+
+/// @brief
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+#include <android/log.h>
+
+#include "../../PluginManagerImpl.h"
+
+/* Header for class com_example_iotivity_PluginManager */
+
+#define LOG_TAG "PluginManager.cpp"
+#define LOGUNK(...) __android_log_print(ANDROID_LOG_UNKNOWN,LOG_TAG,__VA_ARGS__)
+#define LOGDEF(...) __android_log_print(ANDROID_LOG_DEFAULT,LOG_TAG,__VA_ARGS__)
+#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
+#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
+#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
+#define LOGF(...) __android_log_print(ANDROID_FATAL_ERROR,LOG_TAG,__VA_ARGS__)
+#define LOGS(...) __android_log_print(ANDROID_SILENT_ERROR,LOG_TAG,__VA_ARGS__)
+
+#ifndef _Included_org_iotivity_service_ppm_PluginManager
+#define _Included_org_iotivity_service_ppm_PluginManager
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+OIC::PluginManagerImpl *pluginManagerImpl;
+JavaVM *jvm;
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: jniStartPlugins
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ppm_PluginManager_jniStartPlugins(JNIEnv *, jobject,
+ jstring, jstring);
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: jniStopPlugins
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ppm_PluginManager_jniStopPlugins(JNIEnv *, jobject, jstring,
+ jstring);
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: jniRescanPlugin
+ * Signature: (V)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ppm_PluginManager_jniRescanPlugin(JNIEnv *, jobject);
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: jniGetPlugins
+ * Signature: (V)[Lorg/iotivity/service/ppm/Plugin;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_service_ppm_PluginManager_jniGetPlugins(JNIEnv *, jobject);
+
+/*
+ * Class: org_iotivity_service_ppm_PluginManager
+ * Method: jniGetState
+ * Signature: (Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_iotivity_service_ppm_PluginManager_jniGetState(JNIEnv *, jobject,
+ jstring);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /dev/null
+##
+# Protocol plug-in manager service JNI build script
+##
+
+import os
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', exports = 'lib_env')
+
+ppm_jni_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+ppm_sdk = env.get('SRC_DIR') + '/service/protocol-plugin/plugin-manager'
+
+######################################################################
+# Build flags
+######################################################################
+ppm_jni_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-DLINUX', '-DNDEBUG'])
+ppm_jni_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+ppm_jni_env.PrependUnique(LIBS = ['pmimpl', 'ppm', 'expat', 'cpluff', 'boost_system', 'boost_thread', 'gnustl_shared', 'log'])
+
+ppm_jni_env.AppendUnique(CPPPATH = [ppm_sdk+'/src'])
+ppm_jni_env.AppendUnique(CPPPATH = [ppm_sdk+'/../lib/cpluff/libcpluff'])
+ppm_jni_env.AppendUnique(CPPPATH = [env.get('SRC_DIR')+'/extlibs/rapidxml'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+ppm_jni_src = ['PluginManager.cpp']
+ppm_jni = ppm_jni_env.SharedLibrary('PluginManager', ppm_jni_src)
+
+ppm_jni_env.InstallTarget(ppm_jni, 'libPluginManager')
+
+######################################################################
+# Install the libraries to /libs/<TARGET_ARCH> directory
+######################################################################
+ppm_jni_env.Install(ppm_sdk+'/src/Android/libs/'+env.get('TARGET_ARCH'),ppm_jni)
+ppm_jni_env.Install(ppm_sdk+'/src/Android/libs/'+env.get('TARGET_ARCH'),env.get('BUILD_DIR')+'/libpmimpl.so')
+ppm_jni_env.Install(ppm_sdk+'/src/Android/libs/'+env.get('TARGET_ARCH'),env.get('SRC_DIR')+'/dep/android/'+env.get('TARGET_ARCH')+'/usr/lib/libexpat.so')
+
+gnu_lib_paths = env.get('LIBPATH')
+for gnu_lib_path in gnu_lib_paths:
+ gnu_lib_path = gnu_lib_path + '/libgnustl_shared.so'
+ if os.path.exists(gnu_lib_path):
+ ppm_jni_env.Install(ppm_sdk+'/src/Android/libs/'+env.get('TARGET_ARCH'), gnu_lib_path)
+ break
+
+
+
+
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+</lint>
\ No newline at end of file
--- /dev/null
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# 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 *;
+#}
--- /dev/null
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-22
--- /dev/null
+<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:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context="org.iotivity.service.ppm.MainActivity$PlaceholderFragment" >
+
+ <ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <TextView
+ android:id="@+id/textView5"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="Belkin Plug : "
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <Button
+ android:id="@+id/btn_belkin"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="ON/OFF" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/Button01"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="START PLUGIN"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button02"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="STOP PLUGIN"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button03"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="GET PLUGIN"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button04"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="GET STATE"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button05"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="RESCAN PLUGIN"
+ android:textSize="10dp" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <TextView
+ android:id="@+id/textView4"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="Gear Plug : "
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <Button
+ android:id="@+id/btn_gear"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="ON/OFF" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/Button06"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="START PLUGIN"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button07"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="STOP PLUGIN"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button08"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="GET PLUGIN"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button09"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="GET STATE"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button10"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="RESCAN PLUGIN"
+ android:textSize="10dp" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+ <TextView
+ android:id="@+id/textView3"
+ android:layout_width="120dp"
+ android:layout_height="wrap_content"
+ android:text="Hue Bulb : "
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:layout_gravity="center"/>
+ <ToggleButton
+ android:id="@+id/tbtn_hue_power"
+ android:layout_width="100dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:onClick="onToggleClicked"
+ android:textOff="OFF"
+ android:textOn="ON" />
+ <NumberPicker
+ android:id="@+id/np_hue_color"
+ android:layout_width="100dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"/>
+ </LinearLayout>
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/Button11"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="START PLUGIN"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button12"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="STOP PLUGIN"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button13"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="GET PLUGIN"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button14"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="GET STATE"
+ android:textSize="10dp" />
+
+ <Button
+ android:id="@+id/Button15"
+ android:layout_width="65dp"
+ android:layout_height="wrap_content"
+ android:text="RESCAN PLUGIN"
+ android:textSize="10dp" />
+
+ </LinearLayout>
+ </LinearLayout>
+ </ScrollView>
+
+</RelativeLayout>
--- /dev/null
+<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:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context="org.iotivity.service.ppm.MainActivity$PlaceholderFragment" >
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ tools:context="org.iotivity.service.ppm.MainActivity" >
+
+ <item
+ android:id="@+id/action_settings"
+ android:orderInCategory="100"
+ android:title="@string/action_settings"/>
+
+</menu>
--- /dev/null
+<resources>
+
+ <!--
+ Base application theme for API 11+. This theme completely replaces
+ AppBaseTheme from res/values/styles.xml on API 11+ devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Light">
+ <!-- API 11 theme customizations can go here. -->
+ </style>
+
+</resources>
--- /dev/null
+<resources>
+
+ <!--
+ Base application theme for API 14+. This theme completely replaces
+ AppBaseTheme from BOTH res/values/styles.xml and
+ res/values-v11/styles.xml on API 14+ devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Light">
+ <!-- API 14 theme customizations can go here. -->
+ </style>
+
+</resources>
--- /dev/null
+<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>
--- /dev/null
+<resources>
+
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+
+</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="app_name">Android</string>
+ <string name="hello_world">Hello world!</string>
+ <string name="action_settings">Settings</string>
+
+</resources>
--- /dev/null
+<resources>
+
+ <!--
+ Base application theme, dependent on API level. This theme is replaced
+ by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Light">
+ <!--
+ Theme customizations available in newer API levels can go in
+ res/values-vXX/styles.xml, while customizations related to
+ backward-compatibility can go here.
+ -->
+ </style>
+
+ <!-- Application theme. -->
+ <style name="AppTheme" parent="AppBaseTheme">
+ <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+ </style>
+
+</resources>
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file FelixManager.java
+
+package org.iotivity.service.ppm;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.framework.Felix;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+import android.content.Context;
+import android.content.res.AssetManager;
+import android.os.FileObserver;
+import android.util.Log;
+
+public class FelixManager {
+ private static Felix m_felix = null;
+ private static ArrayList<FileObserver> m_observer;
+ private static FelixManager m_felixmgr;
+ private static Context m_context;
+ private static final int TRUE = 1;
+ private static final int FALSE = 0;
+
+ static final String ANDROID_FRAMEWORK_PACKAGES = ("android,"
+ + "android.app,"
+ + "android.content,"
+ + "android.content.pm,"
+ + "android.content.res,"
+ + "android.database,"
+ + "android.database.sqlite,"
+ + "android.graphics,"
+ + "android.graphics.drawable,"
+ + "android.graphics.glutils,"
+ + "android.hardware,"
+ + "android.location,"
+ + "android.media,"
+ + "android.net,"
+ + "android.net.wifi,"
+ + "android.net.http,"
+ + "android.opengl,"
+ + "android.os,"
+ + "android.provider,"
+ + "android.sax,"
+ + "android.speech.recognition,"
+ + "android.telephony,"
+ + "android.telephony.gsm,"
+ + "android.text,"
+ + "android.text.format,"
+ + "android.text.method,"
+ + "android.text.style,"
+ + "android.text.util,"
+ + "android.util,"
+ + "android.view,"
+ + "android.view.animation,"
+ + "android.webkit,"
+ + "android.widget,"
+ + "javax.xml.parsers,"
+ + "org.xml.sax,"
+ + "org.w3c.dom,"
+ + "com.example.felixmanager,"
+ + "org.iotivity.base");
+
+ // FelixManager singleton
+ public static FelixManager getInstance(Context ctx) {
+ if (m_felixmgr == null) {
+ m_felixmgr = new FelixManager(ctx);
+ copyFiles("files");
+ }
+
+ return m_felixmgr;
+ }
+
+ public static void LogEx(String info) {
+ Log.d("felix", info);
+ }
+
+ private FelixManager(Context ctx) {
+ m_context = ctx;
+ m_observer = new ArrayList<FileObserver>();
+
+ Map configMap = new HashMap();
+ String mCacheDir = ctx.getDir("org.osgi.framework.storage",
+ Context.MODE_WORLD_WRITEABLE).toString();
+ configMap.put("org.osgi.framework.storage", mCacheDir);
+ configMap.put("felix.embedded.execution", "true");
+ configMap.put("org.osgi.service.http.port", "9990");
+ configMap.put("org.osgi.framework.startlevel.beginning", "5");
+ configMap.put("felix.bootdelegation.implicit", "false");
+ configMap.put("felix.service.urlhandlers", "false");
+ configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
+ ANDROID_FRAMEWORK_PACKAGES);
+ try {
+ m_felix = new Felix(configMap);
+ m_felix.init();
+ m_felix.start();
+
+ for (org.osgi.framework.Bundle b : m_felix.getBundleContext()
+ .getBundles()) {
+ LogEx("Bundle: " + b.getSymbolicName());
+ }
+ } catch (Throwable ex) {
+ Log.d("Felix", "could not create framework: " + ex.getMessage(), ex);
+ }
+ }
+
+ public static int registerPlugin(String path) {
+
+ int flag = FALSE;
+
+ flag = installPlugin(path);
+ if (flag == TRUE)
+ flag = loadPluginInfoToManager(path);
+
+ return flag;
+ }
+
+ public static int registerAllPlugin(String path) {
+
+ int flag = FALSE;
+
+ flag = findPluginRecursive(path);
+ if (flag == TRUE)
+ flag = loadPluginInfoToManager(path);
+
+ return flag;
+ }
+
+ public static int unregisterPlugin(String id) {
+ int flag = TRUE;
+ try {
+ BundleContext bContext = m_felix.getBundleContext();
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+ for (org.osgi.framework.Bundle b : bundles) {
+ if (b.getSymbolicName().equals(id)) {
+ Log.d("Felix", "bundle: " + b.getBundleId()
+ + " symbolicName : " + b.getSymbolicName());
+ b.uninstall();
+ Log.d("Felix", "uninstall end");
+ }
+ }
+ } catch (BundleException e) {
+ e.printStackTrace();
+ flag = FALSE;
+ }
+
+ return flag;
+ }
+
+ public static int unregisterAllPlugin() {
+ int flag = TRUE;
+ try {
+ BundleContext bContext = m_felix.getBundleContext();
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+ for (org.osgi.framework.Bundle b : bundles) {
+ if (!b.getSymbolicName().equals("org.apache.felix.framework")) {
+ Log.d("Felix", "bundle: " + b.getBundleId()
+ + " symbolicName : " + b.getSymbolicName());
+ b.uninstall();
+ Log.d("Felix", "uninstall end");
+ }
+ }
+ } catch (BundleException e) {
+ e.printStackTrace();
+ flag = FALSE;
+ }
+
+ return flag;
+ }
+
+ public static org.osgi.framework.Bundle[] getAllPlugins() {
+ try {
+ BundleContext bContext = m_felix.getBundleContext();
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+ return bundles;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public static org.osgi.framework.Bundle[] findPulgins(String key,
+ String value) {
+ BundleContext bContext = m_felix.getBundleContext();
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+
+ return bundles;
+ }
+
+ public static org.osgi.framework.Bundle getPlugin(int ID) {
+ BundleContext bContext = m_felix.getBundleContext();
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ if (bundles[i].getBundleId() == ID) {
+ return bundles[i];
+ }
+ }
+ return null;
+ }
+
+ public static int start(String id) {
+ int flag = TRUE;
+ Log.d("Felix", "String id : " + id);
+ try {
+ BundleContext bContext = m_felix.getBundleContext();
+ bContext.registerService(Context.class.getName(), m_context, null);
+
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+ for (org.osgi.framework.Bundle b : bundles) {
+ Log.d("Felix", "symbolicName : " + b.getSymbolicName());
+ if (b.getSymbolicName().equals(id)) {
+ Log.d("Felix", "bundle: " + b.getBundleId()
+ + " symbolicName : " + b.getSymbolicName());
+ b.start();
+ Log.d("Felix", "start end");
+ }
+ }
+ } catch (BundleException e) {
+ e.printStackTrace();
+ flag = FALSE;
+ }
+ return flag;
+ }
+
+ public static int stop(String id) {
+ int flag = TRUE;
+ try {
+ BundleContext bContext = m_felix.getBundleContext();
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+ for (org.osgi.framework.Bundle b : bundles) {
+ if (b.getSymbolicName().equals(id)) {
+ Log.d("Felix", "bundle: " + b.getBundleId()
+ + " symbolicName : " + b.getSymbolicName());
+ b.stop();
+ b.uninstall();
+ Log.d("Felix", "stop end");
+ }
+ }
+ } catch (BundleException e) {
+ e.printStackTrace();
+ flag = FALSE;
+ }
+ return flag;
+ }
+
+ public static boolean isStarted(String name) {
+ String state = getState(name);
+ if (state.equals("ACTIVE") || state.equals("STARTING"))
+ return true;
+ return false;
+ }
+
+ public static String getValue(String name, String key) {
+ Log.d("FELIX", "getValue");
+ BundleContext bContext = m_felix.getBundleContext();
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+ for (org.osgi.framework.Bundle b : bundles) {
+ Dictionary<String, String> dic = b.getHeaders();
+ String bundlename = b.getSymbolicName();
+ Log.d("FELIX", "Bundlename: " + bundlename);
+
+ if (bundlename.equals(name)) {
+ if (dic.get("Bundle-" + key) == null) {
+ Log.d("FELIX", name + " null");
+ return "";
+ }
+ Log.d("FELIX", name + " " + dic.get("Bundle-" + key));
+ return dic.get("Bundle-" + key);
+ }
+ }
+ return "";
+ }
+
+ public static String getState(String name) {
+ Log.d("FELIX", "getState");
+ BundleContext bContext = m_felix.getBundleContext();
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+ for (org.osgi.framework.Bundle b : bundles) {
+ Dictionary<String, String> dic = b.getHeaders();
+ String bundlename = b.getSymbolicName();
+
+ if (bundlename.equals(name)) {
+ Log.d("FELIX", state_to_string(b.getState()));
+ return state_to_string(b.getState());
+ }
+ }
+ Log.d("FELIX", "null");
+ return "";
+ }
+
+ public static String printPluginList() {
+ String str = "";
+ str += "id | state | symbolname | ";
+ BundleContext bContext = m_felix.getBundleContext();
+ org.osgi.framework.Bundle[] bundles = bContext.getBundles();
+ for (org.osgi.framework.Bundle b : bundles) {
+ str += "\n" + b.getBundleId() + " "
+ + state_to_string(b.getState()) + " " + b.getSymbolicName();
+ }
+ return str;
+ }
+
+ public static void stop_felix() {
+ try {
+ m_felix.stop();
+ m_felix.waitForStop(0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static ArrayList<String> getFileList(String path, boolean recursive) {
+ File file = new File(path);
+ File[] files = file.listFiles();
+ ArrayList<String> array = new ArrayList<String>();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ if (recursive == true) {
+ ArrayList<String> directory_list = getFileList(files[i]
+ + "/", true);
+ array.addAll(directory_list);
+ }
+ Log.v("Directory : ", files[i].getName());
+ } else {
+ if (files[i].getName().endsWith("jar")) {
+ Log.v("File :", files[i].getName());
+ if (path.charAt(path.length() - 1) != '/') {
+ path += "/";
+ }
+ array.add(path + files[i].getName());
+ }
+ }
+ }
+ return array;
+ }
+
+ private static String state_to_string(int state) {
+ String str = state + " [unknown state]";
+
+ if (state == org.osgi.framework.Bundle.ACTIVE) {
+ return "ACTIVE";
+ } else if (state == org.osgi.framework.Bundle.INSTALLED) {
+ return "INSTALLED";
+ } else if (state == org.osgi.framework.Bundle.RESOLVED) {
+ return "RESOLVED";
+ } else if (state == org.osgi.framework.Bundle.STARTING) {
+ return "STARTING";
+ } else if (state == org.osgi.framework.Bundle.STOPPING) {
+ return "STOPPING";
+ } else if (state == org.osgi.framework.Bundle.UNINSTALLED) {
+ return "UNINSTALLED";
+ }
+ return str;
+ }
+
+ public static int installPlugin(String path) {
+
+ int flag = TRUE;
+ if (path == "") {
+ System.out.println("PluginManager path is Null\n");
+ }
+
+ ArrayList<String> filearray;
+ BundleContext bContext = m_felix.getBundleContext();
+ String location = "";
+ FileInputStream fin;
+ if (path.charAt(0) != '/') {
+ path = "/" + path;
+ } else if (path.charAt(path.length() - 1) != '/') {
+ path = path + "/";
+ }
+
+ filearray = getFileList(path, false);
+
+ for (int i = 0; i < filearray.size(); i++) {
+ try {
+ location = "file:" + filearray.get(i);
+ fin = new FileInputStream(new File(filearray.get(i)));
+ bContext.installBundle(location, fin);
+ } catch (BundleException e) {
+ e.printStackTrace();
+ flag = FALSE;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ flag = FALSE;
+ }
+ }
+
+ return flag;
+ }
+
+ private static String getEventString(int event) {
+ switch (event) {
+ case FileObserver.ACCESS:
+ return "ACCESS";
+ case FileObserver.MODIFY:
+ return "MODIFY";
+ case FileObserver.ATTRIB:
+ return "ATTRIB";
+ case FileObserver.CLOSE_WRITE:
+ return "CLOSE_WRITE";
+ case FileObserver.CLOSE_NOWRITE:
+ return "CLOSE_NOWRITE";
+ case FileObserver.OPEN:
+ return "OPEN";
+ case FileObserver.MOVED_FROM:
+ return "MOVED_FROM";
+ case FileObserver.MOVED_TO:
+ return "MOVED_TO";
+ case FileObserver.CREATE:
+ return "CREATE";
+ case FileObserver.DELETE:
+ return "DELETE";
+ case FileObserver.DELETE_SELF:
+ return "DELETE_SELF";
+ case FileObserver.MOVE_SELF:
+ return "MOVE_SELF";
+ default:
+ return "UNKNOWN";
+ }
+ }
+
+ public static int ObservePluginPath(String path) {
+ int flag = TRUE;
+ Log.d("FELIX", "ObservePluginPath" + path);
+
+ FileObserver observer = new FileObserver(path) {
+ @Override
+ public void onEvent(int event, String path) {
+ Log.d("FELIX", "Observing start : " + path);
+ Log.d("FELIX", "Observing event : " + getEventString(event));
+ }
+ };
+ observer.startWatching();
+ m_observer.add(observer);
+
+ return flag;
+ }
+
+ public static int findPluginRecursive(String path) {
+ int flag = TRUE;
+ if (path == "") {
+ System.out.println("PluginManager path is Null\n");
+ Log.d("FELIX", "PluginManager path is Null\n");
+ flag = FALSE;
+ return flag;
+ }
+
+ ArrayList<String> filearray;
+ BundleContext bContext = m_felix.getBundleContext();
+ String location = "";
+ FileInputStream fin;
+
+ if (path.charAt(0) != '/') {
+ path = "/" + path;
+ } else if (path.charAt(path.length() - 1) != '/') {
+ path = path + "/";
+ }
+
+ filearray = getFileList(path, true);
+
+ for (int i = 0; i < filearray.size(); i++) {
+ try {
+ location = "file:" + filearray.get(i);
+ fin = new FileInputStream(new File(filearray.get(i)));
+ bContext.installBundle(location, fin);
+ } catch (BundleException e) {
+ e.printStackTrace();
+ flag = FALSE;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ flag = FALSE;
+ }
+ }
+
+ return flag;
+ }
+
+ public static int loadPluginInfoToManager(String path) {
+ int flag = FALSE;
+
+ flag = ObservePluginPath(path);
+ FelixManager.printPluginList();
+
+ return flag;
+ }
+
+ public static String getPackageName() {
+ String packagename;
+
+ packagename = m_context.getPackageName();
+
+ return packagename;
+ }
+
+ private static void copyFiles(String path) {
+ AssetManager assetManager = m_context.getAssets();
+ String assets[] = null;
+
+ try {
+ assets = assetManager.list(path);
+
+ if (assets.length == 0) {
+ copyFile(path);
+ } else {
+ String fullPath = "/data/data/"
+ + m_context.getPackageName() + "/" + path;
+ Log.d("FELIX", fullPath);
+ File dir = new File(fullPath);
+
+ if (!dir.exists())
+ dir.mkdir();
+ for (int i = 0; i < assets.length; ++i) {
+ copyFiles(path + "/" + assets[i]);
+ }
+ }
+ } catch (IOException ex) {
+ Log.e("tag", "I/O Exception", ex);
+ }
+ }
+
+ private static void copyFile(String filename) {
+ AssetManager assetManager = m_context.getAssets();
+ InputStream in = null;
+ OutputStream out = null;
+
+ try {
+ in = assetManager.open(filename);
+ out = m_context.openFileOutput(filename.split("/")[1], Context.MODE_PRIVATE);
+
+ byte[] buffer = new byte[1024];
+
+ int read;
+
+ while ((read = in.read(buffer)) != -1) {
+ out.write(buffer, 0, read);
+ }
+
+ in.close();
+ in = null;
+ out.flush();
+ out.close();
+ out = null;
+ } catch (Exception e) {
+ Log.e("tag", e.getMessage());
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file FoundResource.java
+
+package org.iotivity.service.ppm;
+
+import java.util.HashMap;
+
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcResource;
+
+import android.util.Log;
+
+public class FoundResource implements OcPlatform.OnResourceFoundListener {
+ final private static String TAG = "FoundResource";
+
+ public void onResourceFound(OcResource resource) {
+
+ String resourceURI;
+ String hostAddress;
+
+ if (resource != null) {
+ Log.i(TAG, "DISCOVERED Resource");
+
+ resourceURI = resource.getUri();
+
+ Log.i(TAG, "URI of the resource: " + resourceURI);
+
+ hostAddress = resource.getHost();
+ Log.i(TAG, "Host address of the resource: " + hostAddress);
+
+ if (resourceURI.equals("/a/wemo")) {
+ MainActivity.belkinResource = resource;
+ OnGetBelkinplug onGet = new OnGetBelkinplug();
+ try {
+ resource.get(new HashMap<String, String>(), onGet);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ } else if (resourceURI.equals("/a/galaxy/gear")) {
+ MainActivity.gearResource = resource;
+ OnGetGear onGet = new OnGetGear();
+ try {
+ resource.get(new HashMap<String, String>(), onGet);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ } else if (resourceURI.equals("/a/huebulb")) {
+ MainActivity.hueResource = resource;
+ OnGetHuebulb onGet = new OnGetHuebulb();
+ try {
+ resource.get(new HashMap<String, String>(), onGet);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ } else {
+ Log.e(TAG, "ResourceURI is invalid");
+ }
+ } else {
+ Log.e(TAG, "Resource is invalid");
+ }
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file MainActivity.java
+
+package org.iotivity.service.ppm;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+import org.iotivity.service.ppm.R;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.ToggleButton;
+
+public class MainActivity extends Activity implements
+ android.widget.NumberPicker.OnValueChangeListener {
+ class S_demo_device {
+ public String m_name;
+ public String m_power;
+ public int m_bright;
+ public int m_color;
+ public String m_uri;
+ }
+
+ static S_demo_device belkinplug;
+ static S_demo_device gearplug;
+ static S_demo_device hueplug;
+ static OcResource belkinResource;
+ static OcResource gearResource;
+ static OcResource hueResource;
+ static TextView belkintv;
+ static TextView geartv;
+ static TextView huetv;
+ static ToggleButton Hue;
+ static android.widget.NumberPicker hue_color;
+ static Activity mActivity;
+
+ PluginManager m_pm;
+
+ Button belkinstart;
+ Button belkingetPlugins;
+ Button belkingetstate;
+ Button belkinstop;
+ Button belkinrescan;
+ Button Belkin;
+
+ Button gearstart;
+ Button geargetPlugins;
+ Button geargetstate;
+ Button gearstop;
+ Button gearrescan;
+ Button Gear;
+
+ Button huestart;
+ Button huegetPlugins;
+ Button huegetstate;
+ Button huestop;
+ Button huerescan;
+
+ Context ctx;
+
+ String name;
+ String key;
+ String state;
+ String id;
+ Plugin[] user_plugin;
+ Map<Integer, Integer> onValueChangefinalVal = new HashMap<Integer, Integer>();
+ Map<Integer, Boolean> onValueChangeThreadStart = new HashMap<Integer, Boolean>();
+ String[] np_h = new String[11];
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+
+ super.onCreate(savedInstanceState);
+ ctx = getApplicationContext();
+ m_pm = new PluginManager(ctx);
+
+ setContentView(R.layout.activity_main);
+ mActivity = this;
+ onValueChangeThreadStart.put(R.id.np_hue_color, false);
+ belkinplug = new S_demo_device();
+ gearplug = new S_demo_device();
+ hueplug = new S_demo_device();
+
+ for (int i = 0; i < np_h.length; i++) {
+ np_h[i] = Integer.toString(i);
+ }
+
+ hue_color = (android.widget.NumberPicker) findViewById(R.id.np_hue_color);
+ hue_color.setMaxValue(10);
+ hue_color.setMinValue(0);
+ hue_color.setDisplayedValues(np_h);
+ hue_color.setFocusable(true);
+ hue_color.setFocusableInTouchMode(true);
+ hue_color
+ .setDescendantFocusability(android.widget.NumberPicker.FOCUS_BLOCK_DESCENDANTS);
+ hue_color.setOnValueChangedListener(this);
+
+ PlatformConfig cfg = new PlatformConfig(this, ServiceType.IN_PROC,
+ ModeType.CLIENT_SERVER, "0.0.0.0", 0, QualityOfService.LOW);
+
+ OcPlatform.Configure(cfg);
+
+ try {
+ FoundResource foundResource = new FoundResource();
+ OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY,
+ OcConnectivityType.ALL, foundResource);
+ } catch (Exception e) {
+ Log.e("Felix", "Exception : " + e);
+ }
+
+ Belkin = (Button) findViewById(R.id.btn_belkin);
+ Belkin.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "Belkin button click listener");
+ OcRepresentation rep = new OcRepresentation();
+ try {
+ if (belkinplug.m_power == null) {
+ Log.i("Felix", "m_power is null");
+ belkinplug.m_power = "on";
+ rep.setValue("power", "on");
+ }
+ if (belkinplug.m_power.equals("on")) {
+ Toast.makeText(getApplicationContext(), "Off",
+ Toast.LENGTH_SHORT).show();
+ Log.i("Felix", "belkin wemo off");
+ rep.setValue("power", "off");
+ } else if (belkinplug.m_power.equals("off")) {
+ Toast.makeText(getApplicationContext(), "On",
+ Toast.LENGTH_SHORT).show();
+ Log.i("Felix", "belkin wemo on");
+ rep.setValue("power", "on");
+ } else {
+ rep.setValue("power", "on");
+ }
+ rep.setValue("name", "belkin");
+ rep.setValue("uri", "/a/wemo");
+ rep.setValue("brightness", 0);
+ rep.setValue("color", 0);
+ } catch (OcException e) {
+ Log.e("Felix", e.getMessage());
+ }
+ OnPutBelkinplug onPut = new OnPutBelkinplug();
+ if (belkinResource != null) {
+ try {
+ belkinResource.put(rep, new HashMap<String, String>(),
+ onPut);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ } else {
+ Toast.makeText(getApplicationContext(), "Belkinplug null",
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+
+ belkinstart = (Button) findViewById(R.id.Button01);
+ belkinstart.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "start button click listener");
+ m_pm.startPlugins("ResourceType", "device.smartplug");
+
+ Handler handler = new Handler();
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ Log.i("Felix", "run called!!!");
+ FoundResource foundResource = new FoundResource();
+ try {
+ OcPlatform
+ .findResource(
+ "", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "device.smartplug",
+ OcConnectivityType.ALL, foundResource);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+ }, 3000);
+ }
+ });
+
+ belkinstop = (Button) findViewById(R.id.Button02);
+ belkinstop.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "stop button click listener");
+ m_pm.stopPlugins("ResourceType", "device.smartplug");
+ belkinResource = null;
+ try {
+ java.lang.Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ belkingetPlugins = (Button) findViewById(R.id.Button03);
+ belkingetPlugins.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "getPlugins button click listener");
+ user_plugin = m_pm.getPlugins();
+ // key = "name";
+ state = "";
+ id = "";
+
+ for (int i = 0; i < user_plugin.length; i++) {
+ System.out.println("value name " + user_plugin[i].getName());
+ System.out.println("value id " + user_plugin[i].getID());
+ // name = user_plugin[i].getID();
+ }
+ }
+ });
+
+ belkingetPlugins = (Button) findViewById(R.id.Button04);
+ belkingetPlugins.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "getState click listener");
+ state = m_pm.getState("wemo");
+ if (state == "")
+ state = "null";
+ System.out.println("state: " + state);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ belkinrescan = (Button) findViewById(R.id.Button05);
+ belkinrescan.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "Rescan Plugin click listener");
+ m_pm.rescanPlugin();
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ Gear = (Button) findViewById(R.id.btn_gear);
+ Gear.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "Gear button click listener");
+ OcRepresentation rep = new OcRepresentation();
+
+ try{
+ rep.setValue("power", "Happy New Year!");
+ rep.setValue("name", "gear");
+ rep.setValue("uri", "/a/galaxy/gear");
+ rep.setValue("brightness", 0);
+ rep.setValue("color", 0);
+ } catch (OcException e) {
+ Log.e("Felix", e.getMessage());
+ }
+
+ if (gearResource != null) {
+ Toast.makeText(getApplicationContext(),
+ "Send Noti. to Gear", Toast.LENGTH_SHORT).show();
+ try {
+ OnPutGear onPut = new OnPutGear();
+ gearResource.put(rep, new HashMap<String, String>(),
+ onPut);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ } else {
+ Toast.makeText(getApplicationContext(), "Gear is null",
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+
+ gearstart = (Button) findViewById(R.id.Button06);
+ gearstart.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "start button click listener");
+ m_pm.startPlugins("ResourceType", "device.notify");
+
+ Handler handler = new Handler();
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ Log.i("Felix", "run called!!!");
+ FoundResource foundResource = new FoundResource();
+ try {
+ OcPlatform
+ .findResource(
+ "", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "device.notify",
+ OcConnectivityType.ALL, foundResource);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+ }, 3000);
+ }
+ });
+
+ gearstop = (Button) findViewById(R.id.Button07);
+ gearstop.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "stop button click listener");
+ m_pm.stopPlugins("ResourceType", "device.notify");
+ gearResource = null;
+ try {
+ java.lang.Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ geargetPlugins = (Button) findViewById(R.id.Button08);
+ geargetPlugins.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "getPlugins button click listener");
+ user_plugin = m_pm.getPlugins();
+ state = "";
+ id = "";
+
+ for (int i = 0; i < user_plugin.length; i++) {
+ System.out.println("value name " + user_plugin[i].getName());
+ System.out.println("value id " + user_plugin[i].getID());
+ name = user_plugin[i].getID();
+ }
+ }
+ });
+
+ geargetPlugins = (Button) findViewById(R.id.Button09);
+ geargetPlugins.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "getState click listener");
+ state = m_pm.getState("gearnoti");
+ if (state == "")
+ state = "null";
+ System.out.println("state: " + state);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ gearrescan = (Button) findViewById(R.id.Button10);
+ gearrescan.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "Rescan Plugin click listener");
+ m_pm.rescanPlugin();
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ Hue = (ToggleButton) findViewById(R.id.tbtn_hue_power);
+ Hue.setOnClickListener(new ToggleButton.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "Hue button click listener");
+ OcRepresentation rep = new OcRepresentation();
+ ToggleButton t = (ToggleButton) v;
+ if (t.isChecked()) {
+ Toast.makeText(getApplicationContext(), "Hue ON",
+ Toast.LENGTH_SHORT).show();
+ if (hueplug.m_bright == 0) {
+ Log.e("Felix", "hueplug m_bright is 0");
+ hueplug.m_bright = 128;
+ }
+ try {
+ rep.setValue("power", "on");
+ rep.setValue("name", "hue");
+ rep.setValue("uri", "/a/huebulb");
+ rep.setValue("brightness", hueplug.m_bright);
+ rep.setValue("color", hueplug.m_color);
+ } catch (OcException e) {
+ Log.e("Felix", e.getMessage());
+ }
+
+ OnPutHuebulb onPut = new OnPutHuebulb();
+ if (hueResource != null) {
+ try {
+ hueResource.put(rep, new HashMap<String, String>(),
+ onPut);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ } else {
+ Toast.makeText(getApplicationContext(),
+ "HueResource null", Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ Toast.makeText(getApplicationContext(), "Hue OFF",
+ Toast.LENGTH_SHORT).show();
+ if (hueplug.m_bright == 0) {
+ Log.e("Felix", "hueplug m_bright is 0");
+ hueplug.m_bright = 128;
+ }
+ try {
+ rep.setValue("power", "off");
+ rep.setValue("name", "hue");
+ rep.setValue("uri", "/a/huebulb");
+ rep.setValue("brightness", hueplug.m_bright);
+ rep.setValue("color", hueplug.m_color);
+ } catch (OcException e) {
+ Log.e("Felix", e.getMessage());
+ }
+
+ OnPutHuebulb onPut = new OnPutHuebulb();
+
+ if (hueResource != null) {
+ try {
+ hueResource.put(rep, new HashMap<String, String>(),
+ onPut);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ } else {
+ Toast.makeText(getApplicationContext(),
+ "HueResource null", Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+ });
+
+ huestart = (Button) findViewById(R.id.Button11);
+ huestart.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "start button click listener");
+ m_pm.startPlugins("ResourceType", "device.light");
+
+ Handler handler = new Handler();
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ Log.i("Felix", "run called!!!");
+ FoundResource foundResource = new FoundResource();
+ try {
+ OcPlatform
+ .findResource(
+ "", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "device.light",
+ OcConnectivityType.ALL, foundResource);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+ }, 3000);
+ }
+ });
+
+ huestop = (Button) findViewById(R.id.Button12);
+ huestop.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "stop button click listener");
+ m_pm.stopPlugins("ResourceType", "device.light");
+ hueResource = null;
+ try {
+ java.lang.Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ huegetPlugins = (Button) findViewById(R.id.Button13);
+ huegetPlugins.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "getPlugins button click listener");
+ user_plugin = m_pm.getPlugins();
+ key = "name";
+ state = "";
+ id = "";
+
+ for (int i = 0; i < user_plugin.length; i++) {
+ System.out.println("value name " + user_plugin[i].getName());
+ System.out.println("value id " + user_plugin[i].getID());
+ name = user_plugin[i].getID();
+ }
+ }
+ });
+
+ huegetPlugins = (Button) findViewById(R.id.Button14);
+ huegetPlugins.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "getState click listener");
+ state = m_pm.getState("hue");
+ if (state == "")
+ state = "null";
+ System.out.println("state: " + state);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ huerescan = (Button) findViewById(R.id.Button15);
+ huerescan.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ Log.i("Felix", "Rescan Plugin click listener");
+ m_pm.rescanPlugin();
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ static public void updateConnectStatus(String device, boolean status) {
+ if (device.equals("belkinplug")) {
+ if (status) {
+ Log.i("Felix", "belkingplug status green");
+ Toast.makeText(mActivity.getApplicationContext(),
+ "Belkin Connected", Toast.LENGTH_SHORT).show();
+ } else {
+ Log.i("Felix", "belkingplug status gray");
+ Toast.makeText(mActivity.getApplicationContext(),
+ "Belkin Disonnected", Toast.LENGTH_SHORT).show();
+ }
+ } else if (device.equals("gear")) {
+ if (status) {
+ Log.i("Felix", "gear status green");
+ Toast.makeText(mActivity.getApplicationContext(),
+ "Gear Connected", Toast.LENGTH_SHORT).show();
+ } else {
+ Log.i("Felix", "gear status gray");
+ Toast.makeText(mActivity.getApplicationContext(),
+ "Gear Disconnected", Toast.LENGTH_SHORT).show();
+ }
+ } else if (device.equals("huebulb")) {
+ if (status) {
+ Log.i("Felix", "huebulb status green");
+ Toast.makeText(mActivity.getApplicationContext(),
+ "Hue Connected", Toast.LENGTH_SHORT).show();
+ } else {
+ Log.i("Felix", "huebulb status gray");
+ Toast.makeText(mActivity.getApplicationContext(),
+ "Hue Disconnected", Toast.LENGTH_SHORT).show();
+ }
+
+ if (hueplug.m_power.equals("on")) {
+ Hue.setChecked(true);
+ } else {
+ Hue.setChecked(false);
+ }
+ }
+ }
+
+ static public void updateBelkinStatus() {
+ updateConnectStatus("belkinplug", true);
+ }
+
+ static public void updateGearStatus() {
+ updateConnectStatus("gear", true);
+ }
+
+ static public void updateHuebulbStatus() {
+ updateConnectStatus("huebulb", true);
+ }
+
+ @Override
+ protected void onResume() {
+ Log.i("Felix", "onResume()");
+ super.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ Log.i("Felix", "onPause()");
+ super.onPause();
+ finish();
+ }
+
+ @Override
+ protected void onStop() {
+ Log.i("Felix", "onStop()");
+ super.onStop();
+ }
+
+ @Override
+ protected void onDestroy() {
+ Log.i("Felix", "onDestroy()");
+ System.exit(1);
+ super.onDestroy();
+ }
+
+ private class ValueChangeThread extends Thread {
+ int idx;
+
+ public ValueChangeThread(int idx) {
+ this.idx = idx;
+ }
+
+ public void run() {
+ onValueChangeThreadStart.put(idx, true);
+ try {
+ sleep(1000, 0);
+ } catch (Exception e) {
+ Log.i("Felix", "waitForFinal exception : " + e);
+ }
+ Log.i("Felix", "Final Value for NUMBERPICKER[" + idx + "] : "
+ + onValueChangefinalVal.get(idx));
+
+ if (idx == R.id.np_hue_color) {
+ hueplug.m_color = 6300 * onValueChangefinalVal.get(idx);
+ Log.i("Felix", "m_color = " + hueplug.m_color);
+
+ OcRepresentation rep = new OcRepresentation();
+ if (hueplug.m_power == null) {
+ hueplug.m_power = "on";
+ }
+ if (hueplug.m_bright == 0) {
+ hueplug.m_bright = 128;
+ }
+ try{
+ rep.setValue("power", hueplug.m_power);
+ rep.setValue("name", "huebulb");
+ rep.setValue("uri", "/a/huebulb");
+ rep.setValue("brightness", hueplug.m_bright = 180);
+ rep.setValue("color", hueplug.m_color);
+ } catch (OcException e) {
+ Log.e("Felix", e.getMessage());
+ }
+
+ OnPutHuebulb onPut = new OnPutHuebulb();
+ if (hueResource != null) {
+ Log.i("Felix", "huebulbResource is not null");
+ try {
+ hueResource.put(rep, new HashMap<String, String>(),
+ onPut);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ } else {
+ Log.i("Felix", "huebulbResource is null");
+ }
+ }
+ onValueChangeThreadStart.put(idx, false);
+ }
+ }
+
+ public void onValueChange(android.widget.NumberPicker picker, int oldVal,
+ int newVal) {
+ final int pickerIdx = picker.getId();
+
+ Thread waitForFinal = new ValueChangeThread(pickerIdx);
+ if (onValueChangeThreadStart.get(pickerIdx) == false)
+ waitForFinal.start();
+
+ onValueChangefinalVal.put(pickerIdx, newVal);
+ }
+}
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file OnGetBelkinplug.java
+
+/// @brief This class is OnGetListener for Belkinplug.
+
+package org.iotivity.service.ppm;
+
+import java.util.List;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+
+import android.util.Log;
+
+public class OnGetBelkinplug implements OcResource.OnGetListener {
+ final private static String TAG = "OnGetBelkinplug";
+
+ @Override
+ public void onGetCompleted(List<OcHeaderOption> headerOptions,
+ OcRepresentation rep) {
+ Log.i(TAG, "GET request Belkin wemo plug was successful");
+ Log.i(TAG, "Resource URI : " + rep.getUri());
+ Log.i(TAG, "power : " + MainActivity.belkinplug.m_power);
+
+ try{
+ MainActivity.belkinplug.m_name = rep.getValue("name");
+ MainActivity.belkinplug.m_power = rep.getValue("power");
+ MainActivity.belkinplug.m_bright = rep.getValue("brightness");
+ MainActivity.belkinplug.m_color = rep.getValue("color");
+ MainActivity.belkinplug.m_uri = rep.getValue("uri");
+ } catch (OcException e) {
+ Log.e(TAG, e.getMessage());
+ }
+
+ Log.i(TAG, "name : " + MainActivity.belkinplug.m_name);
+ Log.i(TAG, "power : " + MainActivity.belkinplug.m_power);
+ Log.i(TAG, "brightness : " + MainActivity.belkinplug.m_bright);
+ Log.i(TAG, "color : " + MainActivity.belkinplug.m_color);
+ Log.i(TAG, "uri : " + MainActivity.belkinplug.m_uri);
+
+ Log.e(TAG, "updating display from thread");
+ MainActivity.mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ MainActivity.updateBelkinStatus();
+ }
+ });
+ }
+
+ @Override
+ public void onGetFailed(Throwable ex) {
+ if (ex instanceof OcException) {
+ OcException ocEx = (OcException) ex;
+ ErrorCode errCode = ocEx.getErrorCode();
+ }
+ Log.e(TAG, ex.toString());
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file OnGetGear.java
+
+/// @brief This class is OnGetListener for Gear.
+
+package org.iotivity.service.ppm;
+
+import java.util.List;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+
+import android.util.Log;
+
+public class OnGetGear implements OcResource.OnGetListener {
+ final private static String TAG = "OnGetGear";
+
+ @Override
+ public void onGetCompleted(List<OcHeaderOption> headerOptions,
+ OcRepresentation rep) {
+ Log.i(TAG, "GET request Gear was successful");
+
+ try{
+ MainActivity.gearplug.m_name = rep.getValue("name");
+ MainActivity.gearplug.m_power = rep.getValue("power");
+ MainActivity.gearplug.m_bright = rep.getValue("brightness");
+ MainActivity.gearplug.m_color = rep.getValue("color");
+ MainActivity.gearplug.m_uri = rep.getValue("uri");
+ } catch (OcException e) {
+ Log.e(TAG, e.getMessage());
+ }
+
+ Log.i(TAG, "name : " + MainActivity.gearplug.m_name);
+ Log.i(TAG, "power : " + MainActivity.gearplug.m_power);
+ Log.i(TAG, "brightness : " + MainActivity.gearplug.m_bright);
+ Log.i(TAG, "color : " + MainActivity.gearplug.m_color);
+ Log.i(TAG, "uri : " + MainActivity.gearplug.m_uri);
+
+ Log.e(TAG, "updating display from thread");
+
+ MainActivity.mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ MainActivity.updateGearStatus();
+ }
+ });
+ }
+
+ @Override
+ public void onGetFailed(Throwable ex) {
+ if (ex instanceof OcException) {
+ OcException ocEx = (OcException) ex;
+ ErrorCode errCode = ocEx.getErrorCode();
+ }
+ Log.e(TAG, ex.toString());
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file OnGetHueblub.java
+
+/// @brief This class is OnGetListener for Huebulb.
+
+package org.iotivity.service.ppm;
+
+import java.util.List;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+
+import android.util.Log;
+
+public class OnGetHuebulb implements OcResource.OnGetListener {
+ final private static String TAG = "OnGetHuebulb";
+
+ @Override
+ public void onGetCompleted(List<OcHeaderOption> headerOptions,
+ OcRepresentation rep) {
+ Log.i(TAG, "GET request Hue was successful");
+ Log.i(TAG, "Resource URI : " + rep.getUri());
+
+ try{
+ MainActivity.hueplug.m_name = rep.getValue("name");
+ MainActivity.hueplug.m_power = rep.getValue("power");
+ MainActivity.hueplug.m_bright = rep.getValue("brightness");
+ MainActivity.hueplug.m_color = rep.getValue("color");
+ MainActivity.hueplug.m_uri = rep.getValue("uri");
+ } catch (OcException e) {
+ Log.e(TAG, e.getMessage());
+ }
+
+ Log.i(TAG, "name : " + MainActivity.hueplug.m_name);
+ Log.i(TAG, "power : " + MainActivity.hueplug.m_power);
+ Log.i(TAG, "brightness : " + MainActivity.hueplug.m_bright);
+ Log.i(TAG, "color : " + MainActivity.hueplug.m_color);
+ Log.i(TAG, "uri : " + MainActivity.hueplug.m_uri);
+
+ Log.e(TAG, "updating display from thread");
+ MainActivity.mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ MainActivity.updateHuebulbStatus();
+ }
+ });
+ }
+
+ @Override
+ public void onGetFailed(Throwable ex) {
+ if (ex instanceof OcException) {
+ OcException ocEx = (OcException) ex;
+ ErrorCode errCode = ocEx.getErrorCode();
+ }
+ Log.e(TAG, ex.toString());
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file OnPutBelkinplug.java
+
+/// @brief This class is OnPutListener for Belkinplug.
+
+package org.iotivity.service.ppm;
+
+import java.util.List;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+
+import android.util.Log;
+
+public class OnPutBelkinplug implements OcResource.OnPutListener {
+ final private static String TAG = "OnPutBelkinplug";
+
+ @Override
+ public void onPutCompleted(List<OcHeaderOption> options,
+ OcRepresentation rep) {
+ Log.i(TAG, "PUT request was successful");
+
+ try{
+ MainActivity.belkinplug.m_name = rep.getValue("name");
+ MainActivity.belkinplug.m_power = rep.getValue("power");
+ MainActivity.belkinplug.m_bright = rep.getValue("brightness");
+ MainActivity.belkinplug.m_color = rep.getValue("color");
+ MainActivity.belkinplug.m_uri = rep.getValue("uri");
+ } catch (OcException e) {
+ Log.e(TAG, e.getMessage());
+ }
+
+ Log.i(TAG, "name : " + MainActivity.belkinplug.m_name);
+ Log.i(TAG, "power : " + MainActivity.belkinplug.m_power);
+ Log.i(TAG, "brightness : " + MainActivity.belkinplug.m_bright);
+ Log.i(TAG, "color : " + MainActivity.belkinplug.m_color);
+ Log.i(TAG, "uri : " + MainActivity.belkinplug.m_uri);
+ }
+
+ @Override
+ public void onPutFailed(Throwable ex) {
+ if (ex instanceof OcException) {
+ OcException ocEx = (OcException) ex;
+ ErrorCode errCode = ocEx.getErrorCode();
+ }
+ Log.e(TAG, ex.toString());
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file OnPutGear.java
+
+/// @brief This class is OnPutListener for Gear.
+
+package org.iotivity.service.ppm;
+
+import java.util.List;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+
+import android.util.Log;
+
+public class OnPutGear implements OcResource.OnPutListener {
+ final private static String TAG = "OnPutGear";
+
+ @Override
+ public void onPutCompleted(List<OcHeaderOption> options,
+ OcRepresentation rep) {
+ Log.i(TAG, "PUT request was successful");
+
+ try{
+ MainActivity.gearplug.m_name = rep.getValue("name");
+ MainActivity.gearplug.m_power = rep.getValue("power");
+ MainActivity.gearplug.m_bright = rep.getValue("brightness");
+ MainActivity.gearplug.m_color = rep.getValue("color");
+ MainActivity.gearplug.m_uri = rep.getValue("uri");
+ } catch (OcException e) {
+ Log.e(TAG, e.getMessage());
+ }
+
+ Log.i(TAG, "name : " + MainActivity.gearplug.m_name);
+ Log.i(TAG, "power : " + MainActivity.gearplug.m_power);
+ Log.i(TAG, "brightness : " + MainActivity.gearplug.m_bright);
+ Log.i(TAG, "color : " + MainActivity.gearplug.m_color);
+ Log.i(TAG, "uri : " + MainActivity.gearplug.m_uri);
+ }
+
+ @Override
+ public void onPutFailed(Throwable ex) {
+ if (ex instanceof OcException) {
+ OcException ocEx = (OcException) ex;
+ ErrorCode errCode = ocEx.getErrorCode();
+ }
+ Log.e(TAG, ex.toString());
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file OnPutHuebulb.java
+
+/// @brief This class is OnPutListener for Huebulb.
+
+package org.iotivity.service.ppm;
+
+import java.util.List;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+
+import android.util.Log;
+
+public class OnPutHuebulb implements OcResource.OnPutListener {
+ final private static String TAG = "OnPutHuebulb";
+
+ @Override
+ public void onPutCompleted(List<OcHeaderOption> options,
+ OcRepresentation rep) {
+ Log.i(TAG, "PUT request was successful");
+
+ try{
+ MainActivity.hueplug.m_name = rep.getValue("name");
+ MainActivity.hueplug.m_power = rep.getValue("power");
+ MainActivity.hueplug.m_bright = rep.getValue("brightness");
+ MainActivity.hueplug.m_color = rep.getValue("color");
+ MainActivity.hueplug.m_uri = rep.getValue("uri");
+ } catch (OcException e) {
+ Log.e(TAG, e.getMessage());
+ }
+
+ Log.i(TAG, "name : " + MainActivity.hueplug.m_name);
+ Log.i(TAG, "power : " + MainActivity.hueplug.m_power);
+ Log.i(TAG, "brightness : " + MainActivity.hueplug.m_bright);
+ Log.i(TAG, "color : " + MainActivity.hueplug.m_color);
+ Log.i(TAG, "uri : " + MainActivity.hueplug.m_uri);
+ }
+
+ @Override
+ public void onPutFailed(Throwable ex) {
+ if (ex instanceof OcException) {
+ OcException ocEx = (OcException) ex;
+ ErrorCode errCode = ocEx.getErrorCode();
+ }
+ Log.e(TAG, ex.toString());
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file Plugin.java
+
+/// @brief This class provides information of each plugin installed for JAVA.
+
+package org.iotivity.service.ppm;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Vector;
+
+public class Plugin {
+
+ private Map<String, String> m_attributeMap;
+ private Vector<String> m_supportedType;
+
+ /**
+ * Constructor for Plugin.
+ *
+ */
+ public Plugin() {
+ m_attributeMap = new HashMap<String, String>();
+ m_supportedType = new Vector<String>();
+ }
+
+ /**
+ * Constructor for Plugin(Overlading).
+ *
+ * @param Plugin's name and id Strings.
+ */
+ public Plugin(String name, String id) {
+ this();
+ setValue("Name", name);
+ setValue("Id", id);
+ }
+
+ /**
+ * Get unique ID of the plugin.
+ *
+ * @return unique id String of the plugin. if ID is not exist, it return "".
+ */
+ public String getID() {
+ Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
+ .iterator();
+
+ while (m_iterator.hasNext()) {
+ Entry<String, String> entryMap = m_iterator.next();
+ if (entryMap.getKey().equals("Id"))
+ return entryMap.getValue();
+ }
+ return "";
+ }
+
+ /**
+ * Get version of the plugin.
+ *
+ * @return version information String of the plugin. if Version is not
+ * exist, it return "".
+ */
+ public String getVersion() {
+ Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
+ .iterator();
+
+ while (m_iterator.hasNext()) {
+ Entry<String, String> entryMap = m_iterator.next();
+ if (entryMap.getKey().equals("Version"))
+ return entryMap.getValue();
+ }
+ return "";
+ }
+
+ /**
+ * Get name of the plugin.
+ *
+ * @return name String of the plugin. if Name is not exist, it return "".
+ */
+ public String getName() {
+ Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
+ .iterator();
+
+ while (m_iterator.hasNext()) {
+ Entry<String, String> entryMap = m_iterator.next();
+ if (entryMap.getKey().equals("Name"))
+ return entryMap.getValue();
+ }
+ return "";
+ }
+
+ /**
+ * Get provider name of the plugin.
+ *
+ * @return provider name of the plugin. if ProviderName is not exist, it
+ * return "".
+ */
+ public String getProviderName() {
+ Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
+ .iterator();
+
+ while (m_iterator.hasNext()) {
+ Entry<String, String> entryMap = m_iterator.next();
+ if (entryMap.getKey().equals("Provider"))
+ return entryMap.getValue();
+ }
+ return "";
+ }
+
+ /**
+ * Get value for the attributes.
+ *
+ * @param attriubute
+ * String to get value.
+ * @return value String of the attribute. if "attribute" is not exist, it
+ * return "".
+ */
+ public String getValueByAttribute(String attribute) {
+ Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
+ .iterator();
+
+ while (m_iterator.hasNext()) {
+ Entry<String, String> entryMap = m_iterator.next();
+ if (entryMap.getKey().equals(attribute))
+ return entryMap.getValue();
+ }
+ return "";
+ }
+
+ /**
+ * Set key, value. key is attribute name.
+ *
+ * @param key
+ * is atrribute name.
+ * @param value
+ * for the attribute.
+ * @return void.
+ */
+ public void setValue(String key, String value) {
+ m_attributeMap.put(key, value);
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file PluginManager.java
+
+/// @brief After installing a plug-in in a directory, each plug-in can be managed by this class.
+
+package org.iotivity.service.ppm;
+
+import android.content.Context;
+import android.util.Log;
+
+public class PluginManager {
+
+ /**
+ * Start plug-ins by key-value pair.
+ *
+ * @param key - key information of the plug-in to be started.
+ * @param value - value information of the plug-in to be started.
+ * @return int - 1 on success or 0 on failure.
+ */
+ public int startPlugins(String key, String value) {
+ LogEx("startPlugins() Called.");
+ return jniStartPlugins(key, value);
+ }
+
+ /**
+ * Stop plug-ins by key-value pair.
+ *
+ * @param key - key information of the plug-in to be stopped.
+ * @param value - value information of the plug-in to be stopped.
+ * @return int - 1 on success or 0 on failure.
+ */
+ public int stopPlugins(String key, String value) {
+ LogEx("stopPlugins() Called.");
+ return jniStopPlugins(key, value);
+ }
+
+ /**
+ * Rescan for plug-ins in the registered directory and install plug-ins.
+ *
+ * @param void
+ * @return int - 1 on success or 0 on failure.
+ */
+ public int rescanPlugin() {
+ LogEx("rescanPlugin() Called.");
+ return jniRescanPlugin();
+ }
+
+ /**
+ * Get list of plug-ins.
+ *
+ * @param void
+ * @return Plugin[] - Plug-in array.
+ */
+ public Plugin[] getPlugins() {
+ LogEx("getPlugins() Called.");
+ return jniGetPlugins();
+ }
+
+ /**
+ * Get state of the plug-in.
+ *
+ * @param pluginID - ID of the plug-in to get state.
+ * @return String - state of the plug-in.
+ */
+ public String getState(String plugID) {
+ LogEx("getState() Called.");
+ return jniGetState(plugID);
+ }
+
+ public PluginManager(Context ctx) {
+ LogEx("PluginManager() Called.");
+ FelixManager.getInstance(ctx);
+ System.loadLibrary("PluginManager");
+ }
+
+ private native int jniStartPlugins(String key, String value);
+
+ private native int jniStopPlugins(String key, String value);
+
+ private native int jniRescanPlugin();
+
+ private native Plugin[] jniGetPlugins();
+
+ private native String jniGetState(String plugID);
+
+ private static void LogEx(String info) {
+ Log.d("PluginManager.java", info);
+ }
+}
/// @file Config.cpp
-/// @brief
+/// @brief Config class reads pluginmanager.xml file and configures PPM
#include "Config.h"
Config *Config::s_configinstance = NULL;
-Config::Config()
+Config::Config(void *args)
{
+ std::string path = ".";
/**
* For Tizen Platform, specifiy the absolute location of config file. It is required for
* Tizen 2.3 EFL App to work.
if (loadConfigFile("/opt/usr/apps/org.iotivity.service.ppm.ppmsampleapp/lib/pluginmanager.xml")
!= PM_S_OK)
#else
- if (loadConfigFile("./pluginmanager.xml") != PM_S_OK)
+#ifdef ANDROID
+ JavaVM *jvm = (JavaVM *)args;
+ JNIEnv *env;
+ jvm->GetEnv((void **)&env, JNI_VERSION_1_6);
+
+ jclass cls = env->FindClass("org/iotivity/service/ppm/FelixManager");
+ jmethodID mid = env->GetStaticMethodID(cls, "getPackageName", "()Ljava/lang/String;");
+ jstring jpath = (jstring)env->CallStaticObjectMethod(cls, mid);
+ path = env->GetStringUTFChars(jpath, 0);
+
+ if(path != ".")
+ path = "/data/data/" + path + "/files";
+#endif
+
+ if (loadConfigFile(path + "/pluginmanager.xml") != PM_S_OK)
#endif //#ifdef __TIZEN__
{
fprintf(stderr, "PM Configuration file is not exist current Folder.\n" );
Config::~Config(void)
{
- s_configinstance->deleteinstance();
- s_configinstance = NULL;
+ if (s_configinstance)
+ {
+ s_configinstance->deleteinstance();
+ s_configinstance = NULL;
+ }
}
PMRESULT Config::loadConfigFile(const std::string configfilepath)
{
// Read the xml file
+ xml_document< char > doc;
std::basic_ifstream< char > xmlFile(configfilepath.c_str());
if (!xmlFile.good())
{
return PM_S_FALSE;
}
- xml_document< char > doc;
xmlFile.seekg(0, std::ios::end);
unsigned int size = (unsigned int)xmlFile.tellg();
parsing(&xmlData.front(), &doc);
// Find our root node
- xml_node<> *root_node = doc.first_node("pluginManager");
- xml_node<> *pluginInfo = root_node->first_node("pluginInfo");
+ xml_node< char > *root_node = doc.first_node("pluginManager");
+ if(!root_node)
+ {
+ throw parse_error("No Root Element", 0);
+ }
+
+ xml_node< char > *pluginInfo = root_node->first_node("pluginInfo");
getXmlData(pluginInfo, "pluginPath");
#include "rapidxml.hpp"
#include <fstream>
#include <vector>
+#ifdef ANDROID
+#include <jni.h>
+#endif
using namespace rapidxml;
*
* @return config pointer Address.
*/
- static Config *Getinstance()
+ static Config *Getinstance(void *args = NULL)
{
if (NULL == s_configinstance)
{
- s_configinstance = new Config();
+ s_configinstance = new Config(args);
}
return s_configinstance;
* During construction time, configuration file will be loaded.
*
*/
- Config();
+ Config(void *args = NULL);
/**
* Virtual destructor
CpluffAdapter *CpluffAdapter::s_pinstance;
-CpluffAdapter::CpluffAdapter()
+CpluffAdapter::CpluffAdapter(void *args)
{
m_status = cp_init();
m_context = cp_create_context(&m_status);
m_cp_plugins = nullptr;
m_plugin = nullptr;
- config = Config::Getinstance();
+ config = Config::Getinstance(args);
std::string pluginpath = config->getPluginPath();
if (pluginpath != "")
{
*
* @return OICPluginManager pointer Address.
*/
- static CpluffAdapter *Getinstance()
+ static CpluffAdapter *Getinstance(void *args = NULL)
{
if (NULL == s_pinstance)
{
- s_pinstance = new CpluffAdapter();
+ s_pinstance = new CpluffAdapter(args);
}
return s_pinstance;
* During construction time, all plugins under the root plugin path will be loaded.
*
*/
- CpluffAdapter();
+ CpluffAdapter(void *args = NULL);
/**
* Virtual destructor
{
jvm = args;
- config = Config::Getinstance();
+ config = Config::Getinstance(args);
std::string pluginpath = config->getPluginPath();
if (pluginpath != "")
{
/// @file PluginManagerImpl.cpp
-/// @brief
+/// @brief PluginManagerImple provides abstraction of the plugin manager interface
#include "PluginManagerImpl.h"
PluginManagerImpl::PluginManagerImpl(void *args)
{
- cppm = CpluffAdapter::Getinstance();
+#ifndef ANDROID
+ m_args = args;
+ cppm = CpluffAdapter::Getinstance();
+#endif
#ifdef ANDROID
+ m_args = args;
+ cppm = CpluffAdapter::Getinstance(args);
if (args)
javappm = FelixAdapter::Getinstance(args);
else
javappm = NULL;
#endif
+
refreshPluginInfo();
}
int PluginManagerImpl::registerPlugin(std::string path)
{
int flag = 0;
+
flag = cppm->registerPlugin(path);
#ifdef ANDROID
if (javappm)
int PluginManagerImpl::rescanPlugin()
{
- Config *config = Config::Getinstance();
+ Config *config = Config::Getinstance(m_args);
std::string pluginpath = config->getPluginPath();
if (pluginpath != "")
{
/// @file PluginManagerImpl.h
-/// @brief
+/// @brief PluginManagerImple provides abstraction of the plugin manager interface
#ifndef __PLUGINMANAGERIMPL_H__
#define __PLUGINMANAGERIMPL_H__
*/
virtual std::vector<Plugin> &getAllPlugins(void);
- static PluginManagerImpl *Getinstance(void *arg)
+ static PluginManagerImpl *Getinstance(void *args)
{
if (NULL == s_pinstance)
{
- s_pinstance = new PluginManagerImpl(arg);
+ s_pinstance = new PluginManagerImpl(args);
}
return s_pinstance;
private:
CpluffAdapter *cppm;
+ void *m_args;
#ifdef ANDROID
FelixAdapter *javappm;
#endif
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<pluginManager>
+ <pluginInfo
+ pluginPath="../../../plugins"
+ name="pluginmanager">
+ </pluginInfo>
+ <specialpluginInfo>
+ </specialpluginInfo>
+</pluginManager>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib" path="libs/"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/android.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/felix.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/base.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Samsung GearS Rich Notification Plugin
+Bundle-SymbolicName: gearnoti
+Bundle-ResourceType: device.notify
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .,
+ libs/
+Export-Package: oic.plugin.gear.noti,
+ com.google.gson,
+ com.google.gson.annotations,
+ com.google.gson.internal,
+ com.google.gson.internal.bind,
+ com.google.gson.reflect,
+ com.google.gson.stream,
+ com.samsung.android.sdk,
+ com.samsung.android.sdk.richnotification,
+ com.samsung.android.sdk.richnotification.actions,
+ com.samsung.android.sdk.richnotification.templates
+Import-Package: org.osgi.framework,
+ android.app,
+ android.dalvik;resolution:=optional,
+ android.content,
+ android.content.pm,
+ android.content.res,
+ android.graphics,
+ android.graphics.drawable,
+ android.net,
+ android.os,
+ android.provider,
+ android.text.format,
+ android.util,
+ android.view,
+ android.widget,
+ org.iotivity.base
+Bundle-Activator: oic.plugin.gear.noti.Activator
--- /dev/null
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ libs/
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file Activator.java
+
+package oic.plugin.gear.noti;
+
+import java.util.EnumSet;
+import java.util.UUID;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.ObserveType;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.OcResourceHandle;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ResourceProperty;
+import org.iotivity.base.ServiceType;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.Log;
+
+import com.samsung.android.sdk.SsdkUnsupportedException;
+import com.samsung.android.sdk.richnotification.Srn;
+import com.samsung.android.sdk.richnotification.SrnRichNotification;
+import com.samsung.android.sdk.richnotification.SrnRichNotificationManager;
+import com.samsung.android.sdk.richnotification.SrnRichNotificationManager.ErrorType;
+import com.samsung.android.sdk.richnotification.SrnRichNotificationManager.EventListener;
+
+public class Activator extends Activity implements BundleActivator,
+ EventListener {
+
+ final private static String TAG = "GearNoti";
+
+ public enum TemplateTypes {
+ SMALL_HEADER;
+ }
+
+ private static BundleContext context;
+ public static Context AppContext;
+ public static SrnRichNotificationManager mRichNotificationManager;
+
+ class Notify {
+ public String m_power;
+ public String m_name;
+
+ public Notify() {
+ m_power = "";
+ m_name = "device.notify";
+ }
+ }
+
+ static int OBSERVE_TYPE_TO_USE = ObserveType.OBSERVE
+ .getValue();
+
+ public static Notify myNotify;
+ public static OcResource curResource;
+ public static OcResourceHandle resourceHandle;
+ static int oc = 0;
+ static Activity mActivity;
+
+ static BundleContext getContext() {
+ return context;
+ }
+
+ public void start(BundleContext bundleContext) throws Exception {
+ Activator.context = bundleContext;
+
+ ServiceReference<Context> ref = Activator.context
+ .getServiceReference(Context.class);
+ AppContext = Activator.context.getService(ref);
+
+ myNotify = new Notify();
+
+ Srn srn = new Srn();
+ try {
+ // Initializes an instance of Srn.
+ srn.initialize(AppContext);
+ Log.w(TAG, "SRN initialized");
+ } catch (SsdkUnsupportedException e) {
+ Log.w(TAG, "SsdkUnsupportedException");
+ }
+
+ mRichNotificationManager = new SrnRichNotificationManager(AppContext);
+
+ if (mRichNotificationManager.isConnected()) {
+ // Starts the manager.
+ mRichNotificationManager.start();
+ Log.w(TAG, "RichNoti Manager Started");
+
+ SrnRichNotification myRichNotification = new SrnRichNotification(
+ AppContext);
+ Log.w(TAG, "RichNoti instance created");
+
+ PlatformConfig cfg = new PlatformConfig(this, ServiceType.IN_PROC,
+ ModeType.CLIENT_SERVER, "0.0.0.0", 0, QualityOfService.LOW);
+
+ OcPlatform.Configure(cfg);
+
+ EntityHandlerNoti entitycb = new EntityHandlerNoti();
+
+ resourceHandle = OcPlatform.registerResource("/a/galaxy/gear",
+ "device.notify", "oc.mi.def", entitycb,
+ EnumSet.of(ResourceProperty.DISCOVERABLE));
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mRichNotificationManager.registerRichNotificationListener(this);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mRichNotificationManager.unregisterRichNotificationListener(this);
+ }
+
+ @Override
+ public void onError(UUID arg0, ErrorType arg1) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onRead(UUID arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onRemoved(UUID arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void stop(BundleContext arg0) throws Exception {
+ // TODO Auto-generated method stub
+ OcPlatform.unregisterResource(resourceHandle);
+ context = null;
+ mRichNotificationManager = null;
+ myNotify = null;
+
+ }
+
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file EntityHandlerNoti.java
+
+package oic.plugin.gear.noti;
+
+import java.util.UUID;
+
+import oic.plugin.gear.noti.Activator.TemplateTypes;
+
+import org.iotivity.base.EntityHandlerResult;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResourceRequest;
+import org.iotivity.base.OcResourceResponse;
+import org.iotivity.base.RequestHandlerFlag;
+import org.iotivity.base.RequestType;
+import org.osgi.framework.BundleContext;
+
+import android.util.Log;
+
+public class EntityHandlerNoti implements OcPlatform.EntityHandler {
+
+ final private static String TAG = "EntityHandler";
+
+ public static String textNoti;
+
+ public EntityHandlerResult handleEntity(OcResourceRequest resourcerequest) {
+ Log.e(TAG, "Entity Handler callback. LJH");
+
+ System.out.println("IN Server CPP entity Handler");
+ System.out.println("gear");
+ // OcResourceResponse response = new OcResourceResponse();
+ // int result = 1; // EH_ERROR
+ if (resourcerequest != null
+ && resourcerequest.getResourceUri().equals("/a/galaxy/gear")) {
+ RequestType requestType = resourcerequest.getRequestType();
+ EnumSet<RequestHandlerFlag> handlerFlagSet = resourcerequest
+ .getRequestHandlerFlagSet();
+
+ if(handlerFlagSet.contains(RequestHandlerFlag.INIT))
+ {
+ Log.e(TAG, "requestFlag : Init");
+ }
+ if(handlerFlagSet.contains(RequestHandlerFlag.REQUEST))
+ {
+ OcResourceResponse response = new OcResourceResponse();
+ OcRepresentation representation = new OcRepresentation();
+ response.setRequestHandle(resourcerequest
+ .getRequestHandle());
+ response.setResourceHandle(resourcerequest
+ .getResourceHandle());
+ Log.d("JUDO",
+ "/******************************************************************************/");
+ Log.d("JUDO", "Name: "
+ + resourcerequest.getResourceRepresentation()
+ .getValueString("name"));
+ Log.d("JUDO", "Name: "
+ + resourcerequest.getResourceRepresentation()
+ .getValueString("power"));
+ Log.d("JUDO", "Name: "
+ + resourcerequest.getResourceRepresentation()
+ .getValueInt("brigthness"));
+ Log.d("JUDO", "Name: "
+ + resourcerequest.getResourceRepresentation()
+ .getValueInt("color"));
+ Log.d("JUDO",
+ "/******************************************************************************/");
+ switch (requestType) {
+ case GET:
+ break;
+ case PUT:
+ textNoti = resourcerequest
+ .getResourceRepresentation()
+ .getValueString("power");
+ perform(0);
+ break;
+ case POST:
+ break;
+ }
+ response.setErrorCode(200);
+ // representation.setUri("/a/galaxy/gear");
+ representation.setValueString("name",
+ Activator.myNotify.m_name);
+ representation.setValueString("power",
+ Activator.myNotify.m_power);
+ representation.setValueInt("brightness", 0);
+ representation.setValueInt("color", 0);
+ response.setResourceRepresentation(representation);
+ try {
+ OcPlatform.sendResponse(response);
+ } catch (OcException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return EntityHandlerResult.ERROR;
+ }
+ }
+ if(handlerFlagSet.contains(RequestHandlerFlag.OBSERVER))
+ {
+ Log.e(TAG, "requestFlag : Observer");
+ }
+ return EntityHandlerResult.OK;
+ }
+ return EntityHandlerResult.ERROR;
+ /*
+ * if((requestFlag & 1 << 0) != 0 ) // init flag { Log.e(TAG,
+ * "requestFlag : Init"); } if((requestFlag & 1 << 1) != 0)
+ * //RequestFlag { if(requestType.equals("GET")) {
+ *
+ * } else if(requestType.equals("PUT")) { textNoti =
+ * resourcerequest.getResourceRepresentation().getValueString("power");
+ * perform(0); } else if(requestType.equals("POST")) { }
+ * OcRepresentation representation = new OcRepresentation();
+ * OcResourceResponse response = new OcResourceResponse();
+ * response.setRequestHandle(resourcerequest.getRequestHandle());
+ * response.setResourceHandle(resourcerequest.getResourceHandle());
+ * representation.setUri("/a/galaxy/gear");
+ * representation.setValueString("name", Activator.myNotify.m_name);
+ * representation.setValueString("power", Activator.myNotify.m_power);
+ * representation.setValueInt("brightness", 0);
+ * representation.setValueInt("color", 0); response.setErrorCode(200);
+ * response.setResourceRepresentation(representation); try {
+ * OcPlatform.sendResponse(response); } catch (OcException e) { // TODO
+ * Auto-generated catch block e.printStackTrace(); return
+ * EntityHandlerResult.ERROR; } } if((requestFlag & 1 << 2) != 0)
+ * //ObserverFlag { Log.e(TAG, "requestFlag : Observer"); } } return
+ * EntityHandlerResult.OK;
+ */
+
+ }
+
+ public void stop(BundleContext bundleContext) throws Exception {
+ Activator.AppContext = null;
+ Activator.mRichNotificationManager.stop();
+ }
+
+ public void perform(int primary) {
+ if (primary < 0 || primary >= TemplateTypes.values().length) {
+ return;
+ }
+
+ Log.w(TAG, "Sending Notification");
+
+ switch (TemplateTypes.values()[primary]) {
+ case SMALL_HEADER:
+ performExample(new SmallHeaderExample(Activator.AppContext));
+ break;
+ }
+ }
+
+ private void performExample(IExample example) {
+ UUID uuid = Activator.mRichNotificationManager.notify(example
+ .createRichNoti());
+ Log.w(TAG, "Notification ID: " + uuid);
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file IExample.java
+
+package oic.plugin.gear.noti;
+
+import com.samsung.android.sdk.richnotification.SrnRichNotification;
+
+public interface IExample {
+ SrnRichNotification createRichNoti();
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file SmallHeaderExample.java
+
+package oic.plugin.gear.noti;
+
+import android.content.Context;
+
+import com.samsung.android.sdk.richnotification.SrnRichNotification;
+import com.samsung.android.sdk.richnotification.SrnRichNotification.AlertType;
+import com.samsung.android.sdk.richnotification.templates.SrnPrimaryTemplate;
+import com.samsung.android.sdk.richnotification.templates.SrnStandardTemplate;
+import com.samsung.android.sdk.richnotification.templates.SrnStandardTemplate.HeaderSizeType;
+
+public class SmallHeaderExample implements IExample {
+
+ private final Context mContext;
+
+ public SmallHeaderExample(Context ctx) {
+ mContext = ctx;
+ }
+
+ @Override
+ public SrnRichNotification createRichNoti() {
+ SrnRichNotification noti = new SrnRichNotification(mContext);
+ noti.setReadout(EntityHandlerNoti.textNoti, "");
+ noti.setPrimaryTemplate(getSmallHeaderTemplate());
+
+ noti.setAlertType(AlertType.VIBRATION);
+
+ return noti;
+ }
+
+ public SrnPrimaryTemplate getSmallHeaderTemplate() {
+ SrnStandardTemplate smallHeaderTemplate = new SrnStandardTemplate(
+ HeaderSizeType.SMALL);
+
+ smallHeaderTemplate.setSubHeader(EntityHandlerNoti.textNoti);
+
+ return smallHeaderTemplate;
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib" path="libs/"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/android.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/felix.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/huelocalsdk.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/huesdkresources.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/base.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Philips Hue Plugin
+Bundle-SymbolicName: hue
+Bundle-ResourceType: device.light
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .,
+ libs/
+Export-Package: com.philips.lighting.annotations,
+ com.philips.lighting.hue.listener,
+ com.philips.lighting.hue.sdk,
+ com.philips.lighting.hue.sdk.bridge.impl,
+ com.philips.lighting.hue.sdk.clip,
+ com.philips.lighting.hue.sdk.clip.serialisation,
+ com.philips.lighting.hue.sdk.clip.serialisation.sensors,
+ com.philips.lighting.hue.sdk.connection.impl,
+ com.philips.lighting.hue.sdk.data,
+ com.philips.lighting.hue.sdk.exception,
+ com.philips.lighting.hue.sdk.fbp,
+ com.philips.lighting.hue.sdk.heartbeat,
+ com.philips.lighting.hue.sdk.notification.impl,
+ com.philips.lighting.hue.sdk.upnp,
+ com.philips.lighting.hue.sdk.util,
+ com.philips.lighting.hue.sdk.utilities,
+ com.philips.lighting.hue.sdk.utilities.impl,
+ com.philips.lighting.model,
+ com.philips.lighting.model.rule,
+ com.philips.lighting.model.sensor,
+ com.philips.lighting.model.sensor.metadata,
+ org.json.hue
+Import-Package: org.osgi.framework,
+ android.app,
+ android.dalvik;resolution:=optional,
+ android.util,
+ android.content,
+ android.os,
+ android.graphics,
+ android.view,
+ android.widget,
+ org.iotivity.base
+Bundle-Activator: oic.plugin.hue.Activator
--- /dev/null
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ libs/
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file AccessPointListAdapter.java
+
+package oic.plugin.hue;
+
+import java.util.List;
+
+import android.content.Context;
+import android.graphics.Color;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import com.philips.lighting.hue.sdk.PHAccessPoint;
+
+public class AccessPointListAdapter extends BaseAdapter {
+ private LayoutInflater mInflater;
+ private List<PHAccessPoint> accessPoints;
+
+ class BridgeListItem {
+ private TextView bridgeIp;
+ private TextView bridgeMac;
+ }
+
+ public AccessPointListAdapter(Context context,
+ List<PHAccessPoint> accessPoints) {
+ // Cache the LayoutInflate to avoid asking for a new one each time.
+ mInflater = LayoutInflater.from(context);
+ this.accessPoints = accessPoints;
+ }
+
+ public View getView(final int position, View convertView, ViewGroup parent) {
+
+ BridgeListItem item;
+
+ if (convertView == null) {
+ convertView = mInflater.inflate(0x7f030004, null);
+
+ item = new BridgeListItem();
+ item.bridgeMac = (TextView) convertView.findViewById(0x7f080009);
+ item.bridgeIp = (TextView) convertView.findViewById(0x7f08000a);
+ convertView.setTag(item);
+ } else {
+ item = (BridgeListItem) convertView.getTag();
+ }
+ PHAccessPoint accessPoint = accessPoints.get(0);
+ item.bridgeIp.setTextColor(Color.BLACK);
+ item.bridgeIp.setText(accessPoint.getIpAddress());
+ item.bridgeMac.setTextColor(Color.DKGRAY);
+ item.bridgeMac.setText(accessPoint.getMacAddress());
+ return convertView;
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return 0;
+ }
+
+ @Override
+ public int getCount() {
+ return accessPoints.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return accessPoints.get(position);
+ }
+
+ public void updateData(List<PHAccessPoint> accessPoints) {
+ this.accessPoints = accessPoints;
+ notifyDataSetChanged();
+ }
+
+}
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file Activator.java
+
+package oic.plugin.hue;
+
+import java.util.EnumSet;
+import java.util.List;
+
+import oic.plugin.hue.AccessPointListAdapter;
+import oic.plugin.hue.HueSharedPreferences;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.ObserveType;
+import org.iotivity.base.OcResourceHandle;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ResourceProperty;
+import org.iotivity.base.ServiceType;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import com.philips.lighting.hue.sdk.PHAccessPoint;
+import com.philips.lighting.hue.sdk.PHBridgeSearchManager;
+import com.philips.lighting.hue.sdk.PHHueSDK;
+import com.philips.lighting.hue.sdk.PHSDKListener;
+import com.philips.lighting.model.PHBridge;
+import com.philips.lighting.model.PHHueError;
+import com.philips.lighting.model.PHHueParsingError;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.util.Log;
+
+public class Activator extends Activity implements BundleActivator {
+
+ private static BundleContext context;
+ private static Context AppContext;
+ private PHHueSDK phHueSDK;
+ public static final String TAG = "Hue Plugin";
+ private HueSharedPreferences prefs;
+ private AccessPointListAdapter adapter;
+
+ class Light {
+ public String m_power;
+ public int m_brightness;
+ public int m_color;
+ public String m_name;
+
+ public Light() {
+ m_power = "off";
+ m_brightness = 0;
+ m_color = 0;
+ m_name = "device.light";
+ }
+ }
+
+ static int OBSERVE_TYPE_TO_USE = ObserveType.OBSERVE
+ .getValue();
+
+ public static Light myLight;
+ public static OcResource curResource;
+ public static OcResourceHandle resourceHandle;
+ static int oc = 0;
+ static Activity mActivity;
+
+ static BundleContext getContext() {
+ return context;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mActivity = this;
+ }
+
+ public void start(BundleContext bundleContext) throws Exception {
+ Activator.context = bundleContext;
+
+ ServiceReference<Context> ref = Activator.context
+ .getServiceReference(Context.class);
+ AppContext = Activator.context.getService(ref);
+
+ // Gets an instance of the Hue SDK.
+ phHueSDK = PHHueSDK.getInstance();
+
+ // Set the Device Name (name of your app). This will be stored in your
+ // bridge whitelist entry.
+ phHueSDK.setAppName("QuickStartApp");
+ phHueSDK.setDeviceName(android.os.Build.MODEL);
+
+ // Register the PHSDKListener to receive callbacks from the bridge.
+ phHueSDK.getNotificationManager().registerSDKListener(listener);
+
+ adapter = new AccessPointListAdapter(AppContext,
+ phHueSDK.getAccessPointsFound());
+
+ // Try to automatically connect to the last known bridge. For first time
+ // use this will be empty so a bridge search is automatically started.
+ prefs = HueSharedPreferences.getInstance(AppContext);
+ String lastIpAddress = prefs.getLastConnectedIPAddress();
+ String lastUsername = prefs.getUsername();
+
+ // Automatically try to connect to the last connected IP Address. For
+ // multiple bridge support a different implementation is required.
+ if (lastIpAddress != null && !lastIpAddress.equals("")) {
+ PHAccessPoint lastAccessPoint = new PHAccessPoint();
+ lastAccessPoint.setIpAddress(lastIpAddress);
+ lastAccessPoint.setUsername(lastUsername);
+
+ if (!phHueSDK.isAccessPointConnected(lastAccessPoint)) {
+ phHueSDK.connect(lastAccessPoint);
+ }
+ } else { // First time use, so perform a bridge search.
+ doBridgeSearch();
+ Log.w(TAG, "Searching for Bridges.");
+ }
+
+ myLight = new Light();
+ }
+
+ public void stop(BundleContext bundleContext) throws Exception {
+ OcPlatform.unregisterResource(resourceHandle);
+ context = null;
+ myLight = null;
+ // phHueSDK = null;
+ }
+
+ public void doBridgeSearch() {
+ PHBridgeSearchManager sm = (PHBridgeSearchManager) phHueSDK
+ .getSDKService(PHHueSDK.SEARCH_BRIDGE);
+ // Start the UPNP Searching of local bridges.
+ sm.search(true, true);
+ }
+
+ private PHSDKListener listener = new PHSDKListener() {
+
+ @Override
+ public void onAccessPointsFound(
+ List<PHAccessPoint> accessPoint) {
+ Log.w(TAG, "Access Points Found. "
+ + accessPoint.size());
+ if (accessPoint != null
+ && accessPoint.size() > 0) {
+ phHueSDK.getAccessPointsFound()
+ .clear();
+ phHueSDK.getAccessPointsFound()
+ .addAll(accessPoint);
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ adapter.updateData(phHueSDK
+ .getAccessPointsFound());
+ }
+ });
+
+ HueSharedPreferences prefs2 = HueSharedPreferences
+ .getInstance(AppContext);
+ PHAccessPoint accessPoint2 = (PHAccessPoint) adapter
+ .getItem(0);
+ accessPoint2.setUsername(prefs2
+ .getUsername());
+
+ PHBridge connectedBridge = phHueSDK
+ .getSelectedBridge();
+
+ if (connectedBridge != null) {
+ String connectedIP = connectedBridge
+ .getResourceCache()
+ .getBridgeConfiguration()
+ .getIpAddress();
+ Log.w(TAG, "Connected IP: "
+ + connectedIP);
+ if (connectedIP != null) { // We
+ // are
+ // already
+ // connected
+ // here:-
+ Log.w(TAG,
+ "Connected IP != null");
+ phHueSDK.disableHeartbeat(connectedBridge);
+ phHueSDK.disconnect(connectedBridge);
+ }
+ }
+ phHueSDK.connect(accessPoint2);
+ }
+ }
+
+ @Override
+ public void onCacheUpdated(
+ List<Integer> arg0,
+ PHBridge bridge) {
+ Log.w(TAG, "On CacheUpdated.");
+ }
+
+ @Override
+ public void onBridgeConnected(PHBridge b) {
+ Log.w(TAG,
+ "Connected to the Bridge.");
+ phHueSDK.setSelectedBridge(b);
+ phHueSDK.enableHeartbeat(b,
+ PHHueSDK.HB_INTERVAL);
+ phHueSDK.getLastHeartbeat()
+ .put(b.getResourceCache()
+ .getBridgeConfiguration()
+ .getIpAddress(),
+ System.currentTimeMillis());
+
+ PlatformConfig cfg = new PlatformConfig(
+ this,
+ ServiceType.IN_PROC,
+ ModeType.CLIENT_SERVER,
+ "0.0.0.0", 0,
+ QualityOfService.LOW);
+
+ OcPlatform.Configure(cfg);
+
+ EntityHandlerHue entitycb = new EntityHandlerHue();
+ try {
+ resourceHandle = OcPlatform
+ .registerResource(
+ "/a/huebulb",
+ "device.light",
+ "oc.mi.def",
+ entitycb,
+ EnumSet.of(ResourceProperty.DISCOVERABLE));
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onAuthenticationRequired(
+ PHAccessPoint accessPoint) {
+ Log.w(TAG,
+ "Authentication Required.");
+ phHueSDK.startPushlinkAuthentication(accessPoint);
+ Log.w(TAG, "Access Point IP addr: "
+ + accessPoint.getIpAddress());
+ Log.w(TAG,
+ "Access Point MAC addr: "
+ + accessPoint
+ .getMacAddress());
+ Log.w(TAG, "Access Point key: "
+ + accessPoint.getUsername());
+ }
+
+ @Override
+ public void onConnectionResumed(
+ PHBridge bridge) {
+ // Log.v(TAG, "onConnectionResumed "
+ // +
+ // bridge.getResourceCache().getBridgeConfiguration().getIpAddress());
+ phHueSDK.getLastHeartbeat()
+ .put(bridge
+ .getResourceCache()
+ .getBridgeConfiguration()
+ .getIpAddress(),
+ System.currentTimeMillis());
+ for (int i = 0; i < phHueSDK
+ .getDisconnectedAccessPoint()
+ .size(); i++) {
+ if (phHueSDK
+ .getDisconnectedAccessPoint()
+ .get(i)
+ .getIpAddress()
+ .equals(bridge
+ .getResourceCache()
+ .getBridgeConfiguration()
+ .getIpAddress())) {
+ phHueSDK.getDisconnectedAccessPoint()
+ .remove(i);
+ }
+ }
+ }
+
+ @Override
+ public void onConnectionLost(
+ PHAccessPoint accessPoint) {
+ Log.v(TAG, "onConnectionLost : "
+ + accessPoint.getIpAddress());
+ if (!phHueSDK
+ .getDisconnectedAccessPoint()
+ .contains(accessPoint)) {
+ phHueSDK.getDisconnectedAccessPoint()
+ .add(accessPoint);
+ }
+ }
+
+ @Override
+ public void onError(int code,
+ final String message) {
+ Log.e(TAG, "on Error Called : "
+ + code + ":" + message);
+
+ if (code == PHHueError.NO_CONNECTION) {
+ Log.w(TAG, "On No Connection");
+ } else if (code == PHHueError.AUTHENTICATION_FAILED
+ || code == 1158) {
+
+ } else if (code == PHHueError.BRIDGE_NOT_RESPONDING) {
+ Log.w(TAG,
+ "Bridge Not Responding . . . ");
+ }
+ }
+
+ @Override
+ public void onParsingErrors(
+ List<PHHueParsingError> parsingErrorsList) {
+ for (PHHueParsingError parsingError : parsingErrorsList) {
+ Log.e(TAG,
+ "ParsingError : "
+ + parsingError
+ .getMessage());
+ }
+ }
+ };
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file EntityHandlerHue.java
+
+package oic.plugin.hue;
+
+import java.util.List;
+
+import org.iotivity.base.EntityHandlerResult;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResourceRequest;
+import org.iotivity.base.OcResourceResponse;
+import org.iotivity.base.RequestHandlerFlag;
+import org.iotivity.base.RequestType;
+
+import android.util.Log;
+
+import com.philips.lighting.hue.sdk.PHHueSDK;
+import com.philips.lighting.model.PHBridge;
+import com.philips.lighting.model.PHLight;
+import com.philips.lighting.model.PHLightState;
+
+public class EntityHandlerHue implements OcPlatform.EntityHandler {
+
+ final private static String TAG = "EntityHandler";
+
+ public EntityHandlerResult handleEntity(OcResourceRequest resourcerequest) {
+ Log.e(TAG, "Entity Handler callback.");
+
+ System.out.println("IN Server CPP entity Handler");
+ System.out.println("Hue bulb");
+ // OcResourceResponse response = new OcResourceResponse();
+ // int result = 1; // EH_ERROR
+ if (resourcerequest != null
+ && resourcerequest.getResourceUri().equals("/a/huebulb")) {
+ RequestType requestType = resourcerequest.getRequestType();
+ EnumSet<RequestHandlerFlag> handlerFlagSet = resourcerequest
+ .getRequestHandlerFlagSet();
+
+ if(handlerFlagSet.contains(RequestHandlerFlag.INIT))
+ {
+ Log.e(TAG, "requestFlag : Init");
+ }
+ if(handlerFlagSet.contains(RequestHandlerFlag.REQUEST))
+ {
+ OcResourceResponse response = new OcResourceResponse();
+ OcRepresentation representation = new OcRepresentation();
+ response.setRequestHandle(resourcerequest
+ .getRequestHandle());
+ response.setResourceHandle(resourcerequest
+ .getResourceHandle());
+ switch (requestType) {
+ case GET:
+ PHBridge bridge = PHHueSDK.getInstance()
+ .getSelectedBridge();
+ List<PHLight> myLights = bridge.getResourceCache()
+ .getAllLights();
+ for (PHLight light : myLights) {
+ PHLightState lightState = new PHLightState();
+ lightState = light.getLastKnownLightState();
+ if (lightState.isOn()) {
+ Activator.myLight.m_power = "on";
+ } else if (!lightState.isOn()) {
+ Activator.myLight.m_power = "off";
+ }
+ Activator.myLight.m_color = lightState.getHue();
+ Activator.myLight.m_brightness = lightState
+ .getBrightness();
+ }
+ break;
+ case PUT:
+ PHBridge mbridge = PHHueSDK.getInstance()
+ .getSelectedBridge();
+ List<PHLight> mmyLights = mbridge
+ .getResourceCache().getAllLights();
+ for (PHLight light : mmyLights) {
+ PHLightState lightState = new PHLightState();
+ String str = resourcerequest
+ .getResourceRepresentation()
+ .getValueString("power");
+ if (str.equals("on")) {
+ lightState.setOn(true);
+ Activator.myLight.m_power = "on";
+ } else if (str.equals("off")) {
+ lightState.setOn(false);
+ Activator.myLight.m_power = "off";
+ }
+ lightState.setHue(resourcerequest
+ .getResourceRepresentation()
+ .getValueInt("color"));
+ Activator.myLight.m_color = resourcerequest
+ .getResourceRepresentation()
+ .getValueInt("color");
+ mbridge.updateLightState(light, lightState);
+ }
+ break;
+ case POST:
+ break;
+ }
+ response.setErrorCode(200);
+ // representation.setUri("/a/huebulb");
+ representation.setValueString("name",
+ Activator.myLight.m_name);
+ representation.setValueString("power",
+ Activator.myLight.m_power);
+ representation.setValueInt("brightness",
+ Activator.myLight.m_brightness);
+ representation.setValueInt("color",
+ Activator.myLight.m_color);
+ response.setResourceRepresentation(representation);
+ try {
+ OcPlatform.sendResponse(response);
+ } catch (OcException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return EntityHandlerResult.ERROR;
+ }
+ }
+ if(handlerFlagSet.contains(RequestHandlerFlag.OBSERVER))
+ {
+ Log.e(TAG, "requestFlag : Observer");
+ }
+ return EntityHandlerResult.OK;
+ }
+ return EntityHandlerResult.ERROR;
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file HueSharedPreferences.java
+
+package oic.plugin.hue;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+
+import com.philips.lighting.hue.sdk.connection.impl.PHBridgeInternal;
+
+public class HueSharedPreferences {
+ private static final String HUE_SHARED_PREFERENCES_STORE = "HueSharedPrefs";
+ private static final String LAST_CONNECTED_USERNAME = "LastConnectedUsername";
+ private static final String LAST_CONNECTED_IP = "LastConnectedIP";
+ private static HueSharedPreferences instance = null;
+ private SharedPreferences mSharedPreferences = null;
+
+ private Editor mSharedPreferencesEditor = null;
+
+ public void create() {
+
+ }
+
+ public static HueSharedPreferences getInstance(Context ctx) {
+ if (instance == null) {
+ instance = new HueSharedPreferences(ctx);
+ }
+ return instance;
+ }
+
+ private HueSharedPreferences(Context appContext) {
+ mSharedPreferences = appContext.getSharedPreferences(
+ HUE_SHARED_PREFERENCES_STORE, 0); // 0 - for private mode
+ mSharedPreferencesEditor = mSharedPreferences.edit();
+ }
+
+ public String getUsername() {
+ String username = mSharedPreferences.getString(LAST_CONNECTED_USERNAME,
+ "");
+ if (username == null || username.equals("")) {
+ username = PHBridgeInternal.generateUniqueKey();
+ setUsername(username); // Persist the username in the shared prefs
+ }
+ return username;
+ }
+
+ public boolean setUsername(String username) {
+ mSharedPreferencesEditor.putString(LAST_CONNECTED_USERNAME, username);
+ return (mSharedPreferencesEditor.commit());
+ }
+
+ public String getLastConnectedIPAddress() {
+ return mSharedPreferences.getString(LAST_CONNECTED_IP, "");
+ }
+
+ public boolean setLastConnectedIPAddress(String ipAddress) {
+ mSharedPreferencesEditor.putString(LAST_CONNECTED_IP, ipAddress);
+ return (mSharedPreferencesEditor.commit());
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib" path="libs/"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/android.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/felix.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/Users/yh_.joo/Desktop/Workspace3 (2)/base.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Belkin WeMo Plugin
+Bundle-SymbolicName: wemo
+Bundle-ResourceType: device.smartplug
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .,
+ libs/
+Export-Package: oic.plugin.wemo,
+ com.belkin.wemo.localsdk,
+ com.belkin.wemo.storage,
+ org.cybergarage.http,
+ org.cybergarage.net,
+ org.cybergarage.soap,
+ org.cybergarage.upnp,
+ org.cybergarage.upnp.control,
+ org.cybergarage.upnp.device,
+ org.cybergarage.upnp.event,
+ org.cybergarage.upnp.ssdp,
+ org.cybergarage.upnp.xml,
+ org.cybergarage.util,
+ org.cybergarage.xml,
+ org.cybergarage.xml.parser
+Import-Package: org.osgi.framework,
+ android.dalvik;resolution:=optional,
+ android.app,
+ android.content,
+ android.database,
+ android.database.sqlite,
+ android.net,
+ android.net.wifi,
+ android.net.http,
+ android.os,
+ android.util,
+ javax.xml.parsers,
+ org.xml.sax,
+ org.w3c.dom,
+ org.iotivity.base
+Bundle-Activator: oic.plugin.wemo.Activator
+Bundle-ActivationPolicy: lazy
--- /dev/null
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ libs/
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file Activator.java
+
+package oic.plugin.wemo;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.ObserveType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.OcResourceHandle;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ResourceProperty;
+import org.iotivity.base.ServiceType;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.belkin.wemo.localsdk.WeMoDevice;
+import com.belkin.wemo.localsdk.WeMoSDKContext;
+
+public class Activator extends Activity implements BundleActivator,
+ WeMoSDKContext.NotificationListener {
+ final private static String TAG = "SimpleClient";
+
+ private static BundleContext context;
+ private Context AppContext;
+ public static WeMoSDKContext mWeMoSDKContext = null;
+ WeMoDevice wemoDevice;
+
+ static class SmartPlug {
+ public String m_power;
+ public String m_name;
+
+ public SmartPlug() {
+ m_power = "";
+ m_name = "";
+ }
+ }
+
+ static int OBSERVE_TYPE_TO_USE = ObserveType.OBSERVE
+ .getValue();
+
+ public static SmartPlug mySmartPlug;
+ public static OcResource curResource;
+ public static OcResourceHandle resourceHandle;
+ static int oc = 0;
+ static Activity mActivity;
+
+ static BundleContext getContext() {
+
+ return context;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mActivity = this;
+ }
+
+ public void start(BundleContext bundleContext) throws Exception {
+ /*
+ * OSGi bundle context
+ */
+ context = bundleContext;
+
+ /*
+ * Android Application Context
+ */
+ ServiceReference<Context> ref = context
+ .getServiceReference(Context.class);
+ this.AppContext = ((Context) context.getService(ref));
+
+ /*
+ * WeMo Context
+ */
+ this.mWeMoSDKContext = new WeMoSDKContext(this.AppContext);
+ this.mWeMoSDKContext.addNotificationListener(this);
+ refresh();
+
+ mySmartPlug = new SmartPlug();
+ }
+
+ public void stop(BundleContext bundleContext) throws Exception {
+ OcPlatform.unregisterResource(resourceHandle);
+ context = null;
+ mWeMoSDKContext = null;
+ mySmartPlug = null;
+
+ }
+
+ public void onNotify(final String event, final String udn) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ Activator.this.wemoDevice = Activator.this.mWeMoSDKContext
+ .getWeMoDeviceByUDN(udn);
+ if (event.equals("refresh")) {
+ ArrayList<String> udns = Activator.this.mWeMoSDKContext
+ .getListOfWeMoDevicesOnLAN();
+ ArrayList<WeMoDevice> wemoDevices = new ArrayList();
+ for (String udn : udns) {
+ WeMoDevice listDevice = Activator.this.mWeMoSDKContext
+ .getWeMoDeviceByUDN(udn);
+ if ((listDevice != null) && (listDevice.isAvailable())) {
+ wemoDevices.add(listDevice);
+ Log.i("WeMoPlugin", "WeMo Decive Name: "
+ + listDevice.getFriendlyName());
+ Log.i("WeMoPlugin", "WeMo Decive UDN: "
+ + listDevice.getUDN());
+ Log.i("WeMoPlugin", "WeMo Decive Type: "
+ + listDevice.getType());
+ Log.i("WeMoPlugin", "WeMo Decive Serial #: "
+ + listDevice.getSerialNumber());
+ }
+ }
+ } else if (event.equals(WeMoSDKContext.ADD_DEVICE)) {
+ ArrayList<String> udns = Activator.this.mWeMoSDKContext
+ .getListOfWeMoDevicesOnLAN();
+ ArrayList<WeMoDevice> wemoDevices = new ArrayList();
+ for (String udn : udns) {
+ WeMoDevice listDevice = Activator.this.mWeMoSDKContext
+ .getWeMoDeviceByUDN(udn);
+ if ((listDevice != null) && (listDevice.isAvailable())) {
+ PlatformConfig cfg = new PlatformConfig(
+ this,
+ ServiceType.IN_PROC,
+ ModeType.CLIENT_SERVER, "0.0.0.0", 0,
+ QualityOfService.LOW);
+
+ OcPlatform.Configure(cfg);
+
+ EntityHandlerWemo entitycb = new EntityHandlerWemo();
+ try {
+ resourceHandle = OcPlatform
+ .registerResource(
+ "/a/wemo",
+ "device.smartplug",
+ "oc.mi.def",
+ entitycb,
+ EnumSet.of(ResourceProperty.DISCOVERABLE));
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ });
+ }
+
+ private void refresh() {
+ this.mWeMoSDKContext.refreshListOfWeMoDevicesOnLAN();
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file EntityHandlerWemo.java
+
+package oic.plugin.wemo;
+
+import java.util.ArrayList;
+
+import org.iotivity.base.EntityHandlerResult;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResourceRequest;
+import org.iotivity.base.OcResourceResponse;
+import org.iotivity.base.RequestHandlerFlag;
+import org.iotivity.base.RequestType;
+
+import android.util.Log;
+
+import com.belkin.wemo.localsdk.WeMoDevice;
+
+public class EntityHandlerWemo implements OcPlatform.EntityHandler {
+
+ final private static String TAG = "EntityHandlerWeMo";
+
+ public EntityHandlerResult handleEntity(OcResourceRequest resourcerequest) {
+ Log.e(TAG, "Entity Handler callback");
+
+ // OcResourceResponse response = new OcResourceResponse();
+
+ if (resourcerequest != null
+ && resourcerequest.getResourceUri().equals("/a/wemo")) {
+ RequestType requestType = resourcerequest.getRequestType();
+ EnumSet<RequestHandlerFlag> handlerFlagSet = resourcerequest
+ .getRequestHandlerFlagSet();
+
+ if(handlerFlagSet.contains(RequestHandlerFlag.INIT))
+ {
+ Log.e(TAG, "requestFlag : Init");
+ }
+ if(handlerFlagSet.contains(RequestHandlerFlag.REQUEST))
+ {
+ OcResourceResponse response = new OcResourceResponse();
+ OcRepresentation representation = new OcRepresentation();
+ response.setRequestHandle(resourcerequest
+ .getRequestHandle());
+ response.setResourceHandle(resourcerequest
+ .getResourceHandle());
+ switch (requestType) {
+ case GET:
+ ArrayList<String> udns = Activator.mWeMoSDKContext
+ .getListOfWeMoDevicesOnLAN();
+ for (String udn : udns) {
+ WeMoDevice wemoDevice = Activator.mWeMoSDKContext
+ .getWeMoDeviceByUDN(udn);
+ if (wemoDevice.getState() == "0") {
+ Activator.mySmartPlug.m_power = "off";
+ } else if (wemoDevice.getState() == "1") {
+ Activator.mySmartPlug.m_power = "on";
+ }
+ }
+ break;
+ case PUT:
+ ArrayList<String> uudns = Activator.mWeMoSDKContext
+ .getListOfWeMoDevicesOnLAN();
+ for (String udn : uudns) {
+ WeMoDevice wemoDevice = Activator.mWeMoSDKContext
+ .getWeMoDeviceByUDN(udn);
+ String type = wemoDevice.getType();
+ if (type.equals(WeMoDevice.SWITCH)) {
+ String newState = "";
+ if (resourcerequest
+ .getResourceRepresentation()
+ .getValueString("power")
+ .equals("on")) {
+ Activator.mySmartPlug.m_power = "on";
+ newState = WeMoDevice.WEMO_DEVICE_ON;
+ } else if (resourcerequest
+ .getResourceRepresentation()
+ .getValueString("power")
+ .equals("off")) {
+ Activator.mySmartPlug.m_power = "off";
+ newState = WeMoDevice.WEMO_DEVICE_OFF;
+ }
+ Activator.mWeMoSDKContext.setDeviceState(
+ newState, wemoDevice.getUDN());
+ }
+ }
+ break;
+ case POST:
+ break;
+ }
+ response.setErrorCode(200);
+ // representation.setUri("/a/wemo");
+ representation.setValueString("name",
+ Activator.mySmartPlug.m_name);
+ representation.setValueString("power",
+ Activator.mySmartPlug.m_power);
+ representation.setValueInt("brightness", 0);
+ representation.setValueInt("color", 0);
+ response.setResourceRepresentation(representation);
+ try {
+ OcPlatform.sendResponse(response);
+ } catch (OcException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return EntityHandlerResult.ERROR;
+ }
+ }
+ if(handlerFlagSet.contains(RequestHandlerFlag.OBSERVER))
+ {
+ Log.e(TAG, "requestFlag : Observer");
+ }
+ return EntityHandlerResult.OK;
+ }
+ return EntityHandlerResult.ERROR;
+ }
+}
--- /dev/null
+# =============================================================================
+# User configuration section.
+#
+# Largely, these are options that are designed to make mosquitto run more
+# easily in restrictive environments by removing features.
+#
+# Modify the variable below to enable/disable features.
+#
+# Can also be overriden at the command line, e.g.:
+#
+# make WITH_TLS=no
+# =============================================================================
+
+# Uncomment to compile the broker with tcpd/libwrap support.
+#WITH_WRAP:=yes
+
+# Comment out to disable SSL/TLS support in the broker and client.
+# Disabling this will also mean that passwords must be stored in plain text. It
+# is strongly recommended that you only disable WITH_TLS if you are not using
+# password authentication at all.
+WITH_TLS:=yes
+
+# Comment out to disable TLS/PSK support in the broker and client. Requires
+# WITH_TLS=yes.
+# This must be disabled if using openssl < 1.0.
+WITH_TLS_PSK:=yes
+
+# Comment out to disable client client threading support.
+WITH_THREADING:=yes
+
+# Uncomment to compile the broker with strict protocol support. This means that
+# both the client library and the broker will be very strict about protocol
+# compliance on incoming data. Neither of them will return an error on
+# incorrect "remaining length" values if this is commented out. The old
+# behaviour (prior to 0.12) is equivalent to compiling with
+# WITH_STRICT_PROTOCOL defined and means that clients will be immediately
+# disconnected from the broker on non-compliance.
+#WITH_STRICT_PROTOCOL:=yes
+
+# Comment out to remove bridge support from the broker. This allow the broker
+# to connect to other brokers and subscribe/publish to topics. You probably
+# want to leave this included unless you want to save a very small amount of
+# memory size and CPU time.
+WITH_BRIDGE:=yes
+
+# Comment out to remove persistent database support from the broker. This
+# allows the broker to store retained messages and durable subscriptions to a
+# file periodically and on shutdown. This is usually desirable (and is
+# suggested by the MQTT spec), but it can be disabled if required.
+WITH_PERSISTENCE:=yes
+
+# Comment out to remove memory tracking support from the broker. If disabled,
+# mosquitto won't track heap memory usage nor export '$SYS/broker/heap/current
+# size', but will use slightly less memory and CPU time.
+WITH_MEMORY_TRACKING:=yes
+
+# Compile with database upgrading support? If disabled, mosquitto won't
+# automatically upgrade old database versions.
+# Not currently supported.
+#WITH_DB_UPGRADE:=yes
+
+# Comment out to remove publishing of the $SYS topic hierarchy containing
+# information about the broker state.
+WITH_SYS_TREE:=yes
+
+# Build with Python module. Comment out if Python is not installed, or required
+# Python modules are not available.
+WITH_PYTHON:=yes
+
+# Build with SRV lookup support.
+WITH_SRV:=no
+
+# =============================================================================
+# End of user configuration
+# =============================================================================
+
+
+# Also bump lib/mosquitto.h, lib/python/setup.py, CMakeLists.txt,
+# installer/mosquitto.nsi, installer/mosquitto-cygwin.nsi
+VERSION=1.3.1
+TIMESTAMP:=$(shell date "+%F %T%z")
+
+# Client library SO version. Bump if incompatible API/ABI changes are made.
+SOVERSION=1
+
+# Man page generation requires xsltproc and docbook-xsl
+XSLTPROC=xsltproc
+# For html generation
+DB_HTML_XSL=man/html.xsl
+
+#MANCOUNTRIES=en_GB
+
+UNAME:=$(shell uname -s)
+ifeq ($(UNAME),SunOS)
+ ifeq ($(CC),cc)
+ CFLAGS?=-O
+ else
+ CFLAGS?=-Wall -ggdb -O2
+ endif
+else
+ CFLAGS?=-Wall -ggdb -O2
+endif
+
+LIB_CFLAGS:=${CFLAGS} ${CPPFLAGS} -I. -I.. -I./lib
+LIB_CXXFLAGS:=$(LIB_CFLAGS) ${CPPFLAGS}
+LIB_LDFLAGS:=${LDFLAGS}
+
+BROKER_CFLAGS:=${LIB_CFLAGS} ${CPPFLAGS} -DVERSION="\"${VERSION}\"" -DTIMESTAMP="\"${TIMESTAMP}\"" -DWITH_BROKER
+CLIENT_CFLAGS:=${CFLAGS} ${CPPFLAGS} -I./lib -DVERSION="\"${VERSION}\""
+
+ifeq ($(UNAME),FreeBSD)
+ BROKER_LIBS:=-lm
+else
+ BROKER_LIBS:=-ldl -lm
+endif
+LIB_LIBS:=
+PASSWD_LIBS:=
+
+ifeq ($(UNAME),Linux)
+ BROKER_LIBS:=$(BROKER_LIBS) -lrt
+ LIB_LIBS:=$(LIB_LIBS) -lrt
+endif
+
+CLIENT_LDFLAGS:=$(LDFLAGS) -L./lib ./lib/libmosquitto.so.${SOVERSION}
+
+ifeq ($(UNAME),SunOS)
+ ifeq ($(CC),cc)
+ LIB_CFLAGS:=$(LIB_CFLAGS) -xc99 -KPIC
+ else
+ LIB_CFLAGS:=$(LIB_CFLAGS) -fPIC
+ endif
+
+ ifeq ($(CXX),CC)
+ LIB_CXXFLAGS:=$(LIB_CXXFLAGS) -KPIC
+ else
+ LIB_CXXFLAGS:=$(LIB_CXXFLAGS) -fPIC
+ endif
+else
+ LIB_CFLAGS:=$(LIB_CFLAGS) -fPIC
+ LIB_CXXFLAGS:=$(LIB_CXXFLAGS) -fPIC
+endif
+
+ifneq ($(UNAME),SunOS)
+ LIB_LDFLAGS:=$(LIB_LDFLAGS) -Wl,-soname,libmosquitto.so.$(SOVERSION)
+endif
+
+ifeq ($(UNAME),QNX)
+ BROKER_LIBS:=$(BROKER_LIBS) -lsocket
+ LIB_LIBS:=$(LIB_LIBS) -lsocket
+endif
+
+ifeq ($(WITH_WRAP),yes)
+ BROKER_LIBS:=$(BROKER_LIBS) -lwrap
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_WRAP
+endif
+
+ifeq ($(WITH_TLS),yes)
+ BROKER_LIBS:=$(BROKER_LIBS) -lssl -lcrypto
+ LIB_LIBS:=$(LIB_LIBS) -lssl -lcrypto
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_TLS
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_TLS
+ PASSWD_LIBS:=-lcrypto
+ CLIENT_CFLAGS:=$(CLIENT_CFLAGS) -DWITH_TLS
+
+ ifeq ($(WITH_TLS_PSK),yes)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_TLS_PSK
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_TLS_PSK
+ CLIENT_CFLAGS:=$(CLIENT_CFLAGS) -DWITH_TLS_PSK
+ endif
+endif
+
+ifeq ($(WITH_THREADING),yes)
+ LIB_LIBS:=$(LIB_LIBS) -lpthread
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_THREADING
+endif
+
+ifeq ($(WITH_STRICT_PROTOCOL),yes)
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_STRICT_PROTOCOL
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_STRICT_PROTOCOL
+endif
+
+ifeq ($(WITH_BRIDGE),yes)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_BRIDGE
+endif
+
+ifeq ($(WITH_PERSISTENCE),yes)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_PERSISTENCE
+endif
+
+ifeq ($(WITH_MEMORY_TRACKING),yes)
+ ifneq ($(UNAME),SunOS)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_MEMORY_TRACKING
+ endif
+endif
+
+#ifeq ($(WITH_DB_UPGRADE),yes)
+# BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_DB_UPGRADE
+#endif
+
+ifeq ($(WITH_SYS_TREE),yes)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_SYS_TREE
+endif
+
+ifeq ($(WITH_SRV),yes)
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_SRV
+ LIB_LIBS:=$(LIB_LIBS) -lcares
+endif
+
+ifeq ($(UNAME),SunOS)
+ BROKER_LIBS:=$(BROKER_LIBS) -lsocket -lnsl
+ LIB_LIBS:=$(LIB_LIBS) -lsocket -lnsl
+endif
+
+
+INSTALL?=install
+prefix=/usr/local
+mandir=${prefix}/share/man
+localedir=${prefix}/share/locale
--- /dev/null
+# =============================================================================
+# User configuration section.
+#
+# Largely, these are options that are designed to make mosquitto run more
+# easily in restrictive environments by removing features.
+#
+# Modify the variable below to enable/disable features.
+#
+# Can also be overriden at the command line, e.g.:
+#
+# make WITH_TLS=no
+# =============================================================================
+
+# Uncomment to compile the broker with tcpd/libwrap support.
+#WITH_WRAP:=yes
+
+# Comment out to disable SSL/TLS support in the broker and client.
+# Disabling this will also mean that passwords must be stored in plain text. It
+# is strongly recommended that you only disable WITH_TLS if you are not using
+# password authentication at all.
+WITH_TLS:=yes
+
+# Comment out to disable TLS/PSK support in the broker and client. Requires
+# WITH_TLS=yes.
+# This must be disabled if using openssl < 1.0.
+WITH_TLS_PSK:=yes
+
+# Comment out to disable client client threading support.
+WITH_THREADING:=yes
+
+# Uncomment to compile the broker with strict protocol support. This means that
+# both the client library and the broker will be very strict about protocol
+# compliance on incoming data. Neither of them will return an error on
+# incorrect "remaining length" values if this is commented out. The old
+# behaviour (prior to 0.12) is equivalent to compiling with
+# WITH_STRICT_PROTOCOL defined and means that clients will be immediately
+# disconnected from the broker on non-compliance.
+#WITH_STRICT_PROTOCOL:=yes
+
+# Comment out to remove bridge support from the broker. This allow the broker
+# to connect to other brokers and subscribe/publish to topics. You probably
+# want to leave this included unless you want to save a very small amount of
+# memory size and CPU time.
+WITH_BRIDGE:=yes
+
+# Comment out to remove persistent database support from the broker. This
+# allows the broker to store retained messages and durable subscriptions to a
+# file periodically and on shutdown. This is usually desirable (and is
+# suggested by the MQTT spec), but it can be disabled if required.
+WITH_PERSISTENCE:=yes
+
+# Comment out to remove memory tracking support from the broker. If disabled,
+# mosquitto won't track heap memory usage nor export '$SYS/broker/heap/current
+# size', but will use slightly less memory and CPU time.
+WITH_MEMORY_TRACKING:=yes
+
+# Compile with database upgrading support? If disabled, mosquitto won't
+# automatically upgrade old database versions.
+# Not currently supported.
+#WITH_DB_UPGRADE:=yes
+
+# Comment out to remove publishing of the $SYS topic hierarchy containing
+# information about the broker state.
+WITH_SYS_TREE:=yes
+
+# Build with Python module. Comment out if Python is not installed, or required
+# Python modules are not available.
+WITH_PYTHON:=yes
+
+# Build with SRV lookup support.
+WITH_SRV:=no
+
+# =============================================================================
+# End of user configuration
+# =============================================================================
+
+
+# Also bump lib/mosquitto.h, lib/python/setup.py, CMakeLists.txt,
+# installer/mosquitto.nsi, installer/mosquitto-cygwin.nsi
+VERSION=1.3.1
+TIMESTAMP:=$(shell date "+%F %T%z")
+
+# Client library SO version. Bump if incompatible API/ABI changes are made.
+SOVERSION=1
+
+# Man page generation requires xsltproc and docbook-xsl
+XSLTPROC=xsltproc
+# For html generation
+DB_HTML_XSL=man/html.xsl
+
+#MANCOUNTRIES=en_GB
+
+UNAME:=$(shell uname -s)
+ifeq ($(UNAME),SunOS)
+ ifeq ($(CC),cc)
+ CFLAGS?=-O
+ else
+ CFLAGS?=-Wall -ggdb -O2
+ endif
+else
+ CFLAGS?=-Wall -ggdb -O2
+endif
+
+LIB_CFLAGS:=${CFLAGS} ${CPPFLAGS} -I. -I.. -I./lib
+LIB_CXXFLAGS:=$(LIB_CFLAGS) ${CPPFLAGS}
+LIB_LDFLAGS:=${LDFLAGS}
+
+BROKER_CFLAGS:=${LIB_CFLAGS} ${CPPFLAGS} -DVERSION="\"${VERSION}\"" -DTIMESTAMP="\"${TIMESTAMP}\"" -DWITH_BROKER
+CLIENT_CFLAGS:=${CFLAGS} ${CPPFLAGS} -I./lib -DVERSION="\"${VERSION}\""
+
+ifeq ($(UNAME),FreeBSD)
+ BROKER_LIBS:=-lm
+else
+ BROKER_LIBS:=-ldl -lm
+endif
+LIB_LIBS:=
+PASSWD_LIBS:=
+
+ifeq ($(UNAME),Linux)
+ BROKER_LIBS:=$(BROKER_LIBS) -lrt
+ LIB_LIBS:=$(LIB_LIBS) -lrt
+endif
+
+CLIENT_LDFLAGS:=$(LDFLAGS) -L./lib ./lib/libmosquitto.so.${SOVERSION}
+
+ifeq ($(UNAME),SunOS)
+ ifeq ($(CC),cc)
+ LIB_CFLAGS:=$(LIB_CFLAGS) -xc99 -KPIC
+ else
+ LIB_CFLAGS:=$(LIB_CFLAGS) -fPIC
+ endif
+
+ ifeq ($(CXX),CC)
+ LIB_CXXFLAGS:=$(LIB_CXXFLAGS) -KPIC
+ else
+ LIB_CXXFLAGS:=$(LIB_CXXFLAGS) -fPIC
+ endif
+else
+ LIB_CFLAGS:=$(LIB_CFLAGS) -fPIC
+ LIB_CXXFLAGS:=$(LIB_CXXFLAGS) -fPIC
+endif
+
+ifneq ($(UNAME),SunOS)
+ LIB_LDFLAGS:=$(LIB_LDFLAGS) -Wl,-soname,libmosquitto.so.$(SOVERSION)
+endif
+
+ifeq ($(UNAME),QNX)
+ BROKER_LIBS:=$(BROKER_LIBS) -lsocket
+ LIB_LIBS:=$(LIB_LIBS) -lsocket
+endif
+
+ifeq ($(WITH_WRAP),yes)
+ BROKER_LIBS:=$(BROKER_LIBS) -lwrap
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_WRAP
+endif
+
+ifeq ($(WITH_TLS),yes)
+ BROKER_LIBS:=$(BROKER_LIBS) -lssl -lcrypto
+ LIB_LIBS:=$(LIB_LIBS) -lssl -lcrypto
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_TLS
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_TLS
+ PASSWD_LIBS:=-lcrypto
+ CLIENT_CFLAGS:=$(CLIENT_CFLAGS) -DWITH_TLS
+
+ ifeq ($(WITH_TLS_PSK),yes)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_TLS_PSK
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_TLS_PSK
+ CLIENT_CFLAGS:=$(CLIENT_CFLAGS) -DWITH_TLS_PSK
+ endif
+endif
+
+ifeq ($(WITH_THREADING),yes)
+ LIB_LIBS:=$(LIB_LIBS) -lpthread
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_THREADING
+endif
+
+ifeq ($(WITH_STRICT_PROTOCOL),yes)
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_STRICT_PROTOCOL
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_STRICT_PROTOCOL
+endif
+
+ifeq ($(WITH_BRIDGE),yes)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_BRIDGE
+endif
+
+ifeq ($(WITH_PERSISTENCE),yes)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_PERSISTENCE
+endif
+
+ifeq ($(WITH_MEMORY_TRACKING),yes)
+ ifneq ($(UNAME),SunOS)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_MEMORY_TRACKING
+ endif
+endif
+
+#ifeq ($(WITH_DB_UPGRADE),yes)
+# BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_DB_UPGRADE
+#endif
+
+ifeq ($(WITH_SYS_TREE),yes)
+ BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_SYS_TREE
+endif
+
+ifeq ($(WITH_SRV),yes)
+ LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_SRV
+ LIB_LIBS:=$(LIB_LIBS) -lcares
+endif
+
+ifeq ($(UNAME),SunOS)
+ BROKER_LIBS:=$(BROKER_LIBS) -lsocket -lnsl
+ LIB_LIBS:=$(LIB_LIBS) -lsocket -lnsl
+endif
+
+
+INSTALL?=install
+prefix=/usr/local
+mandir=${prefix}/share/man
+localedir=${prefix}/share/locale
target_os = env.get('TARGET_OS')
if target_os == 'linux':
- SConscript('linux/SConscript')
+ SConscript('linux/SConscript')
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+/// @file mqttclient.cpp
+
+/// @brief Samplecode which controls MQTT-fan plugin using Protocol Plugin Manager.
-// OCClient.cpp : Defines the entry point for the console application.
-//
#include <string>
#include <cstdlib>
#include <pthread.h>
// makes it so that all boolean values are printed as 'true/false' in this stream
std::cout.setf(std::ios::boolalpha);
// Find all resources
- requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.fan";
+ requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.fan";
OCPlatform::findResource("", requestURI.str(), OC_ALL, &foundResourceFan);
std::cout << "Finding Resource... " << std::endl;
while (true)
// Find fan resources
std::ostringstream requestURI;
- requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.fan";
+ requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.fan";
OCPlatform::findResource("", requestURI.str(), OC_ALL, &foundResourceFan);
std::cout << "Finding Resource... " << std::endl;
}