1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
21 #include "JniRcsDiscoveryManager.h"
22 #include "JniRcsObject.h"
23 #include "JniRcsRemoteResourceObject.h"
24 #include "JniRcsResourceAttributes.h"
25 #include "JniRcsResourceObject.h"
26 #include "JniRcsValue.h"
27 #include "JavaClasses.h"
28 #include "JavaExceptions.h"
29 #include "JNIEnvWrapper.h"
32 #define LOG_TAG "JNI-Main"
34 #define JNI_CURRENT_VERSION JNI_VERSION_1_6
38 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
44 if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
46 LOGE("Failed to get the environment using GetEnv()");
50 JNIEnvWrapper envWrapper{ env };
54 initJavaClasses(&envWrapper);
55 initJavaExceptions(&envWrapper);
56 initRCSValue(&envWrapper);
57 initRCSResourceAttributes(&envWrapper);
58 initRCSDiscoveryManager(&envWrapper);
59 initRCSRemoteResourceObject(&envWrapper);
60 initRCSObject(&envWrapper);
61 initRCSResourceObject(&envWrapper);
63 catch (const JavaException&)
65 if (env->ExceptionCheck()) env->ExceptionDescribe();
69 return JNI_CURRENT_VERSION;
72 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
77 if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
79 LOGE("Failed to get the environment using GetEnv()");
83 JNIEnvWrapper envWrapper{ env };
87 clearRCSResourceObject(&envWrapper);
88 clearRCSObject(&envWrapper);
89 clearRCSRemoteResourceObject(&envWrapper);
90 clearRCSDiscoveryManager(&envWrapper);
91 clearRCSResourceAttributes(&envWrapper);
92 clearRCSValue(&envWrapper);
93 clearJavaExceptions(&envWrapper);
94 clearJavaClasses(&envWrapper);
96 catch (const JavaException&)