- Modify Android file structure.
- Add Android Consumer Service Java files to support Android APIs.
- Modify script to build Android.
- Modify %lu->%lld to fix bugs on Android.
Change-Id: I6f1e4565482e33c3cbfb331bca5beaaac6e3276d
Signed-off-by: YounghyunJoo <yh_.joo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9395
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
' build -bservice/notification/android/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE),
emitter = ensure_libs)
jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
-jdk_env.Gradle(target="notification-service/objs",
- source="notification-service/src/main/java/org/iotivity/service/notification/IoTNotification.java")
+jdk_env.Gradle(target="notification-service/objs",
+ source="notification-service/src/main/java/org/iotivity/service/ns/consumer/ConsumerService.java")
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.iotivity.service.notification" />
\ No newline at end of file
+ package="org.iotivity.service.ns.consumer" />
\ No newline at end of file
+++ /dev/null
-package org.iotivity.service.notification;
-
-import android.util.Log;
-import org.iotivity.service.notification.NSMessage;
-import org.iotivity.service.notification.NSConsumer;
-import org.iotivity.service.notification.NSSync;
-
-public class IoTNotification
-{
- public IoTNotification()
- {
- }
-
- static
- {
- System.loadLibrary("notification_provider_jni");
- }
-
- public native int NSStartProvider(boolean access,
- NSSubscriptionListner subscriptionListener,
- NSSynchListner syncListener);
- public native int NSStopProvider();
- public native int NSSendNotification(NSMessage message);
- public native int NSProviderReadCheck(NSMessage message);
- public native int NSAccept(NSConsumer consumer, boolean accepted);
-
- public interface NSSubscriptionListner {
- public void OnNSSubscribedEvent(String consumerId);
- }
-
- public interface NSSynchListner {
- public void OnNSSynchronizedEvent(String messageId, int syncState);
- }
-}
-
+++ /dev/null
-package org.iotivity.service.notification;\r
-\r
-import android.util.Log;\r
-\r
-public class NSConsumer {\r
- \r
- String mId = null;\r
- String mAddress = null;\r
- \r
- public NSConsumer(String id) {\r
- this.mId = id;\r
- }\r
-\r
- public String getId() {\r
- return mId;\r
- }\r
-\r
- public String getAddress() {\r
- return mAddress;\r
- }\r
-\r
- public void setAddress(String address) {\r
- this.mAddress = address;\r
- }\r
-\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
-package org.iotivity.service.notification;\r
-\r
-import android.util.Log;\r
-\r
-public class NSMessage\r
-{\r
- String id = null;\r
- String title = null;\r
- String body = null;\r
- String source = null;\r
-\r
- public NSMessage(String id)\r
- {\r
- this.id = id;\r
- }\r
-\r
- public String getId()\r
- {\r
- return id;\r
- }\r
-\r
- public String getTitle()\r
- {\r
- return title;\r
- }\r
-\r
- public void setTitle(String title)\r
- {\r
- this.title = title;\r
- }\r
-\r
- public String getBody()\r
- {\r
- return body;\r
- }\r
-\r
- public void setBody(String body)\r
- {\r
- this.body = body;\r
- }\r
-\r
- public String getSource()\r
- {\r
- return source;\r
- }\r
-\r
- public void setSource(String source)\r
- {\r
- this.source = source;\r
- }\r
-}\r
+++ /dev/null
-package org.iotivity.service.notification;
-
-import android.util.Log;
-
-public class NSSync {
-
- String mMessageId = null;
- String mDeviceId = null;
- String mSourceId = null;
-
- public NSSync(String id) {
- this.mMessageId = id;
- }
-
- public String getMessageId() {
- return mMessageId;
- }
-
- public String getDeviceId() {
- return mDeviceId;
- }
-
- public void setDeviceId(String id) {
- this.mDeviceId = id;
- }
-
- public String getSourceId() {
- return mSourceId;
- }
-
- public void setSourceId(String id) {
- this.mSourceId = id;
- }
-
-}
--- /dev/null
+package org.iotivity.service.ns;
+
+import android.util.Log;
+import org.iotivity.service.ns.NSMessage;
+import org.iotivity.service.ns.NSConsumer;
+import org.iotivity.service.ns.NSSync;
+
+public class IoTNotification
+{
+ public IoTNotification()
+ {
+ }
+
+ static
+ {
+ System.loadLibrary("notification_provider_jni");
+ }
+
+ public native int NSStartProvider(boolean access,
+ NSSubscriptionListner subscriptionListener,
+ NSSynchListner syncListener);
+ public native int NSStopProvider();
+ public native int NSSendNotification(NSMessage message);
+ public native int NSProviderReadCheck(NSMessage message);
+ public native int NSAccept(NSConsumer consumer, boolean accepted);
+
+ public interface NSSubscriptionListner {
+ public void OnNSSubscribedEvent(String consumerId);
+ }
+
+ public interface NSSynchListner {
+ public void OnNSSynchronizedEvent(String messageId, int syncState);
+ }
+}
+
--- /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
+package org.iotivity.service.ns;\r
+\r
+import android.util.Log;\r
+\r
+public class NSConsumer {\r
+\r
+ String mId = null;\r
+ String mAddress = null;\r
+\r
+ public NSConsumer(String id) {\r
+ this.mId = id;\r
+ }\r
+\r
+ public String getId() {\r
+ return mId;\r
+ }\r
+\r
+ public String getAddress() {\r
+ return mAddress;\r
+ }\r
+\r
+ public void setAddress(String address) {\r
+ this.mAddress = address;\r
+ }\r
+\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
+package org.iotivity.service.ns;\r
+\r
+import android.util.Log;\r
+\r
+public class NSMessage\r
+{\r
+ String id = null;\r
+ String title = null;\r
+ String body = null;\r
+ String source = null;\r
+\r
+ public NSMessage(String id)\r
+ {\r
+ this.id = id;\r
+ }\r
+\r
+ public String getId()\r
+ {\r
+ return id;\r
+ }\r
+\r
+ public String getTitle()\r
+ {\r
+ return title;\r
+ }\r
+\r
+ public void setTitle(String title)\r
+ {\r
+ this.title = title;\r
+ }\r
+\r
+ public String getBody()\r
+ {\r
+ return body;\r
+ }\r
+\r
+ public void setBody(String body)\r
+ {\r
+ this.body = body;\r
+ }\r
+\r
+ public String getSource()\r
+ {\r
+ return source;\r
+ }\r
+\r
+ public void setSource(String source)\r
+ {\r
+ this.source = source;\r
+ }\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
+package org.iotivity.service.ns;\r
+\r
+import android.util.Log;\r
+\r
+public class NSSync {\r
+\r
+ String mMessageId = null;\r
+ String mDeviceId = null;\r
+\r
+ public NSSync(String id) {\r
+ this.mMessageId = id;\r
+ }\r
+\r
+ public String getMessageId() {\r
+ return mMessageId;\r
+ }\r
+\r
+ public String getDeviceId() {\r
+ return mDeviceId;\r
+ }\r
+\r
+ public void setDeviceId(String id) {\r
+ this.mDeviceId = id;\r
+ }\r
+\r
+}\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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+package org.iotivity.service.ns.consumer;
+
+import android.util.Log;
+
+public class ConsumerService {
+
+ private static final String LOG_TAG = "ConsumerService";
+
+ static {
+ System.loadLibrary("notification_consumer_jni");
+ }
+
+ 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 interface OnProviderDiscoveredListner {
+ public void onProviderDiscovered(NSProvider provider);
+ }
+
+ public interface OnSubscriptionAcceptedListener {
+ public void onSubscriptionAccepted(NSProvider provider);
+ }
+
+ public interface OnMessageReceivedListner {
+ public void onMessageReceived(NSMessage message);
+ }
+
+ public interface OnSyncInfoReceivedListner {
+ public void onSyncInfoReceived(NSSyncInfo sync);
+ }
+}
+
--- /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;
+
+public enum NSErrorCode {
+ OK("OK", ""),
+ ERROR("ERROR", ""),
+ SUCCESS("SUCCESS", ""),
+ FAIL("FAIL", ""),
+ ALLOW("ALLOW", ""),
+ DENY("DENY", ""),
+ JNI_EXCEPTION("JNI_EXCEPTION", "Generic Java binder error"),
+ JNI_NO_NATIVE_OBJECT("JNI_NO_NATIVE_OBJECT", ""),
+ JNI_INVALID_VALUE("JNI_INVALID_VALUE", ""),;
+
+ private String error;
+ private String description;
+
+ private NSErrorCode(String error, String description) {
+ this.error = error;
+ this.description = description;
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public static NSErrorCode get(String errorCode) {
+ for (NSErrorCode eCode : NSErrorCode.values()) {
+ if (eCode.getError().equals(errorCode)) {
+ return eCode;
+ }
+ }
+ throw new IllegalArgumentException("Unexpected NSErrorCode value");
+ }
+
+ @Override
+ public String toString() {
+ return error + (description.isEmpty() ? "" : " : " + description);
+ }
+}
\ 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;
+
+public class NSException extends Exception {
+
+ private NSErrorCode errorCode;
+
+ public NSException(NSErrorCode errorCode, String errMessage) {
+ super(errMessage + " " + errorCode.toString());
+ this.errorCode = errorCode;
+ }
+
+ private NSException(String error, String errMessage) {
+ super(errMessage + " " + error);
+ this.errorCode = NSErrorCode.get(error);
+ }
+
+ public NSErrorCode getErrorCode() {
+ return errorCode;
+ }
+
+ private static void addStackTrace(Throwable throwable,
+ String file,
+ String functionName,
+ int line) {
+ StackTraceElement[] stack = throwable.getStackTrace();
+ StackTraceElement[] newStack = new StackTraceElement[stack.length + 1];
+
+ System.arraycopy(stack, 0, newStack, 1, stack.length);
+ newStack[0] = new StackTraceElement("<native>", functionName, file, line);
+ throwable.setStackTrace(newStack);
+ }
+
+ 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.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;
+
+public class NSSyncInfo {
+
+ private static final String LOG_TAG = "ConsumerService_NSSyncInfo";
+
+ 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 String getProviderId() {
+ return providerId;
+ }
+
+ public int getState() {
+ return state;
+ }
+}
\ No newline at end of file
ROOT_PATH := ../../../../../../..
+include $(CLEAR_VARS)
+OIC_LIB_PATH := $(ROOT_PATH)/out/android/$(TARGET_ARCH_ABI)/$(APP_OPTIM)
+LOCAL_MODULE := notification_consumer
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libnotification_consumer.so
+include $(PREBUILT_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_consumer_jni
+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
+
+OIC_SRC_DIR := ../../../../../..
+
+LOCAL_C_INCLUDES := $(OIC_SRC_DIR)/resource/csdk/stack/include
+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/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)/extlibs/
+
+LOCAL_SRC_FILES := consumer/notificationConsumer.c
+LOCAL_SRC_FILES += common/jniNSCommon.c
+
+include $(BUILD_SHARED_LIBRARY)
+
include $(CLEAR_VARS)
LOCAL_MODULE := notification_provider_jni
LOCAL_CPPFLAGS := -std=c++0x -frtti -fexceptions
+LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := ca_interface
LOCAL_STATIC_LIBRARIES += ca
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/provider
-
+
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/extlibs/
LOCAL_SRC_FILES := notificationProvider.c
-LOCAL_LDLIBS := -llog
-include $(BUILD_SHARED_LIBRARY)
+include $(BUILD_SHARED_LIBRARY)
\ 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#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
--- /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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#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
--- /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
import org.iotivity.base.PlatformConfig;\r
import org.iotivity.base.QualityOfService;\r
import org.iotivity.base.ServiceType;\r
-import org.iotivity.service.notification.IoTNotification;\r
-import org.iotivity.service.notification.NSConsumer;\r
-import org.iotivity.service.notification.NSMessage;\r
+import org.iotivity.service.ns.IoTNotification;\r
+import org.iotivity.service.ns.NSConsumer;\r
+import org.iotivity.service.ns.NSMessage;\r
\r
import java.util.HashMap;\r
\r
OICFree(providerId);
NS_LOG_V(DEBUG, "Provider ID : %s", retSync->providerId);
- NS_LOG_V(DEBUG, "Sync ID : %lu", retSync->messageId);
+ NS_LOG_V(DEBUG, "Sync ID : %lld", retSync->messageId);
NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state);
NS_LOG(DEBUG, "NSGetSyncInfo - OUT");
OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_TTL, (int64_t *)&retMsg->ttl);
NS_LOG_V(DEBUG, "Msg Address : %s", retMsg->i_addr->addr);
- NS_LOG_V(DEBUG, "Msg ID : %lu", retMsg->messageId);
+ NS_LOG_V(DEBUG, "Msg ID : %lld", retMsg->messageId);
NS_LOG_V(DEBUG, "Msg Title : %s", retMsg->title);
NS_LOG_V(DEBUG, "Msg Content : %s", retMsg->contentText);
NS_LOG_V(DEBUG, "Msg Source : %s", retMsg->sourceName);
NS_LOG_V(DEBUG, "Msg Type : %d", retMsg->type);
NS_LOG_V(DEBUG, "Msg Date : %s", retMsg->dateTime);
- NS_LOG_V(DEBUG, "Msg ttl : %lu", retMsg->ttl);
+ NS_LOG_V(DEBUG, "Msg ttl : %lld", retMsg->ttl);
return retMsg;
}
NSSyncInfo * retSync = NSCreateSyncInfo_consumer(id, pId, (NSSyncType)state);
NS_VERIFY_NOT_NULL(retSync, NULL);
- NS_LOG_V(DEBUG, "Sync ID : %lu", retSync->messageId);
+ NS_LOG_V(DEBUG, "Sync ID : %lld", retSync->messageId);
NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state);
NS_LOG_V(DEBUG, "Sync Provider ID : %s", retSync->providerId);
NSMessage * NSConsumerGetMessage(uint64_t messageId)
{
char msgId[NS_DEVICE_ID_LENGTH] = { 0, };
- snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lu", messageId);
+ snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", messageId);
return (NSMessage *) NSConsumerFindNSMessage(msgId);
}
NS_VERIFY_NOT_NULL_V(provider);
char msgId[NS_DEVICE_ID_LENGTH] = { 0, };
- snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lu", sync->messageId);
+ snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", sync->messageId);
NSMessage_consumer * msg = NSMessageCacheFind(msgId);
NS_VERIFY_NOT_NULL_V(msg);
pthread_mutex_unlock(mutex);
char msgId[NS_DEVICE_ID_LENGTH] = {0, };
- snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lu", newMsgObj->messageId);
+ snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", newMsgObj->messageId);
NSCacheElement * it = NSStorageRead(list, msgId);
pthread_mutex_lock(mutex);
NSMessage_consumer * msg = (NSMessage_consumer *) data;
char msgId[NS_DEVICE_ID_LENGTH] = {0, };
- snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lu", msg->messageId);
+ snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", msg->messageId);
if (!strcmp(msgId, id))
{
return true;