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_action.h"
22 #include "jni_things_manager_jvm.h"
23 #include "jni_getter.h"
24 #include "jni_setter.h"
26 #include <ActionSet.h>
28 #define JACTION_TARGET ("target")
29 #define JACTION_LISTOF_CAPABILITY ("listOfCapability")
31 JniAction::JniAction(JNIEnv *env, jobject obj) : JObject(env, obj)
35 JniAction::JniAction(JNIEnv *env) : JObject(env, TM_SERVICE_ACTION_PATH)
39 JniAction::~JniAction()
43 bool JniAction::getTarget(std::string &target)
45 //Retrieves target value from JniAction class object
46 return JGetter::getJStringField(m_pEnv, m_pObject, JACTION_TARGET, target);
49 bool JniAction::setTarget(const std::string target)
51 //Sets target value of JniAction class object
52 return JSetter::setJStringField(m_pEnv, m_pObject, JACTION_TARGET, target.c_str());
55 bool JniAction::getJniCapabilityValues(std::vector<OIC::Capability *> &capabilityList)
57 jclass jvectorClass = m_pEnv->FindClass(TM_JAVA_VECTOR_CLASS_PATH);
58 jmethodID vectorMethodID = m_pEnv->GetMethodID(jvectorClass, "get", "(I)Ljava/lang/Object;");
59 jmethodID vectorSizeMethodID = m_pEnv->GetMethodID(jvectorClass, "size", "()I");
61 jobject jAttrList = NULL;
62 bool res = JGetter::getJObjectField(m_pEnv, m_pObject,
63 JACTION_LISTOF_CAPABILITY, TM_JAVA_VECTOR_TYPE, jAttrList);
67 capabilityList.clear();
68 int attrCount = m_pEnv->CallIntMethod(jAttrList, vectorSizeMethodID);
69 for (int i = 0; i < attrCount; i++)
71 JniCapability *attr_var = new JniCapability(m_pEnv,
72 m_pEnv->CallObjectMethod(jAttrList, vectorMethodID, i));
74 OIC::Capability *cap = new OIC::Capability();
75 attr_var->getJniCapabilityValue(cap->capability);
76 attr_var->getJniCapabilityStatus(cap->status);
78 capabilityList.push_back(cap);
81 m_pEnv->DeleteLocalRef(jvectorClass);