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 #ifndef OHOS_WIFI_EXTERNAL_NETWORK_COMMON_BUILDER_MANAGER_H_ 17 #define OHOS_WIFI_EXTERNAL_NETWORK_COMMON_BUILDER_MANAGER_H_ 18 19 #include <mutex> 20 #include "network_selection.h" 21 22 namespace OHOS::Wifi { 23 class ExternalWifiCommonBuildManager { 24 public: 25 static ExternalWifiCommonBuildManager &GetInstance(); 26 27 ExternalWifiCommonBuildManager(const ExternalWifiCommonBuildManager &) = delete; 28 29 const ExternalWifiCommonBuildManager &operator=(const ExternalWifiCommonBuildManager &) = delete; 30 31 /** 32 * Register the common builder function 33 * 34 * @param TagType scoreTag which define where the score or filter should be inserted. 35 * @param tagName the score or filter name. 36 * @param CommonBuilder CommonBuilder function. 37 */ 38 void RegisterCommonBuilder(const TagType &tagType, const std::string &tagName, 39 const CommonBuilder &commonBuilder); 40 /** 41 * Deregister the common builder function 42 * 43 * @param TagType TagType which define where the score or filter should be inserted. 44 * @param tagName the score or filte name. 45 */ 46 void DeregisterCommonBuilder(const TagType &tagType, const std::string &tagName); 47 48 /** 49 * build the compositeScore 50 * 51 * @param scoreTag scoreTag which define where the compositeScore should be inserted. 52 * @param compositeScore the target score to build. 53 */ 54 void BuildScore(const TagType &scoreTag, NetworkSelection::CompositeWifiScorer &compositeScore); 55 56 /** 57 * build the compositeFilter 58 * 59 * @param filterTag filterTag which define where the compositeFilter should be inserted. 60 * @param compositeFilter the target Filter to build. 61 */ 62 void BuildFilter(const TagType &filterTag, NetworkSelection::CompositeWifiFilter &compositeFilter); 63 64 private: 65 ExternalWifiCommonBuildManager() = default; 66 67 ~ExternalWifiCommonBuildManager() = default; 68 69 std::map<std::pair<TagType, std::string>, CommonBuilder> commonBuilders; 70 std::mutex mutex; 71 }; 72 } 73 74 #endif