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 COMMAND_FACTORY_H
17 #define COMMAND_FACTORY_H
18 
19 #include <functional>
20 #include <memory>
21 #include "connect_command.h"
22 #include "disconnect_command.h"
23 #include "force_disconnect_command.h"
24 
25 namespace OHOS::SoftBus {
26 class CommandFactory {
27 public:
28     using ConnectCreator = std::function<std::shared_ptr<ConnectCommand>(const WifiDirectConnectInfo&,
29                                                                          const WifiDirectConnectCallback&)>;
30     using DisconnectCreator = std::function<std::shared_ptr<DisconnectCommand>(const WifiDirectDisconnectInfo&,
31                                                                                const WifiDirectDisconnectCallback&)>;
32     static CommandFactory& GetInstance();
33 
34     std::shared_ptr<ConnectCommand> CreateConnectCommand(const WifiDirectConnectInfo &info,
35                                                          const WifiDirectConnectCallback &callback);
36     std::shared_ptr<DisconnectCommand> CreateDisconnectCommand(const WifiDirectDisconnectInfo &info,
37                                                                const WifiDirectDisconnectCallback &callback);
38     std::shared_ptr<ForceDisconnectCommand> CreateForceDisconnectCommand(const WifiDirectForceDisconnectInfo &info,
39                                                                const WifiDirectDisconnectCallback &callback);
40     void Register(const ConnectCreator &creator);
41     void Register(const DisconnectCreator &creator);
42 
43 private:
44     ConnectCreator connectCreator_;
45     DisconnectCreator disconnectCreator_;
46 };
47 }
48 #endif
49