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 ******************************************************************/
20 #include "jni_things_manager.h"
22 #include "JniOcResource.h"
23 #include "JniOcResourceHandle.h"
24 #include "ThingsManager.h"
25 #include "ActionSet.h"
26 #include "jni_things_manager_jvm.h"
27 #include "jni_things_manager_util.h"
28 #include "jni_things_manager_callbacks.h"
29 #include "jni_action_set.h"
35 * @var g_ThingsManager
36 * @brief ThingsManager static object
38 static ThingsManager g_ThingsManager;
40 jobject ocResourceHandleToJava(JNIEnv *env, jlong resourceHandle);
42 JNIEXPORT jint JNICALL JNIThingsManagerFindCandidateResource(JNIEnv *env, jobject interfaceObject,
43 jobject jResourceTypes, jint waitSec)
45 LOGI("JNIThingsManagerFindCandidateResource: Enter");
49 LOGE("JNIThingsManagerFindCandidateResource: jResourceTypes is NULL!");
50 return OC_STACK_INVALID_PARAM;
53 OCStackResult ocResult = OC_STACK_ERROR;
56 ocResult = g_ThingsManager.findCandidateResources(convertStringVector(env, jResourceTypes),
57 &ThingsManagerCallbacks::onFoundCandidateResource, (int)waitSec);
59 if (OC_STACK_OK != ocResult)
61 LOGE("JNIThingsManagerFindCandidateResource: findCandidateResources failed!");
65 catch (InitializeException &e)
67 LOGE("JNIThingsManagerFindCandidateResource: Exception occurred! %s, %d", e.reason().c_str(),
72 LOGI("JNIThingsManagerFindCandidateResource: Exit");
76 JNIEXPORT jint JNICALL JNIThingsManagerSubscribeCollectionPresence(JNIEnv *env,
77 jobject interfaceObject,
80 LOGI("JNIThingsManagerSubscribeCollectionPresence: Enter");
84 LOGE("JNIThingsManagerSubscribeCollectionPresence: jResource is NULL!");
85 return OC_STACK_INVALID_PARAM;
88 OCStackResult ocResult = OC_STACK_ERROR;
90 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource);
91 if (NULL == jniOcResource)
93 LOGE("JNIThingsManagerSubscribeCollectionPresence: Failed to get jni OcResource!");
97 std::shared_ptr<OCResource> ocResource = jniOcResource->getOCResource();
98 if (NULL == ocResource.get())
100 LOGE("JNIThingsManagerSubscribeCollectionPresence: Failed to get OCResource object!");
104 ocResult = g_ThingsManager.subscribeCollectionPresence(ocResource,
105 &ThingsManagerCallbacks::onSubscribePresence);
106 if (OC_STACK_OK != ocResult)
108 LOGE("JNIThingsManagerSubscribeCollectionPresence: subscribeCollectionPresence failed!");
112 LOGI("JNIThingsManagerSubscribeCollectionPresence: Exit");
116 JNIEXPORT jobject JNICALL JNIThingsManagerBindResourceToGroup(JNIEnv *env, jobject interfaceObject,
117 jobject jResource, jobject jCollectionHandle)
119 LOGI("JNIThingsManagerBindResourceToGroup: Enter");
121 if (!jResource || !jCollectionHandle)
123 LOGE("JNIThingsManagerBindResourceToGroup: Invalid parameter!");
127 std::shared_ptr<OCResource> ocResource;
128 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource);
131 ocResource = jniOcResource->getOCResource();
134 if (NULL == ocResource.get())
136 LOGE("JNIThingsManagerBindResourceToGroup: Failed to get OCResource object!");
140 JniOcResourceHandle *jniOcCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env,
142 if (NULL == jniOcCollectionHandle)
144 LOGE("JNIThingsManagerBindResourceToGroup: collection handle is null!");
148 jobject jResourceHandle = NULL;
151 OCResourceHandle ocChildHandle = NULL;
152 OCResourceHandle ocCollectionHandle = jniOcCollectionHandle->getOCResourceHandle();
153 OCStackResult ocResult = g_ThingsManager.bindResourceToGroup(ocChildHandle, ocResource, ocCollectionHandle);
154 if (OC_STACK_OK != ocResult)
156 LOGE("JNIThingsManagerBindResourceToGroup: bindResourceToGroup failed!");
160 // Convert OCResourceHandle to java type
161 JniOcResourceHandle* jniHandle = new JniOcResourceHandle(ocChildHandle);
162 jlong handle = reinterpret_cast<jlong>(jniHandle);
163 jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle);
164 if (env->ExceptionCheck())
166 LOGE("JNIThingsManagerBindResourceToGroup: Failed to create OcResourceHandle");
171 catch (InitializeException &e)
173 LOGE("JNIThingsManagerBindResourceToGroup: Exception occurred! %s, %d", e.reason().c_str(),
178 LOGI("JNIThingsManagerBindResourceToGroup: Exit");
179 return jResourceHandle;
182 JNIEXPORT jint JNICALL JNIThingsManagerFindGroup(JNIEnv *env, jobject interfaceObject,
183 jobject jResourceTypes)
185 LOGI("JNIThingsManagerFindGroup: Enter");
189 LOGE("JNIThingsManagerFindGroup: jResourceTypes is NULL!");
190 return OC_STACK_INVALID_PARAM;
193 OCStackResult ocResult = OC_STACK_ERROR;
196 ocResult = g_ThingsManager.findGroup((convertStringVector(env, jResourceTypes)),
197 &ThingsManagerCallbacks::onFoundGroup);
198 if (OC_STACK_OK != ocResult)
200 LOGE("JNIThingsManagerFindGroup: findGroup failed!");
204 catch (InitializeException &e)
206 LOGE("JNIThingsManagerFindGroup: Exception occurred! %s, %d", e.reason().c_str(),
210 LOGI("JNIThingsManagerFindGroup: Exit");
214 JNIEXPORT jint JNICALL JNIThingsManagerCreateGroup(JNIEnv *env, jobject interfaceObject,
215 jstring jResourceType)
217 LOGI("JNIThingsManagerCreateGroup: Enter");
221 LOGE("JNIThingsManagerCreateGroup: jResourceType is NULL!");
222 return OC_STACK_INVALID_PARAM;
225 OCStackResult ocResult = OC_STACK_ERROR;
227 const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL);
228 if (NULL == resourceTypePointer)
230 LOGE("JNIThingsManagerCreateGroup: Failed to convert jstring to char string!");
231 return OC_STACK_NO_MEMORY;
234 std::string resourceType(resourceTypePointer);
237 ocResult = g_ThingsManager.createGroup(resourceType);
238 if (OC_STACK_OK != ocResult)
240 LOGE("JNIThingsManagerCreateGroup: CreateGroup failed!");
243 catch (InitializeException &e)
245 LOGE("JNIThingsManagerCreateGroup: Exception occurred! %s, %d", e.reason().c_str(),
248 env->ReleaseStringUTFChars(jResourceType, resourceTypePointer);
249 LOGI("JNIThingsManagerCreateGroup: Exit");
253 JNIEXPORT jint JNICALL JNIThingsManagerJoinGroupString(JNIEnv *env, jobject interfaceObject,
254 jstring jResourceType, jobject jResourceHandle)
256 LOGI("JNIThingsManagerJoinGroupString: Enter");
258 if ((!jResourceType) || (!jResourceHandle))
260 LOGE("JNIThingsManagerJoinGroupString: jResourceType or jResourceHandle is NULL!");
261 return OC_STACK_INVALID_PARAM;
264 OCStackResult ocResult = OC_STACK_ERROR;
266 const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL);
267 if (NULL == resourceTypePointer)
269 LOGE("JNIThingsManagerJoinGroupString: Failed to convert jstring to char string!");
270 return OC_STACK_NO_MEMORY;
273 std::string resourceType(resourceTypePointer);
275 JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env,
279 OCResourceHandle ocResourceHandle = jniOcResourceHandle->getOCResourceHandle();
280 ocResult = g_ThingsManager.joinGroup(resourceType, ocResourceHandle);
281 if (OC_STACK_OK != ocResult)
283 LOGE("JNIThingsManagerJoinGroupString: joinGroup failed!");
286 catch (InitializeException &e)
288 LOGE("JNIThingsManagerJoinGroupString: Exception occurred! %s, %d", e.reason().c_str(),
291 env->ReleaseStringUTFChars(jResourceType, resourceTypePointer);
292 LOGI("JNIThingsManagerJoinGroupString: Exit");
296 JNIEXPORT jint JNICALL JNIThingsManagerJoinGroupObject(JNIEnv *env, jobject interfaceObject,
297 jobject jResource, jobject jResourceHandle)
299 LOGI("JNIThingsManagerJoinGroupObject: Enter");
301 if ((!jResource) || (!jResourceHandle))
303 LOGE("JNIThingsManagerJoinGroupObject: jResource or jResourceHandle is NULL!");
304 return OC_STACK_INVALID_PARAM;
307 OCStackResult ocResult = OC_STACK_ERROR;
309 std::shared_ptr<OCResource> ocResource;
310 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource);
313 ocResource = jniOcResource->getOCResource();
316 if (NULL == ocResource.get())
318 LOGE("JNIThingsManagerJoinGroupObject: Failed to get OCResource object!");
322 JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env,
327 OCResourceHandle resHandle = jniOcResourceHandle->getOCResourceHandle();
329 ocResult = g_ThingsManager.joinGroup(ocResource, resHandle);
330 if (OC_STACK_OK != ocResult)
332 LOGE("JNIThingsManagerJoinGroupObject: joinGroup failed!");
336 catch (InitializeException &e)
338 LOGE("JNIThingsManagerJoinGroupObject: Exception occurred! %s, %d", e.reason().c_str(),
342 LOGI("JNIThingsManagerJoinGroupObject: Exit");
346 JNIEXPORT jint JNICALL JNIThingsManagerLeaveGroup(JNIEnv *env, jobject interfaceObject,
347 jstring jResourceType,
348 jobject jResourceHandle)
350 LOGI("JNIThingsManagerLeaveGroup: Enter");
352 if ((!jResourceType) || (!jResourceHandle))
354 LOGE("JNIThingsManagerLeaveGroup: jResourceType or jResourceHandle is NULL!");
355 return OC_STACK_INVALID_PARAM;
358 OCStackResult ocResult = OC_STACK_ERROR;
360 const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL);
361 if (NULL == resourceTypePointer)
363 LOGE("JNIThingsManagerLeaveGroup: Failed to convert jstring to char string!");
364 return OC_STACK_NO_MEMORY;
367 std::string resourceType(resourceTypePointer);
368 JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env,
373 OCResourceHandle ocResourceHandle = jniOcResourceHandle->getOCResourceHandle();
375 ocResult = g_ThingsManager.leaveGroup(resourceType, ocResourceHandle);
376 if (OC_STACK_OK != ocResult)
378 LOGE("JNIThingsManagerLeaveGroup: leaveGroup failed!");
381 catch (InitializeException &e)
383 LOGE("JNIThingsManagerLeaveGroup: Exception occurred! %s, %d", e.reason().c_str(),
386 env->ReleaseStringUTFChars(jResourceType, resourceTypePointer);
387 LOGI("JNIThingsManagerLeaveGroup: Exit");
391 JNIEXPORT jint JNICALL JNIThingsManagerLeaveGroupForResource(JNIEnv *env, jobject interfaceObject,
393 jstring jResourceType,
394 jobject jResourceHandle)
396 LOGI("JNIThingsManagerLeaveGroupForResource: Enter");
398 if ((!jResource) || (!jResourceType) || (!jResourceHandle))
400 LOGE("JNIThingsManagerLeaveGroupForResource: jResourceType or jResourceHandle is NULL!");
401 return OC_STACK_INVALID_PARAM;
404 OCStackResult ocResult = OC_STACK_ERROR;
406 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource);
407 if (NULL == jniOcResource)
409 LOGE("JNIThingsManagerLeaveGroupForResource: Failed to get jni OcResource!");
413 std::shared_ptr<OCResource> ocResource = jniOcResource->getOCResource();
414 if (NULL == ocResource.get())
416 LOGE("JNIThingsManagerLeaveGroupForResource: Failed to get OCResource object!");
420 const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL);
421 if (NULL == resourceTypePointer)
423 LOGE("JNIThingsManagerLeaveGroupForResource: Failed to convert jstring to char string!");
424 return OC_STACK_NO_MEMORY;
427 std::string resourceType(resourceTypePointer);
428 JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env,
433 OCResourceHandle ocResourceHandle = jniOcResourceHandle->getOCResourceHandle();
435 ocResult = g_ThingsManager.leaveGroup(ocResource, resourceType, ocResourceHandle);
436 if (OC_STACK_OK != ocResult)
438 LOGE("JNIThingsManagerLeaveGroupForResource: leaveGroup failed!");
441 catch (InitializeException &e)
443 LOGE("JNIThingsManagerLeaveGroupForResource: Exception occurred! %s, %d", e.reason().c_str(),
447 env->ReleaseStringUTFChars(jResourceType, resourceTypePointer);
448 LOGI("JNIThingsManagerLeaveGroupForResource: Exit");
452 JNIEXPORT void JNICALL JNIThingsManagerDeleteGroup(JNIEnv *env, jobject interfaceObject,
453 jstring jcollectionResourceType)
455 LOGI("JNIThingsManagerDeleteGroup: Enter");
457 if (!jcollectionResourceType)
459 LOGE("JNIThingsManagerDeleteGroup: jcollectionResourceType is NULL!");
463 const char *collectionResourceTypePointer = env->GetStringUTFChars(jcollectionResourceType, NULL);
464 if (NULL == collectionResourceTypePointer)
466 LOGE("JNIThingsManagerDeleteGroup: Failed to convert jstring to char string!");
470 std::string collectionResourceType(collectionResourceTypePointer);
473 g_ThingsManager.deleteGroup(collectionResourceType);
475 catch (InitializeException &e)
477 LOGE("JNIThingsManagerDeleteGroup: Exception occurred! %s, %d", e.reason().c_str(),
481 env->ReleaseStringUTFChars(jcollectionResourceType, collectionResourceTypePointer);
482 LOGI("JNIThingsManagerDeleteGroup: Exit");
485 JNIEXPORT jobject JNICALL JNIThingsManagerGetGroupList(JNIEnv *env, jobject interfaceObject)
487 LOGI("JNIThingsManagerGetGroupList: Enter");
489 std::map< std::string, OCResourceHandle> groupListMap;
490 jobject jGroupListMap;
492 groupListMap = g_ThingsManager.getGroupList();
493 if (groupListMap.empty())
495 LOGD("getGroupList Map is empty");
499 jclass clazz = env->FindClass("java/util/HashMap");
500 jmethodID init = env->GetMethodID(clazz, "<init>", "()V");
501 jGroupListMap = env->NewObject(clazz, init);
502 jmethodID putMethod = env->GetMethodID(clazz, "put",
503 "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
505 for (auto it = groupListMap.begin(); it != groupListMap.end(); ++it)
507 jstring key = (*env).NewStringUTF( (*it).first.c_str() );
508 JniOcResourceHandle *jniOcResourceHandle = new JniOcResourceHandle(((*it).second));
509 jobject value = ocResourceHandleToJava(env, reinterpret_cast<jlong>(jniOcResourceHandle));
510 env->CallObjectMethod(jGroupListMap, putMethod, key, value);
513 LOGI("JNIThingsManagerGetGroupList: Exit");
514 return jGroupListMap;
517 JNIEXPORT jint JNICALL JNIThingsManagerUpdateConfigurations(JNIEnv *env, jobject interfaceObject,
518 jobject resource, jobject configurations)
520 LOGI("JNIThingsManagerUpdateConfigurations: Enter");
522 if ((!resource) || (!configurations))
524 LOGE("JNIThingsManagerUpdateConfigurations: resource or configurations is NULL!");
525 return OC_STACK_INVALID_PARAM;
528 OCStackResult ocResult = OC_STACK_ERROR;
530 std::shared_ptr<OCResource> ocResource;
531 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
534 ocResource = jniOcResource->getOCResource();
537 if (NULL == ocResource.get())
539 LOGE("JNIThingsManagerUpdateConfigurations: Failed to get OCResource object!");
543 std::map<std::string, std::string> configurationsMap;
544 configurationsMap = convertStringMap(env, configurations);
545 ocResult = g_ThingsManager.updateConfigurations(ocResource, configurationsMap,
546 &ThingsManagerCallbacks::onUpdateConfigurationsResponse);
547 if (OC_STACK_OK != ocResult)
549 LOGE("JNIThingsManagerUpdateConfigurations: updateConfigurations failed!");
553 LOGI("JNIThingsManagerUpdateConfigurations: Exit");
557 JNIEXPORT jint JNICALL JNIThingsManagerGetConfigurations(JNIEnv *env, jobject interfaceObject,
558 jobject resource, jobject configurations)
560 LOGI("JNIThingsManagerGetConfigurations: Enter");
562 if ((!resource) || (!configurations))
564 LOGE("JNIThingsManagerGetConfigurations: resource or configurations is NULL!");
565 return OC_STACK_INVALID_PARAM;
568 OCStackResult ocResult = OC_STACK_ERROR;
570 std::shared_ptr<OCResource> ocResource;
571 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
574 ocResource = jniOcResource->getOCResource();
577 if (NULL == ocResource.get())
579 LOGE("JNIThingsManagerGetConfigurations: Failed to get OCResource object!");
583 ocResult = g_ThingsManager.getConfigurations(ocResource,
584 (convertStringVector(env, configurations)),
585 &ThingsManagerCallbacks::onGetConfigurationsResponse);
586 if (OC_STACK_OK != ocResult)
588 LOGE("JNIThingsManagerGetConfigurations: getConfigurations failed!");
592 LOGI("JNIThingsManagerGetConfigurations: Exit");
596 JNIEXPORT jstring JNICALL JNIThingsManagerGetListOfSupportedConfigurationUnits(JNIEnv *env,
597 jobject interfaceObject)
599 LOGI("JNIThingsManagerGetListOfSupportedConfigurationUnits: Enter");
601 std::string configListString = g_ThingsManager.getListOfSupportedConfigurationUnits();
602 jstring jConfigListString = env->NewStringUTF(configListString.c_str());
604 LOGI("JNIThingsManagerGetListOfSupportedConfigurationUnits: Exit");
605 return jConfigListString;
608 JNIEXPORT jint JNICALL JNIThingsManagerDoBootstrap(JNIEnv *env, jobject interfaceObject)
610 LOGI("JNIThingsManagerDoBootstrap: Enter");
612 OCStackResult ocResult = OC_STACK_ERROR;
615 ocResult = g_ThingsManager.doBootstrap(&ThingsManagerCallbacks::onBootStrapResponse);
616 if (OC_STACK_OK != ocResult)
618 LOGE("JNIThingsManagerDoBootstrap: doBootstrap failed!");
622 catch (InitializeException &e)
624 LOGE("JNIThingsManagerDoBootstrap: Exception occurred! %s, %d", e.reason().c_str(),
629 LOGI("JNIThingsManagerDoBootstrap: Exit");
633 JNIEXPORT jint JNICALL JNIThingsManagerReboot(JNIEnv *env, jobject interfaceObject,
636 LOGI("JNIThingsManagerReboot: Enter");
640 LOGE("JNIThingsManagerReboot: resource is NULL!");
641 return OC_STACK_INVALID_PARAM;
644 OCStackResult ocResult = OC_STACK_ERROR;
646 std::shared_ptr<OCResource> ocResource;
647 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
650 ocResource = jniOcResource->getOCResource();
653 if (NULL == ocResource.get())
655 LOGE("JNIThingsManagerReboot: Failed to get OCResource object!");
659 ocResult = g_ThingsManager.reboot(ocResource, &ThingsManagerCallbacks::onRebootResponse);
660 if (OC_STACK_OK != ocResult)
662 LOGE("JNIThingsManagerReboot: reboot failed!");
666 LOGI("JNIThingsManagerReboot: Exit");
670 JNIEXPORT jint JNICALL JNIThingsManagerFactoryReset(JNIEnv *env, jobject interfaceObject,
673 LOGI("JNIThingsManagerFactoryReset: Enter");
677 LOGE("JNIThingsManagerFactoryReset: resource is NULL!");
678 return OC_STACK_INVALID_PARAM;
681 OCStackResult ocResult = OC_STACK_ERROR;
683 std::shared_ptr<OCResource> ocResource;
684 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
687 ocResource = jniOcResource->getOCResource();
690 if (NULL == ocResource.get())
692 LOGE("JNIThingsManagerFactoryReset: Failed to get OCResource object!");
696 ocResult = g_ThingsManager.factoryReset(ocResource,
697 &ThingsManagerCallbacks::onFactoryResetResponse);
698 if (OC_STACK_OK != ocResult)
700 LOGE("JNIThingsManagerFactoryReset: factoryReset failed!");
704 LOGI("JNIThingsManagerFactoryReset: Exit");
708 JNIEXPORT jint JNICALL JNIThingsManagerAddActionSet(JNIEnv *env, jobject interfaceObject,
710 jobject newActionSet)
712 LOGI("JNIThingsManagerAddActionSet: Entry");
714 if ((!resource) || (!newActionSet))
716 LOGE("JNIThingsManagerAddActionSet: resource or newActionSet is NULL!");
717 return OC_STACK_INVALID_PARAM;
720 OCStackResult ocResult = OC_STACK_ERROR;
722 std::shared_ptr<OCResource> ocResource;
723 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
726 ocResource = jniOcResource->getOCResource();
729 if (NULL == ocResource.get())
731 LOGE("JNIThingsManageraAdActionSet: Failed to get OCResource object!");
735 JniActionSet *jActionSet = new JniActionSet(env, newActionSet);
736 ActionSet *pActionSet = jActionSet->getActionSet(env, newActionSet);
737 if (NULL == pActionSet)
739 LOGE("JNIThingsManageraAdActionSet: Failed to convert ActionSet!");
743 ocResult = g_ThingsManager.addActionSet(ocResource, pActionSet,
744 &ThingsManagerCallbacks::onPutResponse);
745 if (OC_STACK_OK != ocResult)
747 LOGE("JNIThingsManagerAddActionSet: addActionSet is failed!");
751 LOGI("JNIThingsManagerAddActionSet: Exit");
755 JNIEXPORT jint JNICALL JNIThingsManagerExecuteActionSet(JNIEnv *env, jobject interfaceObject,
756 jobject resource, jstring jActionSetName)
758 LOGI("JNIThingsManagerExecuteActionSet: Entry");
760 if ((!resource) || (!jActionSetName))
762 LOGE("JNIThingsManagerExecuteActionSet: resource or jActionSetName is NULL!");
763 return OC_STACK_INVALID_PARAM;
766 OCStackResult ocResult = OC_STACK_ERROR;
768 std::shared_ptr<OCResource> ocResource;
769 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
772 ocResource = jniOcResource->getOCResource();
775 if (NULL == ocResource.get())
777 LOGE("JNIThingsManagerExecuteActionSet: Failed to get OCResource object!");
781 const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0);
782 if (NULL == actionSetNamePointer)
784 LOGE("JNIThingsManagerExecuteActionSet: Failed to convert jstring to char string!");
785 return OC_STACK_NO_MEMORY;
788 std::string actionSetName(actionSetNamePointer);
790 ocResult = g_ThingsManager.executeActionSet(ocResource, actionSetName,
791 &ThingsManagerCallbacks::onPostResponse);
792 if (OC_STACK_OK != ocResult)
794 LOGE("JNIThingsManagerExecuteActionSet: executeActionSet is failed!");
797 env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer);
798 LOGI("JNIThingsManagerExecuteActionSet: Exit");
802 JNIEXPORT jint JNICALL JNIThingsManagerExecuteActionSetWithDelay(JNIEnv *env,
803 jobject interfaceObject,
804 jobject resource, jstring jActionSetName, jlong delay)
806 LOGI("JNIThingsManagerExecuteActionSet: Entry");
808 if ((!resource) || (!jActionSetName))
810 LOGE("JNIThingsManagerExecuteActionSet: resource or jActionSetName is NULL!");
811 return OC_STACK_INVALID_PARAM;
814 OCStackResult ocResult = OC_STACK_ERROR;
816 std::shared_ptr<OCResource> ocResource;
817 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
820 ocResource = jniOcResource->getOCResource();
823 if (NULL == ocResource.get())
825 LOGE("JNIThingsManagerExecuteActionSet: Failed to get OCResource object!");
829 const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0);
830 if (NULL == actionSetNamePointer)
832 LOGE("JNIThingsManagerExecuteActionSet: Failed to convert jstring to char string!");
833 return OC_STACK_NO_MEMORY;
836 std::string actionSetName(actionSetNamePointer);
839 ocResult = g_ThingsManager.executeActionSet(ocResource, actionSetName,
840 &ThingsManagerCallbacks::onPostResponse);
844 ocResult = g_ThingsManager.executeActionSet(ocResource, actionSetName,
846 &ThingsManagerCallbacks::onPostResponse);
848 if (OC_STACK_OK != ocResult)
850 LOGE("JNIThingsManagerExecuteActionSet: executeActionSet is failed!");
853 env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer);
854 LOGI("JNIThingsManagerExecuteActionSet: Exit");
858 JNIEXPORT jint JNICALL JNIThingsManagerCancelActionSet(JNIEnv *env, jobject interfaceObject,
859 jobject resource, jstring jActionSetName)
861 LOGI("JNIThingsManagerCancelActionSet: Entry");
863 if ((!resource) || (!jActionSetName))
865 LOGE("JNIThingsManagerCancelActionSet: resource or jActionSetName is NULL!");
866 return OC_STACK_INVALID_PARAM;
869 OCStackResult ocResult = OC_STACK_ERROR;
871 std::shared_ptr<OCResource> ocResource;
872 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
875 ocResource = jniOcResource->getOCResource();
878 if (NULL == ocResource.get())
880 LOGE("JNIThingsManagerCancelActionSet: Failed to get OCResource object!");
884 const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0);
885 if (NULL == actionSetNamePointer)
887 LOGE("JNIThingsManagerCancelActionSet: Failed to get character sequence from jstring!");
888 return OC_STACK_NO_MEMORY;
891 std::string actionSetName(actionSetNamePointer);
893 ocResult = g_ThingsManager.cancelActionSet(ocResource, actionSetName,
894 &ThingsManagerCallbacks::onPostResponse);
895 if (OC_STACK_OK != ocResult)
897 LOGE("JNIThingsManagerCancelActionSet: cancelActionSet is failed!");
900 env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer);
901 LOGI("JNIThingsManagerCancelActionSet: Exit");
905 JNIEXPORT jint JNICALL JNIThingsManagerGetActionSet(JNIEnv *env, jobject interfaceObject,
907 jstring jActionSetName)
909 LOGI("JNIThingsManagerGetActionSet: Entry");
911 if ((!resource) || (!jActionSetName))
913 LOGE("JNIThingsManagerGetActionSet: resource or jActionSetName is NULL!");
914 return OC_STACK_INVALID_PARAM;
917 OCStackResult ocResult = OC_STACK_ERROR;
919 std::shared_ptr<OCResource> ocResource;
920 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
923 ocResource = jniOcResource->getOCResource();
926 if (NULL == ocResource.get())
928 LOGE("JNIThingsManagerGetActionSet: Failed to get OCResource object!");
932 const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0);
933 std::string actionSetName(actionSetNamePointer);
935 ocResult = g_ThingsManager.getActionSet(ocResource, actionSetName,
936 &ThingsManagerCallbacks::onGetResponse);
937 if (OC_STACK_OK != ocResult)
939 LOGE("JNIThingsManagerGetActionSet: getActionSet is failed!");
942 env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer);
943 LOGI("JNIThingsManagerGetActionSet: Exit");
947 JNIEXPORT jint JNICALL JNIThingsManagerDeleteActionSet(JNIEnv *env, jobject interfaceObject,
949 jstring jActionSetName)
951 LOGI("JNIThingsManagerDeleteActionSet: Entry");
953 if ((!resource) || (!jActionSetName))
955 LOGE("JNIThingsManagerDeleteActionSet: resource or jActionSetName is NULL!");
956 return OC_STACK_INVALID_PARAM;
959 OCStackResult ocResult = OC_STACK_ERROR;
961 std::shared_ptr<OCResource> ocResource;
962 JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource);
965 ocResource = jniOcResource->getOCResource();
968 if (NULL == ocResource.get())
970 LOGE("JNIThingsManagerDeleteActionSet: Failed to get OCResource object!");
974 const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0);
975 std::string actionSetName(actionSetNamePointer);
977 ocResult = g_ThingsManager.deleteActionSet(ocResource, actionSetName,
978 &ThingsManagerCallbacks::onPutResponse);
979 if (OC_STACK_OK != ocResult)
981 LOGE("JNIThingsManagerDeleteActionSet: deleteActionSet is failed!");
984 env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer);
985 LOGI("JNIThingsManagerDeleteActionSet: Exit");
989 jobject ocResourceHandleToJava(JNIEnv *env, jlong resourceHandle)
991 jclass resourceClass = GetJClass(TM_SERVICE_OCRESOURCEHANDLE_PATH);
992 if (NULL == resourceClass)
994 LOGE("ocResourceHandleToJava : failed to find OCResourceHandle java class!");
998 jmethodID constructor = env->GetMethodID(resourceClass, "<init>", "(J)V");
999 if (NULL == constructor)
1001 LOGE("ocResourceHandleToJava: Failed to get constructor method!");
1005 jobject resourceObj = (jobject) env->NewObject(resourceClass, constructor, resourceHandle);
1006 if (NULL == resourceObj)
1008 LOGE("ocResourceHandleToJava: Failed to create OCResouceHandle java object!");