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_info_ipc.h"
17 
18 #include "sensors_errors.h"
19 
20 #undef LOG_TAG
21 #define LOG_TAG "LightInfoIPC"
22 
23 namespace OHOS {
24 namespace Sensors {
GetLightName() const25 std::string LightInfoIPC::GetLightName() const
26 {
27     return lightName_;
28 }
29 
SetLightName(const std::string & lightName)30 void LightInfoIPC::SetLightName(const std::string &lightName)
31 {
32     lightName_ = lightName;
33 }
34 
GetLightId() const35 int32_t LightInfoIPC::GetLightId() const
36 {
37     return lightId_;
38 }
39 
SetLightId(int32_t lightId)40 void LightInfoIPC::SetLightId(int32_t lightId)
41 {
42     lightId_ = lightId;
43 }
44 
GetLightNumber() const45 int32_t LightInfoIPC::GetLightNumber() const
46 {
47     return lightNumber_;
48 }
49 
SetLightNumber(int32_t lightNumber)50 void LightInfoIPC::SetLightNumber(int32_t lightNumber)
51 {
52     lightNumber_ = lightNumber;
53 }
54 
GetLightType() const55 int32_t LightInfoIPC::GetLightType() const
56 {
57     return lightType_;
58 }
59 
SetLightType(int32_t lightType)60 void LightInfoIPC::SetLightType(int32_t lightType)
61 {
62     lightType_ = lightType;
63 }
64 
Marshalling(Parcel & parcel) const65 bool LightInfoIPC::Marshalling(Parcel &parcel) const
66 {
67     if (!parcel.WriteString(lightName_)) {
68         MISC_HILOGE("Failed, write lightName failed");
69         return false;
70     }
71     if (!parcel.WriteInt32(lightId_)) {
72         MISC_HILOGE("Failed, write lightId failed");
73         return false;
74     }
75     if (!parcel.WriteInt32(lightNumber_)) {
76         MISC_HILOGE("Failed, write lightNumber failed");
77         return false;
78     }
79     if (!parcel.WriteInt32(lightType_)) {
80         MISC_HILOGE("Failed, write lightType failed");
81         return false;
82     }
83     return true;
84 }
85 
Unmarshalling(Parcel & parcel)86 std::unique_ptr<LightInfoIPC> LightInfoIPC::Unmarshalling(Parcel &parcel)
87 {
88     auto lightInfo = std::make_unique<LightInfoIPC>();
89     if (!lightInfo->ReadFromParcel(parcel)) {
90         MISC_HILOGE("ReadFromParcel is failed");
91         return nullptr;
92     }
93     return lightInfo;
94 }
95 
ReadFromParcel(Parcel & parcel)96 bool LightInfoIPC::ReadFromParcel(Parcel &parcel)
97 {
98     return (parcel.ReadString(lightName_)) && (parcel.ReadInt32(lightId_)) &&
99         (parcel.ReadInt32(lightNumber_)) && (parcel.ReadInt32(lightType_));
100 }
101 }  // namespace Sensors
102 }  // namespace OHOS