SConscript('protocol-plugin/SConscript')
# Build notification manager project
- if target_os not in ['android']:
- SConscript('notification-manager/SConscript')
+ SConscript('notification-manager/SConscript')
# Build resource-encapsulation project
SConscript('resource-encapsulation/SConscript')
android:targetSdkVersion="21" />
<application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
+ android:allowBackup="true" >
</application>
</manifest>
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_MODULE := ca
-LOCAL_SRC_FILES := ../libs/libconnectivity_abstraction.so
+OIC_LIB_PATH := ../../../../../../android/android_api/base/libs/$(TARGET_ARCH_ABI)
+LOCAL_MODULE := ca_interface
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libca-interface.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
-LOCAL_MODULE := ca_i
-LOCAL_SRC_FILES := ../libs/libca-interface.so
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := ca
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libconnectivity_abstraction.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/release
LOCAL_MODULE := oc_logger_core
-LOCAL_SRC_FILES := ../libs/liboc_logger_core.so
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboc_logger_core.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/release
LOCAL_MODULE := oc_logger
-LOCAL_SRC_FILES := ../libs/liboc_logger.so
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboc_logger.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/release
LOCAL_MODULE := octbstack
-LOCAL_SRC_FILES := ../libs/liboctbstack.so
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboctbstack.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/release
LOCAL_MODULE := oc
-LOCAL_SRC_FILES := ../libs/liboc.so
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboc.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../android/android_api/base/libs/$(TARGET_ARCH_ABI)
LOCAL_MODULE := ocstack-jni
-LOCAL_SRC_FILES := ../libs/libocstack-jni.so
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libocstack-jni.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := rcsCommon
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/librcs_common.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := rcsClient
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/librcs_client.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := rcsServer
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/librcs_server.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/release
LOCAL_MODULE := NotificationManager
-LOCAL_SRC_FILES := ../libs/libNotificationManager.so
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libNotificationManager.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ResourceHosing_JNI
LOCAL_CPPFLAGS := -std=c++0x -frtti -fexceptions
-LOCAL_STATIC_LIBRARIES = ca_i
+LOCAL_STATIC_LIBRARIES := ca_interface
LOCAL_STATIC_LIBRARIES += ca
LOCAL_STATIC_LIBRARIES += oc_logger_core
LOCAL_STATIC_LIBRARIES += oc_logger
LOCAL_STATIC_LIBRARIES += octbstack
LOCAL_STATIC_LIBRARIES += oc
LOCAL_STATIC_LIBRARIES += ocstack-jni
+LOCAL_STATIC_LIBRARIES += rcsCommon
+LOCAL_STATIC_LIBRARIES += rcsClient
+LOCAL_STATIC_LIBRARIES += rcsServer
LOCAL_STATIC_LIBRARIES += NotificationManager
-LOCAL_C_INCLUDES := ../../../../../../resource/csdk/stack/include/
-LOCAL_C_INCLUDES += ../../../../../../resource/csdk/logger/include/
-LOCAL_C_INCLUDES += ../../../../../../resource/include/
-LOCAL_C_INCLUDES += ../../../../../../resource/oc_logger/include/
-LOCAL_C_INCLUDES += ../../../../../../extlibs/boost/boost_1_58_0/
-LOCAL_C_INCLUDES += ../../../../NotificationManager/include/
+OIC_SRC_DIR := ../../../../..
+
+LOCAL_C_INCLUDES := $(OIC_SRC_DIR)/resource/csdk/stack/include \
+ $(OIC_SRC_DIR)/resource/csdk/logger/include \
+ $(OIC_SRC_DIR)/resource/include \
+ $(OIC_SRC_DIR)/resource/c_common \
+ $(OIC_SRC_DIR)/resource/oc_logger/include \
+ $(OIC_SRC_DIR)/extlibs/boost/boost_1_58_0 \
+ $(OIC_SRC_DIR)/service/resource-encapsulation/include \
+ $(OIC_SRC_DIR)/service/notification-manager/NotificationManager/include \
LOCAL_SRC_FILES := ResourceHosing_JNI.cpp
include $(BUILD_SHARED_LIBRARY)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
package org.iotivity.ResourceHosting;
import java.lang.System;
-import java.lang.String;;
+import java.lang.String;
+
/**
* To execute resource hosting function for android sample application .
- *
+ *
* @author Copyright 2015 Samsung Electronics All Rights Reserved.
* @see className class : ResourceHosting</br>
*
/**
* jni function - OicCorrdinatorstart() method.
- *
+ *
* @see Class class :
* org_iotivity_resourcehosting_ResourceHosting</br>
* @see Method method : OICCoordinatorStart</br>
/**
* jni function - OICCoordinatorStop() method.
- *
+ *
* @see Class class :
* org_iotivity_resourcehosting_ResourceHosting</br>
* @see Method method : OICCoordinatorStop</br>
/**
* jni function - ResourceHostingInit() method in order to execute
* OICCoordinatorStart() method.
- *
+ *
* @see Class class :
* org_iotivity_resourcehosting_ResourceHosting</br>
* @see Method method : ResourceHostingInit</br>
/**
* jni function - ResourceHostingTerminate() method in order to terminate
* resource hosting
- *
+ *
* @see Class class :
* org_iotivity_resourcehosting_ResourceHosting</br>
* @see Method method : ResourceHostingTerminate</br>
System.loadLibrary("octbstack");
System.loadLibrary("oc");
System.loadLibrary("ocstack-jni");
+ System.loadLibrary("rcs_common");
+ System.loadLibrary("rcs_client");
+ System.loadLibrary("rcs_server");
System.loadLibrary("NotificationManager");
- System.loadLibrary("ResourceHosing_JNI");
+ System.loadLibrary("ResourceHosing_JNI");
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
package com.example.sample.consumer;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.widget.Toast;
public class SampleConsumer extends Activity implements View.OnClickListener,
- OcPlatform.OnResourceFoundListener, OnGetListener, OnDeleteListener,
- OnObserveListener, OnPutListener
-{
- private final String TAG = "NMConsumer : " + this.getClass().getSimpleName();
-
- public static final int OC_STACK_OK = 0;
- public static final String OBSERVE = "Observe";
- public static final String GET = "Get";
- public static final String PUT = "Put";
- public static final String DELETE = "Delete";
- public static final String POST = "Post";
- public static final String MESSAGE = "message";
- public static String outputString = "";
-
- private Button btn_observe;
- private Button btn_get;
- private Button btn_put;
- private Button btn_post;
- private Button btn_delete;
- private Button btn_clean;
-
- public TextView tv_found_uri;
- public TextView tv_select_method_type;
- public TextView tv_receive_result;
- public TextView tv_current_log_result;
-
- public String current_log_result = "";
- public String found_uri = "";
- public String select_method_type = "";
- public String receive_result = "";
-
- public static OcResource curResource;
- public OcPlatform.OnResourceFoundListener OnResourceFoundListener;
-
- public static int oc = 0;
- /*
- * To initialize UI Function Setting
- * To execute initOICStack for running find resource
- */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.sampleconsumer_layout);
-
- btn_observe = (Button) findViewById(R.id.btn_observe);
- btn_get = (Button) findViewById(R.id.btn_get);
- btn_put = (Button) findViewById(R.id.btn_put);
- btn_post = (Button) findViewById(R.id.btn_post);
- btn_delete = (Button) findViewById(R.id.btn_delete);
- btn_clean = (Button) findViewById(R.id.btn_clean);
- tv_found_uri = (TextView) findViewById(R.id.tv_found_resource_result);
- tv_select_method_type = (TextView) findViewById(R.id.tv_selected_method_type);
- tv_receive_result = (TextView) findViewById(R.id.tv_receive_result);
- tv_current_log_result = (TextView) findViewById(R.id.tv_current_log_result);
- btn_observe.setOnClickListener(this);
- btn_get.setOnClickListener(this);
- btn_put.setOnClickListener(this);
- btn_post.setOnClickListener(this);
- btn_delete.setOnClickListener(this);
- btn_clean.setOnClickListener(this);
-
- initOICStack();
- }
-
- @Override
- protected void onDestroy()
- {
- super.onDestroy();
- onStop();
- }
- /*
- * To reset text String is null for cleaning log
- *
- */
- @Override
- protected void onStop()
- {
- super.onStop();
-
- tv_found_uri = null;
- tv_select_method_type = null;
- tv_receive_result = null;
- tv_current_log_result = null;
-
- current_log_result = "";
- found_uri = "";
- select_method_type = "";
- receive_result = "";
- btn_observe.setClickable(true);
- btn_get.setClickable(true);
- btn_put.setClickable(true);
- btn_delete.setClickable(true);
- }
-
- public void cleanLogString()
- {
- current_log_result = "";
- found_uri = "";
- select_method_type = "";
- receive_result = "";
-
+ OcPlatform.OnResourceFoundListener, OnGetListener, OnDeleteListener,
+ OnObserveListener, OnPutListener {
+ private final String TAG = "NMConsumer : "
+ + this.getClass()
+ .getSimpleName();
+
+ public static final int OC_STACK_OK = 0;
+ public static final String OBSERVE = "Observe";
+ public static final String GET = "Get";
+ public static final String PUT = "Put";
+ public static final String DELETE = "Delete";
+ public static final String POST = "Post";
+ public static final String MESSAGE = "message";
+ public static String outputString = "";
+
+ private Button btn_observe;
+ private Button btn_get;
+ private Button btn_put;
+ private Button btn_post;
+ private Button btn_delete;
+ private Button btn_clean;
+
+ public TextView tv_found_uri;
+ public TextView tv_select_method_type;
+ public TextView tv_receive_result;
+ public TextView tv_current_log_result;
+
+ public String current_log_result = "";
+ public String found_uri = "";
+ public String select_method_type = "";
+ public String receive_result = "";
+
+ public static OcResource curResource;
+ public OcPlatform.OnResourceFoundListener OnResourceFoundListener;
+
+ public static int oc = 0;
+
+ /*
+ * To initialize UI Function Setting To execute initOICStack for running
+ * find resource
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.sampleconsumer_layout);
+
+ btn_observe = (Button) findViewById(R.id.btn_observe);
+ btn_get = (Button) findViewById(R.id.btn_get);
+ btn_put = (Button) findViewById(R.id.btn_put);
+ btn_post = (Button) findViewById(R.id.btn_post);
+ btn_delete = (Button) findViewById(R.id.btn_delete);
+ btn_clean = (Button) findViewById(R.id.btn_clean);
+ tv_found_uri = (TextView) findViewById(R.id.tv_found_resource_result);
+ tv_select_method_type = (TextView) findViewById(R.id.tv_selected_method_type);
+ tv_receive_result = (TextView) findViewById(R.id.tv_receive_result);
+ tv_current_log_result = (TextView) findViewById(R.id.tv_current_log_result);
+ btn_observe.setOnClickListener(this);
+ btn_get.setOnClickListener(this);
+ btn_put.setOnClickListener(this);
+ btn_post.setOnClickListener(this);
+ btn_delete.setOnClickListener(this);
+ btn_clean.setOnClickListener(this);
+
+ initOICStack();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ onStop();
+ }
+
+ /*
+ * To reset text String is null for cleaning log
+ */
+ @Override
+ protected void onStop() {
+ super.onStop();
+
+ tv_found_uri = null;
+ tv_select_method_type = null;
+ tv_receive_result = null;
+ tv_current_log_result = null;
+
+ current_log_result = "";
+ found_uri = "";
+ select_method_type = "";
+ receive_result = "";
+ btn_observe.setClickable(true);
+ btn_get.setClickable(true);
+ btn_put.setClickable(true);
+ btn_delete.setClickable(true);
+ }
+
+ public void cleanLogString() {
+ current_log_result = "";
+ found_uri = "";
+ select_method_type = "";
+ receive_result = "";
+
+ tv_current_log_result.setText(current_log_result);
+ tv_found_uri.setText(found_uri);
+ tv_select_method_type.setText(select_method_type);
+ tv_receive_result.setText(receive_result);
+ }
+
+ public void initOICStack() {
+ PlatformConfig cfg = new PlatformConfig(this, ServiceType.IN_PROC,
+ ModeType.CLIENT, "0.0.0.0", 0, QualityOfService.LOW);
+ OcPlatform.Configure(cfg);
+ current_log_result += "Created Platform...\n";
+ tv_current_log_result.setText(current_log_result);
+ Log.i(TAG, current_log_result);
+ findResourceCandidate();
+ PRINT();
+ }
+
+ public void findResourceCandidate() {
+ nmfindResource("", "/oic/res?rt=Resource.Hosting");
+ current_log_result += "Finding Resource... \n";
+ tv_current_log_result.setText(current_log_result);
+ Log.i(TAG, current_log_result);
+ }
+
+ public void nmfindResource(String host, String resourceName) {
+ try {
+ EnumSet<OcConnectivityType> propertySet = EnumSet
+ .of(OcConnectivityType.CT_DEFAULT);
+ OcPlatform.findResource(host, resourceName, propertySet, this);
+
+ } catch (OcException e) {
+ e.printStackTrace();
+ current_log_result += e.getMessage() + "\n";
tv_current_log_result.setText(current_log_result);
- tv_found_uri.setText(found_uri);
- tv_select_method_type.setText(select_method_type);
- tv_receive_result.setText(receive_result);
+ Log.i(TAG, current_log_result);
}
+ }
- public void initOICStack()
- {
- PlatformConfig cfg = new PlatformConfig(this,ServiceType.IN_PROC,
- ModeType.CLIENT, "0.0.0.0", 0, QualityOfService.LOW);
- OcPlatform.Configure(cfg);
- current_log_result += "Created Platform...\n";
+ /*
+ * No Use until Yet
+ */
+ public void getRepresentation(OcResource resource) {
+ if (resource != null) {
+ current_log_result += "Getting Light Representation...\n";
tv_current_log_result.setText(current_log_result);
Log.i(TAG, current_log_result);
- findResourceCandidate();
- PRINT();
}
+ }
- public void findResourceCandidate()
- {
- nmfindResource("", "/oc/core?rt=Resource.Hosting");
- current_log_result += "Finding Resource... \n";
+ /*
+ * No Use until Yet
+ */
+ public void getLightRepresentation(OcResource resource) {
+ if (resource != null) {
+ current_log_result += "Getting Light Representation...\n";
tv_current_log_result.setText(current_log_result);
Log.i(TAG, current_log_result);
- }
-
- public void nmfindResource(String host, String resourceName)
- {
- try
- {
- OcPlatform.findResource(host, resourceName, OcConnectivityType.ALL,this);
- }
- catch (OcException e)
- {
+ try {
+ Map<String, String> queryParamsMap = new HashMap<String, String>();
+ resource.get(queryParamsMap, this);
+ } catch (OcException e) {
e.printStackTrace();
current_log_result += e.getMessage() + "\n";
tv_current_log_result.setText(current_log_result);
Log.i(TAG, current_log_result);
}
}
+ }
+
+ public void PRINT() {
+ current_log_result += "********************************************\n";
+ current_log_result += "* method Type : 1 - Observe *\n";
+ current_log_result += "* method Type : 2 - Get *\n";
+ current_log_result += "* method Type : 3 - Put *\n";
+ current_log_result += "* method Type : 4 - Delete *\n";
+ current_log_result += "********************************************\n";
+ }
+
+ public void startObserve(OcResource resource) {
+ if (resource != null) {
+ Map<String, String> queryParamsMap = new HashMap<String, String>();
+ current_log_result += "startObserve\n";
+ tv_current_log_result.setText(current_log_result);
+ Log.i(TAG, current_log_result);
- /*
- * No Use until Yet
- */
- public void getRepresentation(OcResource resource)
- {
- if (resource != null)
- {
- current_log_result += "Getting Light Representation...\n";
- tv_current_log_result.setText(current_log_result);
- Log.i(TAG, current_log_result);
- }
- }
-
- /*
- * No Use until Yet
- */
- public void getLightRepresentation(OcResource resource)
- {
- if (resource != null)
- {
- current_log_result += "Getting Light Representation...\n";
+ try {
+ resource.observe(ObserveType.OBSERVE, queryParamsMap, this);
+ } catch (OcException e) {
+ e.printStackTrace();
+ current_log_result += e.getMessage() + "\n";
tv_current_log_result.setText(current_log_result);
Log.i(TAG, current_log_result);
-
- try
- {
- Map<String, String> queryParamsMap = new HashMap<String, String>();
- resource.get(queryParamsMap, this);
- }
- catch (OcException e)
- {
- e.printStackTrace();
- current_log_result += e.getMessage() + "\n";
- tv_current_log_result.setText(current_log_result);
- Log.i(TAG, current_log_result);
- }
}
}
+ }
- public void PRINT()
- {
- current_log_result += "********************************************\n";
- current_log_result += "* method Type : 1 - Observe *\n";
- current_log_result += "* method Type : 2 - Get *\n";
- current_log_result += "* method Type : 3 - Put *\n";
- current_log_result += "* method Type : 4 - Delete *\n";
- current_log_result += "********************************************\n";
- }
+ public void startGet(OcResource resource) {
+ if (resource != null) {
+ Map<String, String> queryParamsMap = new HashMap<String, String>();
+ current_log_result += "startGet\n";
+ tv_current_log_result.setText(current_log_result);
+ Log.i(TAG, current_log_result);
- public void startObserve(OcResource resource)
- {
- if (resource != null)
- {
- Map<String, String> queryParamsMap = new HashMap<String, String>();
- current_log_result += "startObserve\n";
+ try {
+ resource.get(queryParamsMap, this);
+ } catch (OcException e) {
+ e.printStackTrace();
+ current_log_result += e.getMessage() + "\n";
tv_current_log_result.setText(current_log_result);
Log.i(TAG, current_log_result);
-
- try
- {
- resource.observe(ObserveType.OBSERVE, queryParamsMap, this);
- }
- catch (OcException e)
- {
- e.printStackTrace();
- current_log_result += e.getMessage() + "\n";
- tv_current_log_result.setText(current_log_result);
- Log.i(TAG, current_log_result);
- }
}
}
+ }
- public void startGet(OcResource resource)
- {
- if (resource != null)
- {
- Map<String, String> queryParamsMap = new HashMap<String, String>();
- current_log_result += "startGet\n";
- tv_current_log_result.setText(current_log_result);
- Log.i(TAG, current_log_result);
-
- try
- {
- resource.get(queryParamsMap, this);
- }
- catch (OcException e)
- {
- e.printStackTrace();
- current_log_result += e.getMessage() + "\n";
- tv_current_log_result.setText(current_log_result);
- Log.i(TAG, current_log_result);
- }
- }
- }
+ public void startPut(OcResource resource) {
+ if (resource != null) {
+ curResource = resource;
+ OcRepresentation rep = new OcRepresentation();
+ rep.setValueInt("temperature", 25);
+ rep.setValueInt("humidity", 10);
+ Map<String, String> queryParamsMap = new HashMap<String, String>();
+ current_log_result += "startPut\n";
+ tv_current_log_result.setText(current_log_result);
+ Log.i(TAG, current_log_result);
- public void startPut(OcResource resource)
- {
- if (resource != null)
- {
- curResource = resource;
- OcRepresentation rep = new OcRepresentation();
- rep.setValueInt("temperature", 25);
- rep.setValueInt("humidity", 10);
- Map<String, String> queryParamsMap = new HashMap<String, String>();
- current_log_result += "startPut\n";
+ try {
+ resource.put(rep, queryParamsMap, this);
+ } catch (OcException e) {
+ e.printStackTrace();
+ current_log_result += e.getMessage() + "\n";
tv_current_log_result.setText(current_log_result);
Log.i(TAG, current_log_result);
-
- try
- {
- resource.put(rep, queryParamsMap, this);
- }
- catch (OcException e)
- {
- e.printStackTrace();
- current_log_result += e.getMessage() + "\n";
- tv_current_log_result.setText(current_log_result);
- Log.i(TAG, current_log_result);
- }
}
}
-
- public void startDelete(OcResource resource) throws OcException
- {
- curResource = resource;
- if (resource != null)
- {
- resource.deleteResource(this);
- }
- }
-
- @Override
- public void onClick(View v)
- {
- switch (v.getId())
- {
- case R.id.btn_observe:
- tv_select_method_type.setText(OBSERVE);
- Log.i(TAG, "Method: " + OBSERVE);
- startObserve(curResource);
- btn_observe.setClickable(false);
- break;
- case R.id.btn_get:
- tv_select_method_type.setText(GET);
- Log.i(TAG, "Method: " + GET);
- startGet(curResource);
- btn_get.setClickable(false);
- break;
- case R.id.btn_put:
- tv_select_method_type.setText(PUT);
- Log.i(TAG, "Method: " + PUT);
- startPut(curResource);
- btn_put.setClickable(false);
- break;
- case R.id.btn_post:
- tv_select_method_type.setText(POST);
- Toast.makeText(this, "Not Supported Yet", Toast.LENGTH_SHORT)
- .show();
- Log.i(TAG, "Method: " + POST);
- break;
- case R.id.btn_delete:
- tv_select_method_type.setText(DELETE);
- Log.i(TAG, "Method: " + DELETE);
+ }
+
+ public void startDelete(OcResource resource) throws OcException {
+ curResource = resource;
+ if (resource != null) {
+ resource.deleteResource(this);
+ }
+ }
+
+ @Override
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.btn_observe:
+ tv_select_method_type.setText(OBSERVE);
+ Log.i(TAG, "Method: " + OBSERVE);
+ startObserve(curResource);
+ btn_observe.setClickable(false);
+ break;
+ case R.id.btn_get:
+ tv_select_method_type.setText(GET);
+ Log.i(TAG, "Method: " + GET);
+ startGet(curResource);
+ btn_get.setClickable(false);
+ break;
+ case R.id.btn_put:
+ tv_select_method_type.setText(PUT);
+ Log.i(TAG, "Method: " + PUT);
+ startPut(curResource);
+ btn_put.setClickable(false);
+ break;
+ case R.id.btn_post:
+ tv_select_method_type.setText(POST);
+ Toast.makeText(this, "Not Supported Yet", Toast.LENGTH_SHORT)
+ .show();
+ Log.i(TAG, "Method: " + POST);
+ break;
+ case R.id.btn_delete:
+ tv_select_method_type.setText(DELETE);
+ Log.i(TAG, "Method: " + DELETE);
try {
startDelete(curResource);
} catch (OcException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- btn_delete.setClickable(false);
- break;
- case R.id.btn_clean:
- cleanLogString();
- Log.i(TAG, "Log textbox is cleared");
- break;
-
- default:
- break;
- }
+ btn_delete.setClickable(false);
+ break;
+ case R.id.btn_clean:
+ cleanLogString();
+ Log.i(TAG, "Log textbox is cleared");
+ break;
+ default:
+ break;
}
- protected static int observe_count()
- {
- return ++oc;
- }
+ }
- public void viewText()
- {
- SampleConsumer.this.runOnUiThread(new Runnable()
- {
- public void run()
- {
- if (receive_result != null)
- {
- tv_receive_result.setText(receive_result);
- Log.i(TAG, "Received: " + receive_result);
- }
- if (found_uri != null)
- {
- tv_found_uri.setText(found_uri);
- Log.i(TAG, "URI: " + found_uri);
- }
- if (current_log_result != null)
- {
- tv_current_log_result.setText(current_log_result);
- Log.i(TAG, current_log_result);
- }
+ protected static int observe_count() {
+ return ++oc;
+ }
+ public void viewText() {
+ SampleConsumer.this.runOnUiThread(new Runnable() {
+ public void run() {
+ if (receive_result != null) {
+ tv_receive_result.setText(receive_result);
+ Log.i(TAG, "Received: " + receive_result);
}
- });
- }
-
- @Override
- public synchronized void onResourceFound(OcResource resource)
- {
- // synchronized (this) {
- receive_result = "FoundResource";
- String resourceURI;
- String hostAddress;
- if (SampleConsumer.curResource != null)
- {
- current_log_result += "Found another resource, ignoring\n";
- }
- if (resource != null)
- {
- if (resource.getUri().equals("/a/TempHumSensor"))
- {
- current_log_result += "==============================\n";
- current_log_result += "DISCOVERED Resource(Consumer):\n";
- resourceURI = resource.getUri();
- hostAddress = resource.getHost();
- current_log_result += "URI of the resource: " + resourceURI
- + "\n";
- current_log_result += "Host address of the resource: "
- + hostAddress + "\n";
- SampleConsumer.curResource = resource;
+ if (found_uri != null) {
+ tv_found_uri.setText(found_uri);
+ Log.i(TAG, "URI: " + found_uri);
}
- else
- {
- current_log_result += "Uri is not correct.";
+ if (current_log_result != null) {
+ tv_current_log_result.setText(current_log_result);
+ Log.i(TAG, current_log_result);
}
+
}
- else
- {
- current_log_result += "Resource is invalid\n";
+ });
+ }
+
+ @Override
+ public synchronized void onResourceFound(OcResource resource) {
+ // synchronized (this) {
+ receive_result = "FoundResource";
+ String resourceURI;
+ String hostAddress;
+ if (SampleConsumer.curResource != null) {
+ current_log_result += "Found another resource, ignoring\n";
+ }
+ if (resource != null) {
+ if (resource.getUri().equals("/a/TempHumSensor")) {
+ current_log_result += "==============================\n";
+ current_log_result += "DISCOVERED Resource(Consumer):\n";
+ resourceURI = resource.getUri();
+ hostAddress = resource.getHost();
+ current_log_result += "URI of the resource: " + resourceURI
+ + "\n";
+ current_log_result += "Host address of the resource: "
+ + hostAddress + "\n";
+ SampleConsumer.curResource = resource;
+ } else {
+ current_log_result += "Uri is not correct.";
}
-
- viewText();
+ } else {
+ current_log_result += "Resource is invalid\n";
}
- public String getCurrent_log_result()
- {
- return current_log_result;
- }
+ viewText();
+ }
- public void setCurrent_log_result(String current_log_result)
- {
- this.current_log_result = current_log_result;
- }
+ public String getCurrent_log_result() {
+ return current_log_result;
+ }
- public String getFound_uri()
- {
- return found_uri;
- }
+ public void setCurrent_log_result(String current_log_result) {
+ this.current_log_result = current_log_result;
+ }
- public void setFound_uri(String found_uri)
- {
- this.found_uri = found_uri;
- }
+ public String getFound_uri() {
+ return found_uri;
+ }
- public String getSelect_method_type()
- {
- return select_method_type;
- }
+ public void setFound_uri(String found_uri) {
+ this.found_uri = found_uri;
+ }
- public void setSelect_method_type(String select_method_type)
- {
- this.select_method_type = select_method_type;
- }
+ public String getSelect_method_type() {
+ return select_method_type;
+ }
- public String getReceive_result()
- {
- return receive_result;
- }
+ public void setSelect_method_type(String select_method_type) {
+ this.select_method_type = select_method_type;
+ }
- public void setReceive_result(String recieve_result)
- {
- this.receive_result = recieve_result;
- }
- public class MessageReceiver extends BroadcastReceiver
- {
- @Override
- public void onReceive(Context context, Intent intent)
- {
- final String message = intent
- .getStringExtra(MESSAGE);
- tv_current_log_result.setText(message);
- Log.i(TAG, message);
- viewText();
- }
- }
+ public String getReceive_result() {
+ return receive_result;
+ }
- @Override
- public void onGetCompleted(List<OcHeaderOption> options,
- OcRepresentation rep)
- {
- setReceive_result("onGet");
- setCurrent_log_result(getCurrent_log_result()
- + "GET request was successful\n"
- + "GET request was successful\n"
- + "URI: " + rep.getUri() + "\n"
- + "Temperature: " + rep.getValueInt("temperature") + "\n"
- + "Humidity: " + rep.getValueInt("humidity") + "\n");
- viewText();
- btn_get.setClickable(true);
- }
+ public void setReceive_result(String recieve_result) {
+ this.receive_result = recieve_result;
+ }
+ public class MessageReceiver extends BroadcastReceiver {
@Override
- public void onPutCompleted(List<OcHeaderOption> options,
- OcRepresentation rep)
- {
- setReceive_result("onPut");
- current_log_result += "PUT request was successful\n";
-
- int humidity;
- int temperature;
- humidity = rep.getValueInt("humidity");
- temperature = rep.getValueInt("temperature");
-
- setCurrent_log_result(getCurrent_log_result() + "temperature: "
- + temperature + "\n");
- setCurrent_log_result(getCurrent_log_result() + "humidity: " + humidity
- + "\n");
+ public void onReceive(Context context, Intent intent) {
+ final String message = intent.getStringExtra(MESSAGE);
+ tv_current_log_result.setText(message);
+ Log.i(TAG, message);
viewText();
- btn_put.setClickable(true);
}
-
- @Override
- public void onObserveCompleted(List<OcHeaderOption> options,
- OcRepresentation rep, int seqNum)
- {
- setReceive_result("onObserve");
- setCurrent_log_result(getCurrent_log_result() + "SequenceNumber : "
- + seqNum + "\n");
- setCurrent_log_result("========================================================\n"
- + "Receive OBSERVE RESULT:\n"
- + "URI: "
- + rep.getUri()
- + "\n"
- + "SequenceNumber: "
- + seqNum
- + "\n"
- + "Temperature: "
- + rep.getValueInt("temperature")
- + "\n"
- + "Humidity: "
- + rep.getValueInt("humidity") + "\n");
- if (SampleConsumer.observe_count() > 30)
- {
+ }
+
+ @Override
+ public void onGetCompleted(List<OcHeaderOption> options,
+ OcRepresentation rep) {
+ setReceive_result("onGet");
+ setCurrent_log_result(getCurrent_log_result()
+ + "GET request was successful\n"
+ + "GET request was successful\n" + "URI: " + rep.getUri()
+ + "\n" + "Temperature: " + rep.getValueInt("temperature")
+ + "\n" + "Humidity: " + rep.getValueInt("humidity") + "\n");
+ viewText();
+ btn_get.setClickable(true);
+ }
+
+ @Override
+ public void onPutCompleted(List<OcHeaderOption> options,
+ OcRepresentation rep) {
+ setReceive_result("onPut");
+ current_log_result += "PUT request was successful\n";
+
+ int humidity;
+ int temperature;
+ humidity = rep.getValueInt("humidity");
+ temperature = rep.getValueInt("temperature");
+
+ setCurrent_log_result(getCurrent_log_result() + "temperature: "
+ + temperature + "\n");
+ setCurrent_log_result(getCurrent_log_result() + "humidity: " + humidity
+ + "\n");
+ viewText();
+ btn_put.setClickable(true);
+ }
+
+ @Override
+ public void onObserveCompleted(List<OcHeaderOption> options,
+ OcRepresentation rep, int seqNum) {
+ setReceive_result("onObserve");
+ setCurrent_log_result(getCurrent_log_result() + "SequenceNumber : "
+ + seqNum + "\n");
+ setCurrent_log_result("========================================================\n"
+ + "Receive OBSERVE RESULT:\n"
+ + "URI: "
+ + rep.getUri()
+ + "\n"
+ + "SequenceNumber: "
+ + seqNum
+ + "\n"
+ + "Temperature: "
+ + rep.getValueInt("temperature")
+ + "\n"
+ + "Humidity: "
+ + rep.getValueInt("humidity") + "\n");
+ if (SampleConsumer.observe_count() > 30) {
+ setCurrent_log_result(getCurrent_log_result()
+ + "Cancelling Observe...\n");
+ try {
+ SampleConsumer.curResource.cancelObserve();
+ } catch (OcException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
setCurrent_log_result(getCurrent_log_result()
- + "Cancelling Observe...\n");
- try
- {
- SampleConsumer.curResource.cancelObserve();
- }
- catch (OcException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- setCurrent_log_result(getCurrent_log_result()
- + "Cancel result :" + e.getMessage() + "\n");
- }
+ + "Cancel result :" + e.getMessage() + "\n");
}
- viewText();
}
+ viewText();
+ }
- @Override
- public void onDeleteCompleted(List<OcHeaderOption> options)
- {
- setReceive_result("onDelete");
- viewText();
- btn_delete.setClickable(true);
- }
+ @Override
+ public void onDeleteCompleted(List<OcHeaderOption> options) {
+ setReceive_result("onDelete");
+ viewText();
+ btn_delete.setClickable(true);
+ }
- @Override
- public void onPutFailed(Throwable arg0) {
- // TODO Auto-generated method stub
+ @Override
+ public void onPutFailed(Throwable arg0) {
+ // TODO Auto-generated method stub
- }
+ }
- @Override
- public void onObserveFailed(Throwable arg0) {
- // TODO Auto-generated method stub
+ @Override
+ public void onObserveFailed(Throwable arg0) {
+ // TODO Auto-generated method stub
- }
+ }
- @Override
- public void onDeleteFailed(Throwable arg0) {
- // TODO Auto-generated method stub
+ @Override
+ public void onDeleteFailed(Throwable arg0) {
+ // TODO Auto-generated method stub
- }
+ }
- @Override
- public void onGetFailed(Throwable arg0) {
- // TODO Auto-generated method stub
+ @Override
+ public void onGetFailed(Throwable arg0) {
+ // TODO Auto-generated method stub
- }
+ }
}
+++ /dev/null
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-OIC_LIB_PATH := ../../../../out/android/$(TARGET_ARCH_ABI)/release
-LOCAL_MODULE := libandroid-oc_logger
-LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboc_logger.so
-include $(PREBUILT_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-OIC_LIB_PATH := ../../../../out/android/$(TARGET_ARCH_ABI)/release
-LOCAL_MODULE := libandroid-octbstack
-LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboctbstack.so
-include $(PREBUILT_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-OIC_LIB_PATH := ../../../../out/android/$(TARGET_ARCH_ABI)/release
-LOCAL_MODULE := libandroid-oc
-LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboc.so
-include $(PREBUILT_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-OIC_LIB_PATH := ../../../../out/android/$(TARGET_ARCH_ABI)/release
-LOCAL_MODULE := libandroid-ca
-LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libconnectivity_abstraction.so
-include $(PREBUILT_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-OIC_SRC_PATH := ../../../resource
-OIC_OUT_PATH := ../../../out
-LOCAL_MODULE := ocstack-jni
-LOCAL_SRC_FILES := JniOcStack.cpp \
- JniUtils.cpp \
- JniEntityHandler.cpp \
- JniOnResourceFoundListener.cpp \
- JniOnDeviceInfoListener.cpp \
- JniOnPresenceListener.cpp \
- JniOnGetListener.cpp \
- JniOnPutListener.cpp \
- JniOnPostListener.cpp \
- JniOnDeleteListener.cpp \
- JniOnObserveListener.cpp \
- JniOcRepresentation.cpp \
- JniOcResourceHandle.cpp \
- JniOcPresenceHandle.cpp \
- JniOcRequestHandle.cpp \
- JniOcResourceRequest.cpp \
- JniOcResourceResponse.cpp \
- JniOcPlatform.cpp \
- JniOcResource.cpp
-
-LOCAL_LDLIBS := -llog
-LOCAL_STATIC_LIBRARIES := android-oc
-LOCAL_STATIC_LIBRARIES += android-octbstack
-LOCAL_STATIC_LIBRARIES += android-ca
-LOCAL_STATIC_LIBRARIES += android-oc_logger
-LOCAL_CPPFLAGS += -std=c++0x
-LOCAL_CPP_FEATURES := rtti exceptions
-LOCAL_C_INCLUDES := $(OIC_SRC_PATH)/include
-LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/stack/include
-LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/ocsocket/include
-LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/oc_logger/include
-LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/boost/boost_1_58_0
-
-include $(BUILD_SHARED_LIBRARY)
-
-
+++ /dev/null
-NDK_TOOLCHAIN_VERSION := 4.9
-APP_STL := gnustl_shared
\ No newline at end of file
package com.example.sample.provider;
-public interface IMessageLogger
-{
+public interface IMessageLogger {
public void logMessage(String msg);
}
import android.widget.ScrollView;
import android.widget.TextView;
-
-
public class SampleProvider extends Activity implements OnClickListener,
- IMessageLogger
-{
- private final static String TAG = "NMProvider : SampleProvider";
- private TextView mLogTextView;
- private TextView mTempValue;
- private TextView mHumValue;
- private TemperatureResource mySensor;
- private boolean isExecutePresence;
- private ScrollView sv_sclLog;
- private MessageReceiver mMessageReceiver = new MessageReceiver();
- private Handler mHandler;
- private static String message;
- private static SampleProvider sampleProviderObj;
- private String temp;
- private String hum;
-
- /*
- * To initialize UI Function Setting
- * To execute initOICStack for running find resource
- */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
-
- sampleProviderObj = this;
- super.onCreate(savedInstanceState);
- setContentView(R.layout.sampleprovider_layout);
- registerReceiver(mMessageReceiver, new IntentFilter(
- "com.example.sample.provider.SampleProvider"));
-
- mLogTextView = (TextView) findViewById(R.id.txtLog);
- mTempValue = (TextView) findViewById(R.id.temperatureValue);
- mHumValue = (TextView) findViewById(R.id.humidityValue);
-
- sv_sclLog = (ScrollView)findViewById(R.id.sclLog);
- sv_sclLog.fullScroll(View.FOCUS_DOWN);
- findViewById(R.id.btnTemperatureUP).setOnClickListener(this);
- findViewById(R.id.btnTemperatureDown).setOnClickListener(this);
- findViewById(R.id.btnHumidityUP).setOnClickListener(this);
- findViewById(R.id.btnHumidityDown).setOnClickListener(this);
- findViewById(R.id.btnLogClear).setOnClickListener(this);
-
- isExecutePresence = false;
- mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 0:
- String[] tempHum = message.split(":");
- mTempValue.setText(tempHum[0]);
- mHumValue.setText(tempHum[1]);
- }
+ IMessageLogger {
+ private final static String TAG = "NMProvider : SampleProvider";
+ private TextView mLogTextView;
+ private TextView mTempValue;
+ private TextView mHumValue;
+ private TemperatureResource mySensor;
+ private boolean isExecutePresence;
+ private ScrollView sv_sclLog;
+ private MessageReceiver mMessageReceiver = new MessageReceiver();
+ private Handler mHandler;
+ private static String message;
+ private static SampleProvider sampleProviderObj;
+ private String temp;
+ private String hum;
+
+ /*
+ * To initialize UI Function Setting To execute initOICStack for running
+ * find resource
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+
+ sampleProviderObj = this;
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.sampleprovider_layout);
+ registerReceiver(mMessageReceiver, new IntentFilter(
+ "com.example.sample.provider.SampleProvider"));
+
+ mLogTextView = (TextView) findViewById(R.id.txtLog);
+ mTempValue = (TextView) findViewById(R.id.temperatureValue);
+ mHumValue = (TextView) findViewById(R.id.humidityValue);
+
+ sv_sclLog = (ScrollView) findViewById(R.id.sclLog);
+ sv_sclLog.fullScroll(View.FOCUS_DOWN);
+ findViewById(R.id.btnTemperatureUP).setOnClickListener(this);
+ findViewById(R.id.btnTemperatureDown).setOnClickListener(this);
+ findViewById(R.id.btnHumidityUP).setOnClickListener(this);
+ findViewById(R.id.btnHumidityDown).setOnClickListener(this);
+ findViewById(R.id.btnLogClear).setOnClickListener(this);
+
+ isExecutePresence = false;
+ mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case 0:
+ String[] tempHum = message.split(":");
+ mTempValue.setText(tempHum[0]);
+ mHumValue.setText(tempHum[1]);
}
- };
- setmHandler(mHandler);
+ }
+ };
+ setmHandler(mHandler);
+ }
+
+ private void initOICStack() {
+ // create platform config
+ PlatformConfig cfg = new PlatformConfig(this, ServiceType.IN_PROC,
+ ModeType.SERVER, "0.0.0.0", // bind to all available interfaces
+ 0, QualityOfService.LOW);
+
+ OcPlatform.Configure(cfg);
+
+ try {
+ OcPlatform.startPresence(30);
+ isExecutePresence = true;
+ } catch (OcException e) {
+ e.printStackTrace();
}
- private void initOICStack()
- {
- // create platform config
- PlatformConfig cfg = new PlatformConfig(this,ServiceType.IN_PROC,
- ModeType.SERVER, "0.0.0.0", // bind to all available interfaces
- 0, QualityOfService.LOW);
-
- OcPlatform.Configure(cfg);
-
- try
- {
- OcPlatform.startPresence(30);
- isExecutePresence = true;
+ mySensor = new TemperatureResource(this);
+ // create and register a resource
+ mySensor.createResource();
+ }
+
+ /*
+ * To execute initOICStack for running find resource
+ */
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initOICStack();
+
+ }
+
+ /*
+ * To execute initOICStack for running find resource
+ */
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ initOICStack();
+
+ }
+
+ /*
+ * To terminate presence process and unregister messageHandler(to get
+ * message from JNI Function)
+ */
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ try {
+ mySensor.destroyResource();
+
+ if (isExecutePresence == true) {
+ OcPlatform.stopPresence();
+ isExecutePresence = false;
}
- catch (OcException e)
- {
- e.printStackTrace();
- }
-
- mySensor = new TemperatureResource(this);
- // create and register a resource
- mySensor.createResource();
+ } catch (OcException e) {
+ e.printStackTrace();
}
- /*
- * To execute initOICStack for running find resource
- */
- @Override
- protected void onStart()
- {
- super.onStart();
- initOICStack();
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(
+ mMessageReceiver);
+ }
- }
- /*
- * To execute initOICStack for running find resource
- */
+ public class MessageReceiver extends BroadcastReceiver {
@Override
- protected void onRestart()
- {
- super.onRestart();
- initOICStack();
+ public void onReceive(Context context, Intent intent) {
+ final String message = intent
+ .getStringExtra(StringConstants.MESSAGE);
+ logMessage(message);
}
- /*
- * To terminate presence process and unregister messageHandler(to get message from JNI Function)
- */
- @Override
- protected void onDestroy()
- {
- super.onDestroy();
-
- try
- {
- mySensor.destroyResource();
-
- if (isExecutePresence == true)
- {
- OcPlatform.stopPresence();
- isExecutePresence = false;
- }
+ }
+
+ public void logMessage(final String text) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ final Message msg = new Message();
+ msg.obj = text;
+ mLogTextView.append("\n");
+ mLogTextView.append(text);
}
- catch (OcException e)
- {
- e.printStackTrace();
+ });
+ Log.i(TAG, text);
+ }
+
+ /*
+ * To terminate presence process and unregister messagehandler(to get
+ * message from JNI Function)
+ */
+ @Override
+ protected void onStop() {
+ super.onStop();
+ try {
+ mySensor.destroyResource();
+
+ if (isExecutePresence == true) {
+ OcPlatform.stopPresence();
+ isExecutePresence = false;
}
- LocalBroadcastManager.getInstance(this).unregisterReceiver(
+
+ } catch (OcException e) {
+
+ e.printStackTrace();
+ }
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(
mMessageReceiver);
+ }
+
+ @Override
+ public void onClick(View v) {
+ int getId = v.getId();
+
+ switch (getId) {
+ case R.id.btnTemperatureUP:
+ logMessage(TAG + "Click temerature up btn");
+ mySensor.mtemp++;
+ mySensor.notifyObserver();
+ break;
+ case R.id.btnTemperatureDown:
+ logMessage(TAG + "Click temerature down btn");
+ mySensor.mtemp--;
+ mySensor.notifyObserver();
+ break;
+ case R.id.btnHumidityUP:
+ logMessage(TAG + "Click Humidity up btn");
+ mySensor.mhumidity++;
+ mySensor.notifyObserver();
+ break;
+ case R.id.btnHumidityDown:
+ logMessage(TAG + "Click Humidity down btn");
+ mySensor.mhumidity--;
+ mySensor.notifyObserver();
+ break;
+ case R.id.btnLogClear:
+ mLogTextView.setText("");
+ Log.i(TAG, "Log message cleared");
+ break;
}
- public class MessageReceiver extends BroadcastReceiver
- {
- @Override
- public void onReceive(Context context, Intent intent)
- {
- final String message = intent
- .getStringExtra(StringConstants.MESSAGE);
- logMessage(message);
+ mTempValue.setText(String.valueOf(mySensor.getTemp()));
+ mHumValue.setText(String.valueOf(mySensor.getHumidity()));
- }
- }
+ }
- public void logMessage(final String text)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
- final Message msg = new Message();
- msg.obj = text;
- mLogTextView.append("\n");
- mLogTextView.append(text);
- }
- });
- Log.i(TAG, text);
- }
- /*
- * To terminate presence process and unregister messagehandler(to get message from JNI Function)
- */
- @Override
- protected void onStop()
- {
- super.onStop();
- try
- {
+ /*
+ * To handle event about back button
+ */
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ try {
mySensor.destroyResource();
- if (isExecutePresence == true)
- {
+ if (isExecutePresence == true) {
OcPlatform.stopPresence();
isExecutePresence = false;
}
-
- }
- catch (OcException e)
- {
+ } catch (OcException e) {
e.printStackTrace();
}
LocalBroadcastManager.getInstance(this).unregisterReceiver(
- mMessageReceiver);
- }
-
- @Override
- public void onClick(View v)
- {
- int getId = v.getId();
-
- switch (getId)
- {
- case R.id.btnTemperatureUP:
- logMessage(TAG + "Click temerature up btn");
- mySensor.mtemp++;
- mySensor.notifyObserver();
- break;
- case R.id.btnTemperatureDown:
- logMessage(TAG + "Click temerature down btn");
- mySensor.mtemp--;
- mySensor.notifyObserver();
- break;
- case R.id.btnHumidityUP:
- logMessage(TAG + "Click Humidity up btn");
- mySensor.mhumidity++;
- mySensor.notifyObserver();
- break;
- case R.id.btnHumidityDown:
- logMessage(TAG + "Click Humidity down btn");
- mySensor.mhumidity--;
- mySensor.notifyObserver();
- break;
- case R.id.btnLogClear:
- mLogTextView.setText("");
- Log.i(TAG, "Log message cleared");
- break;
- }
-
- mTempValue.setText(String.valueOf(mySensor.getTemp()));
- mHumValue.setText(String.valueOf(mySensor.getHumidity()));
-
- }
- /*
- * To handle event about back button
- */
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK )
- {
- try
- {
- mySensor.destroyResource();
-
- if (isExecutePresence == true)
- {
- OcPlatform.stopPresence();
- isExecutePresence = false;
- }
- }
- catch (OcException e)
- {
-
- e.printStackTrace();
- }
- LocalBroadcastManager.getInstance(this).unregisterReceiver(
mMessageReceiver);
- }
- return super.onKeyDown(keyCode, event);
}
+ return super.onKeyDown(keyCode, event);
+ }
- public Handler getmHandler() {
- return mHandler;
- }
+ public Handler getmHandler() {
+ return mHandler;
+ }
- public void setmHandler(Handler mHandler) {
- this.mHandler = mHandler;
- }
+ public void setmHandler(Handler mHandler) {
+ this.mHandler = mHandler;
+ }
- public static SampleProvider getSampleProviderObject() {
- return sampleProviderObj;
- }
+ public static SampleProvider getSampleProviderObject() {
+ return sampleProviderObj;
+ }
- public static void setmessage(String msg) {
- message = msg;
- }
+ public static void setmessage(String msg) {
+ message = msg;
+ }
}
\ No newline at end of file
import org.iotivity.base.OcPlatform;
-public class StringConstants
-{
- public static final String RESOURCE_URI = "/a/TempHumSensor/hosting";
- public static final String RESOURCE_TYPENAME = "Resource.Hosting";
- public static final String RESOURCE_INTERFACE = OcPlatform.DEFAULT_INTERFACE; //resource interface
- public static final String HUMIDITY = "humidity";
- public static final String TEMPERATURE = "temperature";
- public static final String MESSAGE = "message";
- public static final int ERROR_CODE = 200;
+public class StringConstants {
+ public static final String RESOURCE_URI = "/a/TempHumSensor/hosting";
+ public static final String RESOURCE_TYPENAME = "Resource.Hosting";
+ public static final String RESOURCE_INTERFACE = OcPlatform.DEFAULT_INTERFACE; // resource interface
+ public static final String HUMIDITY = "humidity";
+ public static final String TEMPERATURE = "temperature";
+ public static final String MESSAGE = "message";
+ public static final int ERROR_CODE = 200;
}
\ No newline at end of file
import android.os.Message;
import android.util.Log;
-public class TemperatureResource implements IMessageLogger
-{
- private Context mContext;
- public int mtemp;
- public int mhumidity;
- private OcRepresentation mTempRep;
- private OcResourceHandle mResourceHandle;
- private List<Byte> mObservationIds;
-
- private static String TAG = "NMProvider : TemperatureResource";
-
- TemperatureResource(Context context)
- {
- mContext = context;
- mtemp = 0;
- mhumidity = 0;
+public class TemperatureResource implements IMessageLogger {
+ private Context mContext;
+ public int mtemp;
+ public int mhumidity;
+ private OcRepresentation mTempRep;
+ private OcResourceHandle mResourceHandle;
+ private List<Byte> mObservationIds;
+
+ private static String TAG = "NMProvider : TemperatureResource";
+
+ TemperatureResource(Context context) {
+ mContext = context;
+ mtemp = 0;
+ mhumidity = 0;
+ mResourceHandle = null;
+ mObservationIds = new LinkedList<Byte>();
+ mTempRep = new OcRepresentation();
+ mTempRep.setValueInt(StringConstants.TEMPERATURE, mtemp);
+ mTempRep.setValueInt(StringConstants.HUMIDITY, mhumidity);
+ }
+
+ // accessor methods
+ protected int getTemp() {
+ return mtemp;
+ }
+
+ protected void setTemp(int temp) {
+ mtemp = temp;
+ }
+
+ protected int getHumidity() {
+ return mhumidity;
+ }
+
+ protected void setHumidity(int humidity) {
+ mhumidity = humidity;
+ }
+
+ protected OcResourceHandle getHandle() {
+ return mResourceHandle;
+ }
+
+ protected OcResourceHandle destroyResource() {
+ if (mResourceHandle != null) {
+ try {
+ OcPlatform.unregisterResource(mResourceHandle);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
mResourceHandle = null;
- mObservationIds = new LinkedList<Byte>();
- mTempRep = new OcRepresentation();
- mTempRep.setValueInt(StringConstants.TEMPERATURE, mtemp);
- mTempRep.setValueInt(StringConstants.HUMIDITY, mhumidity);
- }
-
- // accessor methods
- protected int getTemp()
- {
- return mtemp;
- }
-
- protected void setTemp(int temp)
- {
- mtemp = temp;
- }
-
- protected int getHumidity()
- {
- return mhumidity;
- }
-
- protected void setHumidity(int humidity)
- {
- mhumidity = humidity;
- }
-
- protected OcResourceHandle getHandle()
- {
- return mResourceHandle;
}
- protected OcResourceHandle destroyResource()
- {
- if (mResourceHandle != null)
- {
- try
- {
- OcPlatform.unregisterResource(mResourceHandle);
- }
- catch (OcException e)
- {
- e.printStackTrace();
- }
- mResourceHandle = null;
+ return null;
+ }
+
+ protected OcResourceHandle createResource() {
+
+ OcPlatform.EntityHandler eh = new OcPlatform.EntityHandler() {
+ @Override
+ public EntityHandlerResult handleEntity(
+ OcResourceRequest ocResourceRequest) {
+ // this is where the main logic of simpleserver is handled as
+ // different requests (GET, PUT, POST, OBSERVE, DELETE) are
+ // handled
+ return entityHandler(ocResourceRequest);
}
- return null;
+ };
+
+ try {
+ Log.e(TAG, "before registerResource!");
+ mResourceHandle = OcPlatform.registerResource(
+ StringConstants.RESOURCE_URI,
+ StringConstants.RESOURCE_TYPENAME,
+ StringConstants.RESOURCE_INTERFACE, eh, EnumSet.of(
+ ResourceProperty.DISCOVERABLE,
+ ResourceProperty.OBSERVABLE));
+ Log.e(TAG, "after regiterResource");
+ } catch (OcException e) {
+ Log.e(TAG, "go exception");
+ logMessage(TAG + "RegisterResource error. " + e.getMessage());
+ Log.e(TAG, "RegisterResource error. " + e.getMessage());
}
- protected OcResourceHandle createResource()
- {
-
- OcPlatform.EntityHandler eh = new OcPlatform.EntityHandler()
- {
- @Override
- public EntityHandlerResult handleEntity(
- OcResourceRequest ocResourceRequest)
- {
- // this is where the main logic of simpleserver is handled as
- // different requests (GET, PUT, POST, OBSERVE, DELETE) are
- // handled
- return entityHandler(ocResourceRequest);
- }
- };
- try
- {
- Log.e(TAG, "before registerResource!");
- mResourceHandle = OcPlatform.registerResource(
- StringConstants.RESOURCE_URI,
- StringConstants.RESOURCE_TYPENAME,
- StringConstants.RESOURCE_INTERFACE, eh, EnumSet.of(
- ResourceProperty.DISCOVERABLE, ResourceProperty.OBSERVABLE));
- Log.e(TAG, "after regiterResource");
+ // logMessage(TAG + "Successfully registered resource");
+ return mResourceHandle;
+ }
+
+ private void put(OcRepresentation rep) {
+ mtemp = rep.getValueInt(StringConstants.TEMPERATURE);
+ mhumidity = rep.getValueInt(StringConstants.HUMIDITY);
+ logMessage(TAG + "PUT Request" + "temperature : " + mtemp
+ + "humidity : " + mhumidity);
+ notifyObserver();
+ // " Power: " + mPower);
+ String message = mtemp + ":" + mhumidity;
+ Message msg = Message.obtain();
+ msg.what = 0;
+ SampleProvider mainActivityObj = SampleProvider
+ .getSampleProviderObject();
+ SampleProvider.setmessage(message);
+ mainActivityObj.getmHandler().sendMessage(msg);
+
+ }
+
+ protected OcRepresentation get() {
+ mTempRep.setValueInt(StringConstants.TEMPERATURE, mtemp);
+ mTempRep.setValueInt(StringConstants.HUMIDITY, mhumidity);
+ return mTempRep;
+ }
+
+ private EntityHandlerResult entityHandler(OcResourceRequest request) {
+ EntityHandlerResult result = EntityHandlerResult.ERROR;
+ if (null != request) {
+ RequestType requestType = request.getRequestType();
+ EnumSet<RequestHandlerFlag> requestFlag = request
+ .getRequestHandlerFlagSet();
+
+ if (requestFlag.contains(RequestHandlerFlag.INIT)) {
+ logMessage(TAG + "Init");
}
- catch (OcException e)
- {
- Log.e(TAG, "go exception");
- logMessage(TAG + "RegisterResource error. " + e.getMessage());
- Log.e(TAG, "RegisterResource error. " + e.getMessage());
- }
-
- // logMessage(TAG + "Successfully registered resource");
- return mResourceHandle;
- }
-
- private void put(OcRepresentation rep)
- {
- mtemp = rep.getValueInt(StringConstants.TEMPERATURE);
- mhumidity = rep.getValueInt(StringConstants.HUMIDITY);
- logMessage(TAG + "PUT Request" +"temperature : " + mtemp + "humidity : " + mhumidity);
- notifyObserver();
- // " Power: " + mPower);
- String message = mtemp+":"+mhumidity;
- Message msg = Message.obtain();
- msg.what = 0;
- SampleProvider mainActivityObj = SampleProvider.getSampleProviderObject();
- SampleProvider.setmessage(message);
- mainActivityObj.getmHandler().sendMessage(msg);
-
- }
-
- protected OcRepresentation get()
- {
- mTempRep.setValueInt(StringConstants.TEMPERATURE, mtemp);
- mTempRep.setValueInt(StringConstants.HUMIDITY, mhumidity);
- return mTempRep;
- }
-
- private EntityHandlerResult entityHandler(OcResourceRequest request)
- {
- EntityHandlerResult result = EntityHandlerResult.ERROR;
- if (null != request)
- {
- RequestType requestType = request.getRequestType();
- EnumSet<RequestHandlerFlag> requestFlag = request
- .getRequestHandlerFlagSet();
-
-
-
- if (requestFlag.contains(RequestHandlerFlag.INIT))
- {
- logMessage(TAG + "Init");
- }
-
- if (requestFlag.contains(RequestHandlerFlag.REQUEST))
- {
- try
- {
- logMessage(TAG + requestType + "Request");
- OcResourceResponse ocResourceResponse = new OcResourceResponse();
- ocResourceResponse.setRequestHandle(request
- .getRequestHandle());
- ocResourceResponse.setResourceHandle(request
- .getResourceHandle());
-
- switch (requestType)
- {
- // handle GET request
- case GET:
- logMessage("GET");
- ocResourceResponse
- .setResponseResult(EntityHandlerResult.OK);
- ocResourceResponse
- .setErrorCode(StringConstants.ERROR_CODE);
- ocResourceResponse.setResourceRepresentation(get());
- OcPlatform.sendResponse(ocResourceResponse);
- break;
- // handle PUT request
- case PUT:
- logMessage(TAG + "PUT");
- OcRepresentation rep = request
- .getResourceRepresentation();
- put(rep);
- ocResourceResponse
- .setErrorCode(StringConstants.ERROR_CODE);
- ocResourceResponse
- .setResponseResult(EntityHandlerResult.OK);
- ocResourceResponse.setResourceRepresentation(get());
- OcPlatform.sendResponse(ocResourceResponse);
- break;
- // handle POST request
- case POST:
- break;
- // handle DELETE request
- case DELETE:
- logMessage(TAG + "DELETE");
- OcPlatform.unregisterResource(getHandle());
- break;
-
- }
-
- result = EntityHandlerResult.OK;
- }
- catch (Exception e)
- {
- logMessage(TAG + "Error in Request " + e.getMessage());
- Log.e(TAG, e.getMessage());
- }
- }
- // handle OBSERVER request
- if (requestFlag.contains(RequestHandlerFlag.OBSERVER))
- {
- logMessage(TAG + "OBSERVER");
- ObservationInfo observationInfo = request.getObservationInfo();
- switch (observationInfo.getObserveAction())
- {
- case REGISTER:
- mObservationIds.add(observationInfo
- .getOcObservationId());
+ if (requestFlag.contains(RequestHandlerFlag.REQUEST)) {
+ try {
+ logMessage(TAG + requestType + "Request");
+ OcResourceResponse ocResourceResponse = new OcResourceResponse();
+ ocResourceResponse.setRequestHandle(request
+ .getRequestHandle());
+ ocResourceResponse.setResourceHandle(request
+ .getResourceHandle());
+
+ switch (requestType) {
+ // handle GET request
+ case GET:
+ logMessage("GET");
+ ocResourceResponse
+ .setResponseResult(EntityHandlerResult.OK);
+ ocResourceResponse
+ .setErrorCode(StringConstants.ERROR_CODE);
+ ocResourceResponse.setResourceRepresentation(get());
+ OcPlatform.sendResponse(ocResourceResponse);
+ break;
+ // handle PUT request
+ case PUT:
+ logMessage(TAG + "PUT");
+ OcRepresentation rep = request
+ .getResourceRepresentation();
+ put(rep);
+ ocResourceResponse
+ .setErrorCode(StringConstants.ERROR_CODE);
+ ocResourceResponse
+ .setResponseResult(EntityHandlerResult.OK);
+ ocResourceResponse.setResourceRepresentation(get());
+ OcPlatform.sendResponse(ocResourceResponse);
break;
- case UNREGISTER:
- mObservationIds.remove(observationInfo
- .getOcObservationId());
+ // handle POST request
+ case POST:
break;
+ // handle DELETE request
+ case DELETE:
+ logMessage(TAG + "DELETE");
+ OcPlatform.unregisterResource(getHandle());
+ break;
+
}
result = EntityHandlerResult.OK;
+ } catch (Exception e) {
+ logMessage(TAG + "Error in Request " + e.getMessage());
+ Log.e(TAG, e.getMessage());
}
}
- return result;
- }
-
- public void logMessage(String msg)
- {
- logMsg(msg);
- Log.i(TAG, msg);
- }
-
- public void logMsg(final String text)
- {
- Intent intent = new Intent("com.example.sample.provider.SampleProvider");
- intent.putExtra(StringConstants.MESSAGE, text);
- mContext.sendBroadcast(intent);
- }
-
- public void notifyObserver()
- {
- try
- {
- // if observationList is not empty, call notifyListOfObservers
- if (mObservationIds.size() > 0)
- {
- OcResourceResponse ocResourceResponse = new OcResourceResponse();
- ocResourceResponse.setErrorCode(StringConstants.ERROR_CODE);
- ocResourceResponse.setResponseResult(EntityHandlerResult.OK);
- OcRepresentation r = get();
- ocResourceResponse.setResourceRepresentation
- (r, OcPlatform.DEFAULT_INTERFACE);
- OcPlatform.notifyListOfObservers(getHandle(), mObservationIds, ocResourceResponse);
- }
- else
- {
- // notify all observers if mObservationList is empty
- OcPlatform.notifyAllObservers(getHandle());
+ // handle OBSERVER request
+ if (requestFlag.contains(RequestHandlerFlag.OBSERVER)) {
+ logMessage(TAG + "OBSERVER");
+ ObservationInfo observationInfo = request.getObservationInfo();
+ switch (observationInfo.getObserveAction()) {
+ case REGISTER:
+ mObservationIds.add(observationInfo
+ .getOcObservationId());
+
+ break;
+ case UNREGISTER:
+ mObservationIds.remove(observationInfo
+ .getOcObservationId());
+ break;
}
+
+ result = EntityHandlerResult.OK;
}
- catch (OcException e)
- {
- Log.e(TAG, e.getMessage());
+ }
+ return result;
+ }
+
+ public void logMessage(String msg) {
+ logMsg(msg);
+ Log.i(TAG, msg);
+ }
+
+ public void logMsg(final String text) {
+ Intent intent = new Intent("com.example.sample.provider.SampleProvider");
+ intent.putExtra(StringConstants.MESSAGE, text);
+ mContext.sendBroadcast(intent);
+ }
+
+ public void notifyObserver() {
+ try {
+ // if observationList is not empty, call notifyListOfObservers
+ if (mObservationIds.size() > 0) {
+ OcResourceResponse ocResourceResponse = new OcResourceResponse();
+ ocResourceResponse.setErrorCode(StringConstants.ERROR_CODE);
+ ocResourceResponse.setResponseResult(EntityHandlerResult.OK);
+ OcRepresentation r = get();
+ ocResourceResponse.setResourceRepresentation(r,
+ OcPlatform.DEFAULT_INTERFACE);
+ OcPlatform.notifyListOfObservers(getHandle(), mObservationIds,
+ ocResourceResponse);
+ } else {
+ // notify all observers if mObservationList is empty
+ OcPlatform.notifyAllObservers(getHandle());
}
+ } catch (OcException e) {
+ Log.e(TAG, e.getMessage());
}
+ }
}
import org.iotivity.ResourceHosting.ResourceHosting;
import org.iotivity.base.ModeType;
import org.iotivity.base.OcPlatform;
-import org.iotivity.base.OcResourceHandle;
import org.iotivity.base.PlatformConfig;
import org.iotivity.base.QualityOfService;
import org.iotivity.base.ServiceType;
/**
* To execute resource hosting function for android sample application .
+ *
* @author Copyright 2015 Samsung Electronics All Rights Reserved.
- * @see className class : ResourceHosting</br>
+ * @see className class : ResourceHosting</br>
*
*/
-public class ResourceHostingSampleApp extends Activity implements OnClickListener
-{
- private final int OCSTACK_OK = 0;
- private final int OCSTACK_ERROR = 255;
- private final int RESOURCEHOSTING_DO_NOT_THREADRUNNING = -2;
-
- private String TAG = "ResourceHosting";
- private OcResourceHandle mResourceHandle;
- private String mIpAddress;
- private TextView mLogTextView;
- private String mLog = "";
- private ResourceHosting resourceHosting;
- /**
- * To initialize UI Function Setting.
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : onCreate</br>
- */
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mLogTextView = (TextView) findViewById(R.id.txtLog);
- findViewById(R.id.btnStartHosting).setOnClickListener(this);
- findViewById(R.id.btnStopHosting).setOnClickListener(this);
- findViewById(R.id.btLogClear).setOnClickListener(this);
-
- PlatformConfig platformConfigObj;
- resourceHosting = new ResourceHosting();
- platformConfigObj = new PlatformConfig(this,ServiceType.IN_PROC,
- ModeType.CLIENT_SERVER, "0.0.0.0", 0, QualityOfService.LOW);
-
- Log.i(TAG, "Before Calling Configure of ocPlatform");
- OcPlatform.Configure(platformConfigObj);
- Log.i(TAG, "Configuration done Successfully");
- }
-
- /**
- * To execute initOICStack for running Resource hosting.
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : onStart</br>
- */
- @Override
- protected void onStart()
- {
- super.onStart();
- initOICStack();
- }
-
- /**
- * To terminate Resource hosting.
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : onStop</br>
- */
- @Override
- protected void onStop()
- {
- super.onStop();
- int result;
- result = resourceHosting.ResourceHostingTerminate();
- Log.d(TAG, "ResourceHostingTerminate : "+ result);
- }
-
- protected void onResume()
- {
- super.onResume();
- }
-
- /**
- * To execute initOICStack for running Resource hosting.
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : onRestart</br>
- */
- @Override
- protected void onRestart()
- {
- super.onRestart();
- initOICStack();
+public class ResourceHostingSampleApp extends Activity implements
+ OnClickListener {
+
+ private String TAG = "ResourceHosting";
+ private String mIpAddress;
+ private TextView mLogTextView;
+ private String mLog = "";
+ private ResourceHosting resourceHosting;
+
+ /**
+ * To initialize UI Function Setting.
+ *
+ * @see Class class :
+ * com_example_resourcehostingsampleapp_ResourceHosting</br>
+ * @see Method method : onCreate</br>
+ */
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ mLogTextView = (TextView) findViewById(R.id.txtLog);
+ findViewById(R.id.btnStartHosting).setOnClickListener(this);
+ findViewById(R.id.btnStopHosting).setOnClickListener(this);
+ findViewById(R.id.btLogClear).setOnClickListener(this);
+
+ PlatformConfig platformConfigObj;
+ resourceHosting = new ResourceHosting();
+ platformConfigObj = new PlatformConfig(this, ServiceType.IN_PROC,
+ ModeType.CLIENT_SERVER, "0.0.0.0", 0, QualityOfService.LOW);
+
+ Log.i(TAG, "Before Calling Configure of ocPlatform");
+ OcPlatform.Configure(platformConfigObj);
+ Log.i(TAG, "Configuration done Successfully");
+ }
+
+ /**
+ * To execute initOICStack for running Resource hosting.
+ *
+ * @see Class class :
+ * com_example_resourcehostingsampleapp_ResourceHosting</br>
+ * @see Method method : onStart</br>
+ */
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initOICStack();
+ }
+
+ /**
+ * To terminate Resource hosting.
+ *
+ * @see Class class :
+ * com_example_resourcehostingsampleapp_ResourceHosting</br>
+ * @see Method method : onStop</br>
+ */
+ @Override
+ protected void onStop() {
+ super.onStop();
+ int result;
+ result = resourceHosting.ResourceHostingTerminate();
+ Log.d(TAG, "ResourceHostingTerminate : " + result);
+ }
+
+ protected void onResume() {
+ super.onResume();
+ }
+
+ /**
+ * To execute initOICStack for running Resource hosting.
+ *
+ * @see Class class :
+ * com_example_resourcehostingsampleapp_ResourceHosting</br>
+ * @see Method method : onRestart</br>
+ */
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ initOICStack();
+ }
+
+ /**
+ * @see Class class :
+ * com_example_resourcehostingsampleapp_ResourceHosting</br>
+ * @see Method method : onDestroy</br>
+ */
+ protected void onDestroy() {
+ super.onDestroy();
+ }
+
+ /**
+ * get IpAddress and execute resourceHostingInit() method.
+ *
+ * @see Class class :
+ * com_example_resourcehostingsampleapp_ResourceHosting</br>
+ * @see Method method : initOICStack</br>
+ */
+ private void initOICStack() {
+ try {
+ mIpAddress = getIpAddress();
+ int result = 0;
+ result = resourceHosting.ResourceHostingInit(mIpAddress);
+ Log.d(TAG, "ResourceHostingInit : " + result);
+ } catch (Exception e) {
+ e.printStackTrace();
}
-
- /**
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : onDestroy</br>
- */
- protected void onDestroy()
- {
- super.onDestroy();
- }
-
- /**
- * get IpAddress and execute resourceHostingInit() method.
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : initOICStack</br>
- */
- private void initOICStack()
- {
- try
- {
- mIpAddress = getIpAddress();
- int result = 0;
- result = resourceHosting.ResourceHostingInit(mIpAddress);
- Log.d(TAG, "ResourceHostingInit : " + result);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : getIpAddress</br>
- */
- private String getIpAddress()
- {
- try
- {
- for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
- en.hasMoreElements();)
- {
- NetworkInterface intf = (NetworkInterface) en.nextElement();
- for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
- {
- InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
- if (!inetAddress.isLoopbackAddress())
- {
- if (inetAddress instanceof Inet4Address)
- return inetAddress.getHostAddress().toString();
- }
+ }
+
+ /**
+ * @see Class class :
+ * com_example_resourcehostingsampleapp_ResourceHosting</br>
+ * @see Method method : getIpAddress</br>
+ */
+ private String getIpAddress() {
+ try {
+ for (Enumeration<NetworkInterface> en = NetworkInterface
+ .getNetworkInterfaces(); en.hasMoreElements();) {
+ NetworkInterface intf = (NetworkInterface) en.nextElement();
+ for (Enumeration<InetAddress> enumIpAddr = intf
+ .getInetAddresses(); enumIpAddr.hasMoreElements();) {
+ InetAddress inetAddress = (InetAddress) enumIpAddr
+ .nextElement();
+ if (!inetAddress.isLoopbackAddress()) {
+ if (inetAddress instanceof Inet4Address)
+ return inetAddress.getHostAddress().toString();
}
}
}
- catch (SocketException e)
- {
- e.printStackTrace();
- }
- return null;
+ } catch (SocketException e) {
+ e.printStackTrace();
}
-
- /**
- * @see Class class : com_example_resourcehostingsampleapp_ResourceHosting</br>
- * @see Method method : onClick</br>
- * @param v view to choice
- */
- public void onClick(View v)
- {
- int getId = v.getId();
-
- switch (getId)
- {
- case R.id.btnStartHosting:
- try
- {
- int result;
- result = resourceHosting.OICCoordinatorStart();
- Log.d(TAG, "OICCoordinatorStart : " + result);
- }
- catch (Exception e)
- {
- Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
- }
- break;
- case R.id.btnStopHosting:
+ return null;
+ }
+
+ /**
+ * @see Class class :
+ * com_example_resourcehostingsampleapp_ResourceHosting</br>
+ * @see Method method : onClick</br>
+ * @param v
+ * view to choice
+ */
+ public void onClick(View v) {
+ int getId = v.getId();
+
+ switch (getId) {
+ case R.id.btnStartHosting:
+ try {
int result;
- result = resourceHosting.OICCoordinatorStop();
- Log.d(TAG, "OICCoordinatorStop : "+ result);
- break;
- case R.id.btLogClear:
- default:
- break;
- }
+ result = resourceHosting.OICCoordinatorStart();
+ Log.d(TAG, "OICCoordinatorStart : " + result);
+ } catch (Exception e) {
+ Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT)
+ .show();
+ }
+ break;
+ case R.id.btnStopHosting:
+ int result;
+ result = resourceHosting.OICCoordinatorStop();
+ Log.d(TAG, "OICCoordinatorStop : " + result);
+ break;
+ case R.id.btLogClear:
+ default:
+ break;
}
-
+ }
}