1 /* 2 * Copyright (c) 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 "ohos_adapter/bridge/ark_net_connect_adapter_impl.h" 17 18 #include "ohos_adapter/bridge/ark_net_conn_callback_wrapper.h" 19 20 #include "base/bridge/ark_web_bridge_macros.h" 21 22 namespace OHOS::ArkWeb { 23 ArkNetConnectAdapterImpl(std::shared_ptr<OHOS::NWeb::NetConnectAdapter> ref)24ArkNetConnectAdapterImpl::ArkNetConnectAdapterImpl(std::shared_ptr<OHOS::NWeb::NetConnectAdapter> ref) : real_(ref) {} 25 RegisterNetConnCallback(ArkWebRefPtr<ArkNetConnCallback> cb)26int32_t ArkNetConnectAdapterImpl::RegisterNetConnCallback(ArkWebRefPtr<ArkNetConnCallback> cb) 27 { 28 if (CHECK_REF_PTR_IS_NULL(cb)) { 29 return real_->RegisterNetConnCallback(nullptr); 30 } 31 32 return real_->RegisterNetConnCallback(std::make_shared<ArkNetConnCallbackWrapper>(cb)); 33 } 34 UnregisterNetConnCallback(int32_t id)35int32_t ArkNetConnectAdapterImpl::UnregisterNetConnCallback(int32_t id) 36 { 37 return real_->UnregisterNetConnCallback(id); 38 } 39 GetDefaultNetConnect(uint32_t & type,uint32_t & netConnectSubtype)40int32_t ArkNetConnectAdapterImpl::GetDefaultNetConnect(uint32_t& type, uint32_t& netConnectSubtype) 41 { 42 NWeb::NetConnectType nType; 43 NWeb::NetConnectSubtype nSubtype; 44 int32_t result = real_->GetDefaultNetConnect(nType, nSubtype); 45 type = (uint32_t)nType; 46 netConnectSubtype = (uint32_t)nSubtype; 47 return result; 48 } 49 GetDnsServers()50ArkWebStringVector ArkNetConnectAdapterImpl::GetDnsServers() 51 { 52 std::vector<std::string> servers = real_->GetDnsServers(); 53 return ArkWebStringVectorClassToStruct(servers); 54 } 55 GetDnsServersByNetId(int32_t netId)56ArkWebStringVector ArkNetConnectAdapterImpl::GetDnsServersByNetId(int32_t netId) 57 { 58 std::vector<std::string> servers = real_->GetDnsServersByNetId(netId); 59 return ArkWebStringVectorClassToStruct(servers); 60 } 61 62 } // namespace OHOS::ArkWeb 63