if target_os not in ['windows', 'winrt']:
soft_sensor_manager_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-DLINUX'])
if target_os != 'android':
- soft_sensor_manager_env.AppendUnique(CXXFLAGS = ['-pthread'])
+ soft_sensor_manager_env.AppendUnique(LIBS = ['pthread'])
if target_os == 'android':
soft_sensor_manager_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
- soft_sensor_manager_env.AppendUnique(LIBS = ['gnustl_static', 'compatibility'])
-
- if not env.get('RELEASE'):
- soft_sensor_manager_env.AppendUnique(LIBS = ['log'])
+ soft_sensor_manager_env.AppendUnique(LIBS = ['gnustl_static', 'compatibility', 'log'])
#######################################################################
## build SSM SDK
'SSMCore/src/Common/sqlite3.c'
]
-libssmcore = ssmcore_env.StaticLibrary(
+
+static_libssmcore = ssmcore_env.StaticLibrary(
+ target = 'SSMCore',
+ source = [ssm_core_cpp_src, ssm_core_c_src]
+ )
+
+ssmcore_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+ssmcore_env.AppendUnique(LIBS = ['oc', 'octbstack', 'coap', 'oc_logger'])
+
+shared_libssmcore = ssmcore_env.SharedLibrary(
target = 'SSMCore',
source = [ssm_core_cpp_src, ssm_core_c_src]
)
-ssmcore_env.InstallTarget(libssmcore, 'libSSMCORE')
+ssmcore_env.InstallTarget([shared_libssmcore, static_libssmcore], 'libSSMCORE')
#######################################################################
## build SampleApp
import java.util.List;
-import android.util.Log;
-
public class CoreController
{
static
{
String workingPath = System.getProperty( "user.dir" );
- Log.i("SSMTester", "loading ssm lib");
-
// for android: not complete method
if(System.getProperty("os.name").toLowerCase().equals("linux"))
{
//System.out.println("System load Android library");
- System.loadLibrary("SSMCore_Android");
+ System.loadLibrary("oc_logger");
+ System.loadLibrary("coap");
+ System.loadLibrary("octbstack");
+ System.loadLibrary("oc");
+ System.loadLibrary("SSMCore");
}
else
{
- //System.out.println("System load 32bit library");
- workingPath += "/../Outputs/";
+ //System.out.println("System load 32bit library");
System.load( workingPath + "SSMCore_Windows.dll");
}
-
- Log.i("SSMTester", "loading done");
}
catch(UnsatisfiedLinkError e)
{
package org.iotivity.service.ssm;
-public interface IQueryEngineEvent {
- public void OnQueryEngineEvent(int cqid, DataReader result);
+public abstract class IQueryEngineEvent {
+ public abstract void OnQueryEngineEvent(int cqid, DataReader result);
}
\ No newline at end of file
package org.iotivity.service.ssm;
-public interface IReportReceiver {
- public void OnMessageReceived(String tag, String msg);
+public abstract class IReportReceiver {
+ public abstract void OnMessageReceived(String tag, String msg);
}
import java.util.concurrent.locks.ReentrantLock;
public class SSMInterface {
- private class QueryEngineEventReceiver implements IQueryEngineEvent
+ private class QueryEngineEventReceiver extends IQueryEngineEvent
{
private Lock mMtxListener = new ReentrantLock();
private Map<Integer, IQueryEngineEvent> mMapListener = new HashMap<Integer, IQueryEngineEvent>();
env->GetMethodID(g_ClassReportReceiver, "OnMessageReceived",
"(Ljava/lang/String;Ljava/lang/String;)V");
- jclass nonVIrtualObject = env->GetObjectClass(g_objReportReceiver);
-
- env->CallNonvirtualVoidMethod(g_objReportReceiver, nonVIrtualObject, midReportReceiver,
- env->NewStringUTF(tag), env->NewStringUTF(msg));
+ env->CallVoidMethod(g_objReportReceiver, midReportReceiver,
+ env->NewStringUTF(tag), env->NewStringUTF(msg));
DETACH_CURRENT_THREAD(g_JVM);
jmethodID midQueryEngineEvent =
env->GetMethodID(g_ClassQueryEngineEvent, "OnQueryEngineEvent",
- "(ILcom/sec/android/ssmcore/DataReader;)V");
+ "(ILorg/iotivity/service/ssm/DataReader;)V");
- jclass nonVIrtualObject = env->GetObjectClass(m_objQueryEngineEvent);
+ jclass callbackObject = env->GetObjectClass(m_objQueryEngineEvent);
jmethodID cid_DataReader = env->GetMethodID(g_ClassDataReader, "<init>", "(I)V");
if (cid_DataReader == NULL)
return SSM_E_FAIL;
- env->CallNonvirtualVoidMethod(m_objQueryEngineEvent, nonVIrtualObject, midQueryEngineEvent,
- (jint)cqid,
- env->NewObject(g_ClassDataReader, cid_DataReader, (jint)pResult));
+ env->CallVoidMethod(m_objQueryEngineEvent, midQueryEngineEvent,
+ (jint)cqid,
+ env->NewObject(g_ClassDataReader, cid_DataReader, (jint)pResult));
DETACH_CURRENT_THREAD(g_JVM);
return JNI_ERR;
g_ClassQueryEngine = (jclass) env->NewGlobalRef(
- env->FindClass("com/sec/android/ssmcore/QueryEngine"));
+ env->FindClass("org/iotivity/service/ssm/QueryEngine"));
g_ClassDataReader = (jclass) env->NewGlobalRef(
- env->FindClass("com/sec/android/ssmcore/DataReader"));
+ env->FindClass("org/iotivity/service/ssm/DataReader"));
- g_ClassModelData = (jclass) env->NewGlobalRef(env->FindClass("com/sec/android/ssmcore/ModelData"));
+ g_ClassModelData = (jclass) env->NewGlobalRef(env->FindClass("org/iotivity/service/ssm/ModelData"));
g_ClassQueryEngineEvent = (jclass) env->NewGlobalRef(
- env->FindClass("com/sec/android/ssmcore/IQueryEngineEvent"));
+ env->FindClass("org/iotivity/service/ssm/IQueryEngineEvent"));
g_ClassReportReceiver = (jclass) env->NewGlobalRef(
- env->FindClass("com/sec/android/ssmcore/IReportReceiver"));
+ env->FindClass("org/iotivity/service/ssm/IReportReceiver"));
g_JVM = jvm;
delete g_QueryEngineEventReceiver;
}
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_InitializeSSMCore
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_InitializeSSMCore
(JNIEnv *env, jclass clz, jstring jstrXmlDescription)
{
SSMRESULT res = SSM_E_FAIL;
env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), "InitializeSSMCore failed");
}
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_StartSSMCore
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_StartSSMCore
(JNIEnv *env, jclass clz)
{
if (StartSSMCore() != SSM_S_OK)
env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), "StartSSMCore failed");
}
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_StopSSMCore
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_StopSSMCore
(JNIEnv *env, jclass clz)
{
if (StopSSMCore() != SSM_S_OK)
env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), "StopSSMCore failed");
}
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_TerminateSSMCore
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_TerminateSSMCore
(JNIEnv *env, jclass clz)
{
if (TerminateSSMCore() != SSM_S_OK)
env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), "TerminateSSMCore failed");
}
-JNIEXPORT jobject JNICALL Java_com_sec_android_ssmcore_CoreController_CreateQueryEngine
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ssm_CoreController_CreateQueryEngine
(JNIEnv *env, jclass clz)
{
IQueryEngine *pQueryEngine = NULL;
return env->NewObject(g_ClassQueryEngine, cid_QueryEngine, (jint)pQueryEngine);
}
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_ReleaseQueryEngine
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_ReleaseQueryEngine
(JNIEnv *env, jclass clz, jobject queryEngine)
{
IQueryEngine *pQueryEngine = NULL;
return ReleaseQueryEngine(pQueryEngine);
}
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_ExecuteContextQuery
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_ExecuteContextQuery
(JNIEnv *env, jclass clz, jint pQueryEngineInstance, jstring jstrContextQuery)
{
int cqid = 0;
return cqid;
}
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_RegisterQueryEvent
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_RegisterQueryEvent
(JNIEnv *env, jclass clz, jint pQueryEngineInstance, jobject queryEngineEvent)
{
IQueryEngine *pQueryEngine = (IQueryEngine *)pQueryEngineInstance;
pQueryEngine->registerQueryEvent(g_QueryEngineEventReceiver);
}
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_KillContextQuery
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_KillContextQuery
(JNIEnv *env, jclass clz, jint pQueryEngineInstance, jint cqid)
{
IQueryEngine *pQueryEngine = (IQueryEngine *)pQueryEngineInstance;
}
}
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_GetDataId
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_GetDataId
(JNIEnv *env, jclass clz, jint pDataReaderInstance)
{
IModelData *pDataReader = (IModelData *)pDataReaderInstance;
return pDataReader->getDataId();
}
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_GetPropertyCount
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_GetPropertyCount
(JNIEnv *env, jclass clz, jint pIModelDataInstance )
{
IModelData *pModelData = (IModelData *)pIModelDataInstance;
return pModelData->getPropertyCount();
}
-JNIEXPORT jstring JNICALL Java_com_sec_android_ssmcore_CoreController_GetPropertyName
+JNIEXPORT jstring JNICALL Java_org_iotivity_service_ssm_CoreController_GetPropertyName
(JNIEnv *env, jclass clz, jint pIModelDataInstance, jint propertyIndex )
{
IModelData *pModelData = (IModelData *)pIModelDataInstance;
return env->NewStringUTF(pModelData->getPropertyName(propertyIndex).c_str());
}
-JNIEXPORT jstring JNICALL Java_com_sec_android_ssmcore_CoreController_GetPropertyValue
+JNIEXPORT jstring JNICALL Java_org_iotivity_service_ssm_CoreController_GetPropertyValue
(JNIEnv *env, jclass clz, jint pIModelDataInstance, jint propertyIndex )
{
IModelData *pModelData = (IModelData *)pIModelDataInstance;
return env->NewStringUTF(pModelData->getPropertyValue(propertyIndex).c_str());
}
-JNIEXPORT jobject JNICALL Java_com_sec_android_ssmcore_CoreController_GetAffectedModels
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ssm_CoreController_GetAffectedModels
(JNIEnv *env, jclass clz, jint pDataReaderInstance)
{
IDataReader *pDataReader = (IDataReader *)pDataReaderInstance;
return objAffectedModels;
}
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_GetModelDataCount
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_GetModelDataCount
(JNIEnv *env, jclass clz, jint pDataReaderInstance, jstring jstrModelName)
{
IDataReader *pDataReader = (IDataReader *)pDataReaderInstance;
return modelCount;
}
//return IModelData
-JNIEXPORT jobject JNICALL Java_com_sec_android_ssmcore_CoreController_GetModelData
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ssm_CoreController_GetModelData
(JNIEnv *env, jclass clz, jint pDataReaderInstance, jstring jstrModelName, jint jintDataIndex )
{
IDataReader *pDataReader = (IDataReader *)pDataReaderInstance;
return env->NewObject(g_ClassModelData, cid_ModelData, (jint)pModelData);
}
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_RegisterReportReceiver
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_RegisterReportReceiver
(JNIEnv *env, jclass clz, jobject reportReceiver)
{
if (g_objReportReceiver != NULL)
extern "C" {
#endif
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_InitializeSSMCore
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_InitializeSSMCore
(JNIEnv *env, jclass clz, jstring jstrXmlDescription);
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_StartSSMCore
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_StartSSMCore
(JNIEnv *env, jclass clz);
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_StopSSMCore
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_StopSSMCore
(JNIEnv *env, jclass clz);
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_TerminateSSMCore
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_TerminateSSMCore
(JNIEnv *env, jclass clz);
-JNIEXPORT jobject JNICALL Java_com_sec_android_ssmcore_CoreController_CreateQueryEngine
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ssm_CoreController_CreateQueryEngine
(JNIEnv *env, jclass clz);
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_ReleaseQueryEngine
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_ReleaseQueryEngine
(JNIEnv *env, jclass clz, jobject queryEngine);
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_ExecuteContextQuery
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_ExecuteContextQuery
(JNIEnv *env, jclass clz, jint pQueryEngineInstance, jstring jstrContextQuery);
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_RegisterQueryEvent
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_RegisterQueryEvent
(JNIEnv *env, jclass clz, jint pQueryEngineInstance, jobject queryEngineEvent);
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_KillContextQuery
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_KillContextQuery
(JNIEnv *env, jclass clz, jint pQueryEngineInstance, jint cqid);
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_Release
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_Release
(JNIEnv *env, jclass clz, jint pQueryEngineInstance);
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_GetDataId
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_GetDataId
(JNIEnv *env, jclass clz, jint pDataReaderInstance);
-JNIEXPORT jobject JNICALL Java_com_sec_android_ssmcore_CoreController_GetAffectedModels
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ssm_CoreController_GetAffectedModels
(JNIEnv *env, jclass clz, jint pDataReaderInstance);
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_GetModelDataCount
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_GetModelDataCount
(JNIEnv *env, jclass clz, jint pDataReaderInstance, jstring jstrModelName);
-JNIEXPORT jobject JNICALL Java_com_sec_android_ssmcore_CoreController_GetModelData
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ssm_CoreController_GetModelData
(JNIEnv *env, jclass clz, jint pDataReaderInstance, jstring jstrModelName, jint jintDataIndex );
-JNIEXPORT jint JNICALL Java_com_sec_android_ssmcore_CoreController_GetPropertyCount
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_GetPropertyCount
(JNIEnv *env, jclass clz, jint pIModelDataInstance );
-JNIEXPORT jstring JNICALL Java_com_sec_android_ssmcore_CoreController_GetPropertyName
+JNIEXPORT jstring JNICALL Java_org_iotivity_service_ssm_CoreController_GetPropertyName
(JNIEnv *env, jclass clz, jint pIModelDataInstance, jint propertyIndex );
-JNIEXPORT jstring JNICALL Java_com_sec_android_ssmcore_CoreController_GetPropertyValue
+JNIEXPORT jstring JNICALL Java_org_iotivity_service_ssm_CoreController_GetPropertyValue
(JNIEnv *env, jclass clz, jint pIModelDataInstance, jint propertyIndex );
-JNIEXPORT void JNICALL Java_com_sec_android_ssmcore_CoreController_RegisterReportReceiver
+JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_RegisterReportReceiver
(JNIEnv *env, jclass clz, jobject reportReceiver );
#ifdef __cplusplus
--- /dev/null
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.iotivity.service.ssm"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" />
+
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+ <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+ <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.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+ <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
+ <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
+ <uses-permission android:name="android.permission.READ_CALENDAR" />
+ <uses-permission android:name="android.permission.WRITE_CALENDAR" />
+
+ <application android:label="@string/app_name"
+ android:icon="@drawable/ic_launcher"
+ android:theme="@style/AppTheme"
+ android:allowBackup="true"
+ android:debuggable="true">
+
+ <activity
+ android:name="org.iotivity.service.ssm.sample.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
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := coap
+LOCAL_SRC_FILES := ../libs/libcoap.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := oc_logger
+LOCAL_SRC_FILES := ../libs/liboc_logger.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := octbstack
+LOCAL_SRC_FILES := ../libs/liboctbstack.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := oc
+LOCAL_SRC_FILES := ../libs/liboc.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := SSMCore
+LOCAL_SRC_FILES := ../libs/libSSMCore.so
+include $(PREBUILT_SHARED_LIBRARY)
\ No newline at end of file
--- /dev/null
+APP_STL:=gnustl_static
+NDK_TOOLCHAIN_VERSION := 4.9
\ No newline at end of file
--- /dev/null
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ android:paddingBottom="5dp"
+ android:paddingLeft="10dp"
+ android:paddingRight="10dp"
+ android:paddingTop="10dp" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <EditText
+ android:id="@+id/editQuery"
+ android:layout_width="wrap_content"
+ android:layout_height="110dp"
+ android:layout_weight="0.92"
+ android:ems="9"
+ android:inputType="textMultiLine"
+ android:text=""
+ android:textSize="15sp" />
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="0.92"
+ android:orientation="vertical" >
+
+ <Button
+ android:id="@+id/btnRegisterQuery"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Register"
+ android:textSize="18sp" />
+
+ <Button
+ android:id="@+id/btClear"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="CLEAR"
+ android:textSize="18sp" />
+
+ </LinearLayout>
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingTop="10dp" >
+
+ <TextView
+ android:id="@+id/textView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Example Queries"
+ android:textSize="15sp"
+ android:textStyle="bold" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <Button
+ android:id="@+id/btFullDevice"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Search Devices"
+ android:textSize="17sp" />
+
+ <Button
+ android:id="@+id/btDiscomfortIndex"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="DiscomfortIndex"
+ android:textSize="17sp" />
+
+ </LinearLayout>
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingTop="10dp" >
+
+ <TextView
+ android:id="@+id/textView2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Unregister Query"
+ android:textSize="15sp"
+ android:textStyle="bold" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <Button
+ android:id="@+id/btMinus"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text=" - "
+ android:textSize="18sp" />
+
+ <EditText
+ android:id="@+id/editUnregisterQuery"
+ android:layout_width="90dp"
+ android:layout_height="wrap_content"
+ android:text="0"
+ android:textSize="18sp" />
+
+ <Button
+ android:id="@+id/btPlus"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text=" + "
+ android:textSize="18sp" />
+
+ <Button
+ android:id="@+id/btnUnregisterQuery"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="UnRegister"
+ android:textSize="18sp" />
+
+ </LinearLayout>
+
+ </LinearLayout>
+
+ <Space
+ android:layout_width="match_parent"
+ android:layout_height="10dp" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="5dp"
+ android:orientation="vertical"
+ android:background="#111111" >
+ </LinearLayout>
+
+ <Space
+ android:layout_width="match_parent"
+ android:layout_height="5dp" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingTop="0dp" >
+
+ <Button
+ android:id="@+id/btLogClear"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="CLEAR LOG"
+ android:textSize="18sp" />
+
+ <ScrollView
+ android:id="@+id/sclLog"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <TextView
+ android:id="@+id/txtLog"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentLeft="true"
+ android:textSize="15sp" />
+
+ </ScrollView>
+
+ </LinearLayout>
+
+</LinearLayout>
\ No newline at end of file
--- /dev/null
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/menu_settings"
+ android:title="@string/menu_settings"
+ android:orderInCategory="100"
+ android:showAsAction="never" />
+</menu>
--- /dev/null
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light" />
+
+</resources>
\ No newline at end of file
--- /dev/null
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
+
+</resources>
\ No newline at end of file
--- /dev/null
+<resources>
+
+ <string name="app_name">SSM Sample App</string>
+ <string name="menu_settings">Settings</string>
+ <string name="title_activity_main">MainActivity</string>
+
+</resources>
--- /dev/null
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Light" />
+
+</resources>
\ No newline at end of file
--- /dev/null
+package org.iotivity.service.ssm.sample;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+
+import org.iotivity.service.ssm.*;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.content.res.AssetManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+//import android.view.Menu;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+public class MainActivity extends Activity {
+
+ private SSMInterface SoftSensorManager = null;
+ private List<Integer> mRunningQueries = new ArrayList<Integer>();
+
+ private IQueryEngineEvent mQueryEngineEventListener = new IQueryEngineEvent()
+ {
+ @Override
+ public void OnQueryEngineEvent(int cqid, DataReader result)
+ {
+ Log.i("[SSM]", "event received! cqid=" + cqid);
+ PrintLog("Event from cqid " + cqid + " has received");
+
+ List<String> models = result.GetAffectedModels();
+
+ for(String modelName : models)
+ {
+ PrintLog("Model: " + modelName);
+ int dataCount = result.GetModelDataCount(modelName);
+ for(int i=0; i < dataCount; i++)
+ {
+ ModelData modelData =
+ result.GetModelData(modelName, i);
+ for(int j=0; j < modelData.GetPropertyCount(); j++)
+ {
+ PrintLog("Name: " + modelData.GetPropertyName(j) +
+ " Value: " + modelData.GetPropertyValue(j));
+ }
+ }
+ }
+ }
+ };
+
+ void PrintLog(String log)
+ {
+ Message msg = new Message();
+ Bundle data = new Bundle();
+ data.putString("Log", log);
+ msg.setData(data);
+ logHandler.sendMessage(msg);
+ }
+
+ private Handler logHandler = new Handler()
+ {
+ @Override
+ public void handleMessage(Message msg)
+ {
+ tvLog.append(msg.getData().getString("Log") + "\n");
+ svLog.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ };
+
+ private TextView tvLog = null;
+ private ScrollView svLog = null;
+ private EditText edtQuery = null;
+ private EditText edtUnregisterQuery = null;
+
+ View.OnClickListener clickHandler = new View.OnClickListener() {
+
+ public void onClick(View v)
+ {
+ switch(v.getId())
+ {
+ case R.id.btnRegisterQuery:
+ int cqid = SoftSensorManager.registerQuery(edtQuery.getText().toString(), mQueryEngineEventListener);
+ mRunningQueries.add(cqid);
+ PrintLog(edtQuery.getText().toString() + " has executed, cqid=" + cqid);
+ break;
+
+ case R.id.btnUnregisterQuery:
+ Iterator<Integer> it = mRunningQueries.iterator();
+ while(it.hasNext())
+ {
+ if(it.next() == Integer.parseInt(edtUnregisterQuery.getText().toString()))
+ {
+ SoftSensorManager.unregisterQuery(Integer.parseInt(edtUnregisterQuery.getText().toString()));
+ PrintLog("Unregister Query has executed, cqid=" + Integer.parseInt(edtUnregisterQuery.getText().toString()));
+ it.remove();
+ }
+ }
+ break;
+
+ case R.id.btPlus:
+ int queryNum = Integer.parseInt(edtUnregisterQuery.getText().toString()) + 1;
+ edtUnregisterQuery.setText(queryNum + "");
+ break;
+
+ case R.id.btMinus:
+ queryNum = Integer.parseInt(edtUnregisterQuery.getText().toString()) - 1;
+ edtUnregisterQuery.setText(queryNum + "");
+ break;
+ }
+ }
+ };
+
+ View.OnClickListener textAddHandler = new View.OnClickListener() {
+
+ public void onClick(View v)
+ {
+ switch(v.getId())
+ {
+ case R.id.btClear :
+ edtQuery.setText("");
+ break;
+
+ case R.id.btLogClear :
+ tvLog.setText("");
+ break;
+
+ case R.id.btFullDevice:
+ edtQuery.setText("subscribe Device if Device.dataId != 0");
+ break;
+
+ case R.id.btDiscomfortIndex:
+ edtQuery.setText("subscribe Device.DiscomfortIndexSensor if Device.DiscomfortIndexSensor.discomfortIndex > 0");
+ break;
+ }
+ }
+ };
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ tvLog = (TextView)findViewById(R.id.txtLog);
+ svLog = (ScrollView)findViewById(R.id.sclLog);
+ edtQuery = (EditText)findViewById(R.id.editQuery);
+ edtUnregisterQuery = (EditText)findViewById(R.id.editUnregisterQuery);
+
+ findViewById(R.id.btnRegisterQuery).setOnClickListener(clickHandler);
+ findViewById(R.id.btnUnregisterQuery).setOnClickListener(clickHandler);
+ findViewById(R.id.btFullDevice).setOnClickListener(textAddHandler);
+ findViewById(R.id.btDiscomfortIndex).setOnClickListener(textAddHandler);
+ findViewById(R.id.btPlus).setOnClickListener(clickHandler);
+ findViewById(R.id.btMinus).setOnClickListener(clickHandler);
+ findViewById(R.id.btClear).setOnClickListener(textAddHandler);
+ findViewById(R.id.btLogClear).setOnClickListener(textAddHandler);
+
+ copyFiles("lib");
+
+ SoftSensorManager = new SSMInterface();
+
+ String initConfig = "<SSMCore>" +
+ "<Device>" +
+ "<UDN>"+getUUID()+"</UDN>" +
+ "<Name>MyMobile</Name>" +
+ "<Type>Mobile</Type>" +
+ "</Device>" +
+ "<Config>" +
+ "<SoftSensorRepository>/data/data/" + getPackageName() + "/files/</SoftSensorRepository>" +
+ "<SoftSensorDescription>/data/data/" + getPackageName() + "/files/SoftSensorDescription.xml</SoftSensorDescription>" +
+ "</Config>" +
+ "</SSMCore>";
+
+ try
+ {
+ SoftSensorManager.startSSMCore(initConfig);
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected void onDestroy()
+ {
+ SoftSensorManager.stopSSMCore();
+
+ super.onDestroy();
+ }
+
+ private String getUUID()
+ {
+ String PREF_UNIQUE_ID = "PREF_UNIQUE_ID";
+ SharedPreferences sharedPrefs = getSharedPreferences(PREF_UNIQUE_ID, Context.MODE_PRIVATE);
+ String uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null);
+
+ if (uniqueID == null)
+ {
+ uniqueID = UUID.randomUUID().toString();
+ Editor editor = sharedPrefs.edit();
+ editor.putString(PREF_UNIQUE_ID, uniqueID);
+ editor.commit();
+ }
+
+ return uniqueID;
+ }
+
+ private void copyFiles(String path)
+ {
+ AssetManager assetManager = getAssets();
+ String assets[] = null;
+
+ try
+ {
+ assets = assetManager.list(path);
+
+ if (assets.length == 0)
+ {
+ copyFile(path);
+ }
+ else
+ {
+ String fullPath = "/data/data/" + this.getClass().getPackage().toString() + "/" + path;
+ 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 void copyFile(String filename)
+ {
+ AssetManager assetManager = getAssets();
+ InputStream in = null;
+ OutputStream out = null;
+
+ try
+ {
+ in = assetManager.open(filename);
+ out = 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());
+ }
+ }
+}