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 "network_search_result.h"
17
18 #include <securec.h>
19
20 #include "telephony_log_wrapper.h"
21
22 namespace OHOS {
23 namespace Telephony {
NetworkSearchResult()24 NetworkSearchResult::NetworkSearchResult() {}
25
SetNetworkSearchResultValue(int32_t listSize,const std::vector<NetworkInformation> & operatorInfo)26 void NetworkSearchResult::SetNetworkSearchResultValue(
27 int32_t listSize, const std::vector<NetworkInformation> &operatorInfo)
28 {
29 listSize_ = listSize;
30 operatorInfoList_ = operatorInfo;
31 TELEPHONY_LOGI("NetworkSearchResult::SetNetworkSearchResultValue size:%{public}d, %{public}zu)", listSize_,
32 operatorInfoList_.size());
33 }
34
GetNetworkSearchInformation() const35 std::vector<NetworkInformation> NetworkSearchResult::GetNetworkSearchInformation() const
36 {
37 return operatorInfoList_;
38 }
39
GetNetworkSearchInformationSize() const40 int32_t NetworkSearchResult::GetNetworkSearchInformationSize() const
41 {
42 return listSize_;
43 }
44
ReadFromParcel(Parcel & parcel)45 bool NetworkSearchResult::ReadFromParcel(Parcel &parcel)
46 {
47 listSize_ = parcel.ReadInt32();
48 TELEPHONY_LOGI("ReadParcelable<NetworkState> %{public}d", listSize_);
49 for (int32_t i = 0; i < listSize_; i++) {
50 std::unique_ptr<NetworkInformation> networkInfo(parcel.ReadParcelable<NetworkInformation>());
51 if (networkInfo == nullptr) {
52 TELEPHONY_LOGE("ReadParcelable<NetworkState> failed");
53 return false;
54 }
55 operatorInfoList_.emplace_back(*networkInfo);
56 }
57 return true;
58 }
59
Marshalling(Parcel & parcel) const60 bool NetworkSearchResult::Marshalling(Parcel &parcel) const
61 {
62 if (!parcel.WriteInt32(listSize_)) {
63 TELEPHONY_LOGE("NetworkSearchResult::Marshalling WriteInt32 failed");
64 return false;
65 }
66 TELEPHONY_LOGI("ReadParcelable<NetworkState> size:%{public}d", listSize_);
67 for (auto &networkState : operatorInfoList_) {
68 parcel.WriteParcelable(&networkState);
69 }
70 return true;
71 }
72
Unmarshalling(Parcel & parcel)73 NetworkSearchResult *NetworkSearchResult::Unmarshalling(Parcel &parcel)
74 {
75 std::unique_ptr<NetworkSearchResult> param = std::make_unique<NetworkSearchResult>();
76 if (param == nullptr) {
77 return nullptr;
78 }
79 if (!param->ReadFromParcel(parcel)) {
80 return nullptr;
81 }
82 return param.release();
83 }
84 } // namespace Telephony
85 } // namespace OHOS
86