1 /* 2 * Copyright (c) 2021-2022 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 return true; 35 } 36 Unmarshalling(Parcel & parcel)37sptr<InterfaceConfiguration> InterfaceConfiguration::Unmarshalling(Parcel &parcel) 38 { 39 sptr<InterfaceConfiguration> ptr = new (std::nothrow) InterfaceConfiguration(); 40 if (ptr == nullptr) { 41 NETMGR_EXT_LOG_E("ptr is null"); 42 return nullptr; 43 } 44 int32_t mode = 0; 45 if (!parcel.ReadInt32(mode)) { 46 return nullptr; 47 } 48 ptr->mode_ = static_cast<IPSetMode>(mode); 49 sptr<StaticConfiguration> sc = StaticConfiguration::Unmarshalling(parcel); 50 if (sc == nullptr) { 51 NETMGR_EXT_LOG_E("sc is null"); 52 return nullptr; 53 } 54 ptr->ipStatic_ = *sc; 55 return ptr; 56 } 57 } // namespace NetManagerStandard 58 } // namespace OHOS