1 /* 2 * Copyright (c) 2021-2023 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 "interface_configuration.h" 17 18 #include "netmgr_ext_log_wrapper.h" 19 #include "parcel.h" 20 #include "refbase.h" 21 #include "static_configuration.h" 22 23 namespace OHOS { 24 namespace NetManagerStandard { Marshalling(Parcel & parcel) const25bool InterfaceConfiguration::Marshalling(Parcel &parcel) const 26 { 27 if (!parcel.WriteInt32(static_cast<int32_t>(mode_))) { 28 return false; 29 } 30 if (!ipStatic_.Marshalling(parcel)) { 31 NETMGR_EXT_LOG_E("write ipStatic_ to parcel failed"); 32 return false; 33 } 34 if (!httpProxy_.Marshalling(parcel)) { 35 NETMGR_EXT_LOG_E("write httpProxy_ to parcel failed"); 36 return false; 37 } 38 return true; 39 } 40 Unmarshalling(Parcel & parcel)41sptr<InterfaceConfiguration> InterfaceConfiguration::Unmarshalling(Parcel &parcel) 42 { 43 sptr<InterfaceConfiguration> ptr = new (std::nothrow) InterfaceConfiguration(); 44 if (ptr == nullptr) { 45 NETMGR_EXT_LOG_E("ptr is null"); 46 return nullptr; 47 } 48 int32_t mode = 0; 49 if (!parcel.ReadInt32(mode)) { 50 return nullptr; 51 } 52 ptr->mode_ = static_cast<IPSetMode>(mode); 53 sptr<StaticConfiguration> sc = StaticConfiguration::Unmarshalling(parcel); 54 if (sc == nullptr) { 55 NETMGR_EXT_LOG_E("sc is null"); 56 return nullptr; 57 } 58 ptr->ipStatic_ = *sc; 59 if (!HttpProxy::Unmarshalling(parcel, ptr->httpProxy_)) { 60 NETMGR_EXT_LOG_E("Unmarshalling HttpProxy failed."); 61 return nullptr; 62 } 63 return ptr; 64 } 65 } // namespace NetManagerStandard 66 } // namespace OHOS