if target_os == 'android':
notification_env.AppendUnique(CCFLAGS = ['-frtti', '-fexceptions'])
notification_env.AppendUnique(LIBS = ['gnustl_shared','log'])
- notification_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,libnotification_provider.so'])
if not env.get('RELEASE'):
notification_env.AppendUnique(LIBS = ['log'])
if target_os == 'android':
SConscript('android/SConscript')
- # Go to build c++ wrapper
+# Go to build c++ wrapper
SConscript('cpp-wrapper/SConscript')
\ No newline at end of file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.iotivity.service.ns.consumer" />
\ No newline at end of file
+ package="org.iotivity.service.ns" />
\ No newline at end of file
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-package org.iotivity.service.ns.consumer;
+package org.iotivity.service.ns.common;
import android.util.Log;
-public class NSSyncInfo {
+/**
+ * @class MediaContents
+ * @brief This class provides implementation of Notification MediaContents object.
+ */
+public class MediaContents
+{
+ private static final String LOG_TAG = "NotificationService_MediaContents";
- private static final String LOG_TAG = "ConsumerService_NSSyncInfo";
+ public String mIconImage = null;
- long messageId = 0;
- String providerId = null;
- int state = 0;
-
- public NSSyncInfo(long messageId, String providerId, int state) {
-
- Log.i (LOG_TAG, "NSSyncInfo()");
-
- this.messageId = messageId;
- this.providerId = providerId;
- this.state = state;
- }
-
- public long getMessageId() {
- return messageId;
+ public MediaContents(String iconImage)
+ {
+ Log.i (LOG_TAG, "MediaContents()");
+ mIconImage = iconImage;
}
- public String getProviderId() {
- return providerId;
+ public String getIconImage()
+ {
+ return mIconImage;
}
- public int getState() {
- return state;
+ public void setIconImage(String iconImage)
+ {
+ mIconImage = iconImage;
}
-}
\ No newline at end of file
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+package org.iotivity.service.ns.common;
+
+import android.util.Log;
+
+/**
+ * @class Message
+ * @brief This class provides implementation of Notification Message object.
+ */
+public class Message
+{
+ private static final String LOG_TAG = "NotificationService_Message";
+
+ public enum MessageType
+ {
+ ALERT(0),
+ NOTICE(1),
+ EVENT(2),
+ INFO(3);
+ private int type;
+
+ private MessageType(int type)
+ {
+ this.type = type;
+ }
+
+ public int getMessageType()
+ {
+ return this.type;
+ }
+ };
+ public long mMessageId = 0;
+ public String mProviderId = null;
+
+ public String mSourceName = null;
+ public MessageType mType = MessageType.ALERT;
+ public String mTime = null;
+ public long mTTL = 0;
+ public String mTitle = null;
+ public String mContentText = null;
+ public MediaContents mMediaContents = null;
+
+ private long mNativeHandle = 0;
+
+ public Message(String title, String contentText, String sourceName)
+ {
+ Log.i (LOG_TAG, "Message()");
+
+ mTitle = title;
+ mContentText = contentText;
+ mSourceName = sourceName;
+ }
+
+ public long getMessageId()
+ {
+ return mMessageId;
+ }
+
+ public String getProviderId()
+ {
+ return mProviderId;
+ }
+
+ public String getSourceName ()
+ {
+ return mSourceName;
+ }
+
+ public MessageType getType()
+ {
+ return mType;
+ }
+
+ public String getTime()
+ {
+ return mTime;
+ }
+
+ public long getTTL()
+ {
+ return mTTL;
+ }
+
+ public String getTitle()
+ {
+ return mTitle;
+ }
+
+ public String getContentText()
+ {
+ return mContentText;
+ }
+
+ public MediaContents getMediaContents()
+ {
+ return mMediaContents;
+ }
+
+ public void setSourceName (String sourceName)
+ {
+ mSourceName = sourceName;
+ }
+
+ public void setType(MessageType type)
+ {
+ mType = type;
+ }
+
+ public void setTime(String time)
+ {
+ mTime = time;
+ }
+
+ public void setTTL(long ttl)
+ {
+ mTTL = ttl;
+ }
+
+ public void setTitle(String title)
+ {
+ mTitle = title;
+ }
+
+ public void setContentText(String contextText)
+ {
+ mContentText = contextText;
+ }
+
+ public void setMediaContents(MediaContents mediaContents)
+ {
+ mMediaContents = mediaContents;
+ }
+}
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-package org.iotivity.service.ns.consumer;
+package org.iotivity.service.ns.common;
-public enum NSErrorCode {
+public enum NSErrorCode
+{
OK("OK", ""),
ERROR("ERROR", ""),
SUCCESS("SUCCESS", ""),
private String error;
private String description;
- private NSErrorCode(String error, String description) {
- this.error = error;
- this.description = description;
- }
+ private NSErrorCode(String error, String description)
+{
+ this.error = error;
+ this.description = description;
+}
- public String getError() {
- return error;
- }
+public String getError()
+{
+ return error;
+}
- public String getDescription() {
- return description;
- }
+public String getDescription()
+{
+ return description;
+}
- public static NSErrorCode get(String errorCode) {
- for (NSErrorCode eCode : NSErrorCode.values()) {
- if (eCode.getError().equals(errorCode)) {
- return eCode;
- }
+public static NSErrorCode get(String errorCode)
+{
+ for (NSErrorCode eCode : NSErrorCode.values())
+ {
+ if (eCode.getError().equals(errorCode))
+ {
+ return eCode;
}
- throw new IllegalArgumentException("Unexpected NSErrorCode value");
}
+ throw new IllegalArgumentException("Unexpected NSErrorCode value");
+}
- @Override
- public String toString() {
- return error + (description.isEmpty() ? "" : " : " + description);
- }
+@Override
+public String toString()
+{
+ return error + (description.isEmpty() ? "" : " : " + description);
+}
}
\ No newline at end of file
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-package org.iotivity.service.ns.consumer;
-
-public class NSException extends Exception {
+package org.iotivity.service.ns.common;
+public class NSException extends Exception
+{
private NSErrorCode errorCode;
- public NSException(NSErrorCode errorCode, String errMessage) {
+ public NSException(NSErrorCode errorCode, String errMessage)
+ {
super(errMessage + " " + errorCode.toString());
this.errorCode = errorCode;
}
- private NSException(String error, String errMessage) {
+ private NSException(String error, String errMessage)
+ {
super(errMessage + " " + error);
this.errorCode = NSErrorCode.get(error);
}
- public NSErrorCode getErrorCode() {
+ public NSErrorCode getErrorCode()
+ {
return errorCode;
}
private static void addStackTrace(Throwable throwable,
String file,
String functionName,
- int line) {
+ int line)
+ {
StackTraceElement[] stack = throwable.getStackTrace();
StackTraceElement[] newStack = new StackTraceElement[stack.length + 1];
throwable.setStackTrace(newStack);
}
- private void setNativeExceptionLocation(String file, String functionName, int line) {
+ private void setNativeExceptionLocation(String file, String functionName, int line)
+ {
NSException.addStackTrace(this, file, functionName, line);
}
-
}
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+package org.iotivity.service.ns.common;
+
+import android.util.Log;
+
+/**
+ * @class SyncInfo
+ * @brief This class provides implementation of Notification SyncInfo object.
+ */
+public class SyncInfo
+{
+ private static final String LOG_TAG = "NotificationService_SyncInfo";
+
+ public enum SyncType
+ {
+ UNREAD(0),
+ READ(1),
+ DELETED(2);
+ private int type;
+
+ private SyncType(int type)
+ {
+ this.type = type;
+ }
+
+ public int getSyncType()
+ {
+ return this.type;
+ }
+ };
+ public long mMessageId = 0;
+ public String mProviderId = null;
+ public SyncType mState = SyncType.UNREAD;
+
+ public SyncInfo(long messageId, String providerId, SyncType state)
+ {
+ Log.i (LOG_TAG, "SyncInfo()");
+
+ mMessageId = messageId;
+ mProviderId = providerId;
+ mState = state;
+ }
+
+ public long getMessageId()
+ {
+ return mMessageId;
+ }
+
+ public String getProviderId()
+ {
+ return mProviderId;
+ }
+
+ public SyncType getState()
+ {
+ return mState;
+ }
+}
package org.iotivity.service.ns.consumer;
import android.util.Log;
+import org.iotivity.service.ns.common.*;
-public class ConsumerService {
-
+/**
+ * @class ConsumerService
+ * @brief This class provides a set of Java APIs for Notification Consumer.
+ */
+public class ConsumerService
+{
private static final String LOG_TAG = "ConsumerService";
- static {
+ static
+ {
+ System.loadLibrary("gnustl_shared");
+ System.loadLibrary("oc_logger");
+ System.loadLibrary("connectivity_abstraction");
+ System.loadLibrary("ca-interface");
+ System.loadLibrary("octbstack");
+ System.loadLibrary("oc");
+ System.loadLibrary("ocstack-jni");
+ System.loadLibrary("notification_consumer");
+ System.loadLibrary("notification_consumer_wrapper");
System.loadLibrary("notification_consumer_jni");
}
- public ConsumerService() {
+ private static ConsumerService instance;
+ static
+ {
+ instance = new ConsumerService();
+ }
+ public static ConsumerService getInstance()
+ {
+ return instance;
+ }
+
+ public ConsumerService()
+ {
Log.i (LOG_TAG, "ConsumerService()");
}
- public native void Start (
- OnProviderDiscoveredListner onProviderDiscoveredListner,
- OnSubscriptionAcceptedListener onSubscriptionAcceptedListener
- ) throws NSException;
- public native void Stop () throws NSException;
- public native void RescanProvider() throws NSException;
- public native NSProvider GetProvider(String providerId) throws NSException;
+ public void Start(
+ OnProviderDiscoveredListner onProviderDiscoveredListner,
+ OnSubscriptionAcceptedListener onSubscriptionAcceptedListener
+ ) throws NSException
+ {
+ nativeStart(onProviderDiscoveredListner, onSubscriptionAcceptedListener);
+ }
- public interface OnProviderDiscoveredListner {
- public void onProviderDiscovered(NSProvider provider);
+ public void Stop() throws NSException
+ {
+ nativeStop();
}
- public interface OnSubscriptionAcceptedListener {
- public void onSubscriptionAccepted(NSProvider provider);
+ public void EnableRemoteService(String serverAddress) throws NSException
+ {
+ nativeEnableRemoteService(serverAddress);
}
- public interface OnMessageReceivedListner {
- public void onMessageReceived(NSMessage message);
+ public void RescanProvider() throws NSException
+ {
+ nativeRescanProvider();
}
- public interface OnSyncInfoReceivedListner {
- public void onSyncInfoReceived(NSSyncInfo sync);
+ public Provider GetProvider(String providerId) throws NSException
+ {
+ return nativeGetProvider(providerId);
}
-}
+ public interface OnProviderDiscoveredListner
+ {
+ public void onProviderDiscovered(Provider provider);
+ }
+
+ public interface OnSubscriptionAcceptedListener
+ {
+ public void onSubscriptionAccepted(Provider provider);
+ }
+
+ private native void nativeStart (
+ OnProviderDiscoveredListner onProviderDiscoveredListner,
+ OnSubscriptionAcceptedListener onSubscriptionAcceptedListener
+ ) throws NSException;
+
+ private native void nativeStop() throws NSException;
+ private native void nativeEnableRemoteService(String serverAddress) throws NSException;
+ private native void nativeRescanProvider() throws NSException;
+ private native Provider nativeGetProvider(String providerId) throws NSException;
+}
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-package org.iotivity.service.ns.consumer;
-
-import android.util.Log;
-
-public class NSMessage {
-
- private static final String LOG_TAG = "ConsumerService_NSMessage";
-
- long messageId = 0;
- String providerId = null;
-
- String title = null;
- String contentText = null;
- String sourceName = null;
-
- private long mNativeHandle = 0;
-
- public NSMessage(long messageId, String providerId, String title,
- String contentText, String sourceName, long mNativeHandle) {
-
- Log.i (LOG_TAG, "NSMessage()");
-
- this.messageId = messageId;
- this.providerId = providerId;
- this.title = title;
- this.contentText = contentText;
- this.sourceName = sourceName;
-
- this.mNativeHandle = mNativeHandle;
- }
-
- public long getMessageId() {
- return messageId;
- }
-
- public String getProviderId() {
- return providerId;
- }
-
- public String getTitle() {
- return title;
- }
-
- public String getContentText() {
- return contentText;
- }
-
- public String getSource() {
- return sourceName;
- }
-}
\ No newline at end of file
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-package org.iotivity.service.ns.consumer;
-
-import android.util.Log;
-
-public class NSProvider {
-
- private static final String LOG_TAG = "ConsumerService_NSProvider";
-
- String providerId = null;
-
- private long mNativeHandle = 0;
-
- public NSProvider(String providerId, long mNativeHandle) {
- Log.i (LOG_TAG, "NSProvider()");
-
- this.providerId = providerId;
-
- this.mNativeHandle = mNativeHandle;
- }
-
- private native void Subscribe(long provider) throws NSException;
- private native void Unsubscribe(long provider) throws NSException;
- private native void SendSyncInfo(String providerId, long messageId, int syncType) throws NSException;
- public native void SetListener(
- ConsumerService.OnMessageReceivedListner onMessageReceivedListner,
- ConsumerService.OnSyncInfoReceivedListner onSyncInfoReceivedListner
- ) throws NSException;
-
- public String getProviderId () {
- return providerId ;
- }
-
- public void Subscribe() throws NSException {
- this.Subscribe(mNativeHandle);
- }
-
- public void Unsubscribe() throws NSException {
- this.Unsubscribe(mNativeHandle);
- }
-
- public void SendSyncInfo(long messageId, int syncType) throws NSException {
- this.SendSyncInfo(this.providerId, messageId, syncType);
- }
-}
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+package org.iotivity.service.ns.consumer;
+
+import android.util.Log;
+import org.iotivity.service.ns.common.*;
+
+/**
+ * @class Provider
+ * @brief This class provides implementation of Notification Provider object.
+ */
+public class Provider
+{
+ private static final String LOG_TAG = "ConsumerService_Provider";
+
+ public String mProviderId = null;
+ private long mNativeHandle = 0;
+
+ public Provider(String providerId)
+ {
+ Log.i (LOG_TAG, "Provider()");
+
+ mProviderId = providerId;
+ }
+
+ public String getProviderId()
+ {
+ return mProviderId ;
+ }
+
+ public void Subscribe() throws NSException
+ {
+ nativeSubscribe();
+ }
+
+ public void Unsubscribe() throws NSException
+ {
+ nativeUnsubscribe();
+ }
+
+ public void SendSyncInfo(long messageId, SyncInfo.SyncType syncType) throws NSException
+ {
+ nativeSendSyncInfo(messageId, syncType.ordinal());
+ }
+
+ public void SetListener(OnMessageReceivedListner onMessageReceivedListner,
+ OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException
+ {
+ nativeSetListener(onMessageReceivedListner, onSyncInfoReceivedListner);
+ }
+
+ public interface OnMessageReceivedListner
+ {
+ public void onMessageReceived(Message message);
+ }
+
+ public interface OnSyncInfoReceivedListner
+ {
+ public void onSyncInfoReceived(SyncInfo sync);
+ }
+
+ private native void nativeSubscribe() throws NSException;
+ private native void nativeUnsubscribe() throws NSException;
+ private native void nativeSendSyncInfo(long messageId, int syncType) throws NSException;
+ private native void nativeSetListener(
+ OnMessageReceivedListner onMessageReceivedListner,
+ OnSyncInfoReceivedListner onSyncInfoReceivedListner
+ ) throws NSException;
+}
include $(CLEAR_VARS)
OIC_LIB_PATH := $(ROOT_PATH)/out/android/$(TARGET_ARCH_ABI)/$(APP_OPTIM)
-LOCAL_MODULE := notification_provider
-LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libnotification_provider.so
+LOCAL_MODULE := notification_consumer_wrapper
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libnotification_consumer_wrapper.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_CPPFLAGS := -std=c++0x -frtti -fexceptions
LOCAL_LDLIBS := -llog
-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 += notification_consumer
+LOCAL_SHARED_LIBRARIES := ca_interface
+LOCAL_SHARED_LIBRARIES += ca
+LOCAL_SHARED_LIBRARIES += oc_logger_core
+LOCAL_SHARED_LIBRARIES += oc_logger
+LOCAL_SHARED_LIBRARIES += octbstack
+LOCAL_SHARED_LIBRARIES += oc
+LOCAL_SHARED_LIBRARIES += ocstack-jni
+LOCAL_SHARED_LIBRARIES += notification_consumer_wrapper
OIC_SRC_DIR := ../../../../../..
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/csdk/logger/include
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/include
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/c_common
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/c_common/oic_string/include
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/oc_logger/include
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/include
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/src/common
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/src/consumer
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/android/notification-service/src/main/jni/common
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/cpp-wrapper/common
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/cpp-wrapper/consumer/inc
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/extlibs/
-LOCAL_SRC_FILES := consumer/notificationConsumer.c
-LOCAL_SRC_FILES += common/jniNSCommon.c
+LOCAL_SRC_FILES := consumer/JniNotificationConsumer.cpp
+LOCAL_SRC_FILES += common/JniNotificationCommon.cpp
include $(BUILD_SHARED_LIBRARY)
+include $(CLEAR_VARS)
+OIC_LIB_PATH := $(ROOT_PATH)/out/android/$(TARGET_ARCH_ABI)/$(APP_OPTIM)
+LOCAL_MODULE := notification_provider
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libnotification_provider.so
+include $(PREBUILT_SHARED_LIBRARY)
+
include $(CLEAR_VARS)
LOCAL_MODULE := notification_provider_jni
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include "jniNSCommon.h"
-
-static jclass g_cls_NSException = NULL;
-static jmethodID g_mid_NSException_ctor = NULL;
-static jmethodID g_mid_NSException_setNativeExceptionLocation = NULL;
-
-static const char * NSResultToChar(const int nsresult)
-{
- switch (nsresult)
- {
- case NS_OK:
- return "OK";
- case NS_ERROR:
- return "ERROR";
- case NS_SUCCESS:
- return "SUCCESS";
- case NS_FAIL:
- return "FAIL";
- case NS_ALLOW:
- return "ALLOW";
- case NS_DENY:
- return "DENY";
- case JNI_EXCEPTION:
- return "JNI_EXCEPTION";
- case JNI_NO_NATIVE_POINTER:
- return "JNI_NO_NATIVE_POINTER";
- case JNI_INVALID_VALUE:
- return "JNI_INVALID_VALUE";
- default:
- return "";
- }
-}
-
-
-jobject getNSException(JNIEnv* env, const char* file, const char* functionName,
- const int line, const int code, const char* message)
-{
- const char * codeChar = NSResultToChar(code);
- if (!strcmp(codeChar, ""))
- {
- codeChar = NSResultToChar(JNI_INVALID_VALUE);
- }
- jobject exception = (*env)->NewObject(env,
- g_cls_NSException,
- g_mid_NSException_ctor,
- (*env)->NewStringUTF(env, codeChar),
- (*env)->NewStringUTF(env, message));
- if (!exception)
- {
- return NULL;
- }
- (*env)->CallVoidMethod(env,
- exception,
- g_mid_NSException_setNativeExceptionLocation,
- (*env)->NewStringUTF(env, file),
- (*env)->NewStringUTF(env, functionName),
- line);
- if ((*env)->ExceptionCheck(env))
- {
- return NULL;
- }
- return exception;
-}
-
-void throwNSException(JNIEnv * env, jobject exception)
-{
- (*env)->Throw(env, (jthrowable)exception);
-}
-
-int NSExceptionInit(JNIEnv * env)
-{
- if (!env)
- {
- LOGE ("JNIEnv is null");
- return JNI_ERR;
- }
-
- //OcException
- jclass localNSException = (*env)->FindClass(env,
- "org/iotivity/service/ns/consumer/NSException");
- if (!localNSException)
- {
- LOGE ("Failed to get local NSException");
- return JNI_ERR;
- }
- g_cls_NSException = (jclass)(*env)->NewGlobalRef(env, localNSException);
-
-
- g_mid_NSException_ctor = (*env)->GetMethodID(env, g_cls_NSException,
- "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
- if (!g_mid_NSException_ctor)
- {
- LOGE ("Failed to Get MethodID");
- return JNI_ERR;
- }
-
- g_mid_NSException_setNativeExceptionLocation = (*env)->GetMethodID(env, g_cls_NSException,
- "setNativeExceptionLocation",
- "(Ljava/lang/String;Ljava/lang/String;I)V");
- if (!g_mid_NSException_setNativeExceptionLocation)
- {
- LOGE ("Failed to Get MethodID");
- return JNI_ERR;
- }
-
- (*env)->DeleteLocalRef(env, localNSException);
-
- return JNI_CURRENT_VERSION;
-}
\ No newline at end of file
+//******************************************************************\r
+//\r
+// Copyright 2016 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#include "JniNotificationCommon.h"\r
+#include <cstddef>\r
+\r
+static jclass g_cls_NSException = NULL;\r
+static jmethodID g_mid_NSException_ctor = NULL;\r
+static jmethodID g_mid_NSException_setNativeExceptionLocation = NULL;\r
+\r
+static const char *NSResultToChar(const int nsresult)\r
+{\r
+ switch (nsresult)\r
+ {\r
+ case JNI_NS_OK:\r
+ return "OK";\r
+ case JNI_NS_ERROR:\r
+ return "ERROR";\r
+ case JNI_NS_SUCCESS:\r
+ return "SUCCESS";\r
+ case JNI_NS_FAIL:\r
+ return "FAIL";\r
+ case JNI_NS_ALLOW:\r
+ return "ALLOW";\r
+ case JNI_NS_DENY:\r
+ return "DENY";\r
+ case JNI_EXCEPTION:\r
+ return "JNI_EXCEPTION";\r
+ case JNI_NO_NATIVE_POINTER:\r
+ return "JNI_NO_NATIVE_POINTER";\r
+ case JNI_INVALID_VALUE:\r
+ return "JNI_INVALID_VALUE";\r
+ default:\r
+ return "";\r
+ }\r
+}\r
+\r
+\r
+jobject getNSException(JNIEnv *env, const char *file, const char *functionName,\r
+ const int line, const int code, const char *message)\r
+{\r
+ const char *codeChar = NSResultToChar(code);\r
+ if (codeChar[0] == '\0')\r
+ {\r
+ codeChar = NSResultToChar(JNI_INVALID_VALUE);\r
+ }\r
+ jobject exception = env->NewObject(\r
+ g_cls_NSException,\r
+ g_mid_NSException_ctor,\r
+ env->NewStringUTF(codeChar),\r
+ env->NewStringUTF(message));\r
+ if (!exception)\r
+ {\r
+ return NULL;\r
+ }\r
+ env->CallVoidMethod(\r
+ exception,\r
+ g_mid_NSException_setNativeExceptionLocation,\r
+ env->NewStringUTF(file),\r
+ env->NewStringUTF(functionName),\r
+ line);\r
+ if (env->ExceptionCheck())\r
+ {\r
+ return NULL;\r
+ }\r
+ return exception;\r
+}\r
+\r
+void throwNSException(JNIEnv *env, jobject exception)\r
+{\r
+ env->Throw((jthrowable)exception);\r
+}\r
+\r
+int NSExceptionInit(JNIEnv *env)\r
+{\r
+ if (!env)\r
+ {\r
+ LOGE ("JNIEnv is null");\r
+ return JNI_ERR;\r
+ }\r
+\r
+ //OcException\r
+ jclass localNSException = env->FindClass(\r
+ "org/iotivity/service/ns/common/NSException");\r
+ if (!localNSException)\r
+ {\r
+ LOGE ("Failed to get local NSException");\r
+ return JNI_ERR;\r
+ }\r
+ g_cls_NSException = (jclass)env->NewGlobalRef(localNSException);\r
+\r
+\r
+ g_mid_NSException_ctor = env->GetMethodID(g_cls_NSException,\r
+ "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");\r
+ if (!g_mid_NSException_ctor)\r
+ {\r
+ LOGE ("Failed to Get MethodID");\r
+ return JNI_ERR;\r
+ }\r
+\r
+ g_mid_NSException_setNativeExceptionLocation = env->GetMethodID(g_cls_NSException,\r
+ "setNativeExceptionLocation",\r
+ "(Ljava/lang/String;Ljava/lang/String;I)V");\r
+ if (!g_mid_NSException_setNativeExceptionLocation)\r
+ {\r
+ LOGE ("Failed to Get MethodID");\r
+ return JNI_ERR;\r
+ }\r
+\r
+ env->DeleteLocalRef(localNSException);\r
+\r
+ return JNI_CURRENT_VERSION;\r
+}\r
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef _JNI_NS_COMMON_H_
-#define _JNI_NS_COMMON_H_
-
-#include <jni.h>
-#include <android/log.h>
-
-#include "NSCommon.h"
-
-#define LOG_TAG "Notification_Consumer"
-
-#define JNI_CURRENT_VERSION JNI_VERSION_1_6
-
-#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
-#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
-#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
-#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
-
-#define JNI_EXCEPTION 1000
-#define JNI_NO_NATIVE_POINTER 1001
-#define JNI_INVALID_VALUE 1002
-
-jobject getNSException(JNIEnv * env, const char * file, const char * functionName, const int line,
- const int code, const char * message);
-void throwNSException(JNIEnv * env, jobject ex);
-
-#define GetNSException(code, message) getNSException(env, __FILE__, __func__, __LINE__, code, message)
-#define ThrowNSException(code, message) throwNSException(env, GetNSException(code, message))
-
-static const char * NSResultToChar(const int nsresult);
-int NSExceptionInit(JNIEnv * env);
-
-#endif // _JNI_NS_COMMON_H_
\ No newline at end of file
+//******************************************************************\r
+//\r
+// Copyright 2016 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#ifndef _JNI_NOTIFICATION_COMMON_H_\r
+#define _JNI_NOTIFICATION_COMMON_H_\r
+\r
+#include <jni.h>\r
+#include <android/log.h>\r
+\r
+\r
+#define LOG_TAG "Notification_Common"\r
+\r
+#define JNI_CURRENT_VERSION JNI_VERSION_1_6\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)\r
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)\r
+#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)\r
+#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)\r
+\r
+#define JNI_EXCEPTION 1000\r
+#define JNI_NO_NATIVE_POINTER 1001\r
+#define JNI_INVALID_VALUE 1002\r
+\r
+#define JNI_NS_OK 100\r
+#define JNI_NS_ERROR 200\r
+#define JNI_NS_SUCCESS 300\r
+#define JNI_NS_FAIL 400\r
+#define JNI_NS_ALLOW 500\r
+#define JNI_NS_DENY 600\r
+\r
+jobject getNSException(JNIEnv *env, const char *file, const char *functionName, const int line,\r
+ const int code, const char *message);\r
+void throwNSException(JNIEnv *env, jobject ex);\r
+\r
+#define GetNSException(code, message) getNSException(env, __FILE__, __func__, __LINE__, code, message)\r
+#define ThrowNSException(code, message) throwNSException(env, GetNSException(code, message))\r
+\r
+static const char *NSResultToChar(const int nsresult);\r
+int NSExceptionInit(JNIEnv *env);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif // _JNI_NOTIFICATION_COMMON_H_
\ No newline at end of file
--- /dev/null
+//******************************************************************\r
+//\r
+// Copyright 2016 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#include "JniNotificationConsumer.h"\r
+#include "NSConsumerService.h"\r
+\r
+static JavaVM *g_jvm = NULL;\r
+\r
+static jobject g_obj_postListener = NULL;\r
+static jobject g_obj_discoverListener = NULL;\r
+static jobject g_obj_syncListener = NULL;\r
+static jobject g_obj_acceptListener = NULL;\r
+\r
+jclass g_cls_Message;\r
+jclass g_cls_Provider;\r
+jclass g_cls_SyncInfo;\r
+jclass g_cls_MediaContents;\r
+\r
+static JNIEnv *GetJNIEnv(jint *ret)\r
+{\r
+ JNIEnv *env = NULL;\r
+\r
+ *ret = g_jvm->GetEnv((void **) &env, JNI_CURRENT_VERSION);\r
+ switch (*ret)\r
+ {\r
+ case JNI_OK:\r
+ return env;\r
+ case JNI_EDETACHED:\r
+ if (g_jvm->AttachCurrentThread(&env, NULL) != JNI_OK)\r
+ {\r
+ LOGE ("Failed to get the environment");\r
+ return NULL;\r
+ }\r
+ else\r
+ {\r
+ return env;\r
+ }\r
+ case JNI_EVERSION:\r
+ LOGE ("JNI version is not supported");\r
+ default:\r
+ LOGE ("Failed to get the environment");\r
+ return NULL;\r
+ }\r
+}\r
+\r
+void onDiscoverProvider(OIC::Service::NSProvider *provider)\r
+{\r
+ LOGD ("ConsumerService_onDiscoverProvider");\r
+\r
+ jint envRet;\r
+ JNIEnv *env = GetJNIEnv(&envRet);\r
+ if (NULL == env) return ;\r
+\r
+ jobject jDiscoverListener = (jobject) env->NewLocalRef(g_obj_discoverListener);\r
+ if (!jDiscoverListener)\r
+ {\r
+ LOGE ("Failed to Get jDiscoverListener");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+\r
+ LOGD ("ProviderId : %s\n", provider->getProviderId().c_str());\r
+\r
+ jstring jProviderId = env->NewStringUTF(provider->getProviderId().c_str());\r
+ jlong pProvider = (long)provider;\r
+\r
+ jclass cls_provider = (jclass) (env->NewLocalRef(g_cls_Provider));\r
+ if (!cls_provider)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for Provider");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jmethodID mid_provider = env->GetMethodID(\r
+ cls_provider, "<init>", "(Ljava/lang/String;)V");\r
+ if (!mid_provider)\r
+ {\r
+ LOGE ("Failed to Get MethodID for Provider<init>");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jobject obj_provider = env->NewObject(cls_provider, mid_provider,\r
+ jProviderId);\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(cls_provider, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ LOGE("Failed to get nativeHandle for Provider");\r
+ return;\r
+ }\r
+ env->SetLongField(obj_provider, nativeHandle, pProvider);\r
+\r
+ jclass cls = env->GetObjectClass(jDiscoverListener);\r
+ if (!cls)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for jDiscoverListener");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jmethodID mid = env->GetMethodID(\r
+ cls,\r
+ "onProviderDiscovered",\r
+ "(Lorg/iotivity/service/ns/consumer/Provider;)V");\r
+ if (!mid)\r
+ {\r
+ LOGE ("Failed to Get MethodID for onProviderDiscovered");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+\r
+ env->CallVoidMethod(jDiscoverListener, mid, obj_provider);\r
+\r
+ env->DeleteLocalRef(jDiscoverListener);\r
+ env->DeleteLocalRef(cls_provider);\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+}\r
+\r
+void onSubscriptionAccepted(OIC::Service::NSProvider *provider)\r
+{\r
+ LOGD ("ConsumerService_onSubscriptionAccepted");\r
+\r
+ jint envRet;\r
+ JNIEnv *env = GetJNIEnv(&envRet);\r
+ if (NULL == env) return ;\r
+\r
+ jobject jAcceptListener = (jobject) env->NewLocalRef(g_obj_acceptListener);\r
+ if (!jAcceptListener)\r
+ {\r
+ LOGE ("Failed to Get jAcceptListener");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+\r
+ LOGD ("ProviderId : %s\n", provider->getProviderId().c_str());\r
+\r
+ jstring jProviderId = env->NewStringUTF(provider->getProviderId().c_str());\r
+ jlong pProvider = (long)provider;\r
+\r
+ jclass cls_provider = (jclass) (env->NewLocalRef(g_cls_Provider));\r
+ if (!cls_provider)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for Provider");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jmethodID mid_provider = env->GetMethodID(\r
+ cls_provider, "<init>", "(Ljava/lang/String;)V");\r
+ if (!mid_provider)\r
+ {\r
+ LOGE ("Failed to Get MethodID for Provider<init>");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jobject obj_provider = env->NewObject(cls_provider, mid_provider,\r
+ jProviderId);\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(cls_provider, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ LOGE("Failed to get nativeHandle for Provider");\r
+ return;\r
+ }\r
+ env->SetLongField(obj_provider, nativeHandle, pProvider);\r
+\r
+ jclass cls = env->GetObjectClass(jAcceptListener);\r
+ if (!cls)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for jAcceptListener");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jmethodID mid = env->GetMethodID(\r
+ cls,\r
+ "onSubscriptionAccepted",\r
+ "(Lorg/iotivity/service/ns/consumer/Provider;)V");\r
+ if (!mid)\r
+ {\r
+ LOGE ("Failed to Get MethodID for onSubscriptionAccepted");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+\r
+ env->CallVoidMethod(jAcceptListener, mid, obj_provider);\r
+\r
+ env->DeleteLocalRef(jAcceptListener);\r
+ env->DeleteLocalRef(cls_provider);\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+\r
+}\r
+\r
+jobject getJavaMessageType(JNIEnv *env, OIC::Service::NSMessage::NSMessageType type)\r
+{\r
+ switch (type)\r
+ {\r
+ case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_ALERT:\r
+ {\r
+ static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message,\r
+ "ALERT", "Lorg/iotivity/service/ns/common/Message$MessageType;");\r
+ return env->GetStaticObjectField(g_cls_Message, fieldID);\r
+ }\r
+ case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_NOTICE:\r
+ {\r
+ static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message,\r
+ "NOTICE", "Lorg/iotivity/service/ns/common/Message$MessageType;");\r
+ return env->GetStaticObjectField(g_cls_Message, fieldID);\r
+ }\r
+ case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_EVENT:\r
+ {\r
+ static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message,\r
+ "EVENT", "Lorg/iotivity/service/ns/common/Message$MessageType;");\r
+ return env->GetStaticObjectField(g_cls_Message, fieldID);\r
+ }\r
+ case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_INFO:\r
+ {\r
+ static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message,\r
+ "INFO", "Lorg/iotivity/service/ns/common/Message$MessageType;");\r
+ return env->GetStaticObjectField(g_cls_Message, fieldID);\r
+ }\r
+ default:\r
+ return NULL;\r
+ }\r
+ return NULL;\r
+}\r
+\r
+void onMessagePosted(OIC::Service::NSMessage *message)\r
+{\r
+ LOGD ("ConsumerService_onMessagePosted");\r
+\r
+ jint envRet;\r
+ JNIEnv *env = GetJNIEnv(&envRet);\r
+ if (NULL == env) return ;\r
+\r
+ jobject jPostListener = (jobject) env->NewLocalRef(g_obj_postListener);\r
+ if (!jPostListener)\r
+ {\r
+ LOGE ("Failed to Get jPostListener");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+\r
+ LOGD ("id : %llu\n", message->getMessageId());\r
+ LOGD ("title : %s\n", message->getTitle().c_str());\r
+ LOGD ("content : %s\n", message->getContentText().c_str());\r
+ LOGD ("source : %s\n", message->getSourceName().c_str());\r
+\r
+ jlong jMessageId = (jlong) message->getMessageId();\r
+ jstring jProviderId = env->NewStringUTF(message->getProviderId().c_str());\r
+ jstring jTitle = env->NewStringUTF(message->getTitle().c_str());\r
+ jstring jContentText = env->NewStringUTF(message->getContentText().c_str());\r
+ jstring jSourceName = env->NewStringUTF(message->getSourceName().c_str());\r
+\r
+ jstring jTime = env->NewStringUTF(message->getTime().c_str());\r
+ jlong jTTL = (jlong) message->getTTL();\r
+\r
+ jlong pMessage = (long) message;\r
+\r
+ jclass cls_message = (jclass) (env->NewLocalRef(g_cls_Message));\r
+ if (!cls_message)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for Message");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jmethodID mid_message = env->GetMethodID(\r
+ cls_message, "<init>",\r
+ "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");\r
+ if (!mid_message)\r
+ {\r
+ LOGE ("Failed to Get MethodID for Message<init>");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jobject obj_message = env->NewObject(cls_message, mid_message,\r
+ jTitle, jContentText, jSourceName);\r
+\r
+ jfieldID fid_nativeHandle = env->GetFieldID(cls_message, "mNativeHandle", "J");\r
+ if (!fid_nativeHandle)\r
+ {\r
+ LOGE("Failed to get nativeHandle for Message");\r
+ return;\r
+ }\r
+ env->SetLongField(obj_message, fid_nativeHandle, pMessage);\r
+\r
+ jfieldID fid_messageId = env->GetFieldID(cls_message, "mMessageId", "J");\r
+ if (!fid_messageId)\r
+ {\r
+ LOGE("Failed to get field MessageID for Message");\r
+ return;\r
+ }\r
+ env->SetLongField(obj_message, fid_messageId, jMessageId);\r
+\r
+ jfieldID fid_providerId = env->GetFieldID(cls_message, "mProviderId", "Ljava/lang/String;");\r
+ if (!fid_providerId)\r
+ {\r
+ LOGE("Failed to get field ProviderID for Message");\r
+ return;\r
+ }\r
+ env->SetObjectField(obj_message, fid_providerId, jProviderId);\r
+\r
+ jfieldID fid_time = env->GetFieldID(cls_message, "mTime", "Ljava/lang/String;");\r
+ if (!fid_time)\r
+ {\r
+ LOGE("Failed to get field Time for Message");\r
+ return;\r
+ }\r
+ env->SetObjectField(obj_message, fid_time, jTime);\r
+\r
+ jfieldID fid_ttl = env->GetFieldID(cls_message, "mTTL", "J");\r
+ if (!fid_ttl)\r
+ {\r
+ LOGE("Failed to get field TTL for Message");\r
+ return;\r
+ }\r
+ env->SetLongField(obj_message, fid_ttl, jTTL);\r
+\r
+ OIC::Service::NSMediaContents *mediaCont = message->getMediaContents();\r
+ if (mediaCont != nullptr)\r
+ {\r
+ jstring jIconImage = env->NewStringUTF(mediaCont->getIconImage().c_str());\r
+ jclass cls_mediaContents = (jclass) (env->NewLocalRef(g_cls_MediaContents));\r
+ if (!cls_mediaContents)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for MediaContents");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jmethodID mid_mediaContents = env->GetMethodID(\r
+ cls_mediaContents, "<init>", "(Ljava/lang/String;)V");\r
+ if (!mid_mediaContents)\r
+ {\r
+ LOGE ("Failed to Get MethodID for MediaContents<init>");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jobject obj_mediaContents = env->NewObject(cls_mediaContents, mid_mediaContents,\r
+ jIconImage);\r
+\r
+ jfieldID fid_mediaContents = env->GetFieldID(cls_message, "mMediaContents",\r
+ "Lorg/iotivity/service/ns/common/MediaContents;");\r
+ if (!fid_mediaContents)\r
+ {\r
+ LOGE("Failed to get field mediaContents for Message");\r
+ return;\r
+ }\r
+ env->SetObjectField(obj_message, fid_mediaContents, obj_mediaContents);\r
+\r
+ }\r
+\r
+ jobject jType = getJavaMessageType(env, message->getType());\r
+ if (!jType)\r
+ {\r
+ LOGE("Failed to get Type value for Message");\r
+ return;\r
+ }\r
+ jfieldID fid_type = env->GetFieldID(cls_message, "mType",\r
+ "Lorg/iotivity/service/ns/common/Message$MessageType;");\r
+ if (!fid_type)\r
+ {\r
+ LOGE("Failed to get field Type for Message");\r
+ return;\r
+ }\r
+ env->SetObjectField(obj_message, fid_type, jType);\r
+\r
+\r
+ jclass cls = env->GetObjectClass(jPostListener);\r
+ if (!cls)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for jPostListener");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jmethodID mid = env->GetMethodID(\r
+ cls,\r
+ "onMessageReceived",\r
+ "(Lorg/iotivity/service/ns/common/Message;)V");\r
+ if (!mid)\r
+ {\r
+ LOGE ("Failed to Get MethodID for onMessageReceived");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+\r
+ env->CallVoidMethod(jPostListener, mid, obj_message);\r
+\r
+ env->DeleteLocalRef(jPostListener);\r
+ env->DeleteLocalRef(cls_message);\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+}\r
+\r
+void onSyncInfoReceived(OIC::Service::NSSyncInfo *sync)\r
+{\r
+ LOGD ("ConsumerService_onSyncInfoReceived");\r
+\r
+ jint envRet;\r
+ JNIEnv *env = GetJNIEnv(&envRet);\r
+ if (NULL == env) return ;\r
+\r
+ jobject jSyncListener = (jobject) env->NewLocalRef(g_obj_syncListener);\r
+ if (!jSyncListener)\r
+ {\r
+ LOGE ("Failed to Get jSyncListener");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+\r
+ LOGD ("Sync ID : %llu\n", sync->getMessageId());\r
+ LOGD ("Sync ProviderId : %s\n", sync->getProviderId().c_str());\r
+ LOGD ("Sync STATE : %d\n", (int) sync->getState());\r
+\r
+ jlong jMessageId = (jlong) sync->getMessageId();\r
+ jstring jProviderId = env->NewStringUTF(sync->getProviderId().c_str());\r
+ jint jState = (jint) sync->getState();\r
+\r
+ jclass cls_sync = (jclass) (env->NewLocalRef(g_cls_SyncInfo));\r
+ if (!cls_sync)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for SyncInfo");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jmethodID mid_sync = env->GetMethodID(\r
+ cls_sync, "<init>", "(JLjava/lang/String;I)V");\r
+ if (!mid_sync)\r
+ {\r
+ LOGE ("Failed to Get MethodID for SyncInfo<init>");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jobject obj_sync = env->NewObject(cls_sync, mid_sync,\r
+ jMessageId, jProviderId, jState);\r
+\r
+ jclass cls = env->GetObjectClass(jSyncListener);\r
+ if (!cls)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for jSyncListener");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+ jmethodID mid = env->GetMethodID(\r
+ cls,\r
+ "onSyncInfoReceived",\r
+ "(Lorg/iotivity/service/ns/common/SyncInfo;)V");\r
+ if (!mid)\r
+ {\r
+ LOGE ("Failed to Get MethodID for onSyncInfoReceived");\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+ }\r
+\r
+ env->CallVoidMethod(jSyncListener, mid, obj_sync);\r
+\r
+ env->DeleteLocalRef(jSyncListener);\r
+ env->DeleteLocalRef(cls_sync);\r
+ if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
+ return ;\r
+}\r
+\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStart\r
+(JNIEnv *env, jobject jObj, jobject jDiscoverListener, jobject jAccpetListener)\r
+{\r
+ LOGD ("ConsumerService_StartConsumer");\r
+ if (!jDiscoverListener || !jAccpetListener)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Listener cannot be null");\r
+ return ;\r
+ }\r
+\r
+ if (g_obj_discoverListener != NULL)\r
+ {\r
+ env->DeleteGlobalRef(g_obj_discoverListener);\r
+ }\r
+ if (g_obj_acceptListener != NULL)\r
+ {\r
+ env->DeleteGlobalRef(g_obj_acceptListener);\r
+ }\r
+\r
+ g_obj_discoverListener = (jobject) env->NewGlobalRef(jDiscoverListener);\r
+ g_obj_acceptListener = (jobject) env->NewGlobalRef(jAccpetListener);\r
+\r
+ OIC::Service::NSConsumerService::ConsumerConfig cfg;\r
+ cfg.m_discoverCb = onDiscoverProvider;\r
+ cfg.m_acceptedCb = onSubscriptionAccepted;\r
+\r
+ OIC::Service::NSConsumerService::getInstance()->Start(cfg);\r
+\r
+}\r
+\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStop\r
+(JNIEnv *env, jobject jObj)\r
+{\r
+ LOGD ("ConsumerService_StopConsumer");\r
+\r
+ env->DeleteGlobalRef(g_obj_postListener);\r
+ env->DeleteGlobalRef(g_obj_discoverListener);\r
+ env->DeleteGlobalRef(g_obj_syncListener);\r
+ env->DeleteGlobalRef(g_obj_acceptListener);\r
+ g_obj_postListener = NULL;\r
+ g_obj_discoverListener = NULL;\r
+ g_obj_syncListener = NULL;\r
+ g_obj_acceptListener = NULL;\r
+ OIC::Service::NSConsumerService::getInstance()->Stop();\r
+}\r
+\r
+JNIEXPORT jint JNICALL\r
+Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService\r
+(JNIEnv *env, jobject jObj, jstring jServerAddress)\r
+{\r
+ LOGD ("ConsumerService_EnableRemoteService");\r
+ if (!jServerAddress)\r
+ {\r
+ ThrowNSException(NS_ERROR, "EnableRemoteService server address NULL");\r
+ return (jint) OIC::Service::Result::ERROR;\r
+ }\r
+ const char *serverAddress = env->GetStringUTFChars(jServerAddress, 0);\r
+ OIC::Service::Result res =\r
+ OIC::Service::NSConsumerService::getInstance()->EnableRemoteService(std::string(serverAddress));\r
+ env->ReleaseStringUTFChars(jServerAddress, serverAddress);\r
+ return (jint) res;\r
+}\r
+\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeRescanProvider\r
+(JNIEnv *env, jobject jObj)\r
+{\r
+ LOGD ("ConsumerService_RescanProvider");\r
+\r
+ OIC::Service::NSConsumerService::getInstance()->RescanProvider();\r
+}\r
+\r
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetProvider\r
+(JNIEnv *env, jobject jObj, jstring jProviderId)\r
+{\r
+ LOGD ("ConsumerService_GetProvider");\r
+ if (!jProviderId)\r
+ {\r
+ ThrowNSException(NS_ERROR, "ProviderId cannot be null");\r
+ return NULL;\r
+ }\r
+\r
+ const char *providerId = env->GetStringUTFChars(jProviderId, 0);\r
+\r
+ OIC::Service::NSProvider *provider =\r
+ OIC::Service::NSConsumerService::getInstance()->getProvider(std::string(providerId));\r
+ if (provider == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
+ return NULL;\r
+ }\r
+\r
+ LOGD ("ProviderId : %s\n", provider->getProviderId().c_str());\r
+\r
+ jProviderId = env->NewStringUTF(provider->getProviderId().c_str());\r
+ jlong pProvider = (long)provider;\r
+\r
+ jclass cls_provider = (jclass) (env->NewLocalRef(g_cls_Provider));\r
+ if (!cls_provider)\r
+ {\r
+ LOGE ("Failed to Get ObjectClass for Provider");\r
+ return NULL;\r
+ }\r
+ jmethodID mid_provider = env->GetMethodID(\r
+ cls_provider, "<init>", "(Ljava/lang/String;)V");\r
+ if (!mid_provider)\r
+ {\r
+ LOGE ("Failed to Get MethodID for Provider<init>");\r
+ return NULL;\r
+ }\r
+ jobject obj_provider = env->NewObject(cls_provider, mid_provider,\r
+ jProviderId);\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(cls_provider, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
+ return NULL;\r
+ }\r
+ env->SetLongField(obj_provider, nativeHandle, pProvider);\r
+\r
+ env->DeleteLocalRef(cls_provider);\r
+ env->ReleaseStringUTFChars(jProviderId, providerId);\r
+\r
+ return obj_provider;\r
+}\r
+\r
+OIC::Service::NSProvider *getNativeProvider(JNIEnv *env, jobject jObj)\r
+{\r
+ jclass providerClass = env->GetObjectClass(jObj);\r
+ if (!providerClass)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");\r
+ return NULL;\r
+ }\r
+ jfieldID jproviderId = env->GetFieldID(providerClass, "mProviderId", "Ljava/lang/String;");\r
+ if (!jproviderId)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to get providerId for Provider");\r
+ return NULL;\r
+ }\r
+ jstring jprovider_id = (jstring) env->GetObjectField(jObj, jproviderId);\r
+ if (!jprovider_id)\r
+ {\r
+ ThrowNSException(NS_ERROR, "ProviderId cannot be null");\r
+ return NULL;\r
+ }\r
+\r
+ const char *providerId = env->GetStringUTFChars(jprovider_id, 0);\r
+ LOGD ("ProviderId : %s\n", providerId);\r
+\r
+ OIC::Service::NSProvider *provider =\r
+ OIC::Service::NSConsumerService::getInstance()->getProvider(std::string(providerId));\r
+ if (provider == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
+ return NULL;\r
+ }\r
+ env->ReleaseStringUTFChars(jprovider_id, providerId);\r
+ return provider;\r
+}\r
+\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSubscribe\r
+(JNIEnv *env, jobject jObj)\r
+{\r
+ LOGD ("Provider_Subscribe");\r
+ jclass providerClass = env->GetObjectClass(jObj);\r
+ if (!providerClass)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");\r
+ return ;\r
+ }\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
+ return ;\r
+ }\r
+ jlong jProvider = env->GetLongField(jObj, nativeHandle);\r
+ if (jProvider)\r
+ {\r
+ LOGD ("calling subscribe on mNativeHandle");\r
+ OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
+ provider->subscribe();\r
+ }\r
+ else\r
+ {\r
+ OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);\r
+ if (provider == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
+ return;\r
+ }\r
+ LOGD ("calling subscribe on ProviderID");\r
+ provider->subscribe();\r
+ }\r
+}\r
+\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUnsubscribe\r
+(JNIEnv *env, jobject jObj)\r
+{\r
+ LOGD ("Provider_Unsubscribe");\r
+\r
+ jclass providerClass = env->GetObjectClass(jObj);\r
+ if (!providerClass)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");\r
+ return ;\r
+ }\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
+ return ;\r
+ }\r
+ jlong jProvider = env->GetLongField(jObj, nativeHandle);\r
+ if (jProvider)\r
+ {\r
+ LOGD ("calling unSubscribe on mNativeHandle");\r
+ OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
+ provider->unSubscribe();\r
+ }\r
+ else\r
+ {\r
+ OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);\r
+ if (provider == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
+ return;\r
+ }\r
+ LOGD ("calling unSubscribe on ProviderID");\r
+ provider->unSubscribe();\r
+ }\r
+}\r
+\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSendSyncInfo\r
+(JNIEnv *env, jobject jObj, jlong jMessageId, jint jSyncType)\r
+{\r
+ LOGD ("Provider_SendSyncInfo");\r
+ if (!jMessageId)\r
+ {\r
+ ThrowNSException(NS_ERROR, "MessageId cannot be 0");\r
+ return ;\r
+ }\r
+\r
+ jclass providerClass = env->GetObjectClass(jObj);\r
+ if (!providerClass)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");\r
+ return ;\r
+ }\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
+ return ;\r
+ }\r
+ uint64_t messageId = (uint64_t) jMessageId;\r
+\r
+ LOGD("!!!!!!jMessageId: %lld", jMessageId);\r
+ LOGD("!!!!!!messageId: %lld", messageId);\r
+\r
+ jlong jProvider = env->GetLongField(jObj, nativeHandle);\r
+ if (jProvider)\r
+ {\r
+ LOGD ("calling SendSyncInfo on mNativeHandle");\r
+ OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
+ provider->SendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType);\r
+ }\r
+ else\r
+ {\r
+ OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);\r
+ if (provider == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
+ return;\r
+ }\r
+ LOGD ("calling SendSyncInfo on ProviderID");\r
+ provider->SendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType);\r
+ }\r
+}\r
+\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetListener\r
+(JNIEnv *env, jobject jObj, jobject jPostListener, jobject jSyncListener)\r
+{\r
+ LOGD ("Provider_SetListener");\r
+ if (!jPostListener || !jSyncListener)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Listener cannot be null");\r
+ return ;\r
+ }\r
+\r
+ jclass providerClass = env->GetObjectClass(jObj);\r
+ if (!providerClass)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");\r
+ return ;\r
+ }\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
+ return ;\r
+ }\r
+ jlong jProvider = env->GetLongField(jObj, nativeHandle);\r
+ if (jProvider)\r
+ {\r
+ LOGD ("calling SetListener on mNativeHandle");\r
+ if (g_obj_postListener != NULL)\r
+ {\r
+ env->DeleteGlobalRef(g_obj_postListener);\r
+ }\r
+ if (g_obj_syncListener != NULL)\r
+ {\r
+ env->DeleteGlobalRef(g_obj_syncListener);\r
+ }\r
+ g_obj_syncListener = NULL;\r
+ g_obj_acceptListener = NULL;\r
+ g_obj_postListener = (jobject) env->NewGlobalRef(jPostListener);\r
+ g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener);\r
+\r
+ OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
+ provider->setListener(onMessagePosted, onSyncInfoReceived);\r
+ }\r
+ else\r
+ {\r
+ OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);\r
+ if (provider == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
+ return;\r
+ }\r
+ LOGD ("calling SetListener on ProviderID");\r
+ if (g_obj_postListener != NULL)\r
+ {\r
+ env->DeleteGlobalRef(g_obj_postListener);\r
+ }\r
+ if (g_obj_syncListener != NULL)\r
+ {\r
+ env->DeleteGlobalRef(g_obj_syncListener);\r
+ }\r
+ g_obj_syncListener = NULL;\r
+ g_obj_acceptListener = NULL;\r
+ g_obj_postListener = (jobject) env->NewGlobalRef(jPostListener);\r
+ g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener);\r
+\r
+ provider->setListener(onMessagePosted, onSyncInfoReceived);\r
+ }\r
+}\r
+\r
+// JNI OnLoad\r
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)\r
+{\r
+ LOGD("ConsumerService_JNI_OnLoad");\r
+ g_jvm = jvm;\r
+\r
+ JNIEnv *env;\r
+ if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)\r
+ {\r
+ LOGE("Failed to get the environment using GetEnv()");\r
+ return JNI_ERR;\r
+ }\r
+\r
+ jclass localMessage = env->FindClass(\r
+ "org/iotivity/service/ns/common/Message");\r
+ if (!localMessage)\r
+ {\r
+ LOGE("Failed to get local Message class");\r
+ return JNI_ERR;\r
+ }\r
+ g_cls_Message = (jclass) (env->NewGlobalRef(localMessage));\r
+ if (!g_cls_Message)\r
+ {\r
+ LOGE("Failed to set Global Message reference");\r
+ return JNI_ERR;\r
+ }\r
+\r
+ jclass localProvider = env->FindClass(\r
+ "org/iotivity/service/ns/consumer/Provider");\r
+ if (!localProvider)\r
+ {\r
+ LOGE("Failed to get local Provider class");\r
+ return JNI_ERR;\r
+ }\r
+ g_cls_Provider = (jclass) (env->NewGlobalRef(localProvider));\r
+ if (!g_cls_Provider)\r
+ {\r
+ LOGE("Failed to set Global Provider reference");\r
+ return JNI_ERR;\r
+ }\r
+\r
+ jclass localSyncInfo = env->FindClass(\r
+ "org/iotivity/service/ns/common/SyncInfo");\r
+ if (!localSyncInfo)\r
+ {\r
+ LOGE("Failed to get local SyncInfo class");\r
+ return JNI_ERR;\r
+ }\r
+ g_cls_SyncInfo = (jclass) (env->NewGlobalRef(localSyncInfo));\r
+ if (!g_cls_SyncInfo)\r
+ {\r
+ LOGE("Failed to set Global NSSyncInfo reference");\r
+ return JNI_ERR;\r
+ }\r
+\r
+ jclass localMediaContents = env->FindClass(\r
+ "org/iotivity/service/ns/common/MediaContents");\r
+ if (!localMediaContents)\r
+ {\r
+ LOGE("Failed to get local MediaContents class");\r
+ return JNI_ERR;\r
+ }\r
+ g_cls_MediaContents = (jclass) (env->NewGlobalRef(localMediaContents));\r
+ if (!g_cls_MediaContents)\r
+ {\r
+ LOGE("Failed to set Global MediaContents reference");\r
+ return JNI_ERR;\r
+ }\r
+\r
+ env->DeleteLocalRef(localMessage);\r
+ env->DeleteLocalRef(localProvider);\r
+ env->DeleteLocalRef(localSyncInfo);\r
+ env->DeleteLocalRef(localMediaContents);\r
+\r
+ return NSExceptionInit(env);\r
+}\r
+\r
+JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)\r
+{\r
+ LOGI("ConsumerService_JNI_OnUnload");\r
+ JNIEnv *env;\r
+\r
+ if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)\r
+ {\r
+ LOGE("Failed to get the environment using GetEnv()");\r
+ return ;\r
+ }\r
+\r
+ env->DeleteGlobalRef(g_cls_Message);\r
+ env->DeleteGlobalRef(g_cls_Provider);\r
+ env->DeleteGlobalRef(g_cls_SyncInfo);\r
+ env->DeleteGlobalRef(g_cls_MediaContents);\r
+}\r
--- /dev/null
+//******************************************************************\r
+//\r
+// Copyright 2016 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+/* DO NOT EDIT THIS FILE - it is machine generated */\r
+#include "JniNotificationCommon.h"\r
+\r
+#ifndef JNI_NOTIFICATION_CONSUMER_H\r
+#define JNI_NOTIFICATION_CONSUMER_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_ConsumerService\r
+ * Method: nativeStart\r
+ * Signature: (Lorg/iotivity/service/ns/consumer/ConsumerService/OnProviderDiscoveredListner;Lorg/iotivity/service/ns/consumer/ConsumerService/OnSubscriptionAcceptedListener;)V\r
+ */\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStart\r
+(JNIEnv *, jobject, jobject, jobject);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_ConsumerService\r
+ * Method: nativeStop\r
+ * Signature: ()V\r
+ */\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStop\r
+(JNIEnv *, jobject);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_ConsumerService\r
+ * Method: nativeEnableRemoteService\r
+ * Signature: (Ljava/lang/String;)jint\r
+ */\r
+JNIEXPORT jint JNICALL\r
+Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService\r
+(JNIEnv *, jobject, jstring);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_ConsumerService\r
+ * Method: nativeRescanProvider\r
+ * Signature: ()V\r
+ */\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeRescanProvider\r
+(JNIEnv *, jobject);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_ConsumerService\r
+ * Method: nativeGetProvider\r
+ * Signature: (Ljava/lang/String;)Lorg/iotivity/service/ns/consumer/Provider;\r
+ */\r
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetProvider\r
+(JNIEnv *, jobject, jstring);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_Provider\r
+ * Method: nativeSubscribe\r
+ * Signature: ()V\r
+ */\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSubscribe\r
+(JNIEnv *, jobject);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_Provider\r
+ * Method: nativeUnsubscribe\r
+ * Signature: ()V\r
+ */\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUnsubscribe\r
+(JNIEnv *, jobject);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_Provider\r
+ * Method: nativeSendSyncInfo\r
+ * Signature: (JI)V\r
+ */\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSendSyncInfo\r
+(JNIEnv *, jobject, jlong, jint);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_Provider\r
+ * Method: nativeSetListener\r
+ * Signature: (Lorg/iotivity/service/ns/consumer/Provider/OnMessageReceivedListner;Lorg/iotivity/service/ns/consumer/Provider/OnSyncInfoReceivedListner;)V\r
+ */\r
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetListener\r
+(JNIEnv *, jobject, jobject, jobject);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif\r
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include "notificationConsumer.h"
-
-static JavaVM* g_jvm = NULL;
-
-static jobject g_obj_postListener = NULL;
-static jobject g_obj_discoverListener = NULL;
-static jobject g_obj_syncListener = NULL;
-static jobject g_obj_acceptListener = NULL;
-
-jclass g_cls_NSMessage;
-jclass g_cls_NSProvider;
-jclass g_cls_NSSyncInfo;
-
-static JNIEnv * GetJNIEnv(jint * ret)
-{
- JNIEnv * env = NULL;
-
- *ret = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_CURRENT_VERSION);
- switch (*ret) {
- case JNI_OK:
- return env;
- case JNI_EDETACHED:
- if ((*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL) != JNI_OK)
- {
- LOGE ("Failed to get the environment");
- return NULL;
- }
- else
- {
- return env;
- }
- case JNI_EVERSION:
- LOGE ("JNI version is not supported");
- default:
- LOGE ("Failed to get the environment");
- return NULL;
- }
-}
-
-void onMessagePosted(NSMessage * message)
-{
- LOGD ("ConsumerService_onMessagePosted");
-
- jint envRet;
- JNIEnv *env = GetJNIEnv(&envRet);
- if (NULL == env) return ;
-
- jobject jPostListener = (jobject) (*env)->NewLocalRef(env, g_obj_postListener);
- if (!jPostListener)
- {
- LOGE ("Failed to Get jPostListener");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
-
- LOGD ("id : %llu\n", message->messageId);
- LOGD ("title : %s\n", message->title);
- LOGD ("content : %s\n", message->contentText);
- LOGD ("source : %s\n", message->sourceName);
-
- jlong jMessageId = (jlong) message->messageId;
- jstring jProviderId = (*env)->NewStringUTF(env, message->providerId);
- jstring jTitle = (*env)->NewStringUTF(env, message->title);
- jstring jContentText = (*env)->NewStringUTF(env, message->contentText);
- jstring jSourceName = (*env)->NewStringUTF(env, message->sourceName);
- jlong pMessage = (long) message;
-
- jclass cls_message = (jclass) ((*env)->NewLocalRef(env, g_cls_NSMessage));
- if (!cls_message)
- {
- LOGE ("Failed to Get ObjectClass for NSMessage");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jmethodID mid_message = (*env)->GetMethodID(
- env, cls_message, "<init>",
- "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V");
- if (!mid_message)
- {
- LOGE ("Failed to Get MethodID for NSMessage<init>");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jobject obj_message = (*env)->NewObject(env, cls_message, mid_message,
- jMessageId, jProviderId, jTitle, jContentText, jSourceName, pMessage);
-
- jclass cls = (*env)->GetObjectClass(env, jPostListener);
- if (!cls)
- {
- LOGE ("Failed to Get ObjectClass for jPostListener");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jmethodID mid = (*env)->GetMethodID(env,
- cls,
- "onMessageReceived",
- "(Lorg/iotivity/service/ns/consumer/NSMessage;)V");
- if (!mid)
- {
- LOGE ("Failed to Get MethodID for onMessageReceived");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
-
- (*env)->CallVoidMethod(env, jPostListener, mid, obj_message);
-
- (*env)->DeleteLocalRef(env, jPostListener);
- (*env)->DeleteLocalRef(env, cls_message);
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
-}
-
-
-void onDiscoverProvider(NSProvider * provider)
-{
- LOGD ("ConsumerService_onDiscoverProvider");
-
- jint envRet;
- JNIEnv *env = GetJNIEnv(&envRet);
- if (NULL == env) return ;
-
- jobject jDiscoverListener = (jobject) (*env)->NewLocalRef(env, g_obj_discoverListener);
- if (!jDiscoverListener)
- {
- LOGE ("Failed to Get jDiscoverListener");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
-
- LOGD ("ProviderId : %s\n", provider->providerId);
-
- jstring jProviderId = (*env)->NewStringUTF(env, provider->providerId);
- jlong pProvider = (long)provider;
-
- jclass cls_provider = (jclass) ((*env)->NewLocalRef(env, g_cls_NSProvider));
- if (!cls_provider)
- {
- LOGE ("Failed to Get ObjectClass for NSProvider");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jmethodID mid_provider = (*env)->GetMethodID(
- env, cls_provider, "<init>", "(Ljava/lang/String;J)V");
- if (!mid_provider)
- {
- LOGE ("Failed to Get MethodID for NSProvider<init>");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jobject obj_provider = (*env)->NewObject(env, cls_provider, mid_provider,
- jProviderId, pProvider);
-
- jclass cls = (*env)->GetObjectClass(env, jDiscoverListener);
- if (!cls)
- {
- LOGE ("Failed to Get ObjectClass for jDiscoverListener");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jmethodID mid = (*env)->GetMethodID(env,
- cls,
- "onProviderDiscovered",
- "(Lorg/iotivity/service/ns/consumer/NSProvider;)V");
- if (!mid)
- {
- LOGE ("Failed to Get MethodID for onProviderDiscovered");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
-
- (*env)->CallVoidMethod(env, jDiscoverListener, mid, obj_provider);
-
- (*env)->DeleteLocalRef(env, jDiscoverListener);
- (*env)->DeleteLocalRef(env, cls_provider);
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
-}
-
-
-void onSyncInfoReceived(NSSyncInfo * sync)
-{
- LOGD ("ConsumerService_onSyncInfoReceived");
-
- jint envRet;
- JNIEnv *env = GetJNIEnv(&envRet);
- if (NULL == env) return ;
-
- jobject jSyncListener = (jobject) (*env)->NewLocalRef(env, g_obj_syncListener);
- if (!jSyncListener)
- {
- LOGE ("Failed to Get jSyncListener");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
-
- LOGD ("Sync ID : %llu\n", sync->messageId);
- LOGD ("Sync ProviderId : %s\n", sync->providerId);
- LOGD ("Sync STATE : %d\n", sync->state);
-
- jlong jMessageId = (jlong) sync->messageId;
- jstring jProviderId = (*env)->NewStringUTF(env, sync->providerId);
- jint jState = (jint) sync->state;
-
- jclass cls_sync = (jclass) ((*env)->NewLocalRef(env, g_cls_NSSyncInfo));
- if (!cls_sync)
- {
- LOGE ("Failed to Get ObjectClass for NSSyncInfo");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jmethodID mid_sync = (*env)->GetMethodID(
- env, cls_sync, "<init>", "(JLjava/lang/String;I)V");
- if (!mid_sync)
- {
- LOGE ("Failed to Get MethodID for NSSyncInfo<init>");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jobject obj_sync = (*env)->NewObject(env, cls_sync, mid_sync,
- jMessageId, jProviderId, jState);
-
- jclass cls = (*env)->GetObjectClass(env, jSyncListener);
- if (!cls)
- {
- LOGE ("Failed to Get ObjectClass for jSyncListener");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jmethodID mid = (*env)->GetMethodID(env,
- cls,
- "onSyncInfoReceived",
- "(Lorg/iotivity/service/ns/consumer/NSSyncInfo;)V");
- if (!mid)
- {
- LOGE ("Failed to Get MethodID for onSyncInfoReceived");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
-
- (*env)->CallVoidMethod(env, jSyncListener, mid, obj_sync);
-
- (*env)->DeleteLocalRef(env, jSyncListener);
- (*env)->DeleteLocalRef(env, cls_sync);
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
-}
-
-void onSubscriptionAccepted(NSProvider * provider)
-{
- LOGD ("ConsumerService_onSubscriptionAccepted");
-
- jint envRet;
- JNIEnv *env = GetJNIEnv(&envRet);
- if (NULL == env) return ;
-
- jobject jAcceptListener = (jobject) (*env)->NewLocalRef(env, g_obj_acceptListener);
- if (!jAcceptListener)
- {
- LOGE ("Failed to Get jAcceptListener");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
-
- LOGD ("ProviderId : %s\n", provider->providerId);
-
- jstring jProviderId = (*env)->NewStringUTF(env, provider->providerId);
- jlong pProvider = (long)provider;
-
- jclass cls_provider = (jclass) ((*env)->NewLocalRef(env, g_cls_NSProvider));
- if (!cls_provider)
- {
- LOGE ("Failed to Get ObjectClass for NSProvider");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jmethodID mid_provider = (*env)->GetMethodID(
- env, cls_provider, "<init>", "(Ljava/lang/String;J)V");
- if (!mid_provider)
- {
- LOGE ("Failed to Get MethodID for NSProvider<init>");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jobject obj_provider = (*env)->NewObject(env, cls_provider, mid_provider,
- jProviderId, pProvider);
-
- jclass cls = (*env)->GetObjectClass(env, jAcceptListener);
- if (!cls)
- {
- LOGE ("Failed to Get ObjectClass for jAcceptListener");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
- jmethodID mid = (*env)->GetMethodID(env,
- cls,
- "onSubscriptionAccepted",
- "(Lorg/iotivity/service/ns/consumer/NSProvider;)V");
- if (!mid)
- {
- LOGE ("Failed to Get MethodID for onSubscriptionAccepted");
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
- }
-
- (*env)->CallVoidMethod(env, jAcceptListener, mid, obj_provider);
-
- (*env)->DeleteLocalRef(env, jAcceptListener);
- (*env)->DeleteLocalRef(env, cls_provider);
- if (JNI_EDETACHED == envRet) (*g_jvm)->DetachCurrentThread(g_jvm);
- return ;
-
-}
-
-
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_Start
-(JNIEnv * env, jobject jObj, jobject jDiscoverListener, jobject jAccpetListener)
-{
- LOGD ("ConsumerService_StartConsumer");
- if (!jDiscoverListener || !jAccpetListener)
- {
- ThrowNSException(NS_ERROR, "Listener cannot be null");
- return ;
- }
-
- //g_obj_postListener = (jobject) (*env)->NewGlobalRef(env, jPostListener);
- g_obj_discoverListener = (jobject) (*env)->NewGlobalRef(env, jDiscoverListener);
- //g_obj_syncListener = (jobject) (*env)->NewGlobalRef(env, jSyncListener);
- g_obj_acceptListener = (jobject) (*env)->NewGlobalRef(env, jAccpetListener);
-
- NSConsumerConfig cfg;
- cfg.discoverCb = onDiscoverProvider;
- cfg.acceptedCb = onSubscriptionAccepted;
- cfg.messageCb = onMessagePosted;
- cfg.syncInfoCb = onSyncInfoReceived;
-
- NSResult result = NSStartConsumer(cfg);
- if (NS_OK != result)
- {
- ThrowNSException(result, "Failed to start Consumer");
- }
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_Stop
-(JNIEnv * env, jobject jObj)
-{
- LOGD ("ConsumerService_StopConsumer");
-
- (*env)->DeleteGlobalRef(env, g_obj_postListener);
- (*env)->DeleteGlobalRef(env, g_obj_discoverListener);
- (*env)->DeleteGlobalRef(env, g_obj_syncListener);
- (*env)->DeleteGlobalRef(env, g_obj_acceptListener);
-
- NSResult result = NSStopConsumer();
- if (NS_OK != result)
- {
- ThrowNSException(result, "Failed to stop Consumer");
- }
-}
-
-JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_GetProvider
-(JNIEnv * env, jobject jObj, jobject jProviderId)
-{
- LOGD ("ConsumerService_GetProvider");
- if (!jProviderId)
- {
- ThrowNSException(NS_ERROR, "ProviderId cannot be null");
- return NULL;
- }
-
- const char * providerId = (*env)->GetStringUTFChars(env, jProviderId, 0);
-
- NSProvider * provider = NSConsumerGetProvider(providerId);
- LOGD ("ProviderId : %s\n", provider->providerId);
-
- jProviderId = (*env)->NewStringUTF(env, provider->providerId);
- jlong pProvider = (long)provider;
-
- jclass cls_provider = (jclass) ((*env)->NewLocalRef(env, g_cls_NSProvider));
- if (!cls_provider)
- {
- LOGE ("Failed to Get ObjectClass for NSProvider");
- return NULL;
- }
- jmethodID mid_provider = (*env)->GetMethodID(
- env, cls_provider, "<init>", "(Ljava/lang/String;J)V");
- if (!mid_provider)
- {
- LOGE ("Failed to Get MethodID for NSProvider<init>");
- return NULL;
- }
- jobject obj_provider = (*env)->NewObject(env, cls_provider, mid_provider,
- jProviderId, pProvider);
-
- (*env)->DeleteLocalRef(env, cls_provider);
-
- return obj_provider;
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_NSProvider_Subscribe
-(JNIEnv * env, jobject jObj, jlong jProvider)
-{
- LOGD ("NSProvider_Subscribe");
- if (!jProvider)
- {
- ThrowNSException(NS_ERROR, "Provider object cannot be null");
- return ;
- }
-
- NSProvider * provider = (NSProvider *) (jProvider);
-
- NSResult result = NSSubscribe(provider);
- if (NS_OK != result)
- {
- ThrowNSException(result, "Failed to subscribe provider");
- }
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_NSProvider_Unsubscribe
-(JNIEnv * env, jobject jObj, jlong jProvider)
-{
- LOGD ("NSProvider_Unsubscribe");
- if (!jProvider)
- {
- ThrowNSException(NS_ERROR, "Provider object cannot be null");
- return ;
- }
-
- NSProvider * provider = (NSProvider *) (jProvider);
-
- NSResult result = NSUnsubscribe(provider);
- if (NS_OK != result)
- {
- ThrowNSException(result, "Failed to unsubscribe provider");
- }
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_NSProvider_SendSyncInfo
-(JNIEnv * env, jobject jObj, jobject jProviderId, jlong jMessageId, jint jSyncType)
-{
- LOGD ("NSProvider_Unsubscribe");
- if (!jProviderId)
- {
- ThrowNSException(NS_ERROR, "ProviderId cannot be null");
- return ;
- }
- if (!jMessageId)
- {
- ThrowNSException(NS_ERROR, "MessageId cannot be 0");
- return ;
- }
-
- const char * providerId = (*env)->GetStringUTFChars(env, jProviderId, 0);
- uint64_t messageId = (uint64_t) jMessageId;
-
- LOGD("!!!!!!jMessageId: %lld", jMessageId);
- LOGD("!!!!!!messageId: %lld", messageId);
-
- NSResult result = NSConsumerSendSyncInfo(providerId, messageId, (int)jSyncType);
- if (NS_OK != result)
- {
- ThrowNSException(result, "Failed to Send SyncInfo");
- }
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_NSProvider_SetListener
-(JNIEnv * env, jobject jObj, jobject jPostListener, jobject jSyncListener)
-{
- LOGD ("NSProvider_SetListener");
- if (!jPostListener || !jSyncListener)
- {
- ThrowNSException(NS_ERROR, "Listener cannot be null");
- return ;
- }
-
- g_obj_postListener = (jobject) (*env)->NewGlobalRef(env, jPostListener);
- g_obj_syncListener = (jobject) (*env)->NewGlobalRef(env, jSyncListener);
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_RescanProvider
-(JNIEnv * env, jobject jObj)
-{
- LOGD ("ConsumerService_RescanProvider");
-
- NSResult result = NSRescanProvider();
- if (NS_OK != result)
- {
- ThrowNSException(result, "Failed to rescan provider");
- }
-}
-
-// JNI OnLoad
-JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM * jvm, void * reserved)
-{
- LOGD("ConsumerService_JNI_OnLoad");
- g_jvm = jvm;
-
- JNIEnv * env;
- if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
- {
- LOGE("Failed to get the environment using GetEnv()");
- return JNI_ERR;
- }
-
- jclass localNSMessage = (*env)->FindClass(env,
- "org/iotivity/service/ns/consumer/NSMessage");
- if (!localNSMessage)
- {
- LOGE("Failed to get local NSMessage");
- return JNI_ERR;
- }
- g_cls_NSMessage = (jclass) ((*env)->NewGlobalRef(env, localNSMessage));
- if (!g_cls_NSMessage)
- {
- LOGE("Failed to set Global NSMessage");
- return JNI_ERR;
- }
-
- jclass localNSProvider = (*env)->FindClass(env,
- "org/iotivity/service/ns/consumer/NSProvider");
- if (!localNSProvider)
- {
- LOGE("Failed to get local NSProvider");
- return JNI_ERR;
- }
- g_cls_NSProvider = (jclass) ((*env)->NewGlobalRef(env, localNSProvider));
- if (!g_cls_NSProvider)
- {
- LOGE("Failed to set Global NSProvider");
- return JNI_ERR;
- }
-
- jclass localNSSyncInfo = (*env)->FindClass(env,
- "org/iotivity/service/ns/consumer/NSSyncInfo");
- if (!localNSSyncInfo)
- {
- LOGE("Failed to get local NSSyncInfo");
- return JNI_ERR;
- }
- g_cls_NSSyncInfo = (jclass) ((*env)->NewGlobalRef(env, localNSSyncInfo));
- if (!g_cls_NSSyncInfo)
- {
- LOGE("Failed to set Global NSSyncInfo");
- return JNI_ERR;
- }
-
- (*env)->DeleteLocalRef(env, localNSMessage);
- (*env)->DeleteLocalRef(env, localNSProvider);
- (*env)->DeleteLocalRef(env, localNSSyncInfo);
-
- return NSExceptionInit(env);
-}
-
-JNIEXPORT void JNICALL JNI_OnUnload(JavaVM * jvm, void * reserved)
-{
- LOGI("ConsumerService_JNI_OnUnload");
- JNIEnv * env;
-
- if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
- {
- LOGE("Failed to get the environment using GetEnv()");
- return ;
- }
-
- (*env)->DeleteGlobalRef(env, g_cls_NSMessage);
- (*env)->DeleteGlobalRef(env, g_cls_NSProvider);
- (*env)->DeleteGlobalRef(env, g_cls_NSSyncInfo);
-}
\ No newline at end of file
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include "jniNSCommon.h"
-
-#include "NSConsumerInterface.h"
-//#include "NSConsumerCommon.h"
-/* Header for class org_iotivity_service_ns_consumer */
-
-#ifndef NOTIFICATION_CONSUMER_JNI_H
-#define NOTIFICATION_CONSUMER_JNI_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
-* Class: org_iotivity_service_ns_consumer_ConsumerService
-* Method: Start
-* Signature:
-*/
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_Start
-(JNIEnv *, jobject, jobject, jobject);
-
-/*
-* Class: org_iotivity_service_ns_consumer_ConsumerService
-* Method: Stop
-* Signature: (V)V
-*/
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_Stop
-(JNIEnv *, jobject);
-
-/*
-* Class: org_iotivity_service_ns_consumer_ConsumerService
-* Method: GetProvider
-* Signature: (Ljava/lang/String;)Lorg/iotivity/service/ns/consumer/NSProvider;
-*/
-JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_GetProvider
-(JNIEnv *, jobject, jobject);
-
-/*
-* Class: org_iotivity_service_ns_consumer_NSProvider
-* Method: Subscribe
-* Signature: (J)V
-*/
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_NSProvider_Subscribe
-(JNIEnv *, jobject, jlong);
-
-/*
-* Class: org_iotivity_service_ns_consumer_NSProvider
-* Method: Unsubscribe
-* Signature: (J)V
-*/
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_NSProvider_Unsubscribe
-(JNIEnv *, jobject, jlong);
-
-/*
-* Class: org_iotivity_service_ns_consumer_NSProvider
-* Method: SendSyncInfo
-* Signature: (Ljava/lang/String;JI)V
-*/
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_NSProvider_SendSyncInfo
-(JNIEnv *, jobject, jobject, jlong, jint);
-
-/*
-* Class: org_iotivity_service_ns_consumer_NSProvider
-* Method: SetListener
-* Signature:
-*/
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_NSProvider_SetListener
-(JNIEnv *, jobject, jobject, jobject);
-
-/*
-* Class: org_iotivity_service_ns_consumer_ConsumerService
-* Method: NSRescanProvider
-* Signature: (V)V
-*/
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_NSRescanProvider
-(JNIEnv *, jobject);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
\ No newline at end of file
'oc_logger',
'notification_consumer'
])
-notification_env.AppendUnique(CXXFLAGS = ['-O2', '-Wall', '-fmessage-length=0', '-std=c++0x','-frtti'])
+
+notification_env.AppendUnique(CXXFLAGS = ['-std=c++0x','-frtti'])
+
+if target_os not in ['windows', 'winrt']:
+ notification_env.AppendUnique(CCFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0'])
+
+if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
+ notification_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
+
+if target_os == 'linux':
+ notification_env.AppendUnique(LIBS = ['pthread'])
+
if target_os == 'android':
notification_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
notification_env.PrependUnique(LIBS = ['gnustl_shared', 'log'])
-if env.get('WITH_CLOUD') == True:
+if not env.get('RELEASE'):
+ notification_env.PrependUnique(LIBS = ['gcov'])
+ notification_env.AppendUnique(CCFLAGS = ['--coverage'])
+
+if env.get('WITH_CLOUD') == True:
notification_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
######################################################################
'libcoap'
])
+notification_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x','-frtti'])
if target_os not in ['windows', 'winrt']:
- notification_sample_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+ notification_sample_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0'])
if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
notification_sample_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
notification_sample_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
notification_sample_env.AppendUnique(LIBS = ['gnustl_shared','log'])
- if not env.get('RELEASE'):
- notification_sample_env.AppendUnique(LIBS = ['log'])
+if not env.get('RELEASE'):
+ notification_sample_env.PrependUnique(LIBS = ['gcov'])
+ notification_sample_env.AppendUnique(CCFLAGS = ['--coverage'])
-if env.get('WITH_CLOUD') == True:
+if env.get('WITH_CLOUD') == True:
notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
####################################################################
'oc_logger',
'notification_provider'
])
-notification_env.AppendUnique(CXXFLAGS = ['-O2', '-Wall', '-fmessage-length=0', '-std=c++0x','-frtti'])
+notification_env.AppendUnique(CXXFLAGS = ['-std=c++0x','-frtti'])
+
+if target_os not in ['windows', 'winrt']:
+ notification_env.AppendUnique(CCFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0'])
+
+if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
+ notification_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
+
+if target_os == 'linux':
+ notification_env.AppendUnique(LIBS = ['pthread'])
+
if target_os == 'android':
notification_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
notification_env.PrependUnique(LIBS = ['gnustl_shared', 'log'])
-if env.get('WITH_CLOUD') == True:
+if not env.get('RELEASE'):
+ notification_env.PrependUnique(LIBS = ['gcov'])
+ notification_env.AppendUnique(CCFLAGS = ['--coverage'])
+
+if env.get('WITH_CLOUD') == True:
notification_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
######################################################################
--- /dev/null
+*.iml\r
+.gradle\r
+/local.properties\r
+/.idea/workspace.xml\r
+/.idea/libraries\r
+.DS_Store\r
+/build\r
+/captures\r
--- /dev/null
+apply plugin: 'com.android.application'\r
+\r
+android {\r
+ compileSdkVersion 23\r
+ buildToolsVersion "23.0.1"\r
+\r
+ defaultConfig {\r
+ applicationId "sample.notification.service.iotivity.org.notificationconsumersample"\r
+ minSdkVersion 21\r
+ targetSdkVersion 23\r
+ versionCode 1\r
+ versionName "1.0"\r
+ }\r
+}\r
+\r
+dependencies {\r
+ compile fileTree(include: ['*.jar'], dir: 'libs')\r
+ compile 'com.android.support:appcompat-v7:23.0.1'\r
+ compile project(':iotivity-base-armeabi-debug')\r
+ compile project(':iotivity-armeabi-notification-service-debug')\r
+}\r
--- /dev/null
+# Add project specific ProGuard rules here.\r
+# By default, the flags in this file are appended to flags specified\r
+# in D:\adt-bundle-windows-x86_64-20140321\sdk/tools/proguard/proguard-android.txt\r
+# You can edit the include path and order by changing the proguardFiles\r
+# directive in build.gradle.\r
+#\r
+# For more details, see\r
+# http://developer.android.com/guide/developing/tools/proguard.html\r
+\r
+# Add any project specific keep options here:\r
+\r
+# If your project uses WebView with JS, uncomment the following\r
+# and specify the fully qualified class name to the JavaScript interface\r
+# class:\r
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {\r
+# public *;\r
+#}\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"\r
+ package="com.sec.noticonsumerexample">\r
+\r
+ <uses-feature android:name="android.hardware.nfc" />\r
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />\r
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />\r
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />\r
+ <uses-permission android:name="android.permission.BLUETOOTH"/>\r
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>\r
+ <uses-permission android:name="android.permission.INTERNET"/>\r
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>\r
+ <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>\r
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>\r
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>\r
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>\r
+ <uses-permission android:name="android.permission.NFC" />\r
+\r
+ <application\r
+ android:allowBackup="true"\r
+ android:icon="@mipmap/ic_launcher"\r
+ android:label="@string/app_name"\r
+ android:supportsRtl="true"\r
+ android:theme="@style/AppTheme">\r
+ <activity android:name=".MainActivity">\r
+ <intent-filter>\r
+ <action android:name="android.intent.action.MAIN" />\r
+\r
+ <category android:name="android.intent.category.LAUNCHER" />\r
+ </intent-filter>\r
+ </activity>\r
+\r
+\r
+ </application>\r
+\r
+</manifest>\r
--- /dev/null
+/******************************************************************\r
+ * Copyright 2016 Samsung Electronics All Rights Reserved.\r
+ * <p>\r
+ * <p>\r
+ * <p>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ ******************************************************************/\r
+\r
+package com.sec.noticonsumerexample;\r
+\r
+import android.app.NotificationManager;\r
+import android.content.Context;\r
+import android.os.Handler;\r
+import android.os.Message;\r
+import android.util.Log;\r
+import android.widget.Toast;\r
+\r
+import org.iotivity.base.ModeType;\r
+import org.iotivity.base.OcPlatform;\r
+import org.iotivity.base.OcResourceHandle;\r
+import org.iotivity.base.PlatformConfig;\r
+import org.iotivity.base.QualityOfService;\r
+import org.iotivity.base.ServiceType;\r
+import org.iotivity.service.ns.common.SyncInfo;\r
+import org.iotivity.service.ns.consumer.ConsumerService;\r
+import org.iotivity.service.ns.consumer.Provider;\r
+\r
+import java.util.HashMap;\r
+\r
+public class ConsumerProxy\r
+ implements ConsumerService.OnProviderDiscoveredListner,\r
+ ConsumerService.OnSubscriptionAcceptedListener,\r
+ Provider.OnMessageReceivedListner, Provider.OnSyncInfoReceivedListner\r
+{\r
+\r
+ private static final String TAG = "NS_CONSUMER_PROXY";\r
+\r
+ private Context mContext = null;\r
+ private ConsumerService consumerService = null;\r
+\r
+ private Handler mHandler = null;\r
+\r
+ private static final int PROVIDER_DISCOVERED = 1;\r
+ private static final int SUBSCRIPTION_ACCEPTED = 2;\r
+ private static final int MESSAGE_RECEIVED = 3;\r
+ private static final int SYNCINFO_RECEIVED = 4;\r
+\r
+ public ConsumerProxy(Context context)\r
+ {\r
+ Log.i(TAG, "Create consumerProxy Instance");\r
+\r
+ this.mContext = context;\r
+ consumerService = new ConsumerService();\r
+ }\r
+\r
+ public void setHandler(Handler handler)\r
+ {\r
+ this.mHandler = handler;\r
+ }\r
+\r
+ private void configurePlatform()\r
+ {\r
+\r
+ PlatformConfig platformConfig = new PlatformConfig(\r
+ mContext,\r
+ ServiceType.IN_PROC,\r
+ ModeType.CLIENT_SERVER,\r
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces\r
+ 0, // Uses randomly available port\r
+ QualityOfService.LOW\r
+ );\r
+\r
+ Log.i(TAG, "Configuring platform.");\r
+ OcPlatform.Configure(platformConfig);\r
+ try\r
+ {\r
+ OcPlatform.stopPresence(); // Initialize OcPlatform\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: stopping presence when configuration step: " + e);\r
+ }\r
+ Log.i(TAG, "Configuration done Successfully");\r
+ }\r
+\r
+ public void startNotificationConsumer()\r
+ {\r
+ configurePlatform();\r
+ try\r
+ {\r
+ consumerService.Start(this, this);\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: startNotificationConsumer : " + e);\r
+ }\r
+ }\r
+\r
+ public void stopNotificationConsumer()\r
+ {\r
+ try\r
+ {\r
+ consumerService.Stop();\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: stopNotificationConsumer : " + e);\r
+ }\r
+ }\r
+\r
+ public void enableRemoteService(String serverAddress)\r
+ {\r
+ try\r
+ {\r
+ consumerService.EnableRemoteService(serverAddress);\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: enableRemoteService : " + e);\r
+ }\r
+ }\r
+\r
+ public void rescanProvider()\r
+ {\r
+ try\r
+ {\r
+ consumerService.RescanProvider();\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: rescanProvider : " + e);\r
+ }\r
+ }\r
+\r
+ public Provider getProvider(String providerId)\r
+ {\r
+ Provider provider = null;\r
+ try\r
+ {\r
+ provider = consumerService.GetProvider(providerId);\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: getProvider : " + e);\r
+ }\r
+ return provider;\r
+ }\r
+\r
+ public void subscribe(String providerId)\r
+ {\r
+ try\r
+ {\r
+ Provider provider = getProvider(providerId);\r
+ if (provider != null)\r
+ provider.Subscribe();\r
+ else\r
+ Log.e(TAG, "providerID is Null : ");\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: Subscribe : " + e);\r
+ }\r
+ }\r
+\r
+ public void unsubscribe(String providerId)\r
+ {\r
+ try\r
+ {\r
+ Provider provider = getProvider(providerId);\r
+ if (provider != null)\r
+ provider.Unsubscribe();\r
+ else\r
+ Log.e(TAG, "providerID is Null : ");\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: Unsubscribe : " + e);\r
+ }\r
+ }\r
+\r
+ public void sendSyncInfo(String providerId, long messageId, SyncInfo.SyncType syncType)\r
+ {\r
+ try\r
+ {\r
+ Provider provider = getProvider(providerId);\r
+ if (provider != null)\r
+ provider.SendSyncInfo(messageId, syncType);\r
+ else\r
+ Log.e(TAG, "providerID is Null : ");\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: SendSyncInfo : " + e);\r
+ }\r
+ }\r
+\r
+ public void setListener(String providerId)\r
+ {\r
+ try\r
+ {\r
+ Provider provider = getProvider(providerId);\r
+ if (provider != null)\r
+ provider.SetListener(this, this);\r
+ else\r
+ Log.e(TAG, "providerID is Null : ");\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ Log.e(TAG, "Exception: SetListener : " + e);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void onProviderDiscovered(Provider provider)\r
+ {\r
+ Log.i(TAG, "onProviderDiscovered");\r
+\r
+ Log.i(TAG, "Provider ID: " + provider.getProviderId() );\r
+ Message msg = mHandler.obtainMessage(PROVIDER_DISCOVERED, provider.getProviderId());\r
+ mHandler.sendMessage(msg);\r
+ subscribe(provider.getProviderId());\r
+ }\r
+\r
+ @Override\r
+ public void onSubscriptionAccepted(Provider provider)\r
+ {\r
+ Log.i(TAG, "onSubscriptionAccepted");\r
+\r
+ Log.i(TAG, "Provider ID: " + provider.getProviderId() );\r
+ Message msg = mHandler.obtainMessage(SUBSCRIPTION_ACCEPTED, provider.getProviderId());\r
+ mHandler.sendMessage(msg);\r
+ setListener(provider.getProviderId());\r
+ }\r
+\r
+ @Override\r
+ public void onMessageReceived(org.iotivity.service.ns.common.Message message)\r
+ {\r
+ Log.i(TAG, "onMessageReceived");\r
+\r
+ Log.i(TAG, "Message Id: " + message.getMessageId());\r
+ Log.i(TAG, "Message title: " + message.getTitle());\r
+ Log.i(TAG, "Message Content: " + message.getContentText());\r
+ Log.i(TAG, "Message Source: " + message.getSourceName());\r
+\r
+ Message msg = mHandler.obtainMessage(MESSAGE_RECEIVED,\r
+ "Message Id: " + message.getMessageId() +\r
+ " / Message title: " + message.getTitle() +\r
+ " / Message Content: " + message.getContentText() +\r
+ " / Message Source: " + message.getSourceName() );\r
+ mHandler.sendMessage(msg);\r
+ }\r
+\r
+ @Override\r
+ public void onSyncInfoReceived(SyncInfo sync)\r
+ {\r
+ Log.i(TAG, "onSyncInfoReceived");\r
+\r
+ Log.i(TAG, "Sync Id: " + sync.getMessageId());\r
+ Log.i(TAG, "Sync STATE: " + sync.getState());\r
+ Message msg = mHandler.obtainMessage(SYNCINFO_RECEIVED,\r
+ "Sync Id: " + sync.getMessageId() +\r
+ " / Sync STATE: " + sync.getState());\r
+ mHandler.sendMessage(msg);\r
+ }\r
+}\r
--- /dev/null
+/******************************************************************\r
+ * Copyright 2016 Samsung Electronics All Rights Reserved.\r
+ * <p>\r
+ * <p>\r
+ * <p>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ ******************************************************************/\r
+\r
+package com.sec.noticonsumerexample;\r
+\r
+import android.app.Notification;\r
+import android.app.NotificationManager;\r
+import android.content.Intent;\r
+import android.os.Bundle;\r
+import android.os.Handler;\r
+import android.os.Message;\r
+import android.support.v7.app.AppCompatActivity;\r
+import android.util.Log;\r
+import android.view.View;\r
+import android.widget.Button;\r
+import android.widget.EditText;\r
+import android.widget.TextView;\r
+import android.widget.Toast;\r
+\r
+public class MainActivity extends AppCompatActivity\r
+{\r
+\r
+ private final String TAG = "NS_MAIN_ACTIVITY";\r
+\r
+ private Button btnStart;\r
+ private Button btnStop;\r
+ private Button btnRescan;\r
+ private static TextView TvLog;\r
+\r
+ private boolean isStarted = false;\r
+ private String consumerId;\r
+\r
+ private ConsumerProxy mConsumerProxy = null;\r
+\r
+ private static final int PROVIDER_DISCOVERED = 1;\r
+ private static final int SUBSCRIPTION_ACCEPTED = 2;\r
+ private static final int MESSAGE_RECEIVED = 3;\r
+ private static final int SYNCINFO_RECEIVED = 4;\r
+\r
+ public static Handler mHandler = new Handler()\r
+ {\r
+ @Override\r
+ public void handleMessage(Message msg)\r
+ {\r
+ switch (msg.what)\r
+ {\r
+ case PROVIDER_DISCOVERED:\r
+ {\r
+ String providerId = (String) msg.obj;\r
+ if (providerId != null)\r
+ {\r
+ TvLog.append("Discovered : ProviderID: " + providerId + "\n");\r
+ }\r
+ break;\r
+ }\r
+ case SUBSCRIPTION_ACCEPTED:\r
+ {\r
+ String providerId = (String) msg.obj;\r
+ if (providerId != null)\r
+ {\r
+ TvLog.append("Subscription Accepted : ProviderID: " + providerId + "\n");\r
+ }\r
+ break;\r
+ }\r
+ case MESSAGE_RECEIVED:\r
+ {\r
+ String message = (String) msg.obj;\r
+ if (message != null)\r
+ {\r
+ TvLog.append("Message Received : " + message + "\n");\r
+ }\r
+ break;\r
+ }\r
+ case SYNCINFO_RECEIVED:\r
+ {\r
+ String sync = (String) msg.obj;\r
+ if (sync != null)\r
+ {\r
+ TvLog.append("SyncInfo Received : " + sync + "\n");\r
+ }\r
+ break;\r
+ }\r
+ default:\r
+ break;\r
+ }\r
+ }\r
+ };\r
+\r
+ public void showToast(final String toast)\r
+ {\r
+ runOnUiThread(new Runnable()\r
+ {\r
+ @Override\r
+ public void run()\r
+ {\r
+ Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ protected void onCreate(Bundle savedInstanceState)\r
+ {\r
+ super.onCreate(savedInstanceState);\r
+ setContentView(R.layout.activity_main);\r
+\r
+ btnStart = (Button) findViewById(R.id.BtnStart);\r
+ btnStop = (Button) findViewById(R.id.BtnStop);\r
+ btnRescan = (Button) findViewById(R.id.BtnRescan);\r
+\r
+ TvLog = (TextView) findViewById(R.id.TvLog);\r
+\r
+ btnStart.setOnClickListener(mClickListener);\r
+ btnStop.setOnClickListener(mClickListener);\r
+ btnRescan.setOnClickListener(mClickListener);\r
+\r
+ mConsumerProxy = new ConsumerProxy(getApplicationContext());\r
+ mConsumerProxy.setHandler(mHandler);\r
+ }\r
+\r
+ @Override\r
+ protected void onDestroy()\r
+ {\r
+ if(isStarted)\r
+ mConsumerProxy.stopNotificationConsumer();\r
+ super.onDestroy();\r
+ }\r
+\r
+ public ConsumerProxy getProviderProxy()\r
+ {\r
+ return mConsumerProxy;\r
+ }\r
+\r
+ Button.OnClickListener mClickListener = new View.OnClickListener()\r
+ {\r
+ public void onClick(View v)\r
+ {\r
+ switch (v.getId())\r
+ {\r
+\r
+ case R.id.BtnStart:\r
+ {\r
+ if (isStarted == false)\r
+ {\r
+ Log.i(TAG, "Start NS Consumer Service");\r
+\r
+ TvLog.setText("Start NS-Consumer\n");\r
+ mConsumerProxy.startNotificationConsumer();\r
+ isStarted = true;\r
+ }\r
+ else\r
+ {\r
+ Log.e(TAG, "NS Consumer Service had already started");\r
+ }\r
+ }\r
+ break;\r
+\r
+ case R.id.BtnStop:\r
+ {\r
+ if (isStarted == false)\r
+ {\r
+ Log.e(TAG, "Fail to stop service");\r
+ break;\r
+ }\r
+\r
+ mConsumerProxy.stopNotificationConsumer();\r
+ isStarted = false;\r
+\r
+ TvLog.append("Stop NS-Consumer\n");\r
+ }\r
+ break;\r
+ case R.id.BtnRescan:\r
+ {\r
+ if (isStarted == false)\r
+ {\r
+ Log.e(TAG, "Fail to rescan");\r
+ break;\r
+ }\r
+\r
+ mConsumerProxy.rescanProvider();\r
+ TvLog.append("Rescan NS-Consumer\n");\r
+ }\r
+ break;\r
+\r
+ }\r
+ }\r
+ };\r
+}\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ xmlns:tools="http://schemas.android.com/tools"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
+ android:paddingBottom="@dimen/activity_vertical_margin"\r
+ android:paddingLeft="@dimen/activity_horizontal_margin"\r
+ android:paddingRight="@dimen/activity_horizontal_margin"\r
+ android:paddingTop="@dimen/activity_vertical_margin"\r
+ tools:context="com.sec.noticonsumerexample.MainActivity">\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="16dp"\r
+ android:paddingRight="16dp"\r
+ android:orientation="vertical" >\r
+\r
+ <View\r
+ android:layout_width="match_parent"\r
+ android:layout_height="1dp"\r
+ android:layout_alignParentBottom="true"\r
+ android:background="@android:color/darker_gray"/>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="10dp">\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="vertical" >\r
+\r
+ <Button\r
+ android:layout_gravity="center_vertical|center_horizontal"\r
+ android:layout_height="60dp"\r
+ android:layout_width="match_parent"\r
+ android:id="@+id/BtnStart"\r
+ android:text="START"/>\r
+ <Button\r
+ android:layout_gravity="center_vertical|center_horizontal"\r
+ android:layout_height="60dp"\r
+ android:layout_width="match_parent"\r
+ android:id="@+id/BtnRescan"\r
+ android:text="RESCAN"/>\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="10dp">\r
+ </LinearLayout>\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="horizontal" >\r
+\r
+ <TextView\r
+ android:layout_gravity="center_vertical|center_horizontal"\r
+ android:layout_height="wrap_content"\r
+ android:layout_width="match_parent"\r
+ android:id="@+id/logging"\r
+ android:text="Log.."/>\r
+ </LinearLayout>\r
+\r
+ <ScrollView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:fillViewport="true">\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="150dp"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="horizontal" >\r
+\r
+ <TextView\r
+ android:layout_gravity="center_vertical|center_horizontal"\r
+ android:layout_height="300dp"\r
+ android:layout_width="match_parent"\r
+ android:scrollbars="vertical"\r
+ android:id="@+id/TvLog"/>\r
+ </LinearLayout>\r
+\r
+ </ScrollView>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="horizontal" >\r
+\r
+ <Button\r
+ android:layout_gravity="center_vertical|center_horizontal"\r
+ android:layout_height="60dp"\r
+ android:layout_width="match_parent"\r
+ android:id="@+id/BtnStop"\r
+ android:text="STOP"/>\r
+ </LinearLayout>\r
+\r
+ <View\r
+ android:layout_width="match_parent"\r
+ android:layout_height="1dp"\r
+ android:layout_alignParentBottom="true"\r
+ android:background="@android:color/darker_gray"/>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="20dp">\r
+ </LinearLayout>\r
+\r
+ </LinearLayout>\r
+\r
+\r
+</RelativeLayout>\r
--- /dev/null
+<resources>\r
+ <!-- Example customization of dimensions originally defined in res/values/dimens.xml\r
+ (such as screen margins) for screens with more than 820dp of available width. This\r
+ would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->\r
+ <dimen name="activity_horizontal_margin">64dp</dimen>\r
+</resources>\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<resources>\r
+ <color name="colorPrimary">#3F51B5</color>\r
+ <color name="colorPrimaryDark">#303F9F</color>\r
+ <color name="colorAccent">#FF4081</color>\r
+</resources>\r
--- /dev/null
+<resources>\r
+ <!-- Default screen margins, per the Android Design guidelines. -->\r
+ <dimen name="activity_horizontal_margin">16dp</dimen>\r
+ <dimen name="activity_vertical_margin">16dp</dimen>\r
+</resources>\r
--- /dev/null
+<resources>\r
+ <string name="app_name">NotificationConsumerExample</string>\r
+ <string name="btn_title">Title</string>\r
+ <string name="btn_body">Body</string>\r
+ <string name="btn_send">Send Notification</string>\r
+ <string name="btn_create_noti">Create Notification</string>\r
+</resources>\r
--- /dev/null
+<resources>\r
+\r
+ <!-- Base application theme. -->\r
+ <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">\r
+ <!-- Customize your theme here. -->\r
+ <item name="colorPrimary">@color/colorPrimary</item>\r
+ <item name="colorPrimaryDark">@color/colorPrimaryDark</item>\r
+ <item name="colorAccent">@color/colorAccent</item>\r
+ </style>\r
+\r
+</resources>\r
--- /dev/null
+package com.sec.noticonsumerexample;\r
+\r
+import org.junit.Test;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+/**\r
+ * To work on unit tests, switch the Test Artifact in the Build Variants view.\r
+ */\r
+public class ExampleUnitTest {\r
+ @Test\r
+ public void addition_isCorrect() throws Exception {\r
+ assertEquals(4, 2 + 2);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+// Top-level build file where you can add configuration options common to all sub-projects/modules.\r
+\r
+buildscript {\r
+ repositories {\r
+ jcenter()\r
+ }\r
+ dependencies {\r
+ classpath 'com.android.tools.build:gradle:1.5.0'\r
+\r
+ // NOTE: Do not place your application dependencies here; they belong\r
+ // in the individual module build.gradle files\r
+ }\r
+}\r
+\r
+allprojects {\r
+ repositories {\r
+ jcenter()\r
+ }\r
+}\r
+\r
+task clean(type: Delete) {\r
+ delete rootProject.buildDir\r
+}\r
--- /dev/null
+@if "%DEBUG%" == "" @echo off\r
+@rem ##########################################################################\r
+@rem\r
+@rem Gradle startup script for Windows\r
+@rem\r
+@rem ##########################################################################\r
+\r
+@rem Set local scope for the variables with windows NT shell\r
+if "%OS%"=="Windows_NT" setlocal\r
+\r
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r
+set DEFAULT_JVM_OPTS=\r
+\r
+set DIRNAME=%~dp0\r
+if "%DIRNAME%" == "" set DIRNAME=.\r
+set APP_BASE_NAME=%~n0\r
+set APP_HOME=%DIRNAME%\r
+\r
+@rem Find java.exe\r
+if defined JAVA_HOME goto findJavaFromJavaHome\r
+\r
+set JAVA_EXE=java.exe\r
+%JAVA_EXE% -version >NUL 2>&1\r
+if "%ERRORLEVEL%" == "0" goto init\r
+\r
+echo.\r
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r
+echo.\r
+echo Please set the JAVA_HOME variable in your environment to match the\r
+echo location of your Java installation.\r
+\r
+goto fail\r
+\r
+:findJavaFromJavaHome\r
+set JAVA_HOME=%JAVA_HOME:"=%\r
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe\r
+\r
+if exist "%JAVA_EXE%" goto init\r
+\r
+echo.\r
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r
+echo.\r
+echo Please set the JAVA_HOME variable in your environment to match the\r
+echo location of your Java installation.\r
+\r
+goto fail\r
+\r
+:init\r
+@rem Get command-line arguments, handling Windowz variants\r
+\r
+if not "%OS%" == "Windows_NT" goto win9xME_args\r
+if "%@eval[2+2]" == "4" goto 4NT_args\r
+\r
+:win9xME_args\r
+@rem Slurp the command line arguments.\r
+set CMD_LINE_ARGS=\r
+set _SKIP=2\r
+\r
+:win9xME_args_slurp\r
+if "x%~1" == "x" goto execute\r
+\r
+set CMD_LINE_ARGS=%*\r
+goto execute\r
+\r
+:4NT_args\r
+@rem Get arguments from the 4NT Shell from JP Software\r
+set CMD_LINE_ARGS=%$\r
+\r
+:execute\r
+@rem Setup the command line\r
+\r
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar\r
+\r
+@rem Execute Gradle\r
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\r
+\r
+:end\r
+@rem End local scope for the variables with windows NT shell\r
+if "%ERRORLEVEL%"=="0" goto mainEnd\r
+\r
+:fail\r
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r
+rem the _cmd.exe /c_ return code!\r
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1\r
+exit /b 1\r
+\r
+:mainEnd\r
+if "%OS%"=="Windows_NT" endlocal\r
+\r
+:omega\r
--- /dev/null
+configurations.maybeCreate("default")
+artifacts.add("default", file('iotivity-armeabi-notification-service-debug.aar'))
\ No newline at end of file
--- /dev/null
+configurations.maybeCreate("default")
+artifacts.add("default", file('iotivity-base-armeabi-debug.aar'))
\ No newline at end of file
--- /dev/null
+include ':app', ':iotivity-base-armeabi-debug', ':iotivity-armeabi-notification-service-debug'
\ No newline at end of file