1 //******************************************************************
\r
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
7 // Licensed under the Apache License, Version 2.0 (the "License");
\r
8 // you may not use this file except in compliance with the License.
\r
9 // You may obtain a copy of the License at
\r
11 // http://www.apache.org/licenses/LICENSE-2.0
\r
13 // Unless required by applicable law or agreed to in writing, software
\r
14 // distributed under the License is distributed on an "AS IS" BASIS,
\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 // See the License for the specific language governing permissions and
\r
17 // limitations under the License.
\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
21 #include "JniNotificationCommon.h"
\r
23 #include "JniUtils.h"
\r
25 static jclass g_cls_NSException = NULL;
\r
26 static jmethodID g_mid_NSException_ctor = NULL;
\r
27 static jmethodID g_mid_NSException_setNativeExceptionLocation = NULL;
\r
29 static const char *NSResultToChar(const int nsresult)
\r
37 case JNI_NS_SUCCESS:
\r
46 return "JNI_EXCEPTION";
\r
47 case JNI_NO_NATIVE_POINTER:
\r
48 return "JNI_NO_NATIVE_POINTER";
\r
49 case JNI_INVALID_VALUE:
\r
50 return "JNI_INVALID_VALUE";
\r
57 jobject getNSException(JNIEnv *env, const char *file, const char *functionName,
\r
58 const int line, const int code, const char *message)
\r
60 const char *codeChar = NSResultToChar(code);
\r
61 if (codeChar[0] == '\0')
\r
63 codeChar = NSResultToChar(JNI_INVALID_VALUE);
\r
65 jobject exception = env->NewObject(
\r
67 g_mid_NSException_ctor,
\r
68 env->NewStringUTF(codeChar),
\r
69 env->NewStringUTF(message));
\r
74 env->CallVoidMethod(
\r
76 g_mid_NSException_setNativeExceptionLocation,
\r
77 env->NewStringUTF(file),
\r
78 env->NewStringUTF(functionName),
\r
80 if (env->ExceptionCheck())
\r
87 void throwNSException(JNIEnv *env, jobject exception)
\r
89 env->Throw((jthrowable)exception);
\r
92 int NSExceptionInit(JNIEnv *env)
\r
96 LOGE ("JNIEnv is null");
\r
101 jclass localNSException = env->FindClass(
\r
102 "org/iotivity/service/ns/common/NSException");
\r
103 if (!localNSException)
\r
105 LOGE ("Failed to get local NSException");
\r
108 g_cls_NSException = (jclass)env->NewGlobalRef(localNSException);
\r
111 g_mid_NSException_ctor = env->GetMethodID(g_cls_NSException,
\r
112 "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
\r
113 if (!g_mid_NSException_ctor)
\r
115 LOGE ("Failed to Get MethodID");
\r
119 g_mid_NSException_setNativeExceptionLocation = env->GetMethodID(g_cls_NSException,
\r
120 "setNativeExceptionLocation",
\r
121 "(Ljava/lang/String;Ljava/lang/String;I)V");
\r
122 if (!g_mid_NSException_setNativeExceptionLocation)
\r
124 LOGE ("Failed to Get MethodID");
\r
128 env->DeleteLocalRef(localNSException);
\r
130 return JNI_CURRENT_VERSION;
\r