RcsBundleInfo not needs native peer any more.
The dependency on rcs_common.so for building jni is removed.
Change-Id: I8e8af13a95f418eb9a3d2683eefd7f320ed6668d
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3777
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
/.idea/libraries
.DS_Store
/build/*
-/service/build/*
-/service/src/main/obj/*
-/service/src/main/libs/*
+/resource-container/build/*
+/resource-container/src/main/obj/*
+/resource-container/src/main/libs/*
def ensure_libs(target, source, env):
- return target, [source, env.get('BUILD_DIR') + 'librcs_server.so',
- env.get('BUILD_DIR') + 'librcs_client.so',
- env.get('BUILD_DIR') + 'librcs_container.so']
+ return target, [source, env.get('BUILD_DIR') + 'librcs_container.so']
jdk_env = Environment(ENV=os.environ)
jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') +
emitter = ensure_libs)
jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
-jdk_env.Gradle(target="service/objs",
+jdk_env.Gradle(target="resource-container/objs",
source="resource-container/src/main/java/org/iotivity/service/resourcecontainer/RcsBundleInfo.java")
*/
package org.iotivity.service.resourcecontainer;
-import org.iotivity.service.utils.RcsObject;
-
/**
* This class provides APIs for getting and setting the Bundle Information
*/
-public class RcsBundleInfo extends RcsObject {
- private native String nativeGetID();
-
- private native String nativeGetPath();
-
- private native String nativeGetActivatorName();
-
- private native String nativeGetLibraryPath();
-
- private native String nativeGetVersion();
+public class RcsBundleInfo {
+ private final String mId;
+ private final String mPath;
+ private final String mActivatorName;
+ private final String mLibraryPath;
+ private final String mVersion;
- private RcsBundleInfo() {
+ private RcsBundleInfo(String id, String path, String activatorName,
+ String libraryPath, String version) {
+ mId = id;
+ mPath = path;
+ mActivatorName = activatorName;
+ mLibraryPath = libraryPath;
+ mVersion = version;
}
/**
*
*/
public String getID() {
- return nativeGetID();
+ return mId;
}
/**
*
*/
public String getPath() {
- return nativeGetPath();
+ return mPath;
}
/**
*
*/
public String getActivatorName() {
- return nativeGetActivatorName();
+ return mActivatorName;
}
/**
*
*/
public String getLibraryPath() {
- return nativeGetLibraryPath();
+ return mLibraryPath;
}
/**
*
*/
public String getVersion() {
- return nativeGetVersion();
+ return mVersion;
}
}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-package org.iotivity.service.utils;
-
-/**
- * An exception that indicates there was an error with execution of Rcs APIs.
- */
-public class RcsException extends Exception {
-
- private static final long serialVersionUID = 7044421943523001940L;
-
- public RcsException(String message) {
- super(message);
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-package org.iotivity.service.utils;
-
-/**
- * Thrown when an action is attempted at a time when not in the correct state.
- *
- */
-public class RcsIllegalStateException extends RcsException {
-
- private static final long serialVersionUID = 6142669404885957616L;
-
- public RcsIllegalStateException(String message) {
- super(message);
- }
-
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package org.iotivity.service.utils;
-
-public class RcsObject {
- 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("rcs_client");
- System.loadLibrary("rcs_server");
- System.loadLibrary("rcs_common");
- System.loadLibrary("rcs_container");
- System.loadLibrary("resource_container_jni");
- }
-
- private long mNativeHandle;
-
- private native void nativeDispose();
-
- protected RcsObject() {
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
-
- dispose();
- }
-
- protected void dispose() {
- if (mNativeHandle != 0L) nativeDispose();
- }
-
- protected boolean hasHandle() {
- return mNativeHandle != 0L;
- }
-}
+++ /dev/null
-package org.iotivity.service.utils;
-
-/**
- * Thrown when an operation that has base-layer dependency is failed.
- *
- */
-public class RcsPlatformException extends RcsException {
-
- private static final long serialVersionUID = -6093438347973754721L;
-
- private final int mReasonCode;
-
- public RcsPlatformException(String message, int reasonCode) {
- super(message);
-
- mReasonCode = reasonCode;
- }
-
- public int getReasonCode() {
- return mReasonCode;
- }
-}
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
-LOCAL_LDLIBS := -L$(LOCAL_PATH)/$(IOTIVITY_LIB_PATH)/
-LOCAL_LDLIBS += -lrcs_common
-
OIC_SRC_DIR := ../../../../../..
LOCAL_MODULE := resource_container_jni
LOCAL_C_INCLUDES := $(LOCAL_PATH)/util
-LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/c_common
-LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/csdk/stack/include
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/extlibs/boost/boost_1_58_0
-LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/resource-encapsulation/include
LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/resource-container/include
-LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/resource-encapsulation/src/serverBuilder/include
LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/util/*.cpp))
LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/*.cpp))
LOCAL_CPPFLAGS := -std=c++0x -frtti -fexceptions
-LOCAL_LDLIBS += -llog
+LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES += rcs_container
*
******************************************************************/
-#include "JniRcsObject.h"
-
#include "JniRcsResourceContainer.h"
#include "JavaClasses.h"
-#include "JavaExceptions.h"
#include "JNIEnvWrapper.h"
#include "Log.h"
try
{
initJavaClasses(&envWrapper);
- initJavaExceptions(&envWrapper);
- initRCSObject(&envWrapper);
initRCSResourceContainer(&envWrapper);
}
catch (const JavaException &)
try
{
clearRCSResourceContainer(&envWrapper);
- clearRCSObject(&envWrapper);
- clearJavaExceptions(&envWrapper);
clearJavaClasses(&envWrapper);
}
catch (const JavaException &)
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "JniRcsBundleInfo.h"
-
-#include "Log.h"
-#include "Verify.h"
-#include "JniRcsObject.h"
-
-#include "RCSBundleInfo.h"
-
-#define LOG_TAG "JNI-RCSBundleInfo"
-
-using namespace OIC::Service;
-
-namespace
-{
- RCSBundleInfo *getNativeBundleInfo(JNIEnv *env, jobject obj)
- {
- return getNativeHandleAs< RCSBundleInfo * >(env, obj);
- }
-}
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetID
-(JNIEnv *env, jobject obj)
-{
- LOGI("nativeGetID");
-
- auto bundleInfo = getNativeBundleInfo(env, obj);
- VERIFY_NO_EXC_RET_DEF(env);
-
- return newStringObject(env, bundleInfo->getID());
-}
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetPath
-(JNIEnv *env, jobject obj)
-{
- LOGI("nativeGetPath");
-
- auto bundleInfo = getNativeBundleInfo(env, obj);
- VERIFY_NO_EXC_RET_DEF(env);
-
- return newStringObject(env, bundleInfo->getPath());
-}
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetActivatorName
-(JNIEnv *env, jobject obj)
-{
- LOGI("nativeGetActivatorName");
-
- auto bundleInfo = getNativeBundleInfo(env, obj);
- VERIFY_NO_EXC_RET_DEF(env);
-
- return newStringObject(env, bundleInfo->getActivatorName());
-}
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetLibraryPath
-(JNIEnv *env, jobject obj)
-{
- LOGI("nativeGetLibraryPath");
-
- auto bundleInfo = getNativeBundleInfo(env, obj);
- VERIFY_NO_EXC_RET_DEF(env);
-
- return newStringObject(env, bundleInfo->getLibraryPath());
-}
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetVersion
-(JNIEnv *env, jobject obj)
-{
- LOGI("nativeGetVersion");
-
- auto bundleInfo = getNativeBundleInfo(env, obj);
- VERIFY_NO_EXC_RET_DEF(env);
-
- return newStringObject(env, bundleInfo->getVersion());
-}
-
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-/** @file jni_re_rcs_bundle_info.h
- *
- * @brief This file contains the JniBundleInfo class
- * & declaration of RCSBundleInfo APIs for JNI implementation
- */
-
-#ifndef JNI_RCS_BUNDLE_INFO_H_
-#define JNI_RCS_BUNDLE_INFO_H_
-
-#include <jni.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetID
-(JNIEnv *, jobject);
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetPath
-(JNIEnv *, jobject);
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetActivatorName
-(JNIEnv *, jobject);
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetLibraryPath
-(JNIEnv *, jobject);
-
-JNIEXPORT jstring JNICALL
-Java_org_iotivity_service_resourcecontainer_RcsBundleInfo_nativeGetVersion
-(JNIEnv *, jobject);
-
-#ifdef __cplusplus
-}
-#endif
-#endif // JNI_RCS_BUNDLE_INFO_H_
-
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "JniRcsObject.h"
-
-#include "JavaClasses.h"
-#include "JNIEnvWrapper.h"
-#include "Log.h"
-#include "Verify.h"
-
-#define LOG_TAG "JNI-RCSObject"
-
-jfieldID g_field_mNativeHandle;
-
-void initRCSObject(JNIEnvWrapper *env)
-{
- auto clsRCSObject = env->FindClass(PACKAGE_NAME "/utils/RcsObject");
-
- g_field_mNativeHandle = env->GetFieldID(clsRCSObject, "mNativeHandle", "J");
-}
-
-void clearRCSObject(JNIEnvWrapper *env)
-{
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_service_utils_RcsObject_nativeDispose(JNIEnv *env, jobject obj)
-{
- LOGD("release nativeHandle!");
- releaseNativeHandle(env, obj);
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#ifndef JNI_RCS_OBJECT_H_
-#define JNI_RCS_OBJECT_H_
-
-#include <jni.h>
-
-#include <memory>
-
-#include "JavaClasses.h"
-#include "JNIEnvWrapper.h"
-
-extern jfieldID g_field_mNativeHandle;
-
-void initRCSObject(JNIEnvWrapper *);
-void clearRCSObject(JNIEnvWrapper *);
-
-namespace Detail
-{
- struct BaseHandleHolder
- {
- virtual ~BaseHandleHolder() {}
- };
-
- template< typename T >
- struct HandleHolder: public BaseHandleHolder
- {
- HandleHolder(T *ptr) : m_ptr { ptr } {}
-
- virtual ~HandleHolder() { delete m_ptr; }
-
- T *m_ptr;
- };
-
- template< typename ENV >
- void *getNativeHandle(ENV *env, jobject obj)
- {
- return reinterpret_cast< void * >(env->GetLongField(obj, g_field_mNativeHandle));
- }
-}
-
-template< typename ENV >
-bool hasNativeHandle(ENV *env, jobject obj)
-{
- return Detail::getNativeHandle(env, obj) != nullptr;
-}
-
-template< typename T, typename ENV, typename ...PARAMS >
-inline void setSafeNativeHandle(ENV *env, jobject obj, PARAMS &&... params)
-{
- static_assert(!std::is_array< T >::value, "Array is not supported!");
-
- std::unique_ptr< Detail::HandleHolder< T > > p(
- new Detail::HandleHolder< T > { new T{ std::forward< PARAMS >(params)... } });
-
- env->SetLongField(obj, g_field_mNativeHandle, reinterpret_cast< jlong >(p.get()));
-
- if (env->ExceptionCheck()) return;
-
- p.release();
-}
-
-template< typename ENV >
-void releaseNativeHandle(ENV *env, jobject obj)
-{
- auto handleHolder = reinterpret_cast< Detail::BaseHandleHolder * >(
- env->GetLongField(obj, g_field_mNativeHandle));
-
- delete handleHolder;
-
- env->SetLongField(obj, g_field_mNativeHandle, 0);
-}
-
-
-template< typename T >
-inline T &getNativeHandleAs(JNIEnv *env, jobject obj)
-{
- auto handleHolder = static_cast< Detail::HandleHolder< T >* >(Detail::getNativeHandle(env, obj));
-
- if (!handleHolder)
- {
- env->ThrowNew(env->FindClass(EXC_NAME_ILLEGAL_STATE), "Internal handle is null!");
- }
-
- return *handleHolder->m_ptr;
-}
-
-template< typename T >
-inline T &getNativeHandleAs(JNIEnvWrapper *env, jobject obj)
-{
- getNativeHandleAs< T >(env->get(), obj);
- if (env->ExceptionCheck()) throw JavaException();
-}
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_service_utils_RcsObject_nativeDispose(JNIEnv *, jobject);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // JNI_RCS_OBJECT_H_
#include "JniRcsResourceContainer.h"
+#include "JavaClasses.h"
#include "JavaLocalRef.h"
#include "JNIEnvWrapper.h"
#include "Log.h"
#include "Verify.h"
-#include "JniRcsObject.h"
#include "RCSResourceContainer.h"
-#include "RCSBundleInfo.h"
#define LOG_TAG "JNI-RCSResourceContainer"
using namespace OIC::Service;
-#define CLS_NAME_BUNDLE_INFO PACKAGE_NAME "/resourcecontainer/RcsBundleInfo"
-
-#include <android/log.h>
-
-
+#define CLS_NAME_BUNDLE_INFO "org/iotivity/service/resourcecontainer/RcsBundleInfo"
namespace
{
JavaLocalObject entryObj { env, invoke_Iterator_next(env, iterObj) };
JavaLocalString keyObj { env,
- static_cast< jstring >(invoke_MapEntry_getKey(env, entryObj))
- };
+ static_cast< jstring >(invoke_MapEntry_getKey(env, entryObj)) };
+
JavaLocalString valueObj { env,
- static_cast< jstring >(invoke_MapEntry_getValue(env, entryObj))
- };
+ static_cast< jstring >(invoke_MapEntry_getValue(env, entryObj)) };
ret.emplace(toStdString(env, keyObj), toStdString(env, valueObj));
}
return ret;
}
+
+ jobject newBundleInfoObj(JNIEnvWrapper *env, const std::unique_ptr< RCSBundleInfo > &bundleInfo)
+ {
+ JavaLocalString id{env, newStringObject(env, bundleInfo->getID()) };
+ JavaLocalString path{env, newStringObject(env, bundleInfo->getPath()) };
+ JavaLocalString activatorName{env, newStringObject(env, bundleInfo->getActivatorName()) };
+ JavaLocalString libraryPath{env, newStringObject(env, bundleInfo->getLibraryPath()) };
+ JavaLocalString version{env, newStringObject(env, bundleInfo->getVersion()) };
+
+ return env->NewObject(g_cls_RCSBundleInfo, g_ctor_RCSBundleInfo,
+ id.get(), path.get(), activatorName.get(), libraryPath.get(), version.get());
+ }
}
void initRCSResourceContainer(JNIEnvWrapper *env)
{
g_cls_RCSBundleInfo = env->FindClassAsGlobalRef(CLS_NAME_BUNDLE_INFO);
- g_ctor_RCSBundleInfo = env->GetConstructorID(g_cls_RCSBundleInfo, "()V");
+ g_ctor_RCSBundleInfo = env->GetConstructorID(g_cls_RCSBundleInfo, "("
+ AS_SIG(CLS_NAME_STRING)
+ AS_SIG(CLS_NAME_STRING)
+ AS_SIG(CLS_NAME_STRING)
+ AS_SIG(CLS_NAME_STRING)
+ AS_SIG(CLS_NAME_STRING)
+ ")V");
}
void clearRCSResourceContainer(JNIEnvWrapper *env)
{
auto listObj = newArrayList(&envWrapper);
- for (auto& uniqeBundleInfo : RCSResourceContainer::getInstance()->listBundles())
+ for (const auto& bundleInfo : RCSResourceContainer::getInstance()->listBundles())
{
- RCSBundleInfo* bundleInfo = uniqeBundleInfo.release();
- JavaLocalObject bundleInfoObj { &envWrapper,
- envWrapper.NewObject(g_cls_RCSBundleInfo, g_ctor_RCSBundleInfo) };
-
- setSafeNativeHandle< RCSBundleInfo* >(&envWrapper, bundleInfoObj, bundleInfo);
-
+ JavaLocalObject bundleInfoObj{ &envWrapper, newBundleInfoObj(&envWrapper, bundleInfo) };
invoke_Collection_add(&envWrapper, listObj, bundleInfoObj);
}
return listObj;
auto listObj = newArrayList(&envWrapper);
- for (const auto & s : RCSResourceContainer::getInstance()->listBundleResources(id))
+ for (const auto& s : RCSResourceContainer::getInstance()->listBundleResources(id))
{
- JavaLocalString strObj { &envWrapper, newStringObject(&envWrapper, s) };
+ JavaLocalString strObj{ &envWrapper, newStringObject(&envWrapper, s) };
invoke_Collection_add(&envWrapper, listObj, strObj);
}
#include "JNIEnvWrapper.h"
-jclass g_cls_String;
-jclass g_cls_Integer;
-jclass g_cls_Double;
-jclass g_cls_Boolean;
-
jclass g_cls_ArrayList;
jclass g_cls_Set;
jclass g_cls_Map;
jclass g_cls_MapEntry;
jclass g_cls_Iterator;
-jmethodID g_method_Boolean_booleanValue;
-jmethodID g_method_Integer_intValue;
-jmethodID g_method_Double_doubleValue;
-
jmethodID g_method_Collection_add;
jmethodID g_method_Set_iterator;
jmethodID g_method_Iterator_hasNext;
jmethodID g_method_Iterator_next;
-jmethodID g_ctor_Boolean;
-jmethodID g_ctor_Integer;
-jmethodID g_ctor_Double;
-
jmethodID g_ctor_ArrayList;
-namespace
-{
- inline void initPrimitiveTypes(JNIEnvWrapper *env)
- {
- g_cls_Boolean = env->FindClassAsGlobalRef(CLS_NAME_BOOLEAN);
- g_ctor_Boolean = env->GetConstructorID(g_cls_Boolean, "(Z)V");
- g_method_Boolean_booleanValue = env->GetMethodID(g_cls_Boolean, "booleanValue", "()Z");
-
- g_cls_Integer = env->FindClassAsGlobalRef(CLS_NAME_INTEGER);
- g_ctor_Integer = env->GetConstructorID(g_cls_Integer, "(I)V");
- g_method_Integer_intValue = env->GetMethodID(g_cls_Integer, "intValue", "()I");
-
- g_cls_Double = env->FindClassAsGlobalRef(CLS_NAME_DOUBLE);
- g_ctor_Double = env->GetConstructorID(g_cls_Double, "(D)V");
- g_method_Double_doubleValue = env->GetMethodID(g_cls_Double, "doubleValue", "()D");
-
- g_cls_String = env->FindClassAsGlobalRef(CLS_NAME_STRING);
- }
-}
-
void initJavaClasses(JNIEnvWrapper *env)
{
- initPrimitiveTypes(env);
-
auto clsCollection = env->FindClass(CLS_NAME_COLLECTION);
g_method_Collection_add = env->GetMethodID(clsCollection, "add",
"(" AS_SIG(CLS_NAME_OBJECT) ")Z");
void clearJavaClasses(JNIEnvWrapper *env)
{
- env->DeleteGlobalRef(g_cls_Boolean);
- env->DeleteGlobalRef(g_cls_Integer);
- env->DeleteGlobalRef(g_cls_Double);
- env->DeleteGlobalRef(g_cls_String);
env->DeleteGlobalRef(g_cls_Set);
env->DeleteGlobalRef(g_cls_Map);
env->DeleteGlobalRef(g_cls_MapEntry);
#include <string>
-#define PACKAGE_NAME "org/iotivity/service"
-
#define CLS_NAME_OBJECT "java/lang/Object"
#define CLS_NAME_STRING "java/lang/String"
-#define CLS_NAME_INTEGER "java/lang/Integer"
-#define CLS_NAME_DOUBLE "java/lang/Double"
-#define CLS_NAME_BOOLEAN "java/lang/Boolean"
#define CLS_NAME_COLLECTION "java/util/Collection"
#define CLS_NAME_ARRAY_LIST "java/util/ArrayList"
#define CLS_NAME_MAP_ENTRY "java/util/Map$Entry"
#define CLS_NAME_ITERATOR "java/util/Iterator"
-#define EXC_NAME_RCS PACKAGE_NAME "/utils/RcsException"
-#define EXC_NAME_PLATFORM PACKAGE_NAME "/utils/RcsPlatformException"
-#define EXC_NAME_ILLEGAL_STATE PACKAGE_NAME "/utils/RcsIllegalStateException"
-
#define AS_SIG(CLS_NAME) "L" CLS_NAME ";"
class JNIEnvWrapper;
-extern jclass g_cls_Integer;
-extern jclass g_cls_Double;
-extern jclass g_cls_Boolean;
-extern jclass g_cls_String;
-
extern jclass g_cls_ArrayList;
extern jclass g_cls_Set;
extern jclass g_cls_Map;
extern jclass g_cls_MapEntry;
extern jclass g_cls_Iterator;
-extern jmethodID g_method_Boolean_booleanValue;
-extern jmethodID g_method_Integer_intValue;
-extern jmethodID g_method_Double_doubleValue;
-
extern jmethodID g_method_Collection_add;
extern jmethodID g_method_Set_iterator;
extern jmethodID g_method_Iterator_hasNext;
extern jmethodID g_method_Iterator_next;
-extern jmethodID g_ctor_Boolean;
-extern jmethodID g_ctor_Integer;
-extern jmethodID g_ctor_Double;
-
extern jmethodID g_ctor_ArrayList;
void initJavaClasses(JNIEnvWrapper *);
void clearJavaClasses(JNIEnvWrapper *);
template< typename ENV >
-inline jobject newBooleanObject(ENV *env, bool value)
-{
- return env->NewObject(g_cls_Boolean, g_ctor_Boolean, value);
-}
-
-template< typename ENV >
-inline jobject newIntegerObject(ENV *env, int value)
-{
- return env->NewObject(g_cls_Integer, g_ctor_Integer, value);
-}
-
-template< typename ENV >
-inline jobject newDoubleObject(ENV *env, double value)
-{
- return env->NewObject(g_cls_Double, g_ctor_Double, value);
-}
-
-template< typename ENV >
inline jstring newStringObject(ENV *env, const std::string &value)
{
return env->NewStringUTF(value.c_str());
}
template< typename ENV >
-inline bool invoke_Boolean_booleanValue(ENV *env, jobject obj)
-{
- return env->CallBooleanMethod(obj, g_method_Boolean_booleanValue);
-}
-
-template< typename ENV >
-inline int invoke_Integer_intValue(ENV *env, jobject obj)
-{
- return env->CallIntMethod(obj, g_method_Integer_intValue);
-}
-
-template< typename ENV >
-inline double invoke_Double_doubleValue(ENV *env, jobject obj)
-{
- return env->CallDoubleMethod(obj, g_method_Double_doubleValue);
-}
-
-template< typename ENV >
inline jboolean invoke_Collection_add(ENV *env, jobject collectionObj, jobject valueObj)
{
return env->CallBooleanMethod(collectionObj, g_method_Collection_add, valueObj);
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "JavaExceptions.h"
-
-#include "JNIEnvWrapper.h"
-#include "Verify.h"
-
-#include "RCSException.h"
-
-namespace
-{
- jclass g_cls_PlatformException;
-
- jmethodID g_ctor_PlatformException;
-}
-
-void initJavaExceptions(JNIEnvWrapper *env)
-{
- g_cls_PlatformException = env->FindClassAsGlobalRef(EXC_NAME_PLATFORM);
- g_ctor_PlatformException = env->GetConstructorID(g_cls_PlatformException,
- "(" AS_SIG(CLS_NAME_STRING) "I)V");
-}
-
-void clearJavaExceptions(JNIEnvWrapper *env)
-{
- env->DeleteGlobalRef(g_cls_PlatformException);
-}
-
-void throwPlatformException(JNIEnv *env, const OIC::Service::RCSPlatformException &e)
-{
- auto msg = newStringObject(env, e.getReason());
- VERIFY_NO_EXC(env);
-
- auto exObj = env->NewObject(g_cls_PlatformException, g_ctor_PlatformException,
- msg, e.getReasonCode());
- VERIFY_NO_EXC(env);
-
- env->Throw(static_cast< jthrowable >(exObj));
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#ifndef JAVA_EXCEPTIONS_H_
-#define JAVA_EXCEPTIONS_H_
-
-#include <jni.h>
-
-#include "JavaClasses.h"
-
-namespace OIC
-{
- namespace Service
- {
- class RCSPlatformException;
- }
-}
-
-class JNIEnvWrapper;
-
-void initJavaExceptions(JNIEnvWrapper *);
-void clearJavaExceptions(JNIEnvWrapper *);
-
-void throwPlatformException(JNIEnv *, const OIC::Service::RCSPlatformException &);
-
-template < typename ENV >
-void throwRCSException(ENV *env, const char *msg)
-{
- env->ThrowNew(env->FindClass(EXC_NAME_RCS), msg);
-}
-
-
-#endif // JAVA_EXCEPTIONS_H_
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#ifndef JAVA_GLOBAL_REF_H_
-#define JAVA_GLOBAL_REF_H_
-
-#include <memory>
-#include <cassert>
-
-#include "ScopedEnv.h"
-
-class JavaGlobalRef
-{
- public:
- JavaGlobalRef(JNIEnv *env, jobject obj) noexcept :
- m_obj { }
- {
- assert(env &&"JNIEnv is nullptr");
-
- static auto deleter = [](jobject * obj)
- {
- if (obj && *obj)
- {
- ScopedEnv env;
- env->DeleteGlobalRef(*obj);
- }
- delete obj;
- };
-
- m_obj.reset(new jobject{ env->NewGlobalRef(obj) }, deleter);
- }
-
- operator jobject() const noexcept
- {
- return *m_obj;
- }
-
- private:
- std::shared_ptr< jobject > m_obj;
-};
-
-
-
-#endif // JAVA_GLOBAL_REF_H_
template < typename T >
class JavaLocalRef
{
- public:
+public:
JavaLocalRef(JNIEnv *env, T obj) noexcept :
m_env { env },
m_obj { obj }
{
- assert(env &&"JNIEnv is nullptr");
+ assert(env && "JNIEnv is nullptr");
}
- template< typename ENV >
+ template< typename ENV >
JavaLocalRef(ENV *env, T obj) noexcept :
- m_env { env->get() },
- m_obj { obj }
- {
- assert(env &&"JNIEnv is nullptr");
- }
+ m_env { env->get() },
+ m_obj { obj }
+ {
+ assert(env && "JNIEnv is nullptr");
+ }
- ~JavaLocalRef()
- {
- if (m_obj) m_env->DeleteLocalRef(m_obj);
- }
+ ~JavaLocalRef()
+ {
+ if (m_obj) m_env->DeleteLocalRef(m_obj);
+ }
- operator bool() const noexcept { return m_obj; }
- operator T() const noexcept { return m_obj; }
+ operator bool() const noexcept { return m_obj; }
+ operator T() const noexcept { return m_obj; }
- jobject get() const noexcept { return m_obj; }
+ jobject get() const noexcept { return m_obj; }
- JavaLocalRef(const JavaLocalRef &) = delete;
- JavaLocalRef &operator=(const JavaLocalRef &) = delete;
+ JavaLocalRef(const JavaLocalRef &) = delete;
+ JavaLocalRef &operator=(const JavaLocalRef &) = delete;
- JavaLocalRef &operator=(JavaLocalRef && ) = delete;
+ JavaLocalRef &operator=(JavaLocalRef && ) = delete;
- private:
- JNIEnv *m_env;
- T m_obj;
+private:
+ JNIEnv *m_env;
+ T m_obj;
};
typedef JavaLocalRef< jobject > JavaLocalObject;
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#ifndef RCS_JIN_SCOPEDENV_H_
-#define RCS_JIN_SCOPEDENV_H_
-
-#include <utility>
-
-#include <jni.h>
-
-#include "JNIEnvWrapper.h"
-#include "Log.h"
-
-extern JavaVM *g_jvm;
-
-namespace Detail
-{
- inline std::pair<JNIEnv *, bool> getEnv()
- {
- JNIEnv *env { };
- bool needToDetach { };
-
- auto ret = g_jvm->GetEnv((void **) &env, JNI_VERSION_1_6);
-
- switch (ret)
- {
- case JNI_OK:
- break;
-
- case JNI_EDETACHED:
- {
- auto attachRet = g_jvm->AttachCurrentThread(&env, NULL);
-
- if (attachRet != JNI_OK)
- {
- LOGT_E("JNI-ScopedEnv", "Failed to get the environment : %d", attachRet);
- }
- else
- {
- needToDetach = true;
- }
- break;
- }
- case JNI_EVERSION:
- LOGT_E("JNI-ScopedEnv", "JNI version not supported");
- break;
-
- default:
- LOGT_E("JNI-ScopedEnv", "Failed to get the environment");
- break;
- }
-
- return { env, needToDetach };
- }
-}
-
-class ScopedEnv
-{
- public:
- ScopedEnv() noexcept :
- m_env { },
- m_needToDetach { false }
- {
- auto val = Detail::getEnv();
-
- m_env = val.first;
- m_needToDetach = val.second;
- }
-
- ~ScopedEnv()
- {
- if (m_env && m_needToDetach)
- {
- g_jvm->DetachCurrentThread();
- }
- }
-
- ScopedEnv(const ScopedEnv &) = delete;
- ScopedEnv &operator=(const ScopedEnv &) = delete;
-
- operator bool() const noexcept
- {
- return m_env;
- }
-
- JNIEnv *operator->() noexcept
- {
- return m_env;
- }
-
- JNIEnv *get() noexcept
- {
- return m_env;
- }
-
- private:
- JNIEnv *m_env;
- bool m_needToDetach;
-};
-
-class ScopedEnvWrapper
-{
- public:
- ScopedEnvWrapper() noexcept :
- m_env { },
- m_needToDetach { false }
- {
- auto val = Detail::getEnv();
-
- m_env = val.first;
- m_needToDetach = val.second;
- }
-
- ~ScopedEnvWrapper()
- {
- if (m_env && m_needToDetach)
- {
- g_jvm->DetachCurrentThread();
- }
- }
-
- ScopedEnvWrapper(const ScopedEnvWrapper &) = delete;
- ScopedEnvWrapper &operator=(const ScopedEnvWrapper &) = delete;
-
- operator bool() const noexcept
- {
- return m_env;
- }
-
- JNIEnvWrapper *operator->() noexcept
- {
- return &m_env;
- }
-
- JNIEnvWrapper *get() noexcept
- {
- return &m_env;
- }
-
- private:
- JNIEnvWrapper m_env;
- bool m_needToDetach;
-};
-
-#endif // RCS_JIN_SCOPEDENV_H_