1 /*
2  * Copyright (C) 2021-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 #include "multi_sta_manager.h"
17 #include "wifi_logger.h"
18 
19 DEFINE_WIFILOG_LABEL("MultiStaManager");
20 
21 namespace OHOS {
22 namespace Wifi {
MultiStaManager(MultiStaManager::Role role,int id)23 MultiStaManager::MultiStaManager(MultiStaManager::Role role, int id) : mid(id), curRole(role),
24     pMultiStaStateMachine(nullptr)
25 {}
26 
~MultiStaManager()27 MultiStaManager::~MultiStaManager()
28 {
29     WIFI_LOGE("Exit.");
30     if (pMultiStaStateMachine != nullptr) {
31         delete pMultiStaStateMachine;
32         pMultiStaStateMachine = nullptr;
33     }
34 }
35 
InitMultiStaManager()36 ErrCode MultiStaManager::InitMultiStaManager()
37 {
38     pMultiStaStateMachine = new (std::nothrow) MultiStaStateMachine();
39     if (pMultiStaStateMachine == nullptr) {
40         WIFI_LOGE("Alloc pMultiStaStateMachine failed.\n");
41         return WIFI_OPT_FAILED;
42     }
43     if (pMultiStaStateMachine->InitMultiStaStateMachine() != WIFI_OPT_SUCCESS) {
44         WIFI_LOGE("InitMultiStaStateMachine failed.\n");
45         return WIFI_OPT_FAILED;
46     }
47     pMultiStaStateMachine->RegisterCallback(mcb);
48     pMultiStaStateMachine->SendMessage(MULTI_STA_CMD_START, static_cast<int>(curRole), mid);
49     return WIFI_OPT_SUCCESS;
50 }
51 
RegisterCallback(const MultiStaModeCallback & callbacks)52 ErrCode MultiStaManager::RegisterCallback(const MultiStaModeCallback &callbacks)
53 {
54     mcb = callbacks;
55     return WIFI_OPT_SUCCESS;
56 }
57 
GetMultiStaMachine()58 MultiStaStateMachine *MultiStaManager::GetMultiStaMachine()
59 {
60     return pMultiStaStateMachine;
61 }
62 
SetRole(Role role)63 void MultiStaManager::SetRole(Role role)
64 {
65     curRole = role;
66 }
67 
GetRole()68 MultiStaManager::Role MultiStaManager::GetRole()
69 {
70     return curRole;
71 }
72 
73 } // namespace Wifi
74 } // namespace OHOS