1 /*
2 * Copyright (c) 2024-2024 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 "shutdown/takeover_info.h"
17 #include "power_common.h"
18 #include "string_ex.h"
19
20 namespace OHOS {
21 namespace PowerMgr {
ReadFromParcel(Parcel & parcel)22 bool TakeOverInfo::ReadFromParcel(Parcel& parcel)
23 {
24 std::u16string readReason;
25 bool readFlag = false;
26
27 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(parcel, String16, readReason, false);
28 reason_ = Str16ToStr8(readReason);
29 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(parcel, Bool, readFlag, false);
30 intfParam_ = readFlag;
31 return true;
32 }
33
Marshalling(Parcel & parcel) const34 bool TakeOverInfo::Marshalling(Parcel& parcel) const
35 {
36 RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(parcel, String16, Str8ToStr16(reason_), false);
37 RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(parcel, Bool, intfParam_, false);
38 return true;
39 }
40
Unmarshalling(Parcel & parcel)41 TakeOverInfo* TakeOverInfo::Unmarshalling(Parcel& parcel)
42 {
43 TakeOverInfo* info = new TakeOverInfo();
44 if (info == nullptr) {
45 return nullptr;
46 }
47 if (!info->ReadFromParcel(parcel)) {
48 delete info;
49 return nullptr;
50 }
51 return info;
52 }
53 } // namespace PowerMgr
54 } // namespace OHOS