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_capabilities_adapter_impl.h"
17 #include "ohos_adapter/bridge/ark_net_conn_callback_wrapper.h"
18 #include "ohos_adapter/bridge/ark_net_connection_properties_adapter_impl.h"
19 
20 #include "base/bridge/ark_web_bridge_macros.h"
21 
22 namespace OHOS::ArkWeb {
23 
ArkNetConnCallbackWrapper(ArkWebRefPtr<ArkNetConnCallback> ref)24 ArkNetConnCallbackWrapper::ArkNetConnCallbackWrapper(ArkWebRefPtr<ArkNetConnCallback> ref) : ctocpp_(ref) {}
25 
NetAvailable()26 int32_t ArkNetConnCallbackWrapper::NetAvailable()
27 {
28     return ctocpp_->NetAvailable();
29 }
30 
NetCapabilitiesChange(const OHOS::NWeb::NetConnectType & netConnectType,const OHOS::NWeb::NetConnectSubtype & netConnectSubtype)31 int32_t ArkNetConnCallbackWrapper::NetCapabilitiesChange(
32     const OHOS::NWeb::NetConnectType& netConnectType, const OHOS::NWeb::NetConnectSubtype& netConnectSubtype)
33 {
34     return ctocpp_->NetCapabilitiesChange((uint32_t)netConnectType, (uint32_t)netConnectSubtype);
35 }
36 
NetConnectionPropertiesChange()37 int32_t ArkNetConnCallbackWrapper::NetConnectionPropertiesChange()
38 {
39     return ctocpp_->NetConnectionPropertiesChange();
40 }
41 
NetUnavailable()42 int32_t ArkNetConnCallbackWrapper::NetUnavailable()
43 {
44     return ctocpp_->NetUnavailable();
45 }
46 
OnNetCapabilitiesChanged(const std::shared_ptr<NWeb::NetCapabilitiesAdapter> capabilities)47 int32_t ArkNetConnCallbackWrapper::OnNetCapabilitiesChanged(
48     const std::shared_ptr<NWeb::NetCapabilitiesAdapter> capabilities)
49 {
50     if (CHECK_SHARED_PTR_IS_NULL(capabilities)) {
51         return ctocpp_->OnNetCapabilitiesChanged(nullptr);
52     }
53 
54     return ctocpp_->OnNetCapabilitiesChanged(new ArkNetCapabilitiesAdapterImpl(capabilities));
55 }
56 
OnNetConnectionPropertiesChanged(const std::shared_ptr<NWeb::NetConnectionPropertiesAdapter> properties)57 int32_t ArkNetConnCallbackWrapper::OnNetConnectionPropertiesChanged(
58     const std::shared_ptr<NWeb::NetConnectionPropertiesAdapter> properties)
59 {
60     if (CHECK_SHARED_PTR_IS_NULL(properties)) {
61         return ctocpp_->OnNetConnectionPropertiesChanged(nullptr);
62     }
63 
64     return ctocpp_->OnNetConnectionPropertiesChanged(new ArkNetConnectionPropertiesAdapterImpl(properties));
65 }
66 
67 } // namespace OHOS::ArkWeb
68