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 "volume_external.h"
17 
18 namespace OHOS {
19 namespace StorageManager {
VolumeExternal()20 VolumeExternal::VolumeExternal() {}
21 
VolumeExternal(VolumeCore vc)22 VolumeExternal::VolumeExternal(VolumeCore vc)
23     : VolumeExternal::VolumeCore(vc.GetId(), vc.GetType(), vc.GetDiskId(), vc.GetState()) {}
24 
SetFlags(int32_t flags)25 void VolumeExternal::SetFlags(int32_t flags)
26 {
27     flags_ = flags;
28 }
29 
SetFsType(int32_t fsType)30 void VolumeExternal::SetFsType(int32_t fsType)
31 {
32     fsType_ = fsType;
33 }
34 
SetFsUuid(std::string fsUuid)35 void VolumeExternal::SetFsUuid(std::string fsUuid)
36 {
37     fsUuid_ = fsUuid;
38 }
39 
SetPath(std::string path)40 void VolumeExternal::SetPath(std::string path)
41 {
42     path_ = path;
43 }
44 
SetDescription(std::string description)45 void VolumeExternal::SetDescription(std::string description)
46 {
47     description_ = description;
48 }
49 
GetFlags()50 int32_t VolumeExternal::GetFlags()
51 {
52     return flags_;
53 }
54 
GetFsType()55 int32_t VolumeExternal::GetFsType()
56 {
57     return fsType_;
58 }
59 
GetFsTypeString()60 std::string VolumeExternal::GetFsTypeString()
61 {
62     auto it = FS_TYPE_MAP.find(fsType_);
63     if (it == FS_TYPE_MAP.end()) {
64         return "undefined";
65     }
66     return FS_TYPE_MAP[fsType_];
67 }
68 
GetUuid()69 std::string VolumeExternal::GetUuid()
70 {
71     return fsUuid_;
72 }
73 
GetPath()74 std::string VolumeExternal::GetPath()
75 {
76     return path_;
77 }
78 
GetDescription()79 std::string VolumeExternal::GetDescription()
80 {
81     return description_;
82 }
83 
Reset()84 void VolumeExternal::Reset()
85 {
86     path_ = "";
87 }
88 
Marshalling(Parcel & parcel) const89 bool VolumeExternal::Marshalling(Parcel &parcel) const
90 {
91     if (!VolumeCore::Marshalling(parcel)) {
92         return false;
93     }
94 
95     if (!parcel.WriteInt32(flags_)) {
96         return false;
97     }
98 
99     if (!parcel.WriteInt32(fsType_)) {
100         return false;
101     }
102 
103     if (!parcel.WriteString(fsUuid_)) {
104         return false;
105     }
106 
107     if (!parcel.WriteString(path_)) {
108         return false;
109     }
110 
111     if (!parcel.WriteString(description_)) {
112         return false;
113     }
114 
115     return true;
116 }
117 
Unmarshalling(Parcel & parcel)118 std::unique_ptr<VolumeExternal> VolumeExternal::Unmarshalling(Parcel &parcel)
119 {
120     auto obj = std::make_unique<VolumeExternal>(*VolumeCore::Unmarshalling(parcel));
121     obj->flags_ = parcel.ReadInt32();
122     obj->fsType_ = parcel.ReadInt32();
123     obj->fsUuid_ = parcel.ReadString();
124     obj->path_ = parcel.ReadString();
125     obj->description_ = parcel.ReadString();
126     return obj;
127 }
128 }
129 }
130