Imported Upstream version 1.0.1
[platform/upstream/iotivity.git] / service / simulator / java / jni / simulator_jni_utils.cpp
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20 #include "simulator_jni_utils.h"
21 #include "simulator_common_jni.h"
22
23 extern SimulatorClassRefs gSimulatorClassRefs;
24
25 void throwSimulatorException(JNIEnv *env, SimulatorResult errCode, const char *errMessage)
26 {
27     jobject ex = env->NewObject(gSimulatorClassRefs.classSimulatorException,
28                                 gSimulatorClassRefs.classSimulatorExceptionCtor, errCode,
29                                 env->NewStringUTF(errMessage));
30     if (!ex)
31     {
32         return;
33     }
34     env->Throw((jthrowable)ex);
35 }
36
37 void throwInvalidArgsException(JNIEnv *env, SimulatorResult errCode, const char *errMessage)
38 {
39     jobject ex = env->NewObject(gSimulatorClassRefs.classInvalidArgsException,
40                                 gSimulatorClassRefs.classInvalidArgsExceptionCtor, errCode,
41                                 env->NewStringUTF(errMessage));
42     if (!ex)
43     {
44         return;
45     }
46     env->Throw((jthrowable)ex);
47 }
48
49 void throwNoSupportException(JNIEnv *env, SimulatorResult errCode, const char *errMessage)
50 {
51     jobject ex = env->NewObject(gSimulatorClassRefs.classNoSupportException,
52                                 gSimulatorClassRefs.classNoSupportExceptionCtor, errCode,
53                                 env->NewStringUTF(errMessage));
54     if (!ex)
55     {
56         return;
57     }
58     env->Throw((jthrowable)ex);
59 }
60
61 void throwOperationInProgressException(JNIEnv *env, SimulatorResult errCode, const char *errMessage)
62 {
63     jobject ex = env->NewObject(gSimulatorClassRefs.classOperationInProgressException,
64                                 gSimulatorClassRefs.classOperationInProgressExceptionCtor, errCode,
65                                 env->NewStringUTF(errMessage));
66     if (!ex)
67     {
68         return;
69     }
70     env->Throw((jthrowable)ex);
71 }