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 <memory>
17 #include "network_selector_factory.h"
18 #include "wifi_logger.h"
19 
20 namespace OHOS::Wifi {
21 DEFINE_WIFILOG_LABEL("NetworkSelectorFactory")
22 
NetworkSelectorFactory()23 NetworkSelectorFactory::NetworkSelectorFactory()
24 {
25     handleFuncMap[static_cast<uint32_t>(NetworkSelectType::AUTO_CONNECT)] =
26         &NetworkSelectorFactory::CreateAutoConnectNetworkSelector;
27     handleFuncMap[static_cast<uint32_t>(NetworkSelectType::WIFI2WIFI)] =
28         &NetworkSelectorFactory::CreateWifi2WifiNetworkSelector;
29 }
30 
GetNetworkSelector(NetworkSelectType networkSelectType)31 std::optional<std::unique_ptr<NetworkSelection::INetworkSelector>> NetworkSelectorFactory::GetNetworkSelector(
32     NetworkSelectType networkSelectType)
33 {
34     auto iter = handleFuncMap.find(static_cast<uint32_t>(networkSelectType));
35     if (iter != handleFuncMap.end()) {
36         return (this->*(iter->second))();
37     }
38     WIFI_LOGE("not find function to deal, code %{public}u", static_cast<uint32_t>(networkSelectType));
39     return std::nullopt;
40 }
41 
CreateAutoConnectNetworkSelector()42 std::unique_ptr<NetworkSelection::INetworkSelector> NetworkSelectorFactory::CreateAutoConnectNetworkSelector()
43 {
44     return std::make_unique<NetworkSelection::AutoConnectIntegrator>();
45 }
46 
CreateWifi2WifiNetworkSelector()47 std::unique_ptr<NetworkSelection::INetworkSelector> NetworkSelectorFactory::CreateWifi2WifiNetworkSelector()
48 {
49     return std::make_unique<NetworkSelection::Wifi2WifiIntegrator>();
50 }
51 } // namespace OHOS::Wifi
52