1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "thermal_srv_sensor_info.h" 17 18 #include "string_ex.h" 19 #include "thermal_common.h" 20 21 namespace OHOS { 22 namespace PowerMgr { ThermalSrvSensorInfo(std::string & type,int32_t & temp)23ThermalSrvSensorInfo::ThermalSrvSensorInfo(std::string &type, int32_t &temp): type_(type), temp_(temp) 24 {} 25 26 /** 27 * @brief read this Sequenceable object from a Parcel. 28 * 29 * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled. 30 * @return Returns true if read successed; returns false otherwise. 31 */ ReadFromParcel(Parcel & parcel)32bool ThermalSrvSensorInfo::ReadFromParcel(Parcel &parcel) 33 { 34 type_ = Str16ToStr8(parcel.ReadString16()); 35 temp_ = parcel.ReadInt32(); 36 return true; 37 } 38 39 /** 40 * @brief Unmarshals this Sequenceable object from a Parcel. 41 * 42 * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled. 43 */ Unmarshalling(Parcel & parcel)44ThermalSrvSensorInfo *ThermalSrvSensorInfo::Unmarshalling(Parcel &parcel) 45 { 46 ThermalSrvSensorInfo *thermalSrvSensorInfo = new (std::nothrow) ThermalSrvSensorInfo(); 47 if (thermalSrvSensorInfo && !thermalSrvSensorInfo->ReadFromParcel(parcel)) { 48 THERMAL_HILOGE(COMP_FWK, "ThermalSrvSensorInfo::Unmarshalling ReadFromParcel failed"); 49 delete thermalSrvSensorInfo; 50 thermalSrvSensorInfo = nullptr; 51 } 52 return thermalSrvSensorInfo; 53 } 54 55 /** 56 * @brief Marshals this Sequenceable object into a Parcel. 57 * 58 * @param outParcel Indicates the Parcel object to which the Sequenceable object will be marshaled. 59 */ 60 Marshalling(Parcel & parcel) const61bool ThermalSrvSensorInfo::Marshalling(Parcel &parcel) const 62 { 63 return (parcel.WriteString16(Str8ToStr16(type_)) && parcel.WriteInt32(temp_)); 64 } 65 } // namespace PowerMgr 66 } // namespace OHOS 67