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 "simulator_platform_info_jni.h"
22 #include "simulator_utils_jni.h"
23 #include "jni_string.h"
25 extern SimulatorClassRefs gSimulatorClassRefs;
27 jobject JniPlatformInfo::toJava(PlatformInfo &platformInfo)
32 static jmethodID platformInfoCtor = m_env->GetMethodID(gSimulatorClassRefs.platformInfoCls,
34 jobject jPlatformInfo = (jobject) m_env->NewObject(gSimulatorClassRefs.platformInfoCls,
36 setFieldValue(jPlatformInfo, "mPlatformId", platformInfo.getPlatformID());
37 setFieldValue(jPlatformInfo, "mManufacturerName", platformInfo.getManufacturerName());
38 setFieldValue(jPlatformInfo, "mManufacturerUrl", platformInfo.getManufacturerUrl());
39 setFieldValue(jPlatformInfo, "mModelNumber", platformInfo.getModelNumber());
40 setFieldValue(jPlatformInfo, "mDateOfManufacture", platformInfo.getDateOfManfacture());
41 setFieldValue(jPlatformInfo, "mPlatformVersion", platformInfo.getPlatformVersion());
42 setFieldValue(jPlatformInfo, "mOperationSystemVersion", platformInfo.getOSVersion());
43 setFieldValue(jPlatformInfo, "mHardwareVersion", platformInfo.getHardwareVersion());
44 setFieldValue(jPlatformInfo, "mFirmwareVersion", platformInfo.getFirmwareVersion());
45 setFieldValue(jPlatformInfo, "mSupportUrl", platformInfo.getSupportUrl());
46 setFieldValue(jPlatformInfo, "mSystemTime", platformInfo.getSystemTime());
51 PlatformInfo JniPlatformInfo::toCpp(jobject jPlatformInfo)
53 PlatformInfo platformInfo;
54 if (!m_env || !jPlatformInfo)
57 platformInfo.setPlatformID(getFieldValue(jPlatformInfo, "mPlatformId"));
58 platformInfo.setManufacturerName(getFieldValue(jPlatformInfo, "mManufacturerName"));
59 platformInfo.setManufacturerUrl(getFieldValue(jPlatformInfo, "mManufacturerUrl"));
60 platformInfo.setModelNumber(getFieldValue(jPlatformInfo, "mModelNumber"));
61 platformInfo.setDateOfManfacture(getFieldValue(jPlatformInfo, "mDateOfManufacture"));
62 platformInfo.setPlatformVersion(getFieldValue(jPlatformInfo, "mPlatformVersion"));
63 platformInfo.setOSVersion(getFieldValue(jPlatformInfo, "mOperationSystemVersion"));
64 platformInfo.setHardwareVersion(getFieldValue(jPlatformInfo, "mHardwareVersion"));
65 platformInfo.setFirmwareVersion(getFieldValue(jPlatformInfo, "mFirmwareVersion"));
66 platformInfo.setSupportUrl(getFieldValue(jPlatformInfo, "mSupportUrl"));
67 platformInfo.setSystemTime(getFieldValue(jPlatformInfo, "mSystemTime"));
69 return std::move(platformInfo);
72 void JniPlatformInfo::setFieldValue(jobject jPlatformInfo, const std::string &fieldName,
73 const std::string &value)
75 jfieldID fieldID = m_env->GetFieldID(m_env->GetObjectClass(jPlatformInfo), fieldName.c_str(),
76 "Ljava/lang/String;");
77 jstring valueStr = m_env->NewStringUTF(value.c_str());
78 m_env->SetObjectField(jPlatformInfo, fieldID, valueStr);
81 std::string JniPlatformInfo::getFieldValue(jobject jPlatformInfo, const std::string &fieldName)
83 jfieldID fieldID = m_env->GetFieldID(m_env->GetObjectClass(jPlatformInfo), fieldName.c_str(),
84 "Ljava/lang/String;");
85 jstring jvalue = (jstring) m_env->GetObjectField(jPlatformInfo, fieldID);
86 JniString value(m_env, jvalue);