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 "jni_group_synchronization_callbacks.h"
22 #include "JniOcResource.h"
23 #include "GroupSynchronization.h"
24 #include "jni_things_manager_jvm.h"
25 #include "jni_things_manager_util.h"
26 #include "jni_string.h"
28 #define LOG_TAG "GroupSynchronizationCallbacks"
30 #define METHOD_ONGROUP_FIND_CALLBACK "(" TM_SERVICE_OCRESOURCE_TYPE")V"
32 void GroupSynchronizationCallbacks::onFoundGroup(std::shared_ptr<OC::OCResource> groupResource)
34 LOGI("FindGroup : Enter");
36 if (NULL == groupResource.get())
38 LOGE("FindGroup : Invalid received GroupResource!");
42 JNIEnv *env = ThingsManagerJVM::getEnv();
45 LOGE("FindGroup : Getting JNIEnv failed");
49 // Get ThingsManagerCallback class reference
50 jclass groupSynchronizationCallbacks = GetJClass(TM_SERVICE_GROUP_SYNCHRONIZATION_CLASS_PATH);
51 if (NULL == groupSynchronizationCallbacks)
53 LOGE("FindGroup : GetJClass TMServiceCallbackInterface failed");
54 ThingsManagerJVM::releaseEnv();
58 // Get the ThingsManagerCallback class instance
59 jobject jobjectCallback = GetJObjectInstance(TM_SERVICE_GROUP_SYNCHRONIZATION_CLASS_PATH);
60 if (NULL == jobjectCallback)
62 LOGE("FindGroup: getInstance failed!");
63 ThingsManagerJVM::releaseEnv();
67 // Get onGroupFindCallback method reference
68 jmethodID method_id = env->GetMethodID(groupSynchronizationCallbacks,
69 "onGroupFindCallback",
70 METHOD_ONGROUP_FIND_CALLBACK);
71 if (NULL == method_id)
73 LOGE("FindGroup : GetMethodID failed");
74 ThingsManagerJVM::releaseEnv();
78 if ((env)->ExceptionCheck())
80 LOGE("FindGroup : ExceptionCheck failed");
81 ThingsManagerJVM::releaseEnv();
85 JniOcResource *jniOcResource = new JniOcResource(groupResource);
88 LOGE("FindGroup : groupResource is invalid!");
89 ThingsManagerJVM::releaseEnv();
93 jobject resource = OcResourceToJava(env, reinterpret_cast<jlong>(jniOcResource));
95 env->CallVoidMethod(jobjectCallback, method_id, resource);
97 if ((env)->ExceptionCheck())
99 LOGE("FindGroup : CallVoidMethod failed");
100 ThingsManagerJVM::releaseEnv();
104 ThingsManagerJVM::releaseEnv();
105 LOGI("FindGroup : Exit");