1 /*
2 * Copyright (c) 2021-2025 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 "disk.h"
17
18 namespace OHOS {
19 namespace StorageManager {
Disk()20 Disk::Disk() {}
21
Disk(std::string diskId,int64_t sizeBytes,std::string sysPath,std::string vendor,int32_t flag)22 Disk::Disk(std::string diskId, int64_t sizeBytes, std::string sysPath, std::string vendor, int32_t flag)
23 : diskId_(diskId), sizeBytes_(sizeBytes), sysPath_(sysPath), vendor_(vendor), flag_(flag) {}
24
GetDiskId() const25 std::string Disk::GetDiskId() const
26 {
27 return diskId_;
28 }
29
GetSizeBytes()30 int64_t Disk::GetSizeBytes()
31 {
32 return sizeBytes_;
33 }
34
GetSysPath()35 std::string Disk::GetSysPath()
36 {
37 return sysPath_;
38 }
39
GetVendor()40 std::string Disk::GetVendor()
41 {
42 return vendor_;
43 }
44
GetFlag()45 int32_t Disk::GetFlag()
46 {
47 return flag_;
48 }
49
SetFlag(int32_t flag)50 void Disk::SetFlag(int32_t flag)
51 {
52 flag_ = flag;
53 }
54
Marshalling(Parcel & parcel) const55 bool Disk::Marshalling(Parcel &parcel) const
56 {
57 if (!parcel.WriteString(diskId_)) {
58 return false;
59 }
60
61 if (!parcel.WriteInt32(sizeBytes_)) {
62 return false;
63 }
64
65 if (!parcel.WriteString(sysPath_)) {
66 return false;
67 }
68
69 if (!parcel.WriteString(vendor_)) {
70 return false;
71 }
72
73 if (!parcel.WriteInt32(flag_)) {
74 return false;
75 }
76
77 return true;
78 }
79
Unmarshalling(Parcel & parcel)80 Disk *Disk::Unmarshalling(Parcel &parcel)
81 {
82 Disk* obj = new (std::nothrow) Disk();
83 if (!obj) {
84 return nullptr;
85 }
86 obj->diskId_ = parcel.ReadString();
87 obj->sizeBytes_ = parcel.ReadInt32();
88 obj->sysPath_ = parcel.ReadString();
89 obj->vendor_ = parcel.ReadString();
90 obj->flag_ = parcel.ReadInt32();
91 return obj;
92 }
93 }
94 }
95