SDK singleton instance

Signed-off-by: gaosong <gaosong29@huawei.com>
This commit is contained in:
gaosong 2023-08-16 09:49:34 +08:00
parent 03c2b222b6
commit 431b64b958
38 changed files with 122 additions and 204 deletions

View File

@ -22,7 +22,7 @@ namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiExtNAPIHotspot");
std::unique_ptr<WifiHotspot> GetHotspotInstance()
std::shared_ptr<WifiHotspot> GetHotspotInstance()
{
return WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
}
@ -30,7 +30,7 @@ std::unique_ptr<WifiHotspot> GetHotspotInstance()
NO_SANITIZE("cfi") napi_value EnableHotspot(napi_env env, napi_callback_info info)
{
TRACE_FUNC_CALL;
std::unique_ptr<WifiHotspot> hotspot = GetHotspotInstance();
std::shared_ptr<WifiHotspot> hotspot = GetHotspotInstance();
WIFI_NAPI_ASSERT(env, hotspot != nullptr, WIFI_OPT_FAILED, SYSCAP_WIFI_AP_EXT);
ErrCode ret = hotspot->EnableHotspot(ServiceType::WIFI_EXT);
if (ret != WIFI_OPT_SUCCESS) {
@ -42,7 +42,7 @@ NO_SANITIZE("cfi") napi_value EnableHotspot(napi_env env, napi_callback_info inf
NO_SANITIZE("cfi") napi_value DisableHotspot(napi_env env, napi_callback_info info)
{
TRACE_FUNC_CALL;
std::unique_ptr<WifiHotspot> hotspot = GetHotspotInstance();
std::shared_ptr<WifiHotspot> hotspot = GetHotspotInstance();
WIFI_NAPI_ASSERT(env, hotspot != nullptr, WIFI_OPT_FAILED, SYSCAP_WIFI_AP_EXT);
ErrCode ret = hotspot->DisableHotspot(ServiceType::WIFI_EXT);
if (ret != WIFI_OPT_SUCCESS) {
@ -82,7 +82,7 @@ NO_SANITIZE("cfi") napi_value GetSupportedPowerModel(napi_env env, napi_callback
asyncContext->executeFunc = [&](void* data) -> void {
PowerModelListAsyncContext *context = static_cast<PowerModelListAsyncContext *>(data);
std::unique_ptr<WifiHotspot> hotspot = GetHotspotInstance();
std::shared_ptr<WifiHotspot> hotspot = GetHotspotInstance();
if (hotspot == nullptr) {
WIFI_LOGE("hotspot instance is null.");
return;
@ -118,7 +118,7 @@ NO_SANITIZE("cfi") napi_value GetPowerModel(napi_env env, napi_callback_info inf
asyncContext->executeFunc = [&](void* data) -> void {
PowerModelAsyncContext *context = static_cast<PowerModelAsyncContext *>(data);
std::unique_ptr<WifiHotspot> hotspot = GetHotspotInstance();
std::shared_ptr<WifiHotspot> hotspot = GetHotspotInstance();
if (hotspot == nullptr) {
WIFI_LOGE("hotspot instance is null.");
return;
@ -153,7 +153,7 @@ NO_SANITIZE("cfi") napi_value SetPowerModel(napi_env env, napi_callback_info inf
int model = -1;
napi_get_value_int32(env, argv[0], &model);
std::unique_ptr<WifiHotspot> hotspot = GetHotspotInstance();
std::shared_ptr<WifiHotspot> hotspot = GetHotspotInstance();
WIFI_NAPI_ASSERT(env, hotspot != nullptr, WIFI_OPT_FAILED, SYSCAP_WIFI_AP_EXT);
ErrCode ret = hotspot->SetPowerModel(static_cast<PowerModel>(model));
if (ret != WIFI_OPT_SUCCESS) {

View File

@ -25,8 +25,8 @@ namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiNAPIDevice");
static constexpr int DEFAULT_INVALID_VALUE = -1;
std::unique_ptr<WifiDevice> wifiDevicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::unique_ptr<WifiScan> wifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
std::shared_ptr<WifiDevice> wifiDevicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiScan> wifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
NO_SANITIZE("cfi") napi_value EnableWifi(napi_env env, napi_callback_info info)
{

View File

@ -27,6 +27,10 @@ namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiNAPIEvent");
constexpr uint32_t INVALID_REF_COUNT = 0xff;
std::shared_ptr<WifiDevice> g_wifiStaPtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiScan> g_wifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
std::shared_ptr<WifiHotspot> g_wifiHotspotPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
std::shared_ptr<WifiP2p> g_wifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
static std::set<std::string> g_supportEventList = {
EVENT_STA_POWER_STATE_CHANGE,
@ -488,12 +492,11 @@ ErrCode EventRegister::RegisterDeviceEvents(const std::vector<std::string> &even
WIFI_LOGE("Register sta event is empty!");
return WIFI_OPT_FAILED;
}
std::unique_ptr<WifiDevice> wifiStaPtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
if (wifiStaPtr == nullptr) {
if (g_wifiStaPtr == nullptr) {
WIFI_LOGE("Register sta event get instance failed!");
return WIFI_OPT_FAILED;
}
ErrCode ret = wifiStaPtr->RegisterCallBack(wifiDeviceCallback, event);
ErrCode ret = g_wifiStaPtr->RegisterCallBack(wifiDeviceCallback, event);
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Register sta event failed!");
return ret;
@ -507,12 +510,11 @@ ErrCode EventRegister::RegisterScanEvents(const std::vector<std::string> &event)
WIFI_LOGE("Register scan event is empty!");
return WIFI_OPT_FAILED;
}
std::unique_ptr<WifiScan> wifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
if (wifiScanPtr == nullptr) {
if (g_wifiScanPtr == nullptr) {
WIFI_LOGE("Register scan event get instance failed!");
return WIFI_OPT_FAILED;
}
ErrCode ret = wifiScanPtr->RegisterCallBack(wifiScanCallback, event);
ErrCode ret = g_wifiScanPtr->RegisterCallBack(wifiScanCallback, event);
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Register scan event failed!");
return ret;
@ -526,12 +528,11 @@ ErrCode EventRegister::RegisterHotspotEvents(const std::vector<std::string> &eve
WIFI_LOGE("Register hotspot event is empty!");
return WIFI_OPT_FAILED;
}
std::unique_ptr<WifiHotspot> wifiHotspotPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
if (wifiHotspotPtr == nullptr) {
if (g_wifiHotspotPtr == nullptr) {
WIFI_LOGE("Register hotspot event get instance failed!");
return WIFI_OPT_FAILED;
}
ErrCode ret = wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event);
ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event);
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Register hotspot event failed!");
return ret;
@ -545,12 +546,11 @@ ErrCode EventRegister::RegisterP2PEvents(const std::vector<std::string> &event)
WIFI_LOGE("Register p2p event is empty!");
return WIFI_OPT_FAILED;
}
std::unique_ptr<WifiP2p> wifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
if (wifiP2pPtr == nullptr) {
if (g_wifiP2pPtr == nullptr) {
WIFI_LOGE("Register p2p event get instance failed!");
return WIFI_OPT_FAILED;
}
ErrCode ret = wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event);
ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event);
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Register p2p event failed!");
return ret;

View File

@ -24,7 +24,7 @@ namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiNAPIHotspot");
std::unique_ptr<WifiHotspot> wifiHotspotPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
std::shared_ptr<WifiHotspot> wifiHotspotPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
std::map<SecTypeJs, KeyMgmt> g_mapSecTypeToKeyMgmt = {
{SecTypeJs::SEC_TYPE_OPEN, KeyMgmt::NONE},

View File

@ -21,7 +21,7 @@ namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiNAPIP2p");
std::unique_ptr<WifiP2p> wifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
std::shared_ptr<WifiP2p> wifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
static void DeviceInfoToJs(const napi_env& env, const WifiP2pDevice& device, napi_value& result)
{
SetValueUtf8String(env, "deviceName", device.GetDeviceName().c_str(), result);

View File

@ -31,8 +31,8 @@ static std::map<WifiSecurityType, std::string> g_secTypeKeyMgmtMap = {
{WIFI_SEC_TYPE_SAE, "SAE"},
};
std::unique_ptr<OHOS::Wifi::WifiDevice> wifiDevicePtr = OHOS::Wifi::WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::unique_ptr<OHOS::Wifi::WifiScan> wifiScanPtr = OHOS::Wifi::WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
std::shared_ptr<OHOS::Wifi::WifiDevice> wifiDevicePtr = OHOS::Wifi::WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<OHOS::Wifi::WifiScan> wifiScanPtr = OHOS::Wifi::WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
NO_SANITIZE("cfi") WifiErrorCode EnableWifi()
{

View File

@ -30,7 +30,11 @@
#include "../../src/wifi_sa_event.h"
DEFINE_WIFILOG_LABEL("WifiCEvent");
std::set<WifiEvent*> GetEventCallBacks();
std::unique_ptr<OHOS::Wifi::WifiScan> g_wifiScanPtr = nullptr;
std::shared_ptr<OHOS::Wifi::WifiDevice> g_wifiStaPtr = OHOS::Wifi::WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<OHOS::Wifi::WifiScan> g_wifiScanPtr = OHOS::Wifi::WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
std::shared_ptr<OHOS::Wifi::WifiP2p> g_wifiP2pPtr = OHOS::Wifi::WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
std::shared_ptr<OHOS::Wifi::WifiHotspot> g_wifiHotspotPtr =
OHOS::Wifi::WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
std::vector<std::string> WifiCDeviceEventCallback::deviceCallbackEvent = {
EVENT_STA_CONN_STATE_CHANGE,
@ -177,12 +181,11 @@ WifiErrorCode EventManager::RegisterDeviceEvent(const std::vector<std::string> &
WIFI_LOGE("Register sta event is empty!");
return ERROR_WIFI_UNKNOWN;
}
std::unique_ptr<WifiDevice> wifiStaPtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
if (wifiStaPtr == nullptr) {
if (g_wifiStaPtr == nullptr) {
WIFI_LOGE("Register sta event get instance failed!");
return ERROR_WIFI_UNKNOWN;
}
ErrCode ret = wifiStaPtr->RegisterCallBack(wifiCDeviceCallback, event);
ErrCode ret = g_wifiStaPtr->RegisterCallBack(wifiCDeviceCallback, event);
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Register sta event failed!");
return ERROR_WIFI_UNKNOWN;
@ -216,12 +219,11 @@ WifiErrorCode EventManager::RegisterHotspotEvent(const std::vector<std::string>
WIFI_LOGE("Register hotspot event is empty!");
return ERROR_WIFI_UNKNOWN;
}
std::unique_ptr<WifiHotspot> wifiHotspotPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
if (wifiHotspotPtr == nullptr) {
if (g_wifiHotspotPtr == nullptr) {
WIFI_LOGE("Register hotspot event get instance failed!");
return ERROR_WIFI_UNKNOWN;
}
ErrCode ret = wifiHotspotPtr->RegisterCallBack(wifiCHotspotCallback, event);
ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiCHotspotCallback, event);
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Register hotspot event failed!");
return ERROR_WIFI_UNKNOWN;
@ -236,8 +238,7 @@ WifiErrorCode EventManager::RegisterP2PEvent(const std::vector<std::string> &eve
WIFI_LOGE("Register p2p event is empty!");
return ERROR_WIFI_UNKNOWN;
}
std::unique_ptr<WifiP2p> wifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
if (wifiP2pPtr == nullptr) {
if (g_wifiP2pPtr == nullptr) {
WIFI_LOGE("Register p2p event get instance failed!");
return ERROR_WIFI_UNKNOWN;
}
@ -246,7 +247,7 @@ WifiErrorCode EventManager::RegisterP2PEvent(const std::vector<std::string> &eve
WIFI_LOGE("Register p2p event get p2p callback ptr failed!");
return ERROR_WIFI_UNKNOWN;
}
ErrCode ret = wifiP2pPtr->RegisterCallBack(sptrP2PCallback, event);
ErrCode ret = g_wifiP2pPtr->RegisterCallBack(sptrP2PCallback, event);
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Register p2p event failed!");
return ERROR_WIFI_UNKNOWN;
@ -333,12 +334,6 @@ void EventManager::Init()
mSaStatusListener->Init(WIFI_HOTSPOT_ABILITY_ID);
mSaStatusListener->Init(WIFI_P2P_ABILITY_ID);
}
if (g_wifiScanPtr == nullptr) {
g_wifiScanPtr = OHOS::Wifi::WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
WIFI_LOGE("scan ptr is null, create new instance");
return;
}
return;
}

View File

@ -23,7 +23,7 @@
DEFINE_WIFILOG_LABEL("WifiCHid2d");
std::unique_ptr<OHOS::Wifi::Hid2d> wifiHid2dPtr = OHOS::Wifi::Hid2d::GetInstance(WIFI_P2P_ABILITY_ID);
std::shared_ptr<OHOS::Wifi::Hid2d> wifiHid2dPtr = OHOS::Wifi::Hid2d::GetInstance(WIFI_P2P_ABILITY_ID);
NO_SANITIZE("cfi") WifiErrorCode Hid2dRequestGcIp(const unsigned char gcMac[MAC_LEN],
unsigned int ipAddr[IPV4_ARRAY_LEN])

View File

@ -24,7 +24,7 @@
DEFINE_WIFILOG_LABEL("WifiCHotspot");
std::unique_ptr<OHOS::Wifi::WifiHotspot> hotspotPtr = OHOS::Wifi::WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
std::shared_ptr<OHOS::Wifi::WifiHotspot> hotspotPtr = OHOS::Wifi::WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
NO_SANITIZE("cfi") WifiErrorCode EnableHotspot()
{

View File

@ -23,7 +23,7 @@
constexpr int INVALID_VALUE = -1;
DEFINE_WIFILOG_LABEL("WifiCP2P");
std::unique_ptr<OHOS::Wifi::WifiP2p> wifiP2pPtr = OHOS::Wifi::WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
std::shared_ptr<OHOS::Wifi::WifiP2p> wifiP2pPtr = OHOS::Wifi::WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
NO_SANITIZE("cfi") WifiErrorCode EnableP2p()
{

View File

@ -21,28 +21,12 @@ DEFINE_WIFILOG_LABEL("WifiDevice");
namespace OHOS {
namespace Wifi {
NO_SANITIZE("cfi") std::unique_ptr<WifiDevice> WifiDevice::CreateWifiDevice(int systemAbilityId)
NO_SANITIZE("cfi") std::shared_ptr<WifiDevice> WifiDevice::GetInstance(int systemAbilityId)
{
std::unique_ptr<WifiDeviceImpl> device = std::make_unique<WifiDeviceImpl>(systemAbilityId);
if (device != nullptr) {
if (device->Init()) {
WIFI_LOGI("new device successfully!");
return device;
}
}
WIFI_LOGE("new wifi device failed");
return nullptr;
}
NO_SANITIZE("cfi") std::unique_ptr<WifiDevice> WifiDevice::GetInstance(int systemAbilityId)
{
std::unique_ptr<WifiDeviceImpl> device = std::make_unique<WifiDeviceImpl>(systemAbilityId);
if (device != nullptr) {
if (device->Init()) {
WIFI_LOGI("init successfully!");
return device;
}
std::shared_ptr<WifiDeviceImpl> device = DelayedSingleton<WifiDeviceImpl>::GetInstance();
if (device && device->Init(systemAbilityId)) {
WIFI_LOGI("init successfully!");
return device;
}
WIFI_LOGE("new wifi device failed");
@ -50,6 +34,8 @@ NO_SANITIZE("cfi") std::unique_ptr<WifiDevice> WifiDevice::GetInstance(int syste
}
WifiDevice::~WifiDevice()
{}
{
DelayedSingleton<WifiDeviceImpl>::DestroyInstance();
}
} // namespace Wifi
} // namespace OHOS

View File

@ -36,7 +36,7 @@ namespace Wifi {
} \
} while (0)
WifiDeviceImpl::WifiDeviceImpl(int systemAbilityId) : systemAbilityId_(systemAbilityId), client_(nullptr)
WifiDeviceImpl::WifiDeviceImpl() : client_(nullptr)
{}
WifiDeviceImpl::~WifiDeviceImpl()
@ -46,7 +46,7 @@ WifiDeviceImpl::~WifiDeviceImpl()
#endif
}
bool WifiDeviceImpl::Init()
bool WifiDeviceImpl::Init(int systemAbilityId)
{
#ifdef OHOS_ARCH_LITE
WifiDeviceProxy *deviceProxy = WifiDeviceProxy::GetInstance();
@ -62,6 +62,7 @@ bool WifiDeviceImpl::Init()
client_ = deviceProxy;
return true;
#else
systemAbilityId_ = systemAbilityId;
return true;
#endif
}

View File

@ -17,6 +17,7 @@
#include <string>
#include <vector>
#include "singleton.h"
#include "i_wifi_device.h"
#include "i_wifi_device_callback.h"
#include "refbase.h"
@ -27,11 +28,10 @@
namespace OHOS {
namespace Wifi {
class WifiDeviceImpl : public WifiDevice {
public:
explicit WifiDeviceImpl(int systemAbilityId);
~WifiDeviceImpl();
DECLARE_DELAYED_SINGLETON(WifiDeviceImpl)
bool Init();
public:
bool Init(int systemAbilityId);
/**
* @Description Turn on Wi-Fi

View File

@ -22,28 +22,12 @@ DEFINE_WIFILOG_LABEL("Hid2d");
namespace OHOS {
namespace Wifi {
NO_SANITIZE("cfi") std::unique_ptr<Hid2d> Hid2d::CreateWifiHid2d(int systemAbilityId)
NO_SANITIZE("cfi") std::shared_ptr<Hid2d> Hid2d::GetInstance(int systemAbilityId)
{
std::unique_ptr<WifiP2pImpl> impl = std::make_unique<WifiP2pImpl>(systemAbilityId);
if (impl != nullptr) {
if (impl->Init()) {
WIFI_LOGI("new hid2d successfully!");
return impl;
}
}
WIFI_LOGE("new wifi hid2d failed");
return nullptr;
}
NO_SANITIZE("cfi") std::unique_ptr<Hid2d> Hid2d::GetInstance(int systemAbilityId)
{
std::unique_ptr<WifiP2pImpl> impl = std::make_unique<WifiP2pImpl>(systemAbilityId);
if (impl != nullptr) {
if (impl->Init()) {
WIFI_LOGI("init hid2d successfully!");
return impl;
}
std::shared_ptr<WifiP2pImpl> impl = DelayedSingleton<WifiP2pImpl>::GetInstance();
if (impl && impl->Init(systemAbilityId)) {
WIFI_LOGI("init hid2d successfully!");
return impl;
}
WIFI_LOGE("new wifi hid2d failed");
@ -51,6 +35,8 @@ NO_SANITIZE("cfi") std::unique_ptr<Hid2d> Hid2d::GetInstance(int systemAbilityId
}
Hid2d::~Hid2d()
{}
{
DelayedSingleton<WifiP2pImpl>::DestroyInstance();
}
} // namespace Wifi
} // namespace OHOS

View File

@ -22,40 +22,17 @@ DEFINE_WIFILOG_HOTSPOT_LABEL("WifiHotspot");
namespace OHOS {
namespace Wifi {
NO_SANITIZE("cfi") std::unique_ptr<WifiHotspot> WifiHotspot::CreateWifiHotspot(int systemAbilityId, int id)
NO_SANITIZE("cfi") std::shared_ptr<WifiHotspot> WifiHotspot::GetInstance(int systemAbilityId, int id)
{
if (id >= AP_INSTANCE_MAX_NUM) {
WIFI_LOGE("the max obj id is %{public}d, current id is %{public}d", AP_INSTANCE_MAX_NUM, id);
return nullptr;
}
std::unique_ptr<WifiHotspotImpl> hotspot = std::make_unique<WifiHotspotImpl>(systemAbilityId);
if (hotspot != nullptr) {
if (hotspot->Init(id)) {
WIFI_LOGI("ap obj id:%{public}d succeeded", id);
return hotspot;
}
WIFI_LOGE("init wifi hotspot id:%{public}d failed", id);
}
WIFI_LOGE("new wifi hotspot id:%{public}d failed, sa id:%{public}d", id, systemAbilityId);
return nullptr;
}
NO_SANITIZE("cfi") std::unique_ptr<WifiHotspot> WifiHotspot::GetInstance(int systemAbilityId, int id)
{
if (id >= AP_INSTANCE_MAX_NUM) {
WIFI_LOGE("the max obj id is %{public}d, current id is %{public}d", AP_INSTANCE_MAX_NUM, id);
return nullptr;
}
std::unique_ptr<WifiHotspotImpl> hotspot = std::make_unique<WifiHotspotImpl>(systemAbilityId);
if (hotspot != nullptr) {
if (hotspot->Init(id)) {
WIFI_LOGI("ap obj id:%{public}d succeeded", id);
return hotspot;
}
WIFI_LOGE("init wifi hotspot id:%{public}d failed", id);
std::shared_ptr<WifiHotspotImpl> hotspot = DelayedSingleton<WifiHotspotImpl>::GetInstance();
if (hotspot && hotspot->Init(systemAbilityId, id)) {
WIFI_LOGI("ap obj id:%{public}d succeeded, sa id:%{public}d", id, systemAbilityId);
return hotspot;
}
WIFI_LOGE("new wifi hotspot id:%{public}d failed, sa id:%{public}d", id, systemAbilityId);
@ -63,6 +40,8 @@ NO_SANITIZE("cfi") std::unique_ptr<WifiHotspot> WifiHotspot::GetInstance(int sys
}
WifiHotspot::~WifiHotspot()
{}
{
DelayedSingleton<WifiHotspotImpl>::DestroyInstance();
}
} // namespace Wifi
} // namespace OHOS

View File

@ -36,14 +36,15 @@ namespace Wifi {
} \
} while (0)
WifiHotspotImpl::WifiHotspotImpl(int systemAbilityId) : systemAbilityId_(systemAbilityId), instId(0)
WifiHotspotImpl::WifiHotspotImpl() : instId(0)
{}
WifiHotspotImpl::~WifiHotspotImpl()
{}
bool WifiHotspotImpl::Init(int id)
bool WifiHotspotImpl::Init(int systemAbilityId, int id)
{
systemAbilityId_ = systemAbilityId;
instId = id;
return true;
}

View File

@ -19,6 +19,7 @@
#include <cstdint>
#include <set>
#include <vector>
#include "singleton.h"
#include "i_wifi_hotspot.h"
#include "i_wifi_hotspot_callback.h"
#include "refbase.h"
@ -30,16 +31,15 @@
namespace OHOS {
namespace Wifi {
class WifiHotspotImpl : public WifiHotspot {
public:
explicit WifiHotspotImpl(int systemAbilityId);
~WifiHotspotImpl();
DECLARE_DELAYED_SINGLETON(WifiHotspotImpl)
public:
/**
* @Description init ap client.
*
* @return bool - operation result
*/
bool Init(int id);
bool Init(int systemAbilityId, int id);
/**
* @Description Check whether the hotspot is active.

View File

@ -20,28 +20,12 @@ DEFINE_WIFILOG_P2P_LABEL("WifiP2p");
namespace OHOS {
namespace Wifi {
NO_SANITIZE("cfi") std::unique_ptr<WifiP2p> WifiP2p::CreateWifiP2p(int systemAbilityId)
NO_SANITIZE("cfi") std::shared_ptr<WifiP2p> WifiP2p::GetInstance(int systemAbilityId)
{
std::unique_ptr<WifiP2pImpl> impl = std::make_unique<WifiP2pImpl>(systemAbilityId);
if (impl != nullptr) {
if (impl->Init()) {
WIFI_LOGI("new p2p successfully!");
return impl;
}
}
WIFI_LOGE("new wifi p2p failed");
return nullptr;
}
NO_SANITIZE("cfi") std::unique_ptr<WifiP2p> WifiP2p::GetInstance(int systemAbilityId)
{
std::unique_ptr<WifiP2pImpl> impl = std::make_unique<WifiP2pImpl>(systemAbilityId);
if (impl != nullptr) {
if (impl->Init()) {
WIFI_LOGI("init p2p successfully!");
return impl;
}
std::shared_ptr<WifiP2pImpl> impl = DelayedSingleton<WifiP2pImpl>::GetInstance();
if (impl && impl->Init(systemAbilityId)) {
WIFI_LOGI("init p2p successfully!");
return impl;
}
WIFI_LOGE("new wifi p2p failed");
@ -49,6 +33,8 @@ NO_SANITIZE("cfi") std::unique_ptr<WifiP2p> WifiP2p::GetInstance(int systemAbili
}
WifiP2p::~WifiP2p()
{}
{
DelayedSingleton<WifiP2pImpl>::DestroyInstance();
}
} // namespace Wifi
} // namespace OHOS

View File

@ -31,14 +31,15 @@ namespace Wifi {
} \
} while (0)
WifiP2pImpl::WifiP2pImpl(int systemAbilityId) : systemAbilityId_(systemAbilityId), client_(nullptr)
WifiP2pImpl::WifiP2pImpl() : client_(nullptr)
{}
WifiP2pImpl::~WifiP2pImpl()
{}
bool WifiP2pImpl::Init(void)
bool WifiP2pImpl::Init(int systemAbilityId)
{
systemAbilityId_ = systemAbilityId;
return true;
}

View File

@ -15,6 +15,7 @@
#ifndef OHOS_WIFI_P2P_IMPL_H
#define OHOS_WIFI_P2P_IMPL_H
#include "singleton.h"
#include "wifi_p2p.h"
#include "wifi_p2p_proxy.h"
#include "wifi_hid2d.h"
@ -22,11 +23,10 @@
namespace OHOS {
namespace Wifi {
class WifiP2pImpl : public WifiP2p, public Hid2d {
public:
explicit WifiP2pImpl(int systemAbilityId);
~WifiP2pImpl();
DECLARE_DELAYED_SINGLETON(WifiP2pImpl)
bool Init(void);
public:
bool Init(int systemAbilityId);
/**
* @Description Enabling the P2P Mode

View File

@ -24,32 +24,21 @@ DEFINE_WIFILOG_SCAN_LABEL("WifiScan");
namespace OHOS {
namespace Wifi {
NO_SANITIZE("cfi") std::unique_ptr<WifiScan> WifiScan::CreateWifiScan(int systemAbilityId)
NO_SANITIZE("cfi") std::shared_ptr<WifiScan> WifiScan::GetInstance(int systemAbilityId)
{
std::unique_ptr<WifiScanImpl> pImpl = std::make_unique<WifiScanImpl>(systemAbilityId);
if (pImpl != nullptr) {
if (pImpl->Init()) {
WIFI_LOGI("succeeded");
return (pImpl);
}
std::shared_ptr<WifiScanImpl> pImpl = DelayedSingleton<WifiScanImpl>::GetInstance();
if (pImpl && pImpl->Init(systemAbilityId)) {
WIFI_LOGI("succeeded");
return pImpl;
}
WIFI_LOGE("new wifi WifiScan failed");
return nullptr;
}
NO_SANITIZE("cfi") std::unique_ptr<WifiScan> WifiScan::GetInstance(int systemAbilityId)
WifiScan::~WifiScan()
{
std::unique_ptr<WifiScanImpl> pImpl = std::make_unique<WifiScanImpl>(systemAbilityId);
if (pImpl != nullptr) {
if (pImpl->Init()) {
WIFI_LOGI("succeeded");
return pImpl;
}
}
WIFI_LOGE("new wifi WifiScan failed");
return nullptr;
DelayedSingleton<WifiScanImpl>::DestroyInstance();
}
} // namespace Wifi
} // namespace OHOS

View File

@ -34,7 +34,7 @@ namespace Wifi {
} \
} while (0)
WifiScanImpl::WifiScanImpl(int systemAbilityId) : systemAbilityId_(systemAbilityId), client_(nullptr)
WifiScanImpl::WifiScanImpl() : client_(nullptr)
{}
WifiScanImpl::~WifiScanImpl()
@ -44,7 +44,7 @@ WifiScanImpl::~WifiScanImpl()
#endif
}
bool WifiScanImpl::Init()
bool WifiScanImpl::Init(int systemAbilityId)
{
#ifdef OHOS_ARCH_LITE
WifiScanProxy *scanProxy = WifiScanProxy::GetInstance();
@ -60,6 +60,7 @@ bool WifiScanImpl::Init()
client_ = scanProxy;
return true;
#else
systemAbilityId_ = systemAbilityId;
return true;
#endif
}

View File

@ -16,16 +16,17 @@
#ifndef OHOS_WIFI_SCAN_IMPL
#define OHOS_WIFI_SCAN_IMPL
#include "singleton.h"
#include "wifi_scan.h"
#include "wifi_scan_proxy.h"
namespace OHOS {
namespace Wifi {
class WifiScanImpl : public Wifi::WifiScan {
DECLARE_DELAYED_SINGLETON(WifiScanImpl)
public:
explicit WifiScanImpl(int systemAbilityId);
~WifiScanImpl();
bool Init();
bool Init(int systemAbilityId);
/**
* @Description Set the Scan Control Info object

View File

@ -23,9 +23,7 @@ namespace OHOS {
namespace Wifi {
class WifiDevice {
public:
static std::unique_ptr<WifiDevice> CreateWifiDevice(int system_ability_id);
static std::unique_ptr<WifiDevice> GetInstance(int system_ability_id);
static std::shared_ptr<WifiDevice> GetInstance(int system_ability_id);
virtual ~WifiDevice();

View File

@ -24,8 +24,7 @@ namespace OHOS {
namespace Wifi {
class Hid2d {
public:
static std::unique_ptr<Hid2d> CreateWifiHid2d(int system_ability_id);
static std::unique_ptr<Hid2d> GetInstance(int system_ability_id);
static std::shared_ptr<Hid2d> GetInstance(int system_ability_id);
virtual ~Hid2d();

View File

@ -27,9 +27,7 @@ namespace OHOS {
namespace Wifi {
class WifiHotspot {
public:
static std::unique_ptr<WifiHotspot> CreateWifiHotspot(int system_ability_id, int id = 0);
static std::unique_ptr<WifiHotspot> GetInstance(int system_ability_id, int id = 0);
static std::shared_ptr<WifiHotspot> GetInstance(int system_ability_id, int id = 0);
virtual ~WifiHotspot();

View File

@ -24,8 +24,7 @@ namespace OHOS {
namespace Wifi {
class WifiP2p {
public:
static std::unique_ptr<WifiP2p> CreateWifiP2p(int system_ability_id);
static std::unique_ptr<WifiP2p> GetInstance(int system_ability_id);
static std::shared_ptr<WifiP2p> GetInstance(int system_ability_id);
virtual ~WifiP2p();

View File

@ -24,11 +24,9 @@ namespace OHOS {
namespace Wifi {
class WifiScan {
public:
static std::unique_ptr<WifiScan> CreateWifiScan(int system_ability_id);
static std::unique_ptr<WifiScan> GetInstance(int system_ability_id);
static std::shared_ptr<WifiScan> GetInstance(int system_ability_id);
virtual ~WifiScan()
{}
virtual ~WifiScan();
/**
* @Description Set the Scan Control Info object

View File

@ -23,7 +23,7 @@
namespace OHOS {
namespace Wifi {
static std::unique_ptr<WifiP2p> WifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
static std::shared_ptr<WifiP2p> WifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
void RequestServiceTest(const uint8_t* data, size_t size)
{
WifiP2pDevice device;

View File

@ -18,7 +18,7 @@
namespace OHOS {
namespace Wifi {
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
bool AddDeviceConfigFuzzerTest(const uint8_t* data, size_t size)
{
if (devicePtr == nullptr) {

View File

@ -18,7 +18,7 @@
namespace OHOS {
namespace Wifi {
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
bool ConnectToDeviceFuzzerTest(const uint8_t* data, size_t size)
{
if (devicePtr == nullptr) {

View File

@ -18,7 +18,7 @@
namespace OHOS {
namespace Wifi {
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
bool DisableWifiFuzzerTest(const uint8_t* data, size_t size)
{
if (devicePtr == nullptr) {

View File

@ -18,7 +18,7 @@
namespace OHOS {
namespace Wifi {
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
bool DisconnectFuzzerTest(const uint8_t* data, size_t size)
{
if (devicePtr == nullptr) {

View File

@ -18,7 +18,7 @@
namespace OHOS {
namespace Wifi {
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
bool EnableWifiFuzzerTest(const uint8_t* data, size_t size)
{
WifiLinkedInfo info;

View File

@ -18,7 +18,7 @@
namespace OHOS {
namespace Wifi {
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
bool IsConnectedFuzzerTest(const uint8_t* data, size_t size)
{
bool isconnected = false;

View File

@ -18,7 +18,7 @@
namespace OHOS {
namespace Wifi {
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
bool ReAssociateFuzzerTest(const uint8_t* data, size_t size)
{
if (devicePtr == nullptr) {

View File

@ -18,7 +18,7 @@
namespace OHOS {
namespace Wifi {
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
bool ReConnectFuzzerTest(const uint8_t* data, size_t size)
{
if (devicePtr == nullptr) {

View File

@ -29,8 +29,8 @@ using namespace std;
namespace OHOS {
namespace Wifi {
std::unique_ptr<WifiDevice> ptrWifiDevice = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::unique_ptr<WifiScan> ptrWifiScan = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
std::shared_ptr<WifiDevice> ptrWifiDevice = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
std::shared_ptr<WifiScan> ptrWifiScan = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
const int MAX_ARGS = 16;
const int BAND_2GHZ = 1;