1/* 2 * Copyright (c) 2023 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 "light_animation_ipc.h" 17 18#include "sensors_errors.h" 19 20#undef LOG_TAG 21#define LOG_TAG "LightAnimationIPC" 22 23namespace OHOS { 24namespace Sensors { 25int32_t LightAnimationIPC::GetMode() const 26{ 27 return mode_; 28} 29 30void LightAnimationIPC::SetMode(int32_t mode) 31{ 32 mode_ = mode; 33} 34 35int32_t LightAnimationIPC::GetOnTime() const 36{ 37 return onTime_; 38} 39 40void LightAnimationIPC::SetOnTime(int32_t onTime) 41{ 42 onTime_ = onTime; 43} 44 45int32_t LightAnimationIPC::GetOffTime() const 46{ 47 return offTime_; 48} 49 50void LightAnimationIPC::SetOffTime(int32_t offTime) 51{ 52 offTime_ = offTime; 53} 54 55bool LightAnimationIPC::Marshalling(Parcel &parcel) const 56{ 57 if (!parcel.WriteInt32(mode_)) { 58 MISC_HILOGE("Failed, write mode failed"); 59 return false; 60 } 61 if (!parcel.WriteInt32(onTime_)) { 62 MISC_HILOGE("Failed, write onTime failed"); 63 return false; 64 } 65 if (!parcel.WriteInt32(offTime_)) { 66 MISC_HILOGE("Failed, write offTime failed"); 67 return false; 68 } 69 return true; 70} 71 72std::unique_ptr<LightAnimationIPC> LightAnimationIPC::Unmarshalling(Parcel &parcel) 73{ 74 auto lightAnimation = std::make_unique<LightAnimationIPC>(); 75 if (!lightAnimation->ReadFromParcel(parcel)) { 76 MISC_HILOGE("ReadFromParcel is failed"); 77 return nullptr; 78 } 79 return lightAnimation; 80} 81 82bool LightAnimationIPC::ReadFromParcel(Parcel &parcel) 83{ 84 return (parcel.ReadInt32(mode_)) && (parcel.ReadInt32(onTime_)) && (parcel.ReadInt32(offTime_)); 85} 86} // namespace Sensors 87} // namespace OHOS