1 /* 2 * Copyright (C) 2021 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 "wifi_base_hal_interface.h" 17 #include "wifi_log.h" 18 19 #undef LOG_TAG 20 #define LOG_TAG "WifiBaseHalInterface" 21 22 namespace OHOS { 23 namespace Wifi { WifiBaseHalInterface()24WifiBaseHalInterface::WifiBaseHalInterface() 25 { 26 #ifdef HDI_WPA_INTERFACE_SUPPORT 27 mHdiWpaClient = nullptr; 28 #else 29 mIdlClient = nullptr; 30 #endif 31 } 32 ~WifiBaseHalInterface()33WifiBaseHalInterface::~WifiBaseHalInterface() 34 { 35 #ifdef HDI_WPA_INTERFACE_SUPPORT 36 if (mHdiWpaClient != nullptr) { 37 delete mHdiWpaClient; 38 mHdiWpaClient = nullptr; 39 } 40 #else 41 if (mIdlClient != nullptr) { 42 delete mIdlClient; 43 mIdlClient = nullptr; 44 } 45 #endif 46 } 47 48 #ifdef HDI_WPA_INTERFACE_SUPPORT InitHdiWpaClient(void)49bool WifiBaseHalInterface::InitHdiWpaClient(void) 50 { 51 if (mHdiWpaClient == nullptr) { 52 mHdiWpaClient = new (std::nothrow) WifiHdiWpaClient; 53 } 54 if (mHdiWpaClient == nullptr) { 55 LOGE("Failed to create hdi wpa client"); 56 return false; 57 } 58 return true; 59 } 60 #else InitIdlClient(void)61bool WifiBaseHalInterface::InitIdlClient(void) 62 { 63 if (mIdlClient == nullptr) { 64 mIdlClient = new (std::nothrow) WifiIdlClient; 65 } 66 if (mIdlClient == nullptr) { 67 LOGE("Failed to create idl client"); 68 return false; 69 } 70 if (mIdlClient->InitClient() != 0) { 71 LOGE("Failed to init idl client"); 72 return false; 73 } 74 return true; 75 } 76 ExitAllIdlClient(void)77void WifiBaseHalInterface::ExitAllIdlClient(void) 78 { 79 LOGI("Exit all idl client!"); 80 if (mIdlClient != nullptr) { 81 mIdlClient->ExitAllClient(); 82 } 83 return; 84 } 85 #endif 86 } // namespace Wifi 87 } // namespace OHOS