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