• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "net_supplier_info.h"
17 
18 #include "parcel.h"
19 #include "refbase.h"
20 
21 #include "net_mgr_log_wrapper.h"
22 namespace OHOS {
23 namespace NetManagerStandard {
Marshalling(Parcel & parcel) const24 bool NetSupplierInfo::Marshalling(Parcel &parcel) const
25 {
26     if (!parcel.WriteBool(isAvailable_)) {
27         return false;
28     }
29     if (!parcel.WriteBool(isRoaming_)) {
30         return false;
31     }
32     if (!parcel.WriteInt8(strength_)) {
33         return false;
34     }
35     if (!parcel.WriteUint32(frequency_)) {
36         return false;
37     }
38     if (!parcel.WriteUint32(linkUpBandwidthKbps_)) {
39         return false;
40     }
41     if (!parcel.WriteUint32(linkDownBandwidthKbps_)) {
42         return false;
43     }
44     if (!parcel.WriteInt32(uid_)) {
45         return false;
46     }
47     return true;
48 }
49 
Unmarshalling(Parcel & parcel)50 sptr<NetSupplierInfo> NetSupplierInfo::Unmarshalling(Parcel &parcel)
51 {
52     sptr<NetSupplierInfo> ptr = new (std::nothrow) NetSupplierInfo();
53     if (ptr == nullptr) {
54         NETMGR_LOG_E("make_unique<NetSupplierInfo>() failed");
55         return nullptr;
56     }
57     if (!parcel.ReadBool(ptr->isAvailable_)) {
58         return nullptr;
59     }
60     if (!parcel.ReadBool(ptr->isRoaming_)) {
61         return nullptr;
62     }
63     if (!parcel.ReadInt8(ptr->strength_)) {
64         NETMGR_LOG_E("read strength_ from parcel failed");
65         return nullptr;
66     }
67     if (!parcel.ReadUint32(ptr->frequency_)) {
68         return nullptr;
69     }
70     if (!parcel.ReadUint32(ptr->linkUpBandwidthKbps_)) {
71         return nullptr;
72     }
73     if (!parcel.ReadUint32(ptr->linkDownBandwidthKbps_)) {
74         return nullptr;
75     }
76     if (!parcel.ReadInt32(ptr->uid_)) {
77         return nullptr;
78     }
79     return ptr;
80 }
81 
Marshalling(Parcel & parcel,const sptr<NetSupplierInfo> & object)82 bool NetSupplierInfo::Marshalling(Parcel &parcel, const sptr<NetSupplierInfo> &object)
83 {
84     if (object == nullptr) {
85         NETMGR_LOG_E("NetSupplierInfo object ptr is nullptr");
86         return false;
87     }
88     if (!parcel.WriteBool(object->isAvailable_)) {
89         return false;
90     }
91     if (!parcel.WriteBool(object->isRoaming_)) {
92         return false;
93     }
94     if (!parcel.WriteInt8(object->strength_)) {
95         return false;
96     }
97     if (!parcel.WriteUint32(object->frequency_)) {
98         return false;
99     }
100     if (!parcel.WriteUint32(object->linkUpBandwidthKbps_)) {
101         return false;
102     }
103     if (!parcel.WriteUint32(object->linkDownBandwidthKbps_)) {
104         return false;
105     }
106     if (!parcel.WriteInt32(object->uid_)) {
107         return false;
108     }
109     return true;
110 }
111 
ToString(const std::string & tab) const112 std::string NetSupplierInfo::ToString(const std::string &tab) const
113 {
114     std::string str;
115     str.append(tab);
116     str.append("[NetSupplierInfo]");
117 
118     str.append(tab);
119     str.append("isAvailable_ = ");
120     str.append(std::to_string(isAvailable_));
121 
122     str.append(tab);
123     str.append("isRoaming_ = ");
124     str.append(std::to_string(isRoaming_));
125 
126     str.append(tab);
127     str.append("strength_ = ");
128     str.append(std::to_string(strength_));
129 
130     str.append(tab);
131     str.append("frequency_ = ");
132     str.append(std::to_string(frequency_));
133 
134     str.append(tab);
135     str.append("linkUpBandwidthKbps_ = ");
136     str.append(std::to_string(linkUpBandwidthKbps_));
137 
138     str.append(tab);
139     str.append("linkDownBandwidthKbps_ = ");
140     str.append(std::to_string(linkDownBandwidthKbps_));
141 
142     str.append(tab);
143     str.append("uid_ = ");
144     str.append(std::to_string(uid_));
145 
146     return str;
147 }
148 } // namespace NetManagerStandard
149 } // namespace OHOS