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 #include "command_factory.h"
16
17 namespace OHOS::SoftBus {
GetInstance()18 CommandFactory& CommandFactory::GetInstance()
19 {
20 static CommandFactory instance;
21 return instance;
22 }
23
CreateConnectCommand(const WifiDirectConnectInfo & info,const WifiDirectConnectCallback & callback)24 std::shared_ptr<ConnectCommand> CommandFactory::CreateConnectCommand(const WifiDirectConnectInfo &info,
25 const WifiDirectConnectCallback &callback)
26 {
27 if (connectCreator_ == nullptr) {
28 return std::make_shared<ConnectCommand>(info, callback);
29 }
30 return connectCreator_(info, callback);
31 }
32
CreateDisconnectCommand(const WifiDirectDisconnectInfo & info,const WifiDirectDisconnectCallback & callback)33 std::shared_ptr<DisconnectCommand> CommandFactory::CreateDisconnectCommand(const WifiDirectDisconnectInfo &info,
34 const WifiDirectDisconnectCallback &callback)
35 {
36 if (disconnectCreator_ == nullptr) {
37 return std::make_shared<DisconnectCommand>(info, callback);
38 }
39 return disconnectCreator_(info, callback);
40 }
41
CreateForceDisconnectCommand(const WifiDirectForceDisconnectInfo & info,const WifiDirectDisconnectCallback & callback)42 std::shared_ptr<ForceDisconnectCommand> CommandFactory::CreateForceDisconnectCommand(
43 const WifiDirectForceDisconnectInfo &info, const WifiDirectDisconnectCallback &callback)
44 {
45 return std::make_shared<ForceDisconnectCommand>(info, callback);
46 }
47
Register(const ConnectCreator & creator)48 void CommandFactory::Register(const ConnectCreator &creator)
49 {
50 connectCreator_ = creator;
51 }
52
Register(const DisconnectCreator & creator)53 void CommandFactory::Register(const DisconnectCreator &creator)
54 {
55 disconnectCreator_ = creator;
56 }
57 }
58
59