1 /* 2 * Copyright (c) 2024 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 WIFI_DIRECT_EXECUTOR_FACTORY_H 17 #define WIFI_DIRECT_EXECUTOR_FACTORY_H 18 19 #include <memory> 20 #include <utility> 21 22 #include <wifi_direct_executor.h> 23 24 namespace OHOS::SoftBus { 25 class WifiDirectExecutorFactory { 26 public: GetInstance()27 static WifiDirectExecutorFactory &GetInstance() 28 { 29 static WifiDirectExecutorFactory instance; 30 return instance; 31 } 32 33 using ExecutorGenerator = std::function<std::shared_ptr<WifiDirectExecutor>(const std::string &remoteDeviceId, 34 WifiDirectScheduler &scheduler, std::shared_ptr<WifiDirectProcessor> &processor, bool active)>; 35 NewExecutor(const std::string & remoteDeviceId,WifiDirectScheduler & scheduler,std::shared_ptr<WifiDirectProcessor> & processor,bool active)36 std::shared_ptr<WifiDirectExecutor> NewExecutor(const std::string &remoteDeviceId, WifiDirectScheduler &scheduler, 37 std::shared_ptr<WifiDirectProcessor> &processor, bool active) 38 { 39 std::shared_ptr<WifiDirectExecutor> executor = (executorGenerator_ == nullptr) ? 40 std::make_shared<WifiDirectExecutor>(remoteDeviceId, scheduler, processor, active) : 41 executorGenerator_(remoteDeviceId, scheduler, processor, active); 42 executor->Start(); 43 return executor; 44 } 45 Register(ExecutorGenerator generator)46 void Register(ExecutorGenerator generator) 47 { 48 executorGenerator_ = std::move(generator); 49 } 50 51 private: 52 ExecutorGenerator executorGenerator_; 53 }; 54 } // namespace OHOS::SoftBus 55 #endif